Skip to content

Commit 34fd7fe

Browse files
committed
feat: Upgrade Docker build to use custom TRT + CUDNN
- Upgrade Ubuntu version to 22.04 - Make custom build args for TensorRT and CUDNN versions, user-specifiable in a.b.c version format - Make build args required, without defaults, to improve code cleanliness and reduce amount of changes needed when versions shift - Provide clear error messages when the build args are not provided by the user - Add documentation of the change in the Docker README
1 parent ad5e764 commit 34fd7fe

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

docker/Dockerfile

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Base image starts with CUDA
2-
ARG BASE_IMG=nvidia/cuda:11.7.1-devel-ubuntu20.04
2+
ARG BASE_IMG=nvidia/cuda:11.7.1-devel-ubuntu22.04
33
FROM ${BASE_IMG} as base
44

5+
ARG TENSORRT_VERSION
6+
RUN test -n "$TENSORRT_VERSION" || (echo "No tensorrt version specified, please use --build-arg TENSORRT_VERSION==x.y.z to specify a version." && exit 1)
7+
ARG CUDNN_VERSION
8+
RUN test -n "$CUDNN_VERSION" || (echo "No cudnn version specified, please use --build-arg CUDNN_VERSION==x.y.z to specify a version." && exit 1)
9+
510
ARG USE_CXX11_ABI
611
ENV USE_CXX11=${USE_CXX11_ABI}
12+
ENV DEBIAN_FRONTEND=noninteractive
713

814
# Install basic dependencies
915
RUN apt-get update
10-
RUN DEBIAN_FRONTEND=noninteractive apt install -y build-essential manpages-dev wget zlib1g software-properties-common git
16+
RUN apt install -y build-essential manpages-dev wget zlib1g software-properties-common git
1117
RUN add-apt-repository ppa:deadsnakes/ppa
1218
RUN apt install -y python3.8 python3.8-distutils python3.8-dev
1319
RUN wget https://bootstrap.pypa.io/get-pip.py
@@ -16,20 +22,20 @@ RUN python get-pip.py
1622
RUN pip3 install wheel
1723

1824
# Install CUDNN + TensorRT
19-
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
20-
RUN mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
21-
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
25+
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
26+
RUN mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
27+
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/7fa2af80.pub
2228
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 536F8F1DE80F6A35
2329
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/ubuntu2004/x86_64/ /"
30+
RUN add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /"
2531
RUN apt-get update
26-
RUN apt-get install -y libcudnn8=8.5.0* libcudnn8-dev=8.5.0*
32+
RUN apt-get install -y libcudnn8=${CUDNN_VERSION}* libcudnn8-dev=${CUDNN_VERSION}*
2733

28-
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
29-
RUN add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
34+
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub
35+
RUN add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /"
3036
RUN apt-get update
3137

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*
38+
RUN apt-get install -y libnvinfer8=${TENSORRT_VERSION}* libnvinfer-plugin8=${TENSORRT_VERSION}* libnvinfer-dev=${TENSORRT_VERSION}* libnvinfer-plugin-dev=${TENSORRT_VERSION}* libnvonnxparsers8=${TENSORRT_VERSION}-1* libnvonnxparsers-dev=${TENSORRT_VERSION}-1* libnvparsers8=${TENSORRT_VERSION}-1* libnvparsers-dev=${TENSORRT_VERSION}-1*
3339

3440
# Setup Bazel
3541
RUN wget -q https://github.com/bazelbuild/bazelisk/releases/download/v1.16.0/bazelisk-linux-amd64 -O /usr/bin/bazel \
@@ -42,7 +48,7 @@ ARG ARCH="x86_64"
4248
ARG TARGETARCH="amd64"
4349

4450
RUN apt-get install -y python3-setuptools
45-
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub
51+
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub
4652

4753
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
4854

@@ -63,6 +69,7 @@ COPY --from=torch-tensorrt-builder /workspace/torch_tensorrt/src/py/dist/ .
6369

6470
RUN cp /opt/torch_tensorrt/docker/WORKSPACE.docker /opt/torch_tensorrt/WORKSPACE
6571
RUN pip install -r /opt/torch_tensorrt/py/requirements.txt
72+
RUN pip install tensorrt==${TENSORRT_VERSION}.*
6673
RUN pip3 install *.whl && rm -fr /workspace/torch_tensorrt/py/dist/* *.whl
6774

6875
WORKDIR /opt/torch_tensorrt

docker/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* Use `Dockerfile` to build a container which provides the exact development environment that our master branch is usually tested against.
44

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.
5+
* The `Dockerfile` currently uses <a href="https://github.com/bazelbuild/bazelisk">Bazelisk</a> to select the Bazel version, and uses the exact library versions of Torch and CUDA listed in <a href="https://github.com/pytorch/TensorRT#dependencies">dependencies</a>. The desired versions of CUDNN and TensorRT must be specified as build-args, with major, minor, and patch versions as in: `--build-arg TENSORRT_VERSION=a.b.c --build-arg CUDNN_VERSION=x.y.z`
66

77
* This `Dockerfile` installs `pre-cxx11-abi` versions of Pytorch and builds Torch-TRT using `pre-cxx11-abi` libtorch as well.
88

@@ -14,11 +14,14 @@ Note: By default the container uses the `pre-cxx11-abi` version of Torch + Torch
1414

1515
### Instructions
1616

17+
- The example below uses CUDNN 8.5.0 and TensorRT 8.5.1
18+
- See <a href="https://github.com/pytorch/TensorRT#dependencies">dependencies</a> for a list of current default dependencies.
19+
1720
> From root of Torch-TensorRT repo
1821
1922
Build:
2023
```
21-
DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile -t torch_tensorrt:latest .
24+
DOCKER_BUILDKIT=1 docker build --build-arg TENSORRT_VERSION=8.5.1 --build-arg CUDNN_VERSION=8.5.0 -f docker/Dockerfile -t torch_tensorrt:latest .
2225
```
2326

2427
Run:

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} \

0 commit comments

Comments
 (0)