Skip to content

Commit fbce402

Browse files
committed
Merge branch 'master' into kwargs_py_api
2 parents 7a4b59f + f49604d commit fbce402

File tree

15 files changed

+131
-161
lines changed

15 files changed

+131
-161
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.06
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+
RUN patch -u /opt/conda/lib/python3.8/site-packages/pytorch_quantization/nn/modules/tensor_quantizer.py -i /workspace/trtorch/docker/qat.patch
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/Dockerfile.21.03

Lines changed: 0 additions & 41 deletions
This file was deleted.

docker/Dockerfile.21.06

Lines changed: 0 additions & 42 deletions
This file was deleted.

docker/Dockerfile.21.07

Lines changed: 0 additions & 42 deletions
This file was deleted.

docker/WORKSPACE.cu.docker

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,25 @@ git_repository(
2929
shallow_since = "1570114335 -0400"
3030
)
3131

32+
# External dependency for trtorch if you already have precompiled binaries.
33+
# This is currently used in pytorch NGC container CI testing.
34+
local_repository(
35+
name = "trtorch",
36+
path = "/opt/conda/lib/python3.8/site-packages/trtorch"
37+
)
38+
3239
# CUDA should be installed on the system locally
3340
new_local_repository(
3441
name = "cuda",
3542
path = "/usr/local/cuda",
3643
build_file = "@//third_party/cuda:BUILD",
3744
)
3845

46+
new_local_repository(
47+
name = "cublas",
48+
build_file = "@//third_party/cublas:BUILD",
49+
path = "/usr",
50+
)
3951

4052
####################################################################################
4153
# Locally installed dependencies (use in cases of custom dependencies or aarch64)

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

docker/mha.patch

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- torch/nn/functional.py 2021-10-01 16:53:42.827338664 -0700
2+
+++ functional.py 2021-10-01 16:53:34.639338618 -0700
3+
@@ -4975,7 +4975,7 @@
4+
f"was expecting embedding dimension of {embed_dim_to_check}, but got {embed_dim}"
5+
if isinstance(embed_dim, torch.Tensor):
6+
# embed_dim can be a tensor when JIT tracing
7+
- head_dim = embed_dim.div(num_heads, rounding_mode='trunc')
8+
+ head_dim = int(embed_dim.div(num_heads, rounding_mode='trunc'))
9+
else:
10+
head_dim = embed_dim // num_heads
11+
assert head_dim * num_heads == embed_dim, f"embed_dim {embed_dim} not divisible by num_heads {num_heads}"
12+
@@ -5044,6 +5044,7 @@
13+
#
14+
# reshape q, k, v for multihead attention and make em batch first
15+
#
16+
+ bsz = int(bsz)
17+
q = q.contiguous().view(tgt_len, bsz * num_heads, head_dim).transpose(0, 1)
18+
if static_k is None:
19+
k = k.contiguous().view(k.shape[0], bsz * num_heads, head_dim).transpose(0, 1)

docker/qat.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- /opt/conda/lib/python3.8/site-packages/pytorch_quantization/nn/modules/tensor_quantizer.py 2021-08-16 22:50:37.000000000 +0000
2+
+++ tensor_quantizer.py 2021-10-19 20:41:54.288077426 +0000
3+
@@ -291,7 +291,7 @@
4+
quant_dim = list(amax.shape).index(list(amax_sequeeze.shape)[0])
5+
scale = amax_sequeeze / bound
6+
outputs = torch.fake_quantize_per_channel_affine(
7+
- inputs, scale.data, torch.zeros_like(scale, dtype=torch.long).data, quant_dim,
8+
+ inputs, scale.data, torch.zeros_like(scale, dtype=torch.int32).data, quant_dim,
9+
-bound - 1 if not self._unsigned else 0, bound)
10+
11+
return outputs

py/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def run(self):
234234
long_description=long_description,
235235
ext_modules=ext_modules,
236236
install_requires=[
237-
'torch>=1.9.0+cu111,<1.10.0',
237+
'torch>=1.9.0<1.11.0',
238238
],
239239
setup_requires=[],
240240
cmdclass={

0 commit comments

Comments
 (0)