Implementation:Tensorflow Serving Machine Learning Metadata
| Knowledge Sources | |
|---|---|
| Domains | Model Serving, ML Metadata |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Integrates ML Metadata (MLMD) with TensorFlow Serving by publishing MLMD UUIDs from loaded models as monitoring gauge metrics.
Description
The Machine Learning Metadata module provides the MaybePublishMLMDStreamz function that checks for an MLMD UUID file in the SavedModel's assets.extra directory and, if present, publishes it as a Streamz (monitoring) gauge metric.
The implementation:
1. Constructs the expected path for the MLMD key file: {export_dir}/assets.extra/mlmd_uuid
2. Checks if the file exists using the default environment
3. If found, reads the file contents (the MLMD UUID string)
4. Publishes the UUID to a monitoring gauge at /tensorflow/serving/mlmd_map with dimensions for model_name and version
The gauge metric mlmd_map has two labels: "model_name" and "version", allowing monitoring systems to map MLMD UUIDs to specific model deployments. This enables traceability between model artifacts tracked in ML Metadata and their deployed serving instances.
If the file does not exist, the function silently returns. If the file exists but cannot be read, a warning is logged.
Usage
Use this module during model loading to establish MLMD traceability. It is called by TfrtSavedModelFactory::CreateTfrtSavedModelWithMetadata after successfully loading a model. Models that want MLMD integration should include an mlmd_uuid file in their assets.extra directory during export.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- Files:
tensorflow_serving/servables/tensorflow/machine_learning_metadata.h(lines 1-36)tensorflow_serving/servables/tensorflow/machine_learning_metadata.cc(lines 1-53)
Signature
void MaybePublishMLMDStreamz(const string& export_dir,
const string& model_name,
int64_t version);
Import
#include "tensorflow_serving/servables/tensorflow/machine_learning_metadata.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| export_dir | string |
Yes | Path to the SavedModel export directory |
| model_name | string |
Yes | Name of the model for the metric label |
| version | int64_t |
Yes | Version of the model for the metric label |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | gauge metric | Publishes MLMD UUID to /tensorflow/serving/mlmd_map if mlmd_uuid file exists |
Usage Examples
Publishing MLMD During Model Load
MaybePublishMLMDStreamz("/path/to/saved_model", "my_model", 1);
// If /path/to/saved_model/assets.extra/mlmd_uuid exists,
// its content is published to the mlmd_map gauge metric.