Skip to content

Commit 74b3464

Browse files
authored
feat: Dockerfile restructure for 1.3 release (#1492)
Signed-off-by: Dheeraj Peri <[email protected]>
1 parent fe37a86 commit 74b3464

File tree

10 files changed

+94
-169
lines changed

10 files changed

+94
-169
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ torch.jit.save(trt_ts_module, "trt_torchscript_module.ts") # save the TRT embedd
110110
111111
### Dependencies
112112

113-
These are the following dependencies used to verify the testcases. Torch-TensorRT can work with other versions, but the tests are not guaranteed to pass.
113+
These are the following dependencies used to verify the testcases. Check out `py/requirements.txt` for python dependencies. Torch-TensorRT can work with other versions, but the tests are not guaranteed to pass.
114114

115115
- Bazel 5.2.0
116116
- Libtorch 1.13.0 (built with CUDA 11.7)

docker/Dockerfile

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,80 @@
1-
ARG BASE=22.04
2-
ARG BASE_IMG=nvcr.io/nvidia/tensorrt:${BASE}-py3
1+
# Base image starts with CUDA
2+
ARG BASE_IMG=nvidia/cuda:11.7.1-devel-ubuntu18.04
33
FROM ${BASE_IMG} as base
44

5-
FROM base as torch-tensorrt-builder-base
5+
# Install basic dependencies
6+
RUN apt-get update
7+
RUN apt install -y build-essential manpages-dev wget zlib1g software-properties-common git
8+
RUN add-apt-repository ppa:deadsnakes/ppa
9+
RUN apt install -y python3.8 python3.8-distutils python3.8-dev
10+
RUN wget https://bootstrap.pypa.io/get-pip.py
11+
RUN ln -s /usr/bin/python3.8 /usr/bin/python
12+
RUN python get-pip.py
13+
RUN pip3 install wheel
14+
15+
# Install Pytorch
16+
RUN pip3 install torch==1.13.0 torchvision==0.14.0
17+
18+
# Install CUDNN + TensorRT
19+
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
20+
RUN mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
21+
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
22+
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 536F8F1DE80F6A35
23+
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
24+
RUN add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
25+
RUN apt-get update
26+
RUN apt-get install -y libcudnn8=8.5.0* libcudnn8-dev=8.5.0*
27+
28+
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
29+
RUN add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
30+
RUN apt-get update
31+
32+
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*
33+
34+
# 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 \
37+
&& chmod a+x /usr/bin/bazel
38+
39+
# Remove cuda symlink to avoid bazel circle symlink errors
40+
RUN rm /usr/local/cuda-11.7/cuda-11.7
641

7-
# Removing any bazel or torch-tensorrt pre-installed from the base image
8-
RUN rm -rf /opt/pytorch/torch_tensorrt /usr/bin/bazel
42+
# Build Torch-TensorRT in an auxillary container
43+
FROM base as torch-tensorrt-builder-base
944

1045
ARG ARCH="x86_64"
1146
ARG TARGETARCH="amd64"
12-
ARG BAZEL_VERSION=5.2.0
13-
14-
RUN [[ "$TARGETARCH" == "amd64" ]] && ARCH="x86_64" || ARCH="${TARGETARCH}" \
15-
&& wget -q https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-linux-${ARCH} -O /usr/bin/bazel \
16-
&& chmod a+x /usr/bin/bazel
1747

18-
# Workaround for bazel expecting both static and shared versions, we only use shared libraries inside container
19-
RUN touch /usr/lib/$HOSTTYPE-linux-gnu/libnvinfer_static.a
20-
21-
RUN rm -rf /usr/local/cuda/lib* /usr/local/cuda/include \
22-
&& ln -sf /usr/local/cuda/targets/$HOSTTYPE-linux/lib /usr/local/cuda/lib64 \
23-
&& ln -sf /usr/local/cuda/targets/$HOSTTYPE-linux/include /usr/local/cuda/include
48+
RUN apt-get install -y python3-setuptools
49+
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
50+
RUN apt-get update
2451

2552
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
2653

2754
FROM torch-tensorrt-builder-base as torch-tensorrt-builder
2855

29-
# Removing any bazel or torch-tensorrt pre-installed from the base image
30-
RUN rm -rf /opt/pytorch/torch_tensorrt
31-
3256
COPY . /workspace/torch_tensorrt/src
3357
WORKDIR /workspace/torch_tensorrt/src
3458
RUN cp ./docker/WORKSPACE.docker WORKSPACE
3559

3660
# This script builds both libtorchtrt bin/lib/include tarball and the Python wheel, in dist/
3761
RUN ./docker/dist-build.sh
3862

63+
# Copy and install Torch-TRT into the main container
3964
FROM base as torch-tensorrt
4065

41-
# Removing any bazel or torch-tensorrt pre-installed from the base image
42-
RUN rm -rf /opt/pytorch/torch_tensorrt
43-
44-
# copy source repo
45-
COPY . /workspace/torch_tensorrt
66+
COPY . /opt/torch_tensorrt
4667
COPY --from=torch-tensorrt-builder /workspace/torch_tensorrt/src/py/dist/ .
4768

48-
RUN pip3 install ipywidgets --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org
49-
RUN jupyter nbextension enable --py widgetsnbextension
50-
69+
RUN cp /opt/torch_tensorrt/docker/WORKSPACE.docker /opt/torch_tensorrt/WORKSPACE
5170
RUN pip3 install *.whl && rm -fr /workspace/torch_tensorrt/py/dist/* *.whl
5271

53-
ENV LD_LIBRARY_PATH /usr/local/lib/python3.8/dist-packages/torch/lib:/usr/local/lib/python3.8/dist-packages/torch_tensorrt/lib:${LD_LIBRARY_PATH}
72+
# Install native tensorrt python package required by torch_tensorrt whl file
73+
RUN pip install nvidia-pyindex
74+
RUN pip install nvidia-tensorrt
75+
76+
WORKDIR /opt/torch_tensorrt
77+
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}
5478
ENV PATH /usr/local/lib/python3.8/dist-packages/torch_tensorrt/bin:${PATH}
55-
#
56-
WORKDIR /workspace
57-
RUN mv /workspace/torch_tensorrt /opt/torch_tensorrt
58-
RUN cp /opt/torch_tensorrt/docker/WORKSPACE.docker /opt/torch_tensorrt/WORKSPACE
59-
RUN mkdir torch_tensorrt
60-
RUN ln -s /opt/torch_tensorrt/notebooks /workspace/torch_tensorrt/notebooks
6179

6280
CMD /bin/bash

docker/Dockerfile.ngc

Lines changed: 0 additions & 63 deletions
This file was deleted.

docker/README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,41 @@
11
# Building a Torch-TensorRT container
22

3-
### Install Docker and NVIDIA Container Toolkit
3+
* Use `Dockerfile` to build a container which provides the exact development environment that our master branch is usually tested against.
44

5-
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html
5+
* `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

7-
### Build Container
7+
* 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.
9+
10+
### Dependencies
11+
12+
* Install nvidia-docker by following https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker
13+
14+
### Instructions
815

916
> From root of Torch-TensorRT repo
1017
18+
Build:
19+
```
20+
DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile -t torch_tensorrt:latest .
1121
```
12-
# Build:
13-
DOCKER_BUILDKIT=1 docker build --build-arg BASE={TensorRT Base Container Version} -f docker/Dockerfile -t torch_tensorrt1.0:latest .
1422

15-
# Run:
16-
docker run --gpus all -it \
17-
--shm-size=8gb --env="DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
18-
--name=torch_tensorrt1.0 --ipc=host --net=host torch_tensorrt1.0:latest
23+
Run:
1924
```
25+
nvidia-docker run --gpus all -it --shm-size=8gb --env="DISPLAY" --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" --name=torch_tensorrt --ipc=host --net=host torch_tensorrt:latest
26+
```
27+
28+
Test:
29+
30+
31+
You can run any converter test to verify if Torch-TRT built sucessfully inside the container. Once you launch the container, you can run
32+
```
33+
bazel test //tests/core/conversion/converters:test_activation --compilation_mode=opt --test_output=summary --config use_precompiled_torchtrt --config pre_cxx11_abi
34+
```
35+
36+
* `--config use_precompiled_torchtrt` : Indicates bazel to use pre-installed Torch-TRT library to test an application.
37+
* `--config pre_cxx11_abi` : This flag ensures `bazel test` uses `pre_cxx11_abi` version of `libtorch`. Use this flag corresponding to the ABI format of your Torch-TensorRT installation.
38+
39+
### Pytorch NGC containers
40+
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/22.XX` branch of Torch-TensorRT for source code that gets shipped with `22.XX` version of Pytorch NGC container.

docker/WORKSPACE.docker

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ git_repository(
3131
shallow_since = "1570114335 -0400",
3232
)
3333

34+
# External dependency for torch_tensorrt if you already have precompiled binaries.
35+
local_repository(
36+
name = "torch_tensorrt",
37+
path = "/usr/local/lib/python3.8/dist-packages/torch_tensorrt",
38+
)
39+
3440
# CUDA should be installed on the system locally
3541
new_local_repository(
3642
name = "cuda",
37-
path = "/usr/local/cuda/",
3843
build_file = "@//third_party/cuda:BUILD",
44+
path = "/usr/local/cuda-11.7/",
3945
)
4046

4147
new_local_repository(
@@ -64,6 +70,7 @@ http_archive(
6470
urls = ["https://download.pytorch.org/libtorch/cu117/libtorch-shared-with-deps-1.13.0%2Bcu117.zip"],
6571
)
6672

73+
6774
####################################################################################
6875
# Locally installed dependencies (use in cases of custom dependencies or aarch64)
6976
####################################################################################

docker/dist-build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
TOP_DIR=$(cd $(dirname $0); pwd)/..
44

55
if [[ -z "${USE_CXX11}" ]]; then
6-
BUILD_CMD="python3 setup.py bdist_wheel"
6+
BUILD_CMD="python setup.py bdist_wheel"
77
else
8-
BUILD_CMD="python3 setup.py bdist_wheel --use-cxx11-abi"
8+
BUILD_CMD="python setup.py bdist_wheel --use-cxx11-abi"
99
fi
1010

1111
cd ${TOP_DIR} \

docker/dist-test.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

docker/mha.patch

Lines changed: 0 additions & 19 deletions
This file was deleted.

docker/qat.patch

Lines changed: 0 additions & 11 deletions
This file was deleted.

docker/setup_nox.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)