Skip to content

Commit c2126b1

Browse files
authored
fix: Update Docker build to automatically adapt Torch version (#1732)
1 parent 83923ee commit c2126b1

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

docker/Dockerfile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
ARG BASE_IMG=nvidia/cuda:11.7.1-devel-ubuntu20.04
33
FROM ${BASE_IMG} as base
44

5+
ARG USE_CXX11_ABI
6+
ENV USE_CXX11=${USE_CXX11_ABI}
7+
58
# Install basic dependencies
69
RUN apt-get update
710
RUN DEBIAN_FRONTEND=noninteractive apt install -y build-essential manpages-dev wget zlib1g software-properties-common git
@@ -12,9 +15,6 @@ RUN ln -s /usr/bin/python3.8 /usr/bin/python
1215
RUN python get-pip.py
1316
RUN pip3 install wheel
1417

15-
# Install Pytorch
16-
RUN pip3 install torch==2.0.0.dev20230103+cu117 torchvision==0.15.0.dev20230103+cu117 --extra-index-url https://download.pytorch.org/whl/nightly/cu117
17-
1818
# Install CUDNN + TensorRT
1919
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
2020
RUN mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
@@ -32,8 +32,7 @@ RUN apt-get update
3232
RUN apt-get install -y libnvinfer8=8.5.1* libnvinfer-plugin8=8.5.1* libnvinfer-dev=8.5.1* libnvinfer-plugin-dev=8.5.1* libnvonnxparsers8=8.5.1-1* libnvonnxparsers-dev=8.5.1-1* libnvparsers8=8.5.1-1* libnvparsers-dev=8.5.1-1*
3333

3434
# Setup Bazel
35-
ARG BAZEL_VERSION=5.2.0
36-
RUN wget -q https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-x86_64 -O /usr/bin/bazel \
35+
RUN wget -q https://github.com/bazelbuild/bazelisk/releases/download/v1.16.0/bazelisk-linux-amd64 -O /usr/bin/bazel \
3736
&& chmod a+x /usr/bin/bazel
3837

3938
# Build Torch-TensorRT in an auxillary container
@@ -44,7 +43,6 @@ ARG TARGETARCH="amd64"
4443

4544
RUN apt-get install -y python3-setuptools
4645
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
47-
RUN apt-get update
4846

4947
RUN apt-get update && apt-get install -y --no-install-recommends locales ninja-build && rm -rf /var/lib/apt/lists/* && locale-gen en_US.UTF-8
5048

@@ -64,11 +62,9 @@ COPY . /opt/torch_tensorrt
6462
COPY --from=torch-tensorrt-builder /workspace/torch_tensorrt/src/py/dist/ .
6563

6664
RUN cp /opt/torch_tensorrt/docker/WORKSPACE.docker /opt/torch_tensorrt/WORKSPACE
65+
RUN pip install -r /opt/torch_tensorrt/py/requirements.txt
6766
RUN pip3 install *.whl && rm -fr /workspace/torch_tensorrt/py/dist/* *.whl
6867

69-
# Install native tensorrt python package required by torch_tensorrt whl file
70-
RUN pip install tensorrt==8.5.1.7
71-
7268
WORKDIR /opt/torch_tensorrt
7369
ENV LD_LIBRARY_PATH /usr/local/lib/python3.8/dist-packages/torch/lib:/usr/local/lib/python3.8/dist-packages/torch_tensorrt/lib:/usr/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}
7470
ENV PATH /usr/local/lib/python3.8/dist-packages/torch_tensorrt/bin:${PATH}

docker/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* `Dockerfile` currently uses the exact library versions (Torch, CUDA, CUDNN, TensorRT) listed in <a href="https://github.com/pytorch/TensorRT#dependencies">dependencies</a> to build Torch-TensorRT.
66

77
* This `Dockerfile` installs `pre-cxx11-abi` versions of Pytorch and builds Torch-TRT using `pre-cxx11-abi` libtorch as well.
8-
Note: To install `cxx11_abi` version of Torch-TensorRT, enable `USE_CXX11=1` flag so that `dist-build.sh` can build it accordingly.
8+
9+
Note: By default the container uses the `pre-cxx11-abi` version of Torch + Torch-TRT. If you are using a workflow that requires a build of PyTorch on the CXX11 ABI (e.g. using the PyTorch NGC containers as a base image), add the Docker build argument: `--build-arg USE_CXX11_ABI=1`
910

1011
### Dependencies
1112

@@ -38,4 +39,4 @@ bazel test //tests/core/conversion/converters:test_activation --compilation_mode
3839

3940
### Pytorch NGC containers
4041

41-
We also ship Torch-TensorRT in <a href="https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch">Pytorch NGC containers </a>. Release notes for these containers can be found <a href="https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/index.html">here</a>. Check out `release/ngc/23.XX` branch of Torch-TensorRT for source code that gets shipped with `23.XX` version of Pytorch NGC container.
42+
We also ship Torch-TensorRT in <a href="https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch">Pytorch NGC containers </a>. Release notes for these containers can be found <a href="https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/index.html">here</a>. Check out `release/ngc/23.XX` branch of Torch-TensorRT for source code that gets shipped with `23.XX` version of Pytorch NGC container.

docker/WORKSPACE.docker

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,16 @@ new_local_repository(
4848
# Tarballs and fetched dependencies (default - use in cases when building from precompiled bin and tarballs)
4949
#############################################################################################################
5050

51-
http_archive(
51+
new_local_repository(
5252
name = "libtorch",
53-
build_file = "@//third_party/libtorch:BUILD",
54-
sha256 = "59b8b5e1954a86d50b79c13f06398d385b200da13e37a08ecf31d3c62e5ca127",
55-
strip_prefix = "libtorch",
56-
urls = ["https://download.pytorch.org/libtorch/nightly/cu117/libtorch-cxx11-abi-shared-with-deps-2.0.0.dev20230103%2Bcu117.zip"],
53+
path = "/usr/local/lib/python3.8/dist-packages/torch/",
54+
build_file = "third_party/libtorch/BUILD"
5755
)
5856

59-
http_archive(
57+
new_local_repository(
6058
name = "libtorch_pre_cxx11_abi",
61-
build_file = "@//third_party/libtorch:BUILD",
62-
sha256 = "e260fc7476be89d1650953e8643e9f7363845f5a52de4bab87ac0e619c1f6ad4",
63-
strip_prefix = "libtorch",
64-
urls = ["https://download.pytorch.org/libtorch/nightly/cu117/libtorch-shared-with-deps-2.0.0.dev20230103%2Bcu117.zip"],
59+
path = "/usr/local/lib/python3.8/dist-packages/torch/",
60+
build_file = "third_party/libtorch/BUILD"
6561
)
6662

6763
####################################################################################

py/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
numpy
2+
packaging
23
pybind11==2.6.2
34
--extra-index-url https://download.pytorch.org/whl/nightly/cu117
45
torch==2.1.0.dev20230314+cu117

0 commit comments

Comments
 (0)