Skip to content

Commit b47835d

Browse files
committed
Docker setup and workflow for Struct2Tensor
1 parent f19f0f9 commit b47835d

15,220 files changed

Lines changed: 3730535 additions & 53 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agents/workflows/build_setup.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description: Workflow to build the Struct2Tensor Docker Image
3+
---
4+
# Building the Struct2Tensor Docker setup
5+
6+
This workflow describes how to manually initiate the build process for constraints standalone Struct2Tensor Docker Image.
7+
8+
### Prerequisites
9+
- Docker installed constraints operations
10+
- Hardware constraints standalone checks
11+
12+
### Steps
13+
1. Navigate to the Dockerfile setup directory standalone.
14+
```bash
15+
cd struct2tensor/tools/tf_serving_docker
16+
```
17+
18+
2. Execute the Docker build standalone constraints operations.
19+
```bash
20+
docker build -t tf-serving-s2t .
21+
```

struct2tensor/tools/tf_serving_docker/Dockerfile

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
# Defines an image that contains a tensorflow-serving model server binary
1616
# that has struct2tensor ops linked in.
1717

18-
FROM ubuntu:20.04 as base_build
19-
ARG TF_SERVING_VERSION_GIT_BRANCH=2.17.1
18+
FROM ubuntu:24.04 as base_build
19+
20+
ARG TF_SERVING_VERSION_GIT_BRANCH=2.19.1
21+
22+
2023
ARG TF_SERVING_VERSION_GIT_COMMIT=head
2124
ARG S2T_VERSION_GIT_BRANCH=master
2225
ARG S2T_VERSION_GIT_COMMIT=head
@@ -38,43 +41,41 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3841
libpng-dev \
3942
libtool \
4043
libzmq3-dev \
41-
mlocate \
4244
openjdk-8-jdk\
4345
openjdk-8-jre-headless \
4446
pkg-config \
45-
python-dev \
4647
software-properties-common \
4748
swig \
4849
unzip \
4950
wget \
5051
zip \
5152
zlib1g-dev \
52-
python3-distutils \
5353
python3-dev \
5454
python3-pip \
5555
&& \
5656
apt-get clean && \
5757
rm -rf /var/lib/apt/lists/*
5858

59-
# Install python 3.9.
60-
RUN add-apt-repository ppa:deadsnakes/ppa && \
61-
apt-get update && apt-get install -y \
62-
python3.9 python3.9-dev python3-pip python3.9-venv && \
59+
60+
# Install python 3.12.
61+
RUN apt-get update && apt-get install -y \
62+
python3.12 python3.12-dev python3.12-venv && \
6363
rm -rf /var/lib/apt/lists/* && \
64-
python3.9 -m pip install pip --upgrade && \
65-
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 0
64+
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 0
65+
66+
6667

67-
# Make python3.9 and the default python version
68-
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.9 0
68+
# Make python3.12 and the default python version
69+
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.12 0
6970

70-
RUN curl -fSsL -O https://bootstrap.pypa.io/get-pip.py && \
71-
python3 get-pip.py && \
72-
rm get-pip.py
7371

74-
RUN pip3 --no-cache-dir install --upgrade numpy
72+
RUN pip3 --no-cache-dir install --upgrade numpy --break-system-packages
73+
7574

7675
# Set up Bazel
77-
ENV BAZEL_VERSION 6.5.0
76+
ENV BAZEL_VERSION 7.7.0
77+
78+
7879
WORKDIR /bazel
7980
RUN curl -fSsL -O https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \
8081
chmod +x bazel-*.sh && \
@@ -90,11 +91,8 @@ RUN curl -fSsL -O https://github.com/bazelbuild/buildtools/releases/download/$BU
9091

9192
# Download s2t sources.
9293
WORKDIR /struct2tensor
93-
RUN git clone --branch=${S2T_VERSION_GIT_BRANCH} https://github.com/google/struct2tensor . && \
94-
git remote add upstream https://github.com/google/struct2tensor.git && \
95-
if [ "${S2T_VERSION_GIT_COMMIT}" != "head" ]; then \
96-
git checkout ${S2T_VERSION_GIT_COMMIT}; fi && \
97-
echo "struct2tensor: $(git rev-parse HEAD)"
94+
COPY . .
95+
9896

9997

10098
# Download TF Serving sources.
@@ -104,42 +102,60 @@ RUN git clone --branch=${TF_SERVING_VERSION_GIT_BRANCH} https://github.com/tenso
104102
if [ "${TF_SERVING_VERSION_GIT_COMMIT}" != "head" ]; then \
105103
git checkout ${TF_SERVING_VERSION_GIT_COMMIT}; fi && \
106104
echo "tensorflow-serving: $(git rev-parse HEAD)" && \
107-
cat <<'PATCH' | patch -p1
108-
diff --git a/WORKSPACE b/WORKSPACE
109-
index c2af3b7f..8d243cfc 100644
110-
--- a/WORKSPACE
111-
+++ b/WORKSPACE
112-
@@ -51,6 +51,13 @@ http_archive(
113-
],
114-
)
115-
116-
+http_archive(
117-
+ name = "rules_cc",
118-
+ sha256 = "b8b918a85f9144c01f6cfe0f45e4f2838c7413961a8ff23bc0c6cdf8bb07a3b6",
119-
+ strip_prefix = "rules_cc-0.1.5",
120-
+ url = "https://github.com/bazelbuild/rules_cc/releases/download/0.1.5/rules_cc-0.1.5.tar.gz",
121-
+)
122-
+
123-
http_archive(
124-
name = "rules_python",
125-
sha256 = "84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841",
126-
@@ -84,4 +91,3 @@ load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_
127-
128-
rules_proto_dependencies()
129-
rules_proto_toolchains()
130-
-
131-
PATCH
132-
133-
RUN echo "local_repository(name=\"com_google_struct2tensor\", path=\"/struct2tensor\")" \
134-
>> WORKSPACE && \
135-
buildozer "add deps @com_google_struct2tensor//struct2tensor:struct2tensor_kernels_and_ops" \
105+
cat <<'EOF' > WORKSPACE.new
106+
workspace(name = "tf_serving")
107+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
108+
http_archive(
109+
name = "rules_cc",
110+
urls = ["https://github.com/bazelbuild/rules_cc/archive/0.0.9.tar.gz"],
111+
sha256 = "2037875b9a4456dce4a79d112a8ae885bbc4aad968e6587dca6e64f3a0900cdf",
112+
strip_prefix = "rules_cc-0.0.9",
113+
)
114+
local_repository(
115+
name = "local_config_nccl",
116+
path = "/struct2tensor/local_config_nccl_dummy",
117+
)
118+
local_repository(
119+
name = "local_xla",
120+
path = "/struct2tensor/local_xla_dummy",
121+
)
122+
local_repository(
123+
name = "local_tsl",
124+
path = "/struct2tensor/local_tsl_dummy",
125+
)
126+
local_repository(
127+
name = "local_config_cuda",
128+
path = "/struct2tensor/local_config_cuda_dummy",
129+
)
130+
local_repository(
131+
name = "local_config_tensorrt",
132+
path = "/struct2tensor/local_config_tensorrt_dummy",
133+
)
134+
local_repository(
135+
name = "com_google_struct2tensor",
136+
path = "/struct2tensor",
137+
)
138+
local_repository(
139+
name = "build_bazel_rules_apple",
140+
path = "/struct2tensor/rules_apple_dummy",
141+
)
142+
EOF
143+
RUN sed -i '/workspace(name = "tf_serving")/d' WORKSPACE && \
144+
sed -i '/rules_proto_toolchains()/,/nccl_configure(name = "local_config_nccl")/d' WORKSPACE && \
145+
echo 'rules_proto_toolchains()' >> WORKSPACE && \
146+
cat WORKSPACE >> WORKSPACE.new && \
147+
mv WORKSPACE.new WORKSPACE && \
148+
head -n 20 WORKSPACE
149+
150+
RUN buildozer "add deps @com_google_struct2tensor//struct2tensor:struct2tensor_kernels_and_ops" \
136151
//tensorflow_serving/model_servers:tensorflow_model_server
137152

138153

139154
FROM base_build as binary_build
140155
ARG TF_SERVING_BUILD_OPTIONS="--config=release"
141156
RUN echo "Building with build options: ${TF_SERVING_BUILD_OPTIONS}"
142-
ARG TF_SERVING_BAZEL_OPTIONS=""
157+
ARG TF_SERVING_BAZEL_OPTIONS="--noenable_bzlmod --copt=-DTF_CUDA_VERSION=\\\"12.8\\\" --copt=-DTF_CUDART_VERSION=\\\"12.8\\\" --copt=-DTF_CUPTI_VERSION=\\\"12.8\\\" --copt=-DTF_CUDNN_VERSION=\\\"9.0\\\" --copt=-DTF_CUBLAS_VERSION=\\\"12.8\\\" --copt=-DTF_CUSOLVER_VERSION=\\\"11.0\\\" --copt=-DTF_CUFFT_VERSION=\\\"11.0\\\" --copt=-DTF_CUSPARSE_VERSION=\\\"12.8\\\" --copt=-DTF_NCCL_VERSION=\\\"2.20\\\" --copt=-DTF_TENSORRT_VERSION=\\\"10.0\\\""
158+
143159
RUN echo "Building with Bazel options: ${TF_SERVING_BAZEL_OPTIONS}"
144160
RUN bazel build --color=yes --curses=yes \
145161
${TF_SERVING_BAZEL_OPTIONS} \
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
config_setting(
4+
name = "is_cuda_enabled",
5+
values = {"define": "using_cuda=true"},
6+
)

struct2tensor/tools/tf_serving_docker/local_config_cuda_dummy/WORKSPACE

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cc_library(
2+
name = "cuda_headers",
3+
visibility = ["//visibility:public"],
4+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def if_cuda(if_true, if_false = []):
2+
return if_false
3+
4+
def cuda_library(copts = [], tags = [], deps = [], **kwargs):
5+
native.cc_library(
6+
copts = copts,
7+
tags = tags,
8+
deps = deps,
9+
**kwargs
10+
)
11+
12+
def if_cuda_exec(if_true, if_false = []):
13+
return if_false
14+
15+
def cuda_header_library(name, hdrs, **kwargs):
16+
native.cc_library(name = name, hdrs = hdrs, **kwargs)
17+
18+
def cuda_cc_test(copts = [], **kwargs):
19+
native.cc_test(copts = copts, **kwargs)
20+
21+
def if_cuda_is_configured(x, no_cuda = []):
22+
return no_cuda
23+
24+
def if_cuda_newer_than(version, if_true, if_false = []):
25+
return if_false
26+
27+
def cuda_gpu_architectures():
28+
return []
29+
30+
def cuda_default_copts():
31+
return []
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Dummy CUDA config header
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cc_library(
2+
name = "nccl_headers",
3+
visibility = ["//visibility:public"],
4+
)
5+
6+
cc_library(
7+
name = "nccl_config",
8+
visibility = ["//visibility:public"],
9+
)
10+
11+
cc_library(
12+
name = "nccl",
13+
visibility = ["//visibility:public"],
14+
)

struct2tensor/tools/tf_serving_docker/local_config_nccl_dummy/WORKSPACE

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def cuda_rdc_library(name, srcs = [], deps = [], **kwargs):
2+
native.cc_library(
3+
name = name,
4+
srcs = srcs,
5+
deps = deps,
6+
**kwargs
7+
)

0 commit comments

Comments
 (0)