From b8ff2d5715f03cc4f103a4ec4a8a3861ca65aaba Mon Sep 17 00:00:00 2001 From: lanluo-nvidia Date: Thu, 15 Aug 2024 21:23:53 -0700 Subject: [PATCH] Fix docker build issue (#3070) --- docker/Dockerfile | 14 ++++-- docker/MODULE.bazel.docker | 77 +++++++++++++++++++++++++++++++++ docker/WORKSPACE.docker | 89 -------------------------------------- docker/dist-build.sh | 2 + py/requirements.txt | 2 +- pyproject.toml | 2 +- 6 files changed, 92 insertions(+), 94 deletions(-) create mode 100644 docker/MODULE.bazel.docker delete mode 100755 docker/WORKSPACE.docker diff --git a/docker/Dockerfile b/docker/Dockerfile index 9d20c2f6e8..b8634ef21a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -67,9 +67,13 @@ RUN apt-get update &&\ FROM torch-tensorrt-builder-base as torch-tensorrt-builder +RUN curl -L https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-`uname -s`-`uname -m` -o envsubst &&\ + chmod +x envsubst && mv envsubst /usr/local/bin + COPY . /workspace/torch_tensorrt/src WORKDIR /workspace/torch_tensorrt/src -RUN cp ./docker/WORKSPACE.docker WORKSPACE + +RUN cat ./docker/MODULE.bazel.docker | envsubst > MODULE.bazel # Symlink the path pyenv is using for python with the /opt directory for package sourcing RUN mkdir -p "/opt/python3/" &&\ @@ -99,8 +103,12 @@ RUN mkdir -p "/opt/python3/" &&\ COPY --from=torch-tensorrt-builder /workspace/torch_tensorrt/src/dist/ . -RUN cp /opt/torch_tensorrt/docker/WORKSPACE.docker /opt/torch_tensorrt/WORKSPACE &&\ - pip install -r /opt/torch_tensorrt/py/requirements.txt &&\ +RUN curl -L https://github.com/a8m/envsubst/releases/download/v1.2.0/envsubst-`uname -s`-`uname -m` -o envsubst &&\ + chmod +x envsubst && mv envsubst /usr/local/bin + +RUN cat ./docker/MODULE.bazel.docker | envsubst > MODULE.bazel + +RUN pip install -r /opt/torch_tensorrt/py/requirements.txt &&\ # Install all dependency wheel files and user-specified TensorRT pip install *.whl &&\ pip install tensorrt==${TENSORRT_VERSION}.* &&\ diff --git a/docker/MODULE.bazel.docker b/docker/MODULE.bazel.docker new file mode 100644 index 0000000000..d8440552e8 --- /dev/null +++ b/docker/MODULE.bazel.docker @@ -0,0 +1,77 @@ +module( + name = "torch_tensorrt", + repo_name = "org_pytorch_tensorrt", + version = "${BUILD_VERSION}" +) + +bazel_dep(name = "googletest", version = "1.14.0") +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "rules_python", version = "0.34.0") + +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain( + ignore_root_user_error = True, + python_version = "3.11", +) + +bazel_dep(name = "rules_pkg", version = "1.0.1") +git_override( + module_name = "rules_pkg", + commit = "17c57f4", + remote = "https://github.com/narendasan/rules_pkg", +) + +local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") + + +new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository") + +# CUDA should be installed on the system locally +new_local_repository( + name = "cuda", + build_file = "@//third_party/cuda:BUILD", + path = "/usr/local/cuda", +) + +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +#################################################################################### +# Locally installed dependencies (use in cases of custom dependencies or aarch64) +#################################################################################### + +# NOTE: In the case you are using just the pre-cxx11-abi path or just the cxx11 abi path +# with your local libtorch, just point deps at the same path to satisfy bazel. + +# NOTE: NVIDIA's aarch64 PyTorch (python) wheel file uses the CXX11 ABI unlike PyTorch's standard +# x86_64 python distribution. If using NVIDIA's version just point to the root of the package +# for both versions here and do not use --config=pre-cxx11-abi + +new_local_repository( + name = "libtorch", + path = "/opt/python3/site-packages/torch/", + build_file = "third_party/libtorch/BUILD" +) + +new_local_repository( + name = "libtorch_pre_cxx11_abi", + path = "/opt/python3/site-packages/torch/", + build_file = "third_party/libtorch/BUILD" +) + +new_local_repository( + name = "tensorrt", + path = "/usr/", + build_file = "@//third_party/tensorrt/local:BUILD" +) + +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") + +pip.parse( + download_only = True, + hub_name = "pypi", + python_version = ${PYTHON_VERSION}, + requirements_lock = "//:requirements_dev.txt", +) + +use_repo(pip, "pypi") \ No newline at end of file diff --git a/docker/WORKSPACE.docker b/docker/WORKSPACE.docker deleted file mode 100755 index 461a22147f..0000000000 --- a/docker/WORKSPACE.docker +++ /dev/null @@ -1,89 +0,0 @@ -workspace(name = "Torch-TensorRT") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "rules_python", - sha256 = "863ba0fa944319f7e3d695711427d9ad80ba92c6edd0b7c7443b84e904689539", - strip_prefix = "rules_python-0.22.0", - url = "https://github.com/bazelbuild/rules_python/releases/download/0.22.0/rules_python-0.22.0.tar.gz", -) - -load("@rules_python//python:repositories.bzl", "py_repositories") - -py_repositories() - -http_archive( - name = "rules_pkg", - sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", - "https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz", - ], -) - -load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") - -rules_pkg_dependencies() - -http_archive( - name = "googletest", - sha256 = "755f9a39bc7205f5a0c428e920ddad092c33c8a1b46997def3f1d4a82aded6e1", - strip_prefix = "googletest-5ab508a01f9eb089207ee87fd547d290da39d015", - urls = ["https://github.com/google/googletest/archive/5ab508a01f9eb089207ee87fd547d290da39d015.zip"], -) - - -# CUDA should be installed on the system locally -new_local_repository( - name = "cuda", - path = "/usr/local/cuda/", - build_file = "@//third_party/cuda:BUILD", -) - -new_local_repository( - name = "cublas", - path = "/usr", - build_file = "@//third_party/cublas:BUILD", -) - -############################################################################################################# -# Tarballs and fetched dependencies (default - use in cases when building from precompiled bin and tarballs) -############################################################################################################# - -new_local_repository( - name = "libtorch", - path = "/opt/python3/site-packages/torch/", - build_file = "third_party/libtorch/BUILD" -) - -new_local_repository( - name = "libtorch_pre_cxx11_abi", - path = "/opt/python3/site-packages/torch/", - build_file = "third_party/libtorch/BUILD" -) - -#################################################################################### -# Locally installed dependencies (use in cases of custom dependencies or aarch64) -#################################################################################### - -new_local_repository( - name = "tensorrt", - path = "/usr/", - build_file = "@//third_party/tensorrt/local:BUILD" -) - -######################################################################### -# Testing Dependencies (optional - comment out on aarch64) -######################################################################### - -load("@rules_python//python:pip.bzl", "pip_parse") - -pip_parse( - name = "devtools_deps", - requirements = "//:requirements-dev.txt", -) - -load("@devtools_deps//:requirements.bzl", "install_deps") - -install_deps() diff --git a/docker/dist-build.sh b/docker/dist-build.sh index 1f1faec6ed..04d2e8b84a 100755 --- a/docker/dist-build.sh +++ b/docker/dist-build.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -x + TOP_DIR=$(cd $(dirname $0); pwd)/.. if [[ -z "${USE_CXX11}" ]]; then diff --git a/py/requirements.txt b/py/requirements.txt index 649ea09706..288d766fa6 100644 --- a/py/requirements.txt +++ b/py/requirements.txt @@ -3,7 +3,7 @@ packaging pybind11==2.6.2 --extra-index-url https://download.pytorch.org/whl/nightly/cu124 torch>=2.5.0.dev,<2.6.0 -torchvision>=0.19.0.dev,<0.20.0 +torchvision>=0.20.0.dev,<0.21.0 --extra-index-url https://pypi.ngc.nvidia.com pyyaml tensorrt==10.1.0 diff --git a/pyproject.toml b/pyproject.toml index 0bd3217be8..1d6570db90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ dependencies = [ dynamic = ["version"] [project.optional-dependencies] -torchvision = ["torchvision >=0.18.dev,<0.19.0"] +torchvision = ["torchvision >=0.20.dev,<0.21.0"] [project.urls] Homepage = "https://pytorch.org/tensorrt"