Implementation:Tensorflow Serving Get Model Metadata Impl
| Knowledge Sources | |
|---|---|
| Domains | Model Serving, Model Metadata |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Implements the GetModelMetadata API for retrieving signature definitions from loaded SavedModel bundles via ServerCore.
Description
GetModelMetadataImpl is a static utility class that provides the implementation for the GetModelMetadata RPC. It supports retrieving signature_def metadata from a loaded SavedModelBundle.
The implementation consists of:
- GetModelMetadata: Entry point that validates the presence of a ModelSpec in the request, then delegates to GetModelMetadataWithModelSpec.
- GetModelMetadataWithModelSpec: Validates that all requested metadata_fields are supported (only "signature_def" is supported), then iterates through requested fields. For the "signature_def" field, it calls SavedModelGetSignatureDef which obtains a ServableHandle to the SavedModelBundle from ServerCore, copies all signature definitions from the MetaGraphDef into a SignatureDefMap protobuf, sets the response's model_spec with the servable's name and version, and packs the SignatureDefMap into the response's metadata Any field.
The constant kSignatureDef ("signature_def") defines the only supported metadata field type.
Usage
Use this module for handling GetModelMetadata requests in the standard TensorFlow serving pipeline (non-TFRT). It is typically called by the PredictionServiceImpl gRPC handler. For TFRT models, metadata retrieval is handled directly by TfrtSavedModelServable::GetModelMetadata.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- Files:
tensorflow_serving/servables/tensorflow/get_model_metadata_impl.h(lines 1-45)tensorflow_serving/servables/tensorflow/get_model_metadata_impl.cc(lines 1-103)
Signature
class GetModelMetadataImpl {
public:
static constexpr const char kSignatureDef[] = "signature_def";
static Status GetModelMetadata(ServerCore* core,
const GetModelMetadataRequest& request,
GetModelMetadataResponse* response);
static Status GetModelMetadataWithModelSpec(
ServerCore* core, const ModelSpec& model_spec,
const GetModelMetadataRequest& request,
GetModelMetadataResponse* response);
};
Import
#include "tensorflow_serving/servables/tensorflow/get_model_metadata_impl.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| core | ServerCore* |
Yes | ServerCore for accessing loaded servables |
| request | GetModelMetadataRequest |
Yes | Request specifying model_spec and metadata_field(s) |
Outputs
| Name | Type | Description |
|---|---|---|
| response | GetModelMetadataResponse* |
Contains model_spec and metadata map with SignatureDefMap packed as Any |
| return | Status |
OK on success; InvalidArgument if model_spec is missing or unsupported metadata field is requested |
Usage Examples
Retrieving Model Metadata
GetModelMetadataRequest request;
request.mutable_model_spec()->set_name("my_model");
request.add_metadata_field("signature_def");
GetModelMetadataResponse response;
Status status = GetModelMetadataImpl::GetModelMetadata(
server_core, request, &response);