Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Tensorflow Serving ServerCore Version Labels

From Leeroopedia
Knowledge Sources
Domains Version_Management, Traffic_Routing
Last Updated 2026-02-13 17:00 GMT

Overview

Concrete tool for mapping version labels to version numbers inside ServerCore, enabling label-based request routing.

Description

ServerCore::UpdateModelVersionLabelMap() validates and atomically updates the internal model_labels_to_versions_ map. GetModelVersionForLabel() resolves a label to a version number during request processing. ServableRequestFromModelSpec() integrates label resolution into the standard request dispatch path.

Validation ensures that labeled versions are actually loaded (available in ServableStateMonitor) unless allow_version_labels_for_unavailable_models is set to true.

Usage

Configure version_labels in your ModelConfig protobuf. Labels are updated whenever ReloadConfig() is called with new label assignments.

Code Reference

Source Location

  • Repository: tensorflow/serving
  • File: tensorflow_serving/model_servers/server_core.cc
  • Lines: L549-614 (UpdateModelVersionLabelMap), L873-892 (GetModelVersionForLabel), L841-871 (ServableRequestFromModelSpec)
  • Config: tensorflow_serving/config/model_server_config.proto L63

Signature

// Update label-to-version mappings (called during ReloadConfig)
absl::Status ServerCore::UpdateModelVersionLabelMap();

// Resolve a label to a version number
absl::Status ServerCore::GetModelVersionForLabel(
    const string& model_name,
    const string& label,
    int64_t* version
);

// Resolve a ModelSpec (which may contain label) to a ServableRequest
absl::Status ServerCore::ServableRequestFromModelSpec(
    const ModelSpec& model_spec,
    ServableRequest* servable_request
);

Import

#include "tensorflow_serving/model_servers/server_core.h"

I/O Contract

Inputs

Name Type Required Description
version_labels map<string, int64> Yes Proto field mapping labels to version numbers
allow_version_labels bool No Options field, default true; enables label routing
allow_version_labels_for_unavailable_models bool No Default false; allow labels for not-yet-loaded versions

Outputs

Name Type Description
model_labels_to_versions_ map Atomically-updated internal label resolution map
ServableRequest struct Resolved request with concrete version number

Usage Examples

Config with Version Labels

model_config_list {
  config {
    name: 'my_model'
    base_path: '/models/my_model/'
    model_platform: 'tensorflow'
    model_version_policy {
      specific {
        versions: 42
        versions: 43
      }
    }
    version_labels {
      key: 'stable'
      value: 42
    }
    version_labels {
      key: 'canary'
      value: 43
    }
  }
}

Client Request with Label

# REST API with version label
curl -d '{"instances": [[1.0, 2.0]]}' \
    http://localhost:8501/v1/models/my_model/labels/stable:predict

# gRPC: set model_spec.version_label = "stable" in PredictRequest

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment