|
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 |
3 | 3 | FROM ${BASE_IMG} as base
|
4 | 4 |
|
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 |
6 | 41 |
|
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 |
9 | 44 |
|
10 | 45 | ARG ARCH="x86_64"
|
11 | 46 | 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 |
17 | 47 |
|
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 |
24 | 51 |
|
25 | 52 | 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
|
26 | 53 |
|
27 | 54 | FROM torch-tensorrt-builder-base as torch-tensorrt-builder
|
28 | 55 |
|
29 |
| -# Removing any bazel or torch-tensorrt pre-installed from the base image |
30 |
| -RUN rm -rf /opt/pytorch/torch_tensorrt |
31 |
| - |
32 | 56 | COPY . /workspace/torch_tensorrt/src
|
33 | 57 | WORKDIR /workspace/torch_tensorrt/src
|
34 | 58 | RUN cp ./docker/WORKSPACE.docker WORKSPACE
|
35 | 59 |
|
36 | 60 | # This script builds both libtorchtrt bin/lib/include tarball and the Python wheel, in dist/
|
37 | 61 | RUN ./docker/dist-build.sh
|
38 | 62 |
|
| 63 | +# Copy and install Torch-TRT into the main container |
39 | 64 | FROM base as torch-tensorrt
|
40 | 65 |
|
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 |
46 | 67 | COPY --from=torch-tensorrt-builder /workspace/torch_tensorrt/src/py/dist/ .
|
47 | 68 |
|
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 |
51 | 70 | RUN pip3 install *.whl && rm -fr /workspace/torch_tensorrt/py/dist/* *.whl
|
52 | 71 |
|
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} |
54 | 78 | 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 |
61 | 79 |
|
62 | 80 | CMD /bin/bash
|
0 commit comments