Skip to main content

TensorFlow Serving Config Utilities

Python utilities for reading, writing, and validating TensorFlow Serving models.config files. This project provides a convenient way to programmatically manage your TensorFlow Serving model configurations using Python.

描述

该项目旨在提供一套 Python 工具,用于处理 TensorFlow Serving 的 models.config 文件。通过使用 Protobuf 定义,您可以轻松地创建、修改和验证模型服务器配置,从而实现自动化部署和管理 TensorFlow Serving 实例。

特性

  • 生成 models.config: 轻松创建符合 TensorFlow Serving 规范的 models.config 文件。
  • 读取和解析: 从现有 models.config 文件中读取并解析配置,方便程序化访问。
  • 验证: 利用 Protobuf 的结构化特性,确保配置文件的格式正确性。
  • 模块化和可重用: 代码遵循面向对象设计原则,易于集成和扩展。

安装

先决条件

  • Python 3.8 或更高版本

使用 pip 安装

pip install tensorflow_serving_config

从源代码安装

  1. 克隆仓库:
    git clone https://github.com/colorblank/tensorflow_serving_config.git
    cd tensorflow_serving_config
    
  2. 安装依赖:
    pip install -r requirements.txt
    
  3. 安装项目:
    python setup.py install
    

依赖

本项目依赖以下库:

  • protobuf>=6.31.1
  • grpcio>=1.73.1
  • grpcio-tools==1.73.1 (用于生成 Protobuf 代码)
  • wheel

使用示例

以下是一个简单的示例,展示如何使用此库生成并读取一个 models.config 文件:

from google.protobuf import text_format
from tensorflow_serving.config import model_server_config_pb2
import os

# --- 生成一个示例 models.config 文件 ---
sample_config = model_server_config_pb2.ModelServerConfig()

# 添加第一个模型配置
model1 = sample_config.model_config_list.config.add()
model1.name = "example_model_a"
model1.base_path = "/var/lib/tensorflow_serving/models/example_model_a"
model1.model_platform = "tensorflow"
model1.model_version_policy.specific.versions.append(1)
model1.model_version_policy.specific.versions.append(2)

# 添加第二个模型配置
model2 = sample_config.model_config_list.config.add()
model2.name = "example_model_b"
model2.base_path = "/var/lib/tensorflow_serving/models/example_model_b"
model2.model_platform = "tensorflow"

config_file_path = "models.config"
with open(config_file_path, "w") as f:
    f.write(text_format.MessageToString(sample_config))
print(f"示例配置文件 '{config_file_path}' 生成成功!")

# --- 读取并解析 models.config 文件 ---
model_server_config = model_server_config_pb2.ModelServerConfig()
try:
    with open(config_file_path, "r") as f:
        config_content = f.read()
        text_format.Parse(config_content, model_server_config)

    print("\n配置文件 'models.config' 读取并解析成功!")
    print("\n--- 读取到的模型配置 ---")

    for model_config in model_server_config.model_config_list.config:
        print(f"模型名称: {model_config.name}")
        print(f"模型路径: {model_config.base_path}")
        print(f"模型平台: {model_config.model_platform}")
        if model_config.model_version_policy.HasField("specific"):
            versions = list(model_config.model_version_policy.specific.versions)
            print(f"版本策略: {versions}")
        else:
            print("版本策略: 默认 (Latest)")
        print("-" * 20)

except FileNotFoundError:
    print(f"错误: 找不到配置文件 '{config_file_path}'")
except text_format.ParseError as e:
    print(f"错误: 解析配置文件失败,请检查文件格式是否正确。错误详情: {e}")

# 清理生成的示例文件
if os.path.exists(config_file_path):
    os.remove(config_file_path)
    print(f"\n清理: 示例配置文件 '{config_file_path}' 已删除。")

许可证

本项目采用 Apache-2.0 许可证。详情请参阅 LICENSE 文件。

联系方式

Metadata

Release files for tensorflow-serving-config 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tensorflow-serving-config 0.0.2
File Size Uploaded
tensorflow_serving_config-0.0.2.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tensorflow-serving-config 0.0.2
File Interpreter ABI Platform
tensorflow_serving_config-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 18.9 kB

Release files / tensorflow_serving_config-0.0.2.tar.gz

Download URL tensorflow_serving_config-0.0.2.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
745761ec16c944fb1c4ddb0f0563a303ed9f64c55a15b0255615fd513917fde7
BLAKE2b-256 checksum
How to use checksums
01804ab8499f265cf96001235fa29bedc18d1266486b029f5d09892fa4265665
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2025.

Transparency log

Release files / tensorflow_serving_config-0.0.2-py3-none-any.whl

Download URL tensorflow_serving_config-0.0.2-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17d734e607c930e6f1c875895d38f360269b4e3e06613592d5481303fac8b0a0
BLAKE2b-256 checksum
How to use checksums
167ef8c627bbf33257e5d843c3554d92d799e2880bd29f9ae812236b6c22e81e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 24, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page