Skip to content

Commit 2525f67

Browse files
authored
Merge pull request #1581 from pytorch/dockerfile_update
chore: Update dockerfile
2 parents d92e409 + fd72efb commit 2525f67

File tree

7 files changed

+83
-166
lines changed

7 files changed

+83
-166
lines changed

docker/Dockerfile

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,79 @@
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==2.0.0.dev20230103+cu117 torchvision==0.15.0.dev20230103+cu117 --extra-index-url https://download.pytorch.org/whl/nightly/cu117
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 tensorrt==8.5.1.7
74+
75+
WORKDIR /opt/torch_tensorrt
76+
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}
5477
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
6178

62-
CMD /bin/bash
79+
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/23.XX` branch of Torch-TensorRT for source code that gets shipped with `23.XX` version of Pytorch NGC container.

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)