Skip to content

Commit 446bf18

Browse files
committed
feat(//docker): New base container to let master build in container
Signed-off-by: Naren Dasan <naren@narendasan.com> Signed-off-by: Naren Dasan <narens@nvidia.com>
1 parent d63a483 commit 446bf18

9 files changed

+161
-90
lines changed

.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ examples/int8/qat/qat
6060
examples/int8/training/vgg16/data/*
6161
examples/int8/datasets/data/*
6262
env/**/*
63-
*.ts
63+
*.ts
64+
.nox/**/*

.github/workflows/docgen.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: echo "::set-output name=sha::$(git rev-parse --short HEAD)"
3131
- name: Build Python Package
3232
run: |
33-
cp docker/WORKSPACE.docs WORKSPACE
33+
cp docker/WORKSPACE.docker WORKSPACE
3434
cd py
3535
python3 setup.py install
3636
- name: Generate New Docs

.github/workflows/linter.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Run image
3535
run: |
3636
docker run -it -d --name cpplinter -e GITHUB_TOKEN=$GITHUB_TOKEN -v $GITHUB_WORKSPACE:/workspace -v $GITHUB_EVENT_PATH:/GITHUB_EVENT.json -w /workspace ghcr.io/nvidia/torch-tensorrt/docgen:latest
37-
docker exec cpplinter bash -c "cp /workspace/docker/WORKSPACE.docs /workspace/WORKSPACE"
37+
docker exec cpplinter bash -c "cp /workspace/docker/WORKSPACE.docker /workspace/WORKSPACE"
3838
env:
3939
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
4040
- name: Install dependencies
@@ -71,7 +71,7 @@ jobs:
7171
- name: Run image
7272
run: |
7373
docker run -it -d --name pylinter -e GITHUB_TOKEN=$GITHUB_TOKEN -v $GITHUB_WORKSPACE:/workspace -v $GITHUB_EVENT_PATH:/GITHUB_EVENT.json -w /workspace ghcr.io/nvidia/torch-tensorrt/docgen:latest
74-
docker exec pylinter bash -c "cp /workspace/docker/WORKSPACE.docs /workspace/WORKSPACE"
74+
docker exec pylinter bash -c "cp /workspace/docker/WORKSPACE.docker /workspace/WORKSPACE"
7575
env:
7676
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
7777
- name: Install dependencies

docker/Dockerfile

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ARG BASE=21.10
2-
ARG BASE_IMG=nvcr.io/nvidia/pytorch:${BASE}-py3
1+
ARG BASE=22.04
2+
ARG BASE_IMG=nvcr.io/nvidia/tensorrt:${BASE}-py3
33
FROM ${BASE_IMG} as base
44

55
FROM base as torch-tensorrt-builder-base
@@ -33,7 +33,7 @@ COPY . /workspace/torch_tensorrt/src
3333
WORKDIR /workspace/torch_tensorrt/src
3434
RUN cp ./docker/WORKSPACE.docker WORKSPACE
3535

36-
# This script builds both libtorchtrt bin/lib/include tarball and the Pythin wheel, in dist/
36+
# This script builds both libtorchtrt bin/lib/include tarball and the Python wheel, in dist/
3737
RUN ./docker/dist-build.sh
3838

3939
FROM base as torch-tensorrt
@@ -44,20 +44,20 @@ RUN rm -rf /opt/pytorch/torch_tensorrt
4444
# copy source repo
4545
COPY . /workspace/torch_tensorrt
4646
COPY --from=torch-tensorrt-builder /workspace/torch_tensorrt/src/py/dist/ .
47-
RUN conda init bash
47+
#RUN conda init bash
4848

4949
RUN pip3 install ipywidgets --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org
5050
RUN jupyter nbextension enable --py widgetsnbextension
5151

5252
RUN pip3 install *.whl && rm -fr /workspace/torch_tensorrt/py/dist/* *.whl
5353

54-
ENV LD_LIBRARY_PATH /opt/conda/lib/python3.8/site-packages/torch/lib:/opt/conda/lib/python3.8/site-packages/torch_tensorrt/lib:${LD_LIBRARY_PATH}
55-
ENV PATH /opt/conda/lib/python3.8/site-packages/torch_tensorrt/bin:${PATH}
54+
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}
55+
ENV PATH /usr/local/lib/python3.8/dist-packages/torch_tensorrt/bin:${PATH}
5656
#
5757
WORKDIR /workspace
58-
RUN mv /workspace/torch_tensorrt /opt/pytorch/torch_tensorrt
59-
RUN cp /opt/pytorch/torch_tensorrt/docker/WORKSPACE.docker /opt/pytorch/torch_tensorrt/WORKSPACE
58+
RUN mv /workspace/torch_tensorrt /opt/torch_tensorrt
59+
RUN cp /opt/torch_tensorrt/docker/WORKSPACE.docker /opt/torch_tensorrt/WORKSPACE
6060
RUN mkdir torch_tensorrt
61-
RUN ln -s /opt/pytorch/torch_tensorrt/notebooks /workspace/torch_tensorrt/notebooks
61+
RUN ln -s /opt/torch_tensorrt/notebooks /workspace/torch_tensorrt/notebooks
6262

6363
CMD /bin/bash

docker/Dockerfile.ngc

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
ARG BASE=21.10
2+
ARG BASE_IMG=nvcr.io/nvidia/pytorch:${BASE}-py3
3+
FROM ${BASE_IMG} as base
4+
5+
FROM base as torch-tensorrt-builder-base
6+
7+
# Removing any bazel or torch-tensorrt pre-installed from the base image
8+
RUN rm -rf /opt/pytorch/torch_tensorrt /usr/bin/bazel
9+
10+
ARG ARCH="x86_64"
11+
ARG TARGETARCH="amd64"
12+
ARG BAZEL_VERSION=5.1.1
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+
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
24+
25+
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+
27+
FROM torch-tensorrt-builder-base as torch-tensorrt-builder
28+
29+
# Removing any bazel or torch-tensorrt pre-installed from the base image
30+
RUN rm -rf /opt/pytorch/torch_tensorrt
31+
32+
COPY . /workspace/torch_tensorrt/src
33+
WORKDIR /workspace/torch_tensorrt/src
34+
RUN cp ./docker/WORKSPACE.docker WORKSPACE
35+
36+
# This script builds both libtorchtrt bin/lib/include tarball and the Pythin wheel, in dist/
37+
RUN USE_CXX11=1 ./docker/dist-build.sh
38+
39+
FROM base as torch-tensorrt
40+
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
46+
COPY --from=torch-tensorrt-builder /workspace/torch_tensorrt/src/py/dist/ .
47+
RUN conda init bash
48+
49+
RUN pip3 install ipywidgets --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org
50+
RUN jupyter nbextension enable --py widgetsnbextension
51+
52+
RUN pip3 install *.whl && rm -fr /workspace/torch_tensorrt/py/dist/* *.whl
53+
54+
ENV LD_LIBRARY_PATH /opt/conda/lib/python3.8/site-packages/torch/lib:/opt/conda/lib/python3.8/site-packages/torch_tensorrt/lib:${LD_LIBRARY_PATH}
55+
ENV PATH /opt/conda/lib/python3.8/site-packages/torch_tensorrt/bin:${PATH}
56+
#
57+
WORKDIR /workspace
58+
RUN mv /workspace/torch_tensorrt /opt/pytorch/torch_tensorrt
59+
RUN cp /opt/pytorch/torch_tensorrt/docker/WORKSPACE.docker /opt/pytorch/torch_tensorrt/WORKSPACE
60+
RUN mkdir torch_tensorrt
61+
RUN ln -s /opt/pytorch/torch_tensorrt/notebooks /workspace/torch_tensorrt/notebooks
62+
63+
CMD /bin/bash

docker/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.
1010
1111
```
1212
# Build:
13-
DOCKER_BUILDKIT=1 docker build --build-arg BASE={PyTorch Base Container Version} -f docker/Dockerfile -t torch_tensorrt1.0:latest .
13+
DOCKER_BUILDKIT=1 docker build --build-arg BASE={TensorRT Base Container Version} -f docker/Dockerfile -t torch_tensorrt1.0:latest .
1414
1515
# Run:
1616
docker run --gpus all -it \

docker/WORKSPACE.docker

+34-41
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,86 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
55

66
http_archive(
7-
name = "rules_python",
8-
url = "https://github.com/bazelbuild/rules_python/releases/download/0.2.0/rules_python-0.2.0.tar.gz",
9-
sha256 = "778197e26c5fbeb07ac2a2c5ae405b30f6cb7ad1f5510ea6fdac03bded96cc6f",
10-
)
7+
name = "rules_python",
8+
sha256 = "778197e26c5fbeb07ac2a2c5ae405b30f6cb7ad1f5510ea6fdac03bded96cc6f",
9+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.2.0/rules_python-0.2.0.tar.gz",
10+
)
1111

1212
load("@rules_python//python:pip.bzl", "pip_install")
1313

1414
http_archive(
1515
name = "rules_pkg",
16+
sha256 = "038f1caa773a7e35b3663865ffb003169c6a71dc995e39bf4815792f385d837d",
1617
urls = [
17-
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
18-
"https://github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
18+
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
19+
"https://github.com/bazelbuild/rules_pkg/releases/download/0.4.0/rules_pkg-0.4.0.tar.gz",
1920
],
20-
sha256 = "038f1caa773a7e35b3663865ffb003169c6a71dc995e39bf4815792f385d837d",
2121
)
22+
2223
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
24+
2325
rules_pkg_dependencies()
2426

2527
git_repository(
2628
name = "googletest",
27-
remote = "https://github.com/google/googletest",
2829
commit = "703bd9caab50b139428cea1aaff9974ebee5742e",
29-
shallow_since = "1570114335 -0400"
30-
)
31-
32-
# External dependency for torch_tensorrt if you already have precompiled binaries.
33-
# This is currently used in pytorch NGC container CI testing.
34-
local_repository(
35-
name = "torch_tensorrt",
36-
path = "/opt/conda/lib/python3.8/site-packages/torch_tensorrt"
30+
remote = "https://github.com/google/googletest",
31+
shallow_since = "1570114335 -0400",
3732
)
3833

3934
# CUDA should be installed on the system locally
4035
new_local_repository(
4136
name = "cuda",
42-
path = "/usr/local/cuda",
37+
path = "/usr/local/cuda/",
4338
build_file = "@//third_party/cuda:BUILD",
4439
)
4540

4641
new_local_repository(
4742
name = "cublas",
48-
build_file = "@//third_party/cublas:BUILD",
4943
path = "/usr",
44+
build_file = "@//third_party/cublas:BUILD",
5045
)
5146

52-
####################################################################################
53-
# Locally installed dependencies (use in cases of custom dependencies or aarch64)
54-
####################################################################################
47+
#############################################################################################################
48+
# Tarballs and fetched dependencies (default - use in cases when building from precompiled bin and tarballs)
49+
#############################################################################################################
5550

56-
new_local_repository(
51+
http_archive(
5752
name = "libtorch",
58-
path = "/opt/conda/lib/python3.8/site-packages/torch",
59-
build_file = "third_party/libtorch/BUILD"
53+
build_file = "@//third_party/libtorch:BUILD",
54+
sha256 = "8d9e829ce9478db4f35bdb7943308cf02e8a2f58cf9bb10f742462c1d57bf287",
55+
strip_prefix = "libtorch",
56+
urls = ["https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.11.0%2Bcu113.zip"],
6057
)
6158

62-
new_local_repository(
59+
http_archive(
6360
name = "libtorch_pre_cxx11_abi",
64-
path = "/opt/conda/lib/python3.8/site-packages/torch",
65-
build_file = "third_party/libtorch/BUILD"
61+
build_file = "@//third_party/libtorch:BUILD",
62+
sha256 = "90159ecce3ff451f3ef3f657493b6c7c96759c3b74bbd70c1695f2ea2f81e1ad",
63+
strip_prefix = "libtorch",
64+
urls = ["https://download.pytorch.org/libtorch/cu113/libtorch-shared-with-deps-1.11.0%2Bcu113.zip"],
6665
)
6766

67+
####################################################################################
68+
# Locally installed dependencies (use in cases of custom dependencies or aarch64)
69+
####################################################################################
70+
6871
new_local_repository(
6972
name = "cudnn",
7073
path = "/usr/",
7174
build_file = "@//third_party/cudnn/local:BUILD"
7275
)
7376

7477
new_local_repository(
75-
name = "tensorrt",
76-
path = "/usr/",
77-
build_file = "@//third_party/tensorrt/local:BUILD"
78+
name = "tensorrt",
79+
path = "/usr/",
80+
build_file = "@//third_party/tensorrt/local:BUILD"
7881
)
7982

8083
#########################################################################
8184
# Testing Dependencies (optional - comment out on aarch64)
8285
#########################################################################
83-
pip_install(
84-
name = "torch_tensorrt_py_deps",
85-
requirements = "//py:requirements.txt",
86-
)
87-
88-
pip_install(
89-
name = "py_test_deps",
90-
requirements = "//tests/py:requirements.txt",
91-
)
92-
9386
pip_install(
9487
name = "pylinter_deps",
9588
requirements = "//tools/linter:requirements.txt",
96-
)
89+
)

0 commit comments

Comments
 (0)