Skip to content

Commit fd72efb

Browse files
committed
chore: Update pytorch, torchvision, tensorrt versions in the dockerfile
Signed-off-by: Dheeraj Peri <[email protected]>
1 parent 3857a6e commit fd72efb

File tree

1 file changed

+52
-35
lines changed

1 file changed

+52
-35
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

0 commit comments

Comments
 (0)