Skip to content

Commit 2709d12

Browse files
author
Anurag Dixit
committed
(//docker): Updated Dockerfile with NGC containers
Signed-off-by: Anurag Dixit <[email protected]>
1 parent 4d95b04 commit 2709d12

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

docker/Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
ARG BASE=21.08
2+
ARG BASE_IMG=nvcr.io/nvidia/pytorch:${BASE}-py3
3+
FROM ${BASE_IMG} as base
4+
5+
FROM base as trtorch-builder-base
6+
7+
# Removing any bazel or trtorch pre-installed from the base image
8+
9+
RUN rm -rf /opt/pytorch/trtorch /usr/bin/bazel
10+
11+
RUN apt-get update && apt-get install --no-install-recommends -y curl gnupg
12+
RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > /etc/apt/trusted.gpg.d/bazel.gpg
13+
RUN echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
14+
15+
RUN apt-get update && apt-get install -y --no-install-recommends bazel-4.0.0
16+
RUN ln -s /usr/bin/bazel-4.0.0 /usr/bin/bazel
17+
18+
# Workaround for bazel expecting both static and shared versions, we only use shared libraries inside container
19+
RUN cp /usr/lib/x86_64-linux-gnu/libnvinfer.so /usr/lib/x86_64-linux-gnu/libnvinfer_static.a
20+
21+
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
22+
23+
FROM trtorch-builder-base as trtorch-builder
24+
25+
COPY . /workspace/trtorch/src
26+
WORKDIR /workspace/trtorch/src
27+
RUN cp ./docker/WORKSPACE.cu.docker WORKSPACE
28+
29+
# This script builds both libtrtorch bin/lib/include tarball and the Pythin wheel, in dist/
30+
RUN ./docker/dist-build.sh
31+
32+
FROM base as trtorch
33+
34+
# copy source repo
35+
COPY . /workspace/trtorch
36+
COPY --from=trtorch-builder /workspace/trtorch/src/dist/ .
37+
38+
RUN conda init bash
39+
40+
RUN pip3 install ipywidgets --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org
41+
RUN jupyter nbextension enable --py widgetsnbextension
42+
43+
RUN mkdir -p /opt/trtorch && tar xvf libtrtorch.tar.gz --strip-components 2 -C /opt/trtorch --exclude=LICENSE && pip3 install *.whl && rm -fr /workspace/trtorch/dist/*
44+
45+
ENV LD_LIBRARY_PATH /opt/conda/lib/python3.8/site-packages/torch/lib:/opt/trtorch/lib:${LD_LIBRARY_PATH}
46+
ENV PATH /opt/trtorch/bin:${PATH}
47+
48+
WORKDIR /workspace/trtorch/
49+
CMD /bin/bash

docker/dist-build.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
mkdir -p dist
4+
5+
bazel build //:libtrtorch --compilation_mode opt
6+
7+
cd py && MAX_JOBS=1 LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 python3 setup.py bdist_wheel --use-cxx11-abi
8+
9+
cd ..
10+
11+
cp bazel-bin/libtrtorch.tar.gz dist/
12+
cp py/dist/* dist/
13+
14+
pip3 install ipywidgets --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org
15+
jupyter nbextension enable --py widgetsnbextension
16+
17+
pip3 install timm
18+
19+
# test install
20+
mkdir -p /opt/trtorch && tar xvf dist/libtrtorch.tar.gz --strip-components 2 -C /opt/trtorch --exclude=LICENSE && pip3 uninstall -y trtorch && pip3 install dist/*.whl
21+

docker/dist-test.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
pip3 install timm --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org
4+
# Build and run unit tests
5+
cd tests/modules && python3 ./hub.py
6+
cd ../..
7+
8+
bazel test //tests:tests //tests:python_api_tests --compilation_mode=opt --jobs=4

0 commit comments

Comments
 (0)