diff --git a/.bazelrc b/.bazelrc index 6278d956d75..c41bf62af6f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -17,7 +17,8 @@ build:cuda_clang --host_copt=-Wno-error=unused-command-line-argument build:cuda_clang --repo_env TF_NEED_TENSORRT=0 build:cuda_clang --action_env=TF_CUDA_CLANG="1" build:cuda_clang --@local_config_cuda//:cuda_compiler=clang -build:cuda_clang --repo_env=TF_CUDA_COMPUTE_CAPABILITIES="sm_60,sm_70,sm_80,sm_89,compute_90" +build:cuda_clang --repo_env=TF_CUDA_COMPUTE_CAPABILITIES="sm_60,sm_70,sm_75,sm_80,sm_86,sm_89,compute_90" +build:cuda_clang --copt=-Dtypeof=__typeof__ common:cuda_clang --repo_env=HERMETIC_CUDA_VERSION="12.5.1" common:cuda_clang --repo_env=HERMETIC_CUDNN_VERSION="9.3.0" @@ -116,6 +117,9 @@ common --repo_env USE_HERMETIC_CC_TOOLCHAIN=1 common --repo_env=HERMETIC_PYTHON_VERSION="3.10" common --repo_env=USE_PYWRAP_RULES=1 build --features=-layering_check +build --host_features=-layering_check +build --features=-module_maps +build --host_features=-module_maps build --define=framework_shared_object=false build --dynamic_mode=off diff --git a/WORKSPACE b/WORKSPACE index 9d53b2fbf8b..ddbd10ac0eb 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -24,8 +24,8 @@ local_repository( load("//tensorflow_serving:repo.bzl", "tensorflow_http_archive") tensorflow_http_archive( name = "org_tensorflow", - sha256 = "54bfd56d61dfced2b82bdeee3262a24fb3d59bed4dbb292d19834af002d85b3b", - git_commit = "c1be979f3130b85f14e8890c05cbca147784f474", + sha256 = "6438396f3b19af5d7ad787cf041f857af7505916dc08092e20b07d1b1f8df492", + git_commit = "a481b10260dfdf833a1b16007eead49c1d7febf3", patch = "//third_party/tensorflow:tensorflow.patch", patch_cmds = [ "sed -i '/cc_library = _cc_library/d' tensorflow/core/platform/rules_cc.bzl", @@ -95,17 +95,16 @@ http_archive( http_archive( name = "rules_python", - sha256 = "8964aa1e7525fea5244ba737458694a057ada1be96a92998a41caa1983562d00", - strip_prefix = "rules_python-1.8.5", + sha256 = "fa7dd2c6b7d63b3585028dd8a90a6cf9db83c33b250959c2ee7b583a6c130e12", + strip_prefix = "rules_python-1.6.0", urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_python/releases/download/1.8.5/rules_python-1.8.5.tar.gz", - "https://github.com/bazelbuild/rules_python/releases/download/1.8.5/rules_python-1.8.5.tar.gz", + "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_python/releases/download/1.6.0/rules_python-1.6.0.tar.gz", + "https://github.com/bazelbuild/rules_python/releases/download/1.6.0/rules_python-1.6.0.tar.gz", ], patches = [ - "@rules_ml_toolchain//third_party/rules_python:rules_python_scope.patch", - "@rules_ml_toolchain//third_party/rules_python:rules_python_freethreaded.patch", - "@rules_ml_toolchain//third_party/rules_python:rules_python_versions.patch", - "@rules_ml_toolchain//third_party/rules_python:rules_python_pip_version.patch", + "@org_tensorflow//third_party/py:rules_python_pip_version.patch", + "@org_tensorflow//third_party/py:rules_python_freethreaded.patch", + "@org_tensorflow//third_party/py:rules_python_versions.patch", ], patch_args = ["-p1"], ) @@ -114,11 +113,15 @@ http_archive( # Details: https://github.com/google-ml-infra/rules_ml_toolchain http_archive( name = "rules_ml_toolchain", - sha256 = "0b42f693a60c6050d87db1e0a0eaeb84ab3f54191fce094d86334faedc807da0", - strip_prefix = "rules_ml_toolchain-398d613aea7a4c294da49b79a6d6f3f8732bd84c", + sha256 = "54c1a357f71f611efdb4891ebd4bcbe4aeb6dfa7e473f14fd7ecad5062096616", + strip_prefix = "rules_ml_toolchain-d8cb9c2c168cd64000eaa6eda0781a9615a26ffe", urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/google-ml-infra/rules_ml_toolchain/archive/398d613aea7a4c294da49b79a6d6f3f8732bd84c.tar.gz", - "https://github.com/google-ml-infra/rules_ml_toolchain/archive/398d613aea7a4c294da49b79a6d6f3f8732bd84c.tar.gz", + "https://storage.googleapis.com/mirror.tensorflow.org/github.com/google-ml-infra/rules_ml_toolchain/archive/d8cb9c2c168cd64000eaa6eda0781a9615a26ffe.tar.gz", + "https://github.com/google-ml-infra/rules_ml_toolchain/archive/d8cb9c2c168cd64000eaa6eda0781a9615a26ffe.tar.gz", + ], + patch_cmds = [ + "mkdir -p third_party/rules_python py && touch third_party/rules_python/BUILD py/BUILD", + "cat << 'EOF' >> cc/cuda/clang/clang_cuda_runtime_wrapper.h\n#if defined(__clang__) && defined(__CUDA__)\n#include \n#ifndef typeof\n#define typeof __typeof__\n#endif\n#ifndef DISABLE_WRAPPERS_STWT\n__device__ inline void __stwt(uint4* ptr, uint4 value) {\n asm volatile(\"st.global.wt.v4.u32 [%0], {%1, %2, %3, %4};\" : : \"l\"(ptr), \"r\"(value.x), \"r\"(value.y), \"r\"(value.z), \"r\"(value.w) : \"memory\");\n}\n#endif\n#endif\nEOF", ], ) @@ -146,7 +149,6 @@ python_init_repositories( "3.11": "@org_tensorflow//:requirements_lock_3_11.txt", "3.12": "@org_tensorflow//:requirements_lock_3_12.txt", "3.13": "@org_tensorflow//:requirements_lock_3_13.txt", - "3.14": "@org_tensorflow//:requirements_lock_3_14.txt", }, ) diff --git a/tensorflow_serving/opensource_only/.bazelrc b/tensorflow_serving/opensource_only/.bazelrc new file mode 100644 index 00000000000..c41bf62af6f --- /dev/null +++ b/tensorflow_serving/opensource_only/.bazelrc @@ -0,0 +1,131 @@ +# Optimizations used for TF Serving release builds. +build:release --copt=-mavx +build:release --copt=-msse4.2 + +# Options used to build with CUDA. +build:cuda --repo_env TF_NEED_CUDA=1 +build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain +build:cuda --@local_config_cuda//:enable_cuda + +# Options used to build with CUDA clang +build:cuda_clang --config=cuda +build:cuda_clang --copt=-Wno-gnu-offsetof-extensions +build:cuda_clang --copt=-Wno-error=unused-command-line-argument +build --linkopt=-Wno-unused-command-line-argument +build --host_linkopt=-Wno-unused-command-line-argument +build:cuda_clang --host_copt=-Wno-error=unused-command-line-argument +build:cuda_clang --repo_env TF_NEED_TENSORRT=0 +build:cuda_clang --action_env=TF_CUDA_CLANG="1" +build:cuda_clang --@local_config_cuda//:cuda_compiler=clang +build:cuda_clang --repo_env=TF_CUDA_COMPUTE_CAPABILITIES="sm_60,sm_70,sm_75,sm_80,sm_86,sm_89,compute_90" +build:cuda_clang --copt=-Dtypeof=__typeof__ + +common:cuda_clang --repo_env=HERMETIC_CUDA_VERSION="12.5.1" +common:cuda_clang --repo_env=HERMETIC_CUDNN_VERSION="9.3.0" +common:cuda_clang --repo_env=HERMETIC_NVSHMEM_VERSION="3.2.5" +common:cuda_clang --repo_env=HERMETIC_NCCL_VERSION="2.29.7" +build:cuda_clang --action_env=GCC_HOST_COMPILER_PATH="/usr/bin/gcc-10" +build:cuda_clang --action_env=CLANG_CUDA_COMPILER_PATH="/usr/lib/llvm-17/bin/clang" + +# Options used to build with TPU support. +build:tpu --define=with_tpu_support=true --define=framework_shared_object=false +build:tpu --copt=-DLIBTPU_ON_GCE + +# Please note that MKL on MacOS or windows is still not supported. +# If you would like to use a local MKL instead of downloading, please set the +# environment variable "TF_MKL_ROOT" every time before build. +build:mkl --define=build_with_mkl=true --define=enable_mkl=true --define=build_with_openmp=false +build:mkl --define=tensorflow_mkldnn_contraction_kernel=0 + +# This config option is used to enable MKL-DNN open source library only, +# without depending on MKL binary version. +build:mkl_open_source_only --define=build_with_mkl_dnn_only=true +build:mkl_open_source_only --define=build_with_mkl=true --define=enable_mkl=true +build:mkl_open_source_only --define=tensorflow_mkldnn_contraction_kernel=0 + +# Config setting to build oneDNN with Compute Library for the Arm Architecture (ACL). +# This build is for the inference regime only. +build:mkl_aarch64 --define=build_with_mkl_aarch64=true --define=enable_mkl=true +build:mkl_aarch64 --define=tensorflow_mkldnn_contraction_kernel=0 +build:mkl_aarch64 --define=build_with_mkl_opensource=true +build:mkl_aarch64 --define=build_with_openmp=true +build:mkl_aarch64 --copt=-march=armv8.2-a +build:mkl_aarch64 --copt=-O3 + +build --define=build_with_onednn_v2=true +build --define=xnn_enable_avxvnni=false +build --define=xnn_enable_avxvnniint8=false +build --define=xnn_enable_avx256vnnigfni=false +build --define=xnn_enable_avx512amx=false +build --define=xnn_enable_avx512fp16=false + +# Processor native optimizations (depends on build host capabilities). +build:nativeopt --copt=-march=native +build:nativeopt --host_copt=-march=native +build:nativeopt --copt=-O3 + +build --keep_going +build --verbose_failures=true +build --spawn_strategy=standalone +build --genrule_strategy=standalone + +build --define=grpc_no_ares=true + +# Sets the default Apple platform to macOS. +build --apple_platform_type=macos + +build -c opt + +# LLVM, MLIR and TF requires C++17. +build --cxxopt=-std=c++17 +build --host_cxxopt=-std=c++17 + +# Adding "--cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0" creates parity with TF +# compilation options. It also addresses memory use due to +# copy-on-write semantics of std::strings of the older ABI. +build --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0 + +build --workspace_status_command=/proc/self/cwd/tools/gen_status_stamp.sh + +build --experimental_repo_remote_exec + +# TF now has `cc_shared_library` targets, so it needs the experimental flag +build --experimental_cc_shared_library + +# Yggdrasil Decision Forests (internal library of TensorFlow Decision Forests) +# uses TensorFlow for all IO operations. +build --define=use_tensorflow_io=1 + +# TensorFlow Decision Forests does not use Absl concurrency primitives on MacOs. +# Reason: TensorFlow/ABSL ODR violation (b/214189609) # copybara:strip +build:macos --define std_synchronization_primitives=1 + +# Taken from https://github.com/openxla/xla/blob/99559d7a4f7c55490f46385ad29a3cbf9c3911af/warnings.bazelrc#L6 +# We silence warnings for code in `external`. +build --per_file_copt=external/.*@-w +build --host_per_file_copt=external/.*@-w +build --copt=-Wno-macro-redefined # absl vs tsl logging clash +build --copt=-Wno-sign-compare # int as loop variable +build --copt=-Wno-deprecated-declarations +build --copt=-Wno-unused-but-set-variable # due to `ifdefs` in ml_dtypes + +# Revert to the legacy WORKSPACE dependency resolution system +# and disable Bzlmod. +common --enable_bzlmod=false +common --incompatible_enable_cc_toolchain_resolution +common --repo_env USE_HERMETIC_CC_TOOLCHAIN=1 +common --repo_env=HERMETIC_PYTHON_VERSION="3.10" +common --repo_env=USE_PYWRAP_RULES=1 +build --features=-layering_check +build --host_features=-layering_check +build --features=-module_maps +build --host_features=-module_maps +build --define=framework_shared_object=false +build --dynamic_mode=off + + +common:clang_local --noincompatible_enable_cc_toolchain_resolution +common:clang_local --noincompatible_enable_android_toolchain_resolution +common:clang_local --@rules_ml_toolchain//cc_toolchain/config:enable_hermetic_cc=False +common:clang_local --repo_env USE_HERMETIC_CC_TOOLCHAIN=0 + diff --git a/tensorflow_serving/opensource_only/root.workspace b/tensorflow_serving/opensource_only/root.workspace new file mode 100644 index 00000000000..ddbd10ac0eb --- /dev/null +++ b/tensorflow_serving/opensource_only/root.workspace @@ -0,0 +1,296 @@ +workspace(name = "tf_serving") + +# TODO(b/269515133): We temporarily remove remote_predict from our builds for +# 2.12 due to a breakage caused by +# github.com/tensorflow/tensorflow/commit/6147c03eb9af1e5d2ae155045b33e909ef96944e +# This will be removed in a subsequent release. +local_repository( + name = "ignore_remote_predict", + path = "tensorflow_serving/experimental/tensorflow/ops/remote_predict/", +) + +# ===== TensorFlow dependency ===== +# +# TensorFlow is imported here instead of in tf_serving_workspace() because +# existing automation scripts that bump the TF commit hash expect it here. +# +# To update TensorFlow to a new revision. +# 1. Update the 'git_commit' args below to include the new git hash. +# 2. Get the sha256 hash of the archive with a command such as... +# curl -L https://github.com/tensorflow/tensorflow/archive/.tar.gz | sha256sum +# and update the 'sha256' arg with the result. +# 3. Request the new archive to be mirrored on mirror.bazel.build for more +# reliable downloads. +load("//tensorflow_serving:repo.bzl", "tensorflow_http_archive") +tensorflow_http_archive( + name = "org_tensorflow", + sha256 = "6438396f3b19af5d7ad787cf041f857af7505916dc08092e20b07d1b1f8df492", + git_commit = "a481b10260dfdf833a1b16007eead49c1d7febf3", + patch = "//third_party/tensorflow:tensorflow.patch", + patch_cmds = [ + "sed -i '/cc_library = _cc_library/d' tensorflow/core/platform/rules_cc.bzl", + "echo -e \"\\ndef cc_library_oss(deps=[], **kwargs):\\n if kwargs.get(\\\"name\\\") == \\\"lib_internal_impl\\\" or \\\"protobuf\\\" in kwargs.get(\\\"name\\\", \\\"\\\"):\\n _cc_library(deps = deps, **kwargs)\\n return\\n if type(deps) == \\\"list\\\":\\n if \\\"@com_google_protobuf//:protobuf\\\" not in deps:\\n deps = deps + [\\\"@com_google_protobuf//:protobuf\\\"]\\n else:\\n deps = deps + [\\\"@com_google_protobuf//:protobuf\\\"]\\n _cc_library(deps = deps, **kwargs)\\ncc_library = cc_library_oss\" >> tensorflow/core/platform/rules_cc.bzl", + "sed -i 's#deps = \\[op_gen\\] + deps#deps = [op_gen] + deps + [clean_dep(\"//tensorflow/core/framework:kernel_shape_util\"), clean_dep(\"//tensorflow/core/framework:full_type_util\")]#' tensorflow/tensorflow.bzl", + "sed -i '/name = \"kernel_shape_util\",/a \\ visibility = [\"//visibility:public\"],' tensorflow/core/framework/BUILD", + "echo -e '\\nalias(name = \"tensorflow_libtensorflow_framework\", actual = \"//tensorflow/core:tensorflow\", visibility = [\"//visibility:public\"])' >> BUILD", + "echo -e '\\nalias(name = \"tensorflow_tf_header_lib\", actual = \"//tensorflow/core:tensorflow\", visibility = [\"//visibility:public\"])' >> BUILD", + "sed -i '/name = \"env\",/,/deps = \\[/ s#deps = \\[#deps = [\":status\", \":statusor\", \":context\", \":tracing\", \"//xla/tsl/profiler/backends/cpu:threadpool_listener_state\", \"//xla/tsl/platform:byte_order\", #' third_party/xla/xla/tsl/platform/default/BUILD", + "sed -i '/name = \"tracing\",/,/deps = \\[/ s#deps = \\[#deps = [\"//xla/tsl/platform:logging\", #' third_party/xla/xla/tsl/platform/default/BUILD", + "sed -i '/name = \"tf_runtime\",/a \\ repo_mapping = {\"@xla\": \"@local_xla\", \"@tsl\": \"@local_tsl\"},' third_party/tf_runtime/workspace.bzl", + "sed -i '/name = \"error_util\",/,/deps = \\[/ s#deps = \\[#deps = [\"@xla//xla/tsl/concurrency:async_value\", \"@xla//xla/tsl/concurrency:concurrent_vector\", \"@xla//xla/tsl/concurrency:executor\", \"@xla//xla/tsl/concurrency:ref_count\", \"@xla//xla/tsl/util:safe_reinterpret_cast\", \"@tsl//tsl/platform:context\", #' tensorflow/core/tfrt/utils/BUILD", + "sed -i '/name = \"work_queue_interface\",/,/deps = \\[/ s#deps = \\[#deps = [\"@xla//xla/tsl/concurrency:ref_count\", #' tensorflow/core/tfrt/runtime/BUILD", + "sed -i '/name = \"execute\",/,/deps = \\[/ s#deps = \\[#deps = [\"@xla//xla/tsl/platform:macros\", \"@xla//xla/tsl/platform:types\", \"@xla//xla/tsl/profiler/utils:no_init\", \"@tsl//tsl/profiler/lib:traceme_encode\", \"@xla//xla/tsl/profiler/utils:traceme_global_flags\", \"@xla//xla/tsl/profiler/backends/cpu:traceme_recorder\", \"@tsl//tsl/platform:bfloat16\", \"@tsl//tsl/platform:ml_dtypes\", \"@tsl//tsl/platform:tstring\", \"@tsl//tsl/platform:cord\", \"@tsl//tsl/platform:refcount\", \"@tsl//tsl/platform:thread_annotations\", \"@tsl//tsl/platform:stringpiece\", \"@xla//xla/tsl/profiler/utils:time_utils\", \"@xla//xla/tsl/profiler/utils:math_utils\", #' tensorflow/core/tfrt/mlrt/interpreter/BUILD", + "sed -i '/tf_vendored(name = \"xla\",/s/)/, repo_mapping = {\"@xla\": \"@local_xla\", \"@tsl\": \"@local_tsl\"})/' tensorflow/workspace3.bzl", + "sed -i '/tf_vendored(name = \"tsl\",/s/)/, repo_mapping = {\"@xla\": \"@local_xla\", \"@tsl\": \"@local_tsl\"})/' tensorflow/workspace3.bzl", + """python3 -c 'import re, glob +for p in glob.glob("third_party/xla/**/BUILD*", recursive=True): + s = open(p).read(); blocks = s.split("cc_library("); + for i in range(1, len(blocks)): + b = blocks[i]; m_th = re.search(r"textual_hdrs\\s*=\\s*(\\[[^\\]]+\\]),?\\n?", b); + if m_th: + th = m_th.group(1); b = b.replace(m_th.group(0), ""); m_h = re.search(r"hdrs\\s*=\\s*(\\[[^\\]]+\\])", b); + if m_h: h = m_h.group(1); merged = h[:-1] + ", " + th[1:]; b = b.replace(m_h.group(0), "hdrs = " + merged); + else: b = "\\n hdrs = " + th + "," + b; + blocks[i] = b + open(p, "w").write("cc_library(".join(blocks))'""", + "echo -e '\\ndiff --git a/WORKSPACE b/WORKSPACE\\n--- a/WORKSPACE\\n+++ b/WORKSPACE\\n@@ -184,25 +184,2 @@\\n sass_repositories()\\n \\n-http_archive(\\n- name = \"xla\",\\n- patch_args = [\"-p1\"],\\n- patches = [\\n- \"//third_party:xla.patch\",\\n- \"//third_party:xla_add_grpc_cares_darwin_arm64_support.patch\",\\n- ],\\n- sha256 = \"ba80ef58f89ca11bc5652e936cf856cdeae91e6b723ce6750e9ce0202cab51ac\",\\n- strip_prefix = \"xla-f094066398e2c884e994711fd677f68864324614\",\\n- urls = [\\n- \"https://github.com/openxla/xla/archive/f094066398e2c884e994711fd677f68864324614.zip\",\\n- ],\\n-)\\n-\\n-http_archive(\\n- name = \"tsl\",\\n- sha256 = \"8cf1e1285c7b1843a7f5f787465c1ef80304b3400ed837870bc76d74ce04f5af\",\\n- strip_prefix = \"tsl-d71df2f7612583617d359c36243695097dd63726\",\\n- urls = [\\n- \"https://github.com/google/tsl/archive/d71df2f7612583617d359c36243695097dd63726.zip\",\\n- ],\\n-)\\n-\\n load(\"@xla//tools/toolchains/python:python_repo.bzl\", \"python_repository\")' >> third_party/xprof/xprof.patch", + ], + repo_mapping = { + "@local_xla": "@local_xla", + "@local_tsl": "@local_tsl", + "@org_tensorflow": "@org_tensorflow", + "@xla": "@local_xla", + "@tsl": "@local_tsl", + }, +) + +# Import all of TensorFlow Serving's external dependencies. +# Downstream projects (projects importing TensorFlow Serving) need to +# duplicate all code below in their WORKSPACE file in order to also initialize +# those external dependencies. +load("//tensorflow_serving:workspace.bzl", "tf_serving_workspace") +tf_serving_workspace() + +# Check bazel version requirement, which is stricter than TensorFlow's. +load("@bazel_skylib//lib:versions.bzl", "versions") +versions.check("7.4.1") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "bazel_skylib", + sha256 = "97e709db2e97b646263b5c5e83e3b00de48c1ae55b9e421e3b5e3f9467d02a3a", + urls = [ + "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/bazel-skylib/releases/download/1.8.0/bazel-skylib-1.8.0.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.0/bazel-skylib-1.8.0.tar.gz", + ], +) + +http_archive( + name = "rules_cc", + sha256 = "b8b918a85f9144c01f6cfe0f45e4f2838c7413961a8ff23bc0c6cdf8bb07a3b6", + strip_prefix = "rules_cc-0.1.5", + url = "https://github.com/bazelbuild/rules_cc/releases/download/0.1.5/rules_cc-0.1.5.tar.gz", +) + +http_archive( + name = "rules_python", + sha256 = "fa7dd2c6b7d63b3585028dd8a90a6cf9db83c33b250959c2ee7b583a6c130e12", + strip_prefix = "rules_python-1.6.0", + urls = [ + "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_python/releases/download/1.6.0/rules_python-1.6.0.tar.gz", + "https://github.com/bazelbuild/rules_python/releases/download/1.6.0/rules_python-1.6.0.tar.gz", + ], + patches = [ + "@org_tensorflow//third_party/py:rules_python_pip_version.patch", + "@org_tensorflow//third_party/py:rules_python_freethreaded.patch", + "@org_tensorflow//third_party/py:rules_python_versions.patch", + ], + patch_args = ["-p1"], +) + +# Toolchains for ML projects hermetic builds. +# Details: https://github.com/google-ml-infra/rules_ml_toolchain +http_archive( + name = "rules_ml_toolchain", + sha256 = "54c1a357f71f611efdb4891ebd4bcbe4aeb6dfa7e473f14fd7ecad5062096616", + strip_prefix = "rules_ml_toolchain-d8cb9c2c168cd64000eaa6eda0781a9615a26ffe", + urls = [ + "https://storage.googleapis.com/mirror.tensorflow.org/github.com/google-ml-infra/rules_ml_toolchain/archive/d8cb9c2c168cd64000eaa6eda0781a9615a26ffe.tar.gz", + "https://github.com/google-ml-infra/rules_ml_toolchain/archive/d8cb9c2c168cd64000eaa6eda0781a9615a26ffe.tar.gz", + ], + patch_cmds = [ + "mkdir -p third_party/rules_python py && touch third_party/rules_python/BUILD py/BUILD", + "cat << 'EOF' >> cc/cuda/clang/clang_cuda_runtime_wrapper.h\n#if defined(__clang__) && defined(__CUDA__)\n#include \n#ifndef typeof\n#define typeof __typeof__\n#endif\n#ifndef DISABLE_WRAPPERS_STWT\n__device__ inline void __stwt(uint4* ptr, uint4 value) {\n asm volatile(\"st.global.wt.v4.u32 [%0], {%1, %2, %3, %4};\" : : \"l\"(ptr), \"r\"(value.x), \"r\"(value.y), \"r\"(value.z), \"r\"(value.w) : \"memory\");\n}\n#endif\n#endif\nEOF", + ], +) + +load( + "@rules_ml_toolchain//cc/deps:cc_toolchain_deps.bzl", + "cc_toolchain_deps", +) + +cc_toolchain_deps() + +register_toolchains("@rules_ml_toolchain//cc:linux_x86_64_linux_x86_64") +register_toolchains("@rules_ml_toolchain//cc:linux_x86_64_linux_x86_64_cuda") +# register_toolchains("@rules_ml_toolchain//cc:linux_aarch64_linux_aarch64") +# register_toolchains("@rules_ml_toolchain//cc:linux_aarch64_linux_aarch64_cuda") + +# Initialize hermetic Python +load("@org_tensorflow//third_party/py:python_init_rules.bzl", "python_init_rules") +python_init_rules() + +load("@org_tensorflow//third_party/py:python_init_repositories.bzl", "python_init_repositories") +python_init_repositories( + default_python_version = "system", + requirements = { + "3.10": "@org_tensorflow//:requirements_lock_3_10.txt", + "3.11": "@org_tensorflow//:requirements_lock_3_11.txt", + "3.12": "@org_tensorflow//:requirements_lock_3_12.txt", + "3.13": "@org_tensorflow//:requirements_lock_3_13.txt", + }, +) + +load("@org_tensorflow//third_party/py:python_init_toolchains.bzl", "python_init_toolchains") +python_init_toolchains() + +load("@org_tensorflow//third_party/py:python_init_pip.bzl", "python_init_pip") +python_init_pip() + +load("@pypi//:requirements.bzl", "install_deps") +install_deps() + +# Initialize TensorFlow's external dependencies. +load("@org_tensorflow//tensorflow:workspace3.bzl", "tf_workspace3") +tf_workspace3() + +load("//tensorflow_serving:repo.bzl", "tf_serving_vendored") + +tf_serving_vendored( + name = "local_xla", + path = "third_party/xla", + repo_mapping = { + "@local_xla": "@local_xla", + "@local_tsl": "@local_tsl", + "@org_tensorflow": "@org_tensorflow", + "@xla": "@local_xla", + "@tsl": "@local_tsl", + }, + root = "@org_tensorflow//:unused", +) + +tf_serving_vendored( + name = "local_tsl", + path = "third_party/xla/third_party/tsl", + repo_mapping = { + "@local_xla": "@local_xla", + "@local_tsl": "@local_tsl", + "@org_tensorflow": "@org_tensorflow", + "@xla": "@local_xla", + "@tsl": "@local_tsl", + }, + root = "@org_tensorflow//:unused", +) +load("@org_tensorflow//tensorflow:workspace2.bzl", "tf_workspace2") +tf_workspace2() +load("@org_tensorflow//tensorflow:workspace1.bzl", "tf_workspace1") +tf_workspace1() +load("@org_tensorflow//tensorflow:workspace0.bzl", "tf_workspace0") +tf_workspace0() + +# Initialize bazel package rules' external dependencies. +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") +rules_pkg_dependencies() + +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +http_archive( + name = "rules_shell", + sha256 = "0d0c56d01c3c40420bf7bf14d73113f8a92fbd9f5cd13205a3b89f72078f0321", + strip_prefix = "rules_shell-0.1.1", + urls = [ + "https://github.com/bazelbuild/rules_shell/releases/download/v0.1.1/rules_shell-v0.1.1.tar.gz", + ], +) + +load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies") + +rules_proto_dependencies() + +load( + "@xla//third_party/py:python_wheel.bzl", + "python_wheel_version_suffix_repository", +) + +python_wheel_version_suffix_repository(name = "tf_wheel_version_suffix") + +load( + "@rules_ml_toolchain//gpu/cuda:cuda_json_init_repository.bzl", + "cuda_json_init_repository", +) + +cuda_json_init_repository() + +load( + "@cuda_redist_json//:distributions.bzl", + "CUDA_REDISTRIBUTIONS", + "CUDNN_REDISTRIBUTIONS", +) +load( + "@rules_ml_toolchain//gpu/cuda:cuda_redist_init_repositories.bzl", + "cuda_redist_init_repositories", + "cudnn_redist_init_repository", +) + +cuda_redist_init_repositories( + cuda_redistributions = CUDA_REDISTRIBUTIONS, +) + +cudnn_redist_init_repository( + cudnn_redistributions = CUDNN_REDISTRIBUTIONS, +) + +load( + "@rules_ml_toolchain//gpu/cuda:cuda_configure.bzl", + "cuda_configure", +) + +cuda_configure(name = "local_config_cuda") + +load( + "@rules_ml_toolchain//gpu/nccl:nccl_redist_init_repository.bzl", + "nccl_redist_init_repository", +) + +nccl_redist_init_repository() + +load( + "@rules_ml_toolchain//gpu/nccl:nccl_configure.bzl", + "nccl_configure", +) + +nccl_configure(name = "local_config_nccl") + +load( + "@rules_ml_toolchain//gpu/nvshmem:nvshmem_json_init_repository.bzl", + "nvshmem_json_init_repository", +) + +nvshmem_json_init_repository() + +load( + "@nvshmem_redist_json//:distributions.bzl", + "NVSHMEM_REDISTRIBUTIONS", +) +load( + "@rules_ml_toolchain//gpu/nvshmem:nvshmem_redist_init_repository.bzl", + "nvshmem_redist_init_repository", +) + +nvshmem_redist_init_repository( + nvshmem_redistributions = NVSHMEM_REDISTRIBUTIONS, +) + +# nvshmem_configure removed in newer rules_ml_toolchain + diff --git a/tensorflow_serving/tools/docker/Dockerfile.devel b/tensorflow_serving/tools/docker/Dockerfile.devel index 7c79a983f49..9f9286ecf7a 100644 --- a/tensorflow_serving/tools/docker/Dockerfile.devel +++ b/tensorflow_serving/tools/docker/Dockerfile.devel @@ -101,7 +101,7 @@ RUN echo "Building with build options: ${TF_SERVING_BUILD_OPTIONS}" ARG TF_SERVING_BAZEL_OPTIONS="" RUN echo "Building with Bazel options: ${TF_SERVING_BAZEL_OPTIONS}" -RUN bazel build --color=yes --curses=yes \ +RUN bazel build --color=yes --noshow_progress --curses=no \ ${TF_SERVING_BAZEL_OPTIONS} \ --verbose_failures \ --output_filter=DONT_MATCH_ANYTHING \ @@ -111,7 +111,7 @@ RUN bazel build --color=yes --curses=yes \ /usr/local/bin/ # Build and install TensorFlow Serving API -RUN bazel build --color=yes --curses=yes \ +RUN bazel build --color=yes --noshow_progress --curses=no \ ${TF_SERVING_BAZEL_OPTIONS} \ --verbose_failures \ --output_filter=DONT_MATCH_ANYTHING \ diff --git a/tensorflow_serving/tools/docker/Dockerfile.devel-gpu b/tensorflow_serving/tools/docker/Dockerfile.devel-gpu index cde11aa6fe4..e914bc214ef 100644 --- a/tensorflow_serving/tools/docker/Dockerfile.devel-gpu +++ b/tensorflow_serving/tools/docker/Dockerfile.devel-gpu @@ -11,7 +11,7 @@ # 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. -FROM nvidia/cuda:12.5.1-base-ubuntu22.04 as base_build +FROM nvidia/cuda:12.2.2-base-ubuntu22.04 as base_build ARG TF_SERVING_VERSION_GIT_BRANCH=master ARG TF_SERVING_VERSION_GIT_COMMIT=HEAD @@ -23,7 +23,11 @@ LABEL tensorflow_serving_github_commit=${TF_SERVING_VERSION_GIT_COMMIT} ENV CUDNN_VERSION=9.3.0.75 ENV TF_TENSORRT_VERSION=8.6.1 -ENV CUDA=12.5 +ENV CUDA=12.2 +ENV HERMETIC_CUDA_VERSION=12.2.0 + +ARG TF_CUDA_COMPUTE_CAPABILITIES="6.0,7.0,7.5,8.0,8.6,8.9,9.0" +ENV TF_CUDA_COMPUTE_CAPABILITIES=${TF_CUDA_COMPUTE_CAPABILITIES} RUN apt-get update && apt-get install -y --no-install-recommends \ curl @@ -35,21 +39,21 @@ RUN curl -sSL --retry 5 https://github.com/tensorflow/serving/tarball/${TF_SERVI RUN /tensorflow-serving/tensorflow_serving/tools/docker/setup.sources.sh RUN apt-get install -y --no-install-recommends \ - cuda-command-line-tools-12-5 \ - cuda-cudart-dev-12-5 \ - cuda-nvcc-12-5 \ - cuda-cupti-12-5 \ - cuda-nvprune-12-5 \ - cuda-libraries-12-5 \ - cuda-libraries-dev-12-5 \ - cuda-nvml-dev-12-5 \ - libcufft-12-5 \ - libcurand-12-5 \ - libcusolver-dev-12-5 \ - libcusparse-dev-12-5 \ - libcublas-12-5 \ - libcublas-dev-12-5 \ - cuda-compat-12-5 \ + cuda-command-line-tools-12-2 \ + cuda-cudart-dev-12-2 \ + cuda-nvcc-12-2 \ + cuda-cupti-12-2 \ + cuda-nvprune-12-2 \ + cuda-libraries-12-2 \ + cuda-libraries-dev-12-2 \ + cuda-nvml-dev-12-2 \ + libcufft-12-2 \ + libcurand-12-2 \ + libcusolver-dev-12-2 \ + libcusparse-dev-12-2 \ + libcublas-12-2 \ + libcublas-dev-12-2 \ + cuda-compat-12-2 \ libnccl-dev=2.25.1-1+cuda12.8 \ libnccl2=2.25.1-1+cuda12.8 \ libcudnn9-dev-cuda-12=9.3.0.75-1 \ @@ -150,12 +154,12 @@ FROM base_build as binary_build # Build, and install TensorFlow Serving ARG TF_SERVING_BUILD_OPTIONS="--config=release" RUN echo "Building with build options: ${TF_SERVING_BUILD_OPTIONS}" -ARG TF_SERVING_BAZEL_OPTIONS="" +ARG TF_SERVING_BAZEL_OPTIONS="--repo_env=HERMETIC_CUDA_VERSION=12.2.0 --repo_env=HERMETIC_CUDA_COMPUTE_CAPABILITIES=7.0,7.5,8.0,8.6,8.9,9.0" RUN echo "Building with Bazel options: ${TF_SERVING_BAZEL_OPTIONS}" RUN ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/stubs/libcuda.so.1 && \ LD_LIBRARY_PATH=/usr/local/cuda/lib64/stubs:${LD_LIBRARY_PATH} \ - bazel build --color=yes --curses=yes --config=cuda_clang --copt="-fPIC"\ + bazel build --color=yes --noshow_progress --curses=no --config=cuda_clang --copt="-fPIC"\ ${TF_SERVING_BAZEL_OPTIONS} \ --verbose_failures \ --output_filter=DONT_MATCH_ANYTHING \ @@ -166,7 +170,7 @@ RUN ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/stubs/lib rm /usr/local/cuda/lib64/stubs/libcuda.so.1 # Build and install TensorFlow Serving API -RUN bazel build --color=yes --curses=yes \ +RUN bazel build --color=yes --noshow_progress --curses=no \ ${TF_SERVING_BAZEL_OPTIONS} \ --verbose_failures \ --output_filter=DONT_MATCH_ANYTHING \ diff --git a/tensorflow_serving/tools/docker/Dockerfile.devel-mkl b/tensorflow_serving/tools/docker/Dockerfile.devel-mkl index 0a74fccc7a2..d87be197933 100644 --- a/tensorflow_serving/tools/docker/Dockerfile.devel-mkl +++ b/tensorflow_serving/tools/docker/Dockerfile.devel-mkl @@ -103,7 +103,7 @@ RUN echo "Building with build options: ${TF_SERVING_BUILD_OPTIONS}" ARG TF_SERVING_BAZEL_OPTIONS="" RUN echo "Building with Bazel options: ${TF_SERVING_BAZEL_OPTIONS}" -RUN bazel build --color=yes --curses=yes \ +RUN bazel build --color=yes --noshow_progress --curses=no \ ${TF_SERVING_BAZEL_OPTIONS} \ --verbose_failures \ --output_filter=DONT_MATCH_ANYTHING \ @@ -113,7 +113,7 @@ RUN bazel build --color=yes --curses=yes \ /usr/local/bin/ # Build and install TensorFlow Serving API -RUN bazel build --color=yes --curses=yes \ +RUN bazel build --color=yes --noshow_progress --curses=no \ ${TF_SERVING_BAZEL_OPTIONS} \ --verbose_failures \ --output_filter=DONT_MATCH_ANYTHING \ diff --git a/tensorflow_serving/tools/docker/Dockerfile.gpu b/tensorflow_serving/tools/docker/Dockerfile.gpu index cee40ca9c9d..61389cce562 100644 --- a/tensorflow_serving/tools/docker/Dockerfile.gpu +++ b/tensorflow_serving/tools/docker/Dockerfile.gpu @@ -16,7 +16,7 @@ ARG TF_SERVING_VERSION=latest ARG TF_SERVING_BUILD_IMAGE=tensorflow/serving:${TF_SERVING_VERSION}-devel-gpu FROM ${TF_SERVING_BUILD_IMAGE} as build_image -FROM nvidia/cuda:12.5.1-base-ubuntu22.04 as base_build +FROM nvidia/cuda:12.2.2-base-ubuntu22.04 as base_build ARG TF_SERVING_VERSION_GIT_BRANCH=master ARG TF_SERVING_VERSION_GIT_COMMIT=HEAD @@ -28,7 +28,8 @@ LABEL tensorflow_serving_github_commit=${TF_SERVING_VERSION_GIT_COMMIT} ENV CUDNN_VERSION=9.3.0.75 ENV TF_TENSORRT_VERSION=8.6.1 -ENV CUDA=12.5 +ENV CUDA=12.2 +ENV HERMETIC_CUDA_VERSION=12.2.0 ENV LD_LIBRARY_PATH /usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -38,22 +39,22 @@ RUN curl -sSL --retry 5 https://raw.githubusercontent.com/tensorflow/serving/${T RUN apt-get install -y --no-install-recommends \ ca-certificates \ - cuda-command-line-tools-12-5 \ - cuda-cupti-12-5 \ - cuda-libraries-12-5 \ - cuda-nvcc-12-5 \ - cuda-nvprune-12-5 \ - cuda-nvrtc-12-5 \ - libcublas-12-5 \ + cuda-command-line-tools-12-2 \ + cuda-cupti-12-2 \ + cuda-libraries-12-2 \ + cuda-nvcc-12-2 \ + cuda-nvprune-12-2 \ + cuda-nvrtc-12-2 \ + libcublas-12-2 \ libcudnn9-cuda-12 \ - libcufft-12-5 \ - libcurand-12-5 \ - libcusolver-12-5 \ - libcusparse-12-5 \ + libcufft-12-2 \ + libcurand-12-2 \ + libcusolver-12-2 \ + libcusparse-12-2 \ libnccl2 \ libnvinfer8 \ libnvinfer-plugin8 \ - cuda-compat-12-5 \ + cuda-compat-12-2 \ libgomp1 \ build-essential \ curl \ diff --git a/third_party/libevent/BUILD b/third_party/libevent/BUILD index 4a6dc97805f..fae802152c7 100644 --- a/third_party/libevent/BUILD +++ b/third_party/libevent/BUILD @@ -51,18 +51,28 @@ lib_files = [ genrule( name = "libevent-srcs", + srcs = glob(["**"]) + ["@sysroot_linux_x86_64//:sysroot"], outs = include_files + lib_files, cmd = "\n".join([ "export INSTALL_DIR=$$(pwd)/$(@D)/libevent", + "export ORIG_DIR=$$(pwd) # force rebuild 1", + "export CC_PATH=$(CC)", + "if [[ $$CC_PATH != /* ]]; then CC_PATH=$$ORIG_DIR/$$CC_PATH; fi", + "export REAL_CLANG=$$(ls $$ORIG_DIR/external/llvm*_linux_x86_64/bin/clang | head -n 1)", + "export GCC_PATH=$$REAL_CLANG", + "export REAL_AR=$$(ls $$ORIG_DIR/external/llvm*_linux_x86_64/bin/llvm-ar | head -n 1)", + "export SYSROOT_DIR=$$(ls -d $$ORIG_DIR/external/sysroot_linux_x86_64_glibc_* | head -n 1)", "export TMP_DIR=$$(mktemp -d -t libevent.XXXXXX)", "mkdir -p $$TMP_DIR", - "cp -R $$(pwd)/external/com_github_libevent_libevent/* $$TMP_DIR", + "cp -R $$ORIG_DIR/external/com_github_libevent_libevent/* $$TMP_DIR", "cd $$TMP_DIR", "./autogen.sh", - "./configure --prefix=$$INSTALL_DIR CFLAGS=-fPIC CXXFLAGS=-fPIC --enable-shared=no --disable-openssl", - "make install", + "CC=$$CC_PATH AR=$$REAL_AR ./configure --prefix=$$INSTALL_DIR CFLAGS=\"-fPIC --sysroot=$$SYSROOT_DIR\" CXXFLAGS=\"-fPIC --sysroot=$$SYSROOT_DIR\" LDFLAGS=\"--sysroot=$$SYSROOT_DIR\" --enable-shared=no --disable-openssl || (cat config.log && false)", + "make install CC=$$CC_PATH AR=$$REAL_AR", "rm -rf $$TMP_DIR", ]), + local = 1, + toolchains = ["@bazel_tools//tools/cpp:current_cc_toolchain"], ) cc_library( diff --git a/third_party/tensorflow/tensorflow.patch b/third_party/tensorflow/tensorflow.patch index 75aa4f5f2ff..e69de29bb2d 100644 --- a/third_party/tensorflow/tensorflow.patch +++ b/third_party/tensorflow/tensorflow.patch @@ -1,10 +0,0 @@ -diff --git a/tensorflow/tools/toolchains/python/python_repo.bzl b/tensorflow/tools/toolchains/python/python_repo.bzl ---- a/tensorflow/tools/toolchains/python/python_repo.bzl -+++ b/tensorflow/tools/toolchains/python/python_repo.bzl -@@ -21,5 +21,6 @@ - TF_PYTHON_VERSION = "{}" - HERMETIC_PYTHON_VERSION = "{}" - WHEEL_NAME = "{}" - WHEEL_COLLAB = "{}" -+USE_PYWRAP_RULES = "False" - """