Implementation:Tensorflow Serving Session Bundle Util
| Knowledge Sources | |
|---|---|
| Domains | Model Serving, Session Bundle, Migration |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Provides utility functions for migrating from the deprecated SessionBundle format to SavedModelBundle, including signature conversion, bundle conversion, and dual-format loading.
Description
The Session Bundle Util module (in the session_bundle namespace) provides backward-compatibility functions for working with the legacy SessionBundle format alongside the current SavedModel format. Key functions include:
Bundle Conversion:
- ConvertSignaturesToSignatureDefs: Converts legacy Signatures in a MetaGraphDef into the modern SignatureDef format.
- ConvertSessionBundleToSavedModelBundle: Converts a SessionBundle into a SavedModelBundle, enabling legacy models to be used with the SavedModel-based serving infrastructure.
Dual-Format Loading:
- LoadSessionBundleOrSavedModelBundle (two overloads): Attempts to load from either a SessionBundle path or a SavedModel path. Sets an optional is_session_bundle output flag indicating whether the model was up-converted from the legacy format. The second overload also supports loading SavedModel configuration from assets.extra/saved_model_config.pb.
Legacy Operations:
- LoadSessionBundleFromPathUsingRunOptions: Loads a SessionBundle with custom RunOptions for restore and init operations (marked as EXPERIMENTAL).
- SetSignatures: Sets Signatures in a MetaGraphDef.
- GetClassificationSignature / GetRegressionSignature: Extracts classification or regression signatures from the default signature in a MetaGraphDef.
- RunClassification / RunRegression: Executes classification or regression using legacy signature formats, validating input/output batch size consistency.
- GetNamedSignature: Retrieves a named Signature from a MetaGraphDef.
Usage
Use these utilities when migrating from SessionBundle to SavedModel format, or when serving infrastructure needs to support both formats simultaneously. The LoadSessionBundleOrSavedModelBundle function is particularly useful for backward-compatible model loading.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- File:
tensorflow_serving/session_bundle/session_bundle_util.h(lines 1-121)
Signature
namespace session_bundle {
Status ConvertSignaturesToSignatureDefs(MetaGraphDef* meta_graph_def);
Status ConvertSessionBundleToSavedModelBundle(
SessionBundle& session_bundle, SavedModelBundle* saved_model_bundle);
Status LoadSessionBundleOrSavedModelBundle(
const SessionOptions& session_options, const RunOptions& run_options,
const string& export_dir, const std::unordered_set<string>& tags,
SavedModelBundle* bundle, bool* is_session_bundle = nullptr);
Status RunClassification(const ClassificationSignature& signature,
const Tensor& input, Session* session,
Tensor* classes, Tensor* scores);
Status RunRegression(const RegressionSignature& signature,
const Tensor& input, Session* session,
Tensor* output);
} // namespace session_bundle
Import
#include "tensorflow_serving/session_bundle/session_bundle_util.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| session_options | SessionOptions |
Yes | TensorFlow session configuration |
| run_options | RunOptions |
Yes | Options for session run operations during loading |
| export_dir | string |
Yes | Path to the model export directory (SessionBundle or SavedModel format) |
| tags | std::unordered_set<string> |
Yes | Tags identifying which MetaGraphDef to load |
Outputs
| Name | Type | Description |
|---|---|---|
| bundle | SavedModelBundle* |
Loaded (and possibly converted) SavedModelBundle |
| is_session_bundle | bool* |
Set to true if the model was loaded from legacy SessionBundle format |
| return | Status |
OK on success; error if loading or conversion fails |
Usage Examples
Loading Either Format
SavedModelBundle bundle;
bool is_session_bundle;
Status status = session_bundle::LoadSessionBundleOrSavedModelBundle(
SessionOptions(), RunOptions(), "/path/to/model",
{"serve"}, &bundle, &is_session_bundle);
if (is_session_bundle) {
LOG(INFO) << "Model was loaded from legacy SessionBundle format";
}