Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ create_config_settings()
cc_library(
name = "ovms_dependencies",
deps = [
"@tensorflow_serving//tensorflow_serving/apis:prediction_service_cc_proto",
"@tensorflow_serving//tensorflow_serving/apis:model_service_cc_proto",
"@tensorflow_serving_protos//:prediction_service_cc_proto",
"@tensorflow_serving_protos//:model_service_cc_proto",
"@minitrace//:trace",
"@com_github_grpc_grpc//:grpc++",
"@com_github_tencent_rapidjson//:rapidjson",
Expand Down
89 changes: 89 additions & 0 deletions CHANGES_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Summary of Changes for TensorFlow Serving Proto Dependency

## Overview
This change replaces the dependency on the entire TensorFlow Serving and TensorFlow repositories with a dependency on just the protobuf files required to create a TensorFlow Serving compatible service.

## Changes Made

### 1. Created `third_party/tensorflow_serving_protos/` Directory
- **Purpose**: Contains only the `.proto` files needed for TensorFlow Serving API compatibility
- **Contents**:
- `tensorflow_serving/apis/` - TensorFlow Serving API proto files (15 files)
- `tensorflow_serving/config/` - TensorFlow Serving config proto files (7 files)
- `tensorflow/core/framework/` - TensorFlow framework proto files (30 files)
- `tensorflow/core/example/` - TensorFlow example proto files (3 files)
- `tensorflow/core/protobuf/` - TensorFlow protobuf definitions (41 files)
- **Total**: 96 proto files extracted from TensorFlow Serving 2.18.0 and TensorFlow commit 5329ec8d

### 2. Created `third_party/tensorflow_serving_protos/BUILD`
- **Purpose**: Bazel build rules for compiling the proto files
- **Targets**:
- `tensorflow_core_framework_cc_proto` - TensorFlow framework protos
- `tensorflow_core_example_cc_proto` - TensorFlow example protos
- `tensorflow_core_protobuf_cc_proto` - TensorFlow protobuf protos
- `tensorflow_serving_config_cc_proto` - TF Serving config protos
- `tensorflow_serving_apis_cc_proto` - TF Serving API protos
- `prediction_service_cc_proto` - Prediction service with gRPC
- `model_service_cc_proto` - Model service with gRPC
- **Style**: Uses `@com_google_protobuf//:protobuf.bzl` consistent with existing codebase

### 3. Updated `WORKSPACE`
- Added `new_local_repository` for `tensorflow_serving_protos`
- Placed before the `tensorflow_serving` git repository definition
- Uses BUILD file from `third_party/tensorflow_serving_protos/BUILD`

### 4. Updated `BUILD.bazel`
- Changed proto dependencies in `ovms_dependencies`:
- FROM: `@tensorflow_serving//tensorflow_serving/apis:prediction_service_cc_proto`
- TO: `@tensorflow_serving_protos//:prediction_service_cc_proto`
- FROM: `@tensorflow_serving//tensorflow_serving/apis:model_service_cc_proto`
- TO: `@tensorflow_serving_protos//:model_service_cc_proto`
- **Kept**: Utility dependencies on `tensorflow_serving/util:json_tensor` (still needed for JSON conversion)

### 5. Updated `src/BUILD`
- Updated `tfs_utils` target:
- Changed from individual API proto deps to single `tensorflow_serving_apis_cc_proto`
- Updated `libovmshttpservermodule` target:
- Changed from `prediction_service_cc_proto` to `tensorflow_serving_apis_cc_proto`
- **Kept**: Utility dependencies on `threadpool_executor`, `json_tensor`, `net_http` (still needed)

### 6. Documentation
- Created `third_party/tensorflow_serving_protos/README.md` explaining:
- Contents of the directory
- Source versions (TF Serving 2.18.0, TF commit 5329ec8d)
- Usage instructions
- Rationale for the approach
- Maintenance guide
- Created `third_party/tensorflow_serving_protos/.gitignore` to exclude generated files

## Benefits

1. **Reduced Build Dependencies**: No longer need to build entire TensorFlow or TensorFlow Serving
2. **Faster Builds**: Only proto compilation needed, not C++ library compilation
3. **Easier Maintenance**: Proto files are simpler to update than full framework dependencies
4. **Bazel-native**: All proto compilation happens in Bazel, not in Dockerfiles
5. **API Compatibility**: Maintains full TensorFlow Serving API compatibility

## What Was NOT Changed

1. **Utility Dependencies**: Still depend on TensorFlow Serving for:
- `tensorflow_serving/util:json_tensor` - JSON tensor conversion utilities
- `tensorflow_serving/util:threadpool_executor` - Thread pool executor
- `tensorflow_serving/util/net_http/server/public:http_server` - HTTP server

These are C++ utilities, not protos, and are still needed for functionality.

2. **TensorFlow Core Framework**: Still depend on `@org_tensorflow//tensorflow/core:framework` for Eigen Tensor support

## Testing Required

1. Build verification: Ensure the project builds successfully with new dependencies
2. Functional testing: Verify TensorFlow Serving API endpoints work correctly
3. Integration testing: Test with existing TF Serving clients
4. Performance testing: Ensure no performance regression

## Future Work

1. Consider extracting utility files (`json_tensor`, `threadpool_executor`, `net_http`) to reduce dependency on full TensorFlow Serving repository
2. Monitor TensorFlow Serving releases for proto file changes
3. Create automated script to update proto files when versions change
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ cc_library(
)


# TensorFlow Serving API protos only (no build dependencies)
new_local_repository(
name = "tensorflow_serving_protos",
build_file = "@//third_party/tensorflow_serving_protos:BUILD",
path = "third_party/tensorflow_serving_protos",
)

# Used for gRPC API protos only
# Tensorflow serving
git_repository(
Expand Down
5 changes: 2 additions & 3 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,7 @@ ovms_cc_library(
srcs = [
"tfs_frontend/tfs_utils.cpp",],
deps = [
"@tensorflow_serving//tensorflow_serving/apis:prediction_service_cc_proto",
"@tensorflow_serving//tensorflow_serving/apis:model_service_cc_proto",
"@tensorflow_serving_protos//:tensorflow_serving_apis_cc_proto",
"@org_tensorflow//tensorflow/core:framework", # Eigen Tensor
"libovmslogging",
"libovmsprofiler",
Expand Down Expand Up @@ -1100,7 +1099,7 @@ ovms_cc_library( # TODO split dependencies
deps = [
"@com_github_jupp0r_prometheus_cpp//core",
"@mediapipe//mediapipe/framework:calculator_framework",
"@tensorflow_serving//tensorflow_serving/apis:prediction_service_cc_proto",
"@tensorflow_serving_protos//:tensorflow_serving_apis_cc_proto",
"@tensorflow_serving//tensorflow_serving/util:threadpool_executor",
"@tensorflow_serving//tensorflow_serving/util:json_tensor",
"libovms_module",
Expand Down
6 changes: 6 additions & 0 deletions third_party/tensorflow_serving_protos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated files
*.pb.h
*.pb.cc
*.pb.o
*.grpc.pb.h
*.grpc.pb.cc
118 changes: 118 additions & 0 deletions third_party/tensorflow_serving_protos/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#
# Copyright (c) 2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# TensorFlow Serving API protobuf definitions
# This package contains only the proto files needed for TensorFlow Serving API compatibility
# without requiring the full TensorFlow or TensorFlow Serving build dependencies.

load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library")
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

# TensorFlow Core Framework protos
cc_proto_library(
name = "tensorflow_core_framework_cc_proto",
srcs = glob(["tensorflow/core/framework/*.proto"]),
cc_libs = ["@com_google_protobuf//:protobuf"],
protoc = "@com_google_protobuf//:protoc",
default_runtime = "@com_google_protobuf//:protobuf",
)

# TensorFlow Core Example protos
cc_proto_library(
name = "tensorflow_core_example_cc_proto",
srcs = glob(["tensorflow/core/example/*.proto"]),
cc_libs = ["@com_google_protobuf//:protobuf"],
protoc = "@com_google_protobuf//:protoc",
default_runtime = "@com_google_protobuf//:protobuf",
)

# TensorFlow Core Protobuf protos
cc_proto_library(
name = "tensorflow_core_protobuf_cc_proto",
srcs = glob(["tensorflow/core/protobuf/*.proto"]),
deps = [
":tensorflow_core_framework_cc_proto",
],
cc_libs = ["@com_google_protobuf//:protobuf"],
protoc = "@com_google_protobuf//:protoc",
default_runtime = "@com_google_protobuf//:protobuf",
)

# TensorFlow Serving Config protos
cc_proto_library(
name = "tensorflow_serving_config_cc_proto",
srcs = glob(["tensorflow_serving/config/*.proto"]),
cc_libs = ["@com_google_protobuf//:protobuf"],
protoc = "@com_google_protobuf//:protoc",
default_runtime = "@com_google_protobuf//:protobuf",
)

# TensorFlow Serving API protos (non-service)
cc_proto_library(
name = "tensorflow_serving_apis_cc_proto",
srcs = [
"tensorflow_serving/apis/classification.proto",
"tensorflow_serving/apis/get_model_metadata.proto",
"tensorflow_serving/apis/get_model_status.proto",
"tensorflow_serving/apis/inference.proto",
"tensorflow_serving/apis/input.proto",
"tensorflow_serving/apis/logging.proto",
"tensorflow_serving/apis/model.proto",
"tensorflow_serving/apis/model_management.proto",
"tensorflow_serving/apis/predict.proto",
"tensorflow_serving/apis/prediction_log.proto",
"tensorflow_serving/apis/regression.proto",
"tensorflow_serving/apis/session_service.proto",
"tensorflow_serving/apis/status.proto",
],
deps = [
":tensorflow_core_example_cc_proto",
":tensorflow_core_framework_cc_proto",
":tensorflow_core_protobuf_cc_proto",
":tensorflow_serving_config_cc_proto",
],
cc_libs = ["@com_google_protobuf//:protobuf"],
protoc = "@com_google_protobuf//:protoc",
default_runtime = "@com_google_protobuf//:protobuf",
)

# Prediction Service proto (with gRPC service)
cc_proto_library(
name = "prediction_service_cc_proto",
srcs = ["tensorflow_serving/apis/prediction_service.proto"],
deps = [":tensorflow_serving_apis_cc_proto"],
cc_libs = ["@com_google_protobuf//:protobuf"],
protoc = "@com_google_protobuf//:protoc",
default_runtime = "@com_google_protobuf//:protobuf",
use_grpc_plugin = True,
)

# Model Service proto (with gRPC service)
cc_proto_library(
name = "model_service_cc_proto",
srcs = ["tensorflow_serving/apis/model_service.proto"],
deps = [":tensorflow_serving_apis_cc_proto"],
cc_libs = ["@com_google_protobuf//:protobuf"],
protoc = "@com_google_protobuf//:protoc",
default_runtime = "@com_google_protobuf//:protobuf",
use_grpc_plugin = True,
)


62 changes: 62 additions & 0 deletions third_party/tensorflow_serving_protos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# TensorFlow Serving Protos

This directory contains protocol buffer (`.proto`) files extracted from TensorFlow and TensorFlow Serving repositories. These proto files are used to provide TensorFlow Serving API compatibility without requiring the full TensorFlow or TensorFlow Serving build dependencies.

## Contents

### TensorFlow Serving APIs (`tensorflow_serving/apis/`)
Proto files defining the TensorFlow Serving gRPC API surface:
- `prediction_service.proto` - Main prediction service API
- `model_service.proto` - Model management service API
- `predict.proto`, `classify.proto`, `regress.proto` - Request/response messages
- `model.proto`, `input.proto` - Common types
- Other supporting proto files

### TensorFlow Serving Config (`tensorflow_serving/config/`)
Configuration proto files for TensorFlow Serving:
- `model_server_config.proto` - Model server configuration
- `logging_config.proto` - Logging configuration
- Other config protos

### TensorFlow Core (`tensorflow/core/`)
Required TensorFlow proto dependencies:
- `framework/*.proto` - Core TensorFlow framework types (tensor, types, etc.)
- `example/*.proto` - TensorFlow Example proto format
- `protobuf/*.proto` - TensorFlow protobuf definitions

## Source Information

- **TensorFlow Serving Version**: 2.18.0
- **TensorFlow Version**: Commit 5329ec8dd396487982ef3e743f98c0195af39a6b

## Usage

The BUILD file in this directory provides Bazel targets for compiling these protos:

```python
# For TensorFlow Serving APIs (non-service protos)
deps = ["@tensorflow_serving_protos//:tensorflow_serving_apis_cc_proto"]

# For Prediction Service (with gRPC)
deps = ["@tensorflow_serving_protos//:prediction_service_cc_proto"]

# For Model Service (with gRPC)
deps = ["@tensorflow_serving_protos//:model_service_cc_proto"]
```

## Rationale

This approach allows OpenVINO Model Server to:
1. Maintain TensorFlow Serving API compatibility
2. Avoid building the entire TensorFlow and TensorFlow Serving stack
3. Reduce build complexity and time
4. Keep proto compilation within Bazel (not in Dockerfiles)

## Maintenance

When updating to a new TensorFlow Serving version:
1. Clone the appropriate TensorFlow Serving tag
2. Clone the matching TensorFlow commit
3. Copy the required proto files from both repositories
4. Update this README with version information
5. Test the build to ensure compatibility
Loading
Loading