forked from dusty-nv/jetson-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.pytorch
176 lines (143 loc) · 6.61 KB
/
Dockerfile.pytorch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
ARG BASE_IMAGE=nvcr.io/nvidia/l4t-base:r32.4.4
FROM ${BASE_IMAGE}
ENV DEBIAN_FRONTEND=noninteractive
#
# install prerequisites (many of these are for numpy)
#
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3-pip \
python3-dev \
libopenblas-dev \
libopenmpi-dev \
openmpi-bin \
openmpi-common \
gfortran \
libomp-dev \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
RUN pip3 install --no-cache-dir setuptools Cython wheel
RUN pip3 install --no-cache-dir --verbose numpy
#
# PyTorch (for JetPack 4.4 DP)
#
# PyTorch v1.2.0 https://nvidia.box.com/shared/static/lufbgr3xu2uha40cs9ryq1zn4kxsnogl.whl (torch-1.2.0-cp36-cp36m-linux_aarch64.whl)
# PyTorch v1.3.0 https://nvidia.box.com/shared/static/017sci9z4a0xhtwrb4ps52frdfti9iw0.whl (torch-1.3.0-cp36-cp36m-linux_aarch64.whl)
# PyTorch v1.4.0 https://nvidia.box.com/shared/static/c3d7vm4gcs9m728j6o5vjay2jdedqb55.whl (torch-1.4.0-cp36-cp36m-linux_aarch64.whl)
# PyTorch v1.5.0 https://nvidia.box.com/shared/static/3ibazbiwtkl181n95n9em3wtrca7tdzp.whl (torch-1.5.0-cp36-cp36m-linux_aarch64.whl)
#
ARG PYTORCH_URL=https://nvidia.box.com/shared/static/lufbgr3xu2uha40cs9ryq1zn4kxsnogl.whl
ARG PYTORCH_WHL=torch-1.2.0-cp36-cp36m-linux_aarch64.whl
RUN wget --quiet --show-progress --progress=bar:force:noscroll --no-check-certificate ${PYTORCH_URL} -O ${PYTORCH_WHL} && \
pip3 install --no-cache-dir --verbose ${PYTORCH_WHL} && \
rm ${PYTORCH_WHL}
#
# torchvision 0.4
#
ARG TORCHVISION_VERSION=v0.4.0
ARG TORCH_CUDA_ARCH_LIST="5.3;6.2;7.2;8.7"
RUN printenv && echo "torchvision version = $TORCHVISION_VERSION" && echo "TORCH_CUDA_ARCH_LIST = $TORCH_CUDA_ARCH_LIST"
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
build-essential \
libjpeg-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
RUN git clone https://github.com/pytorch/vision torchvision && \
cd torchvision && \
git checkout ${TORCHVISION_VERSION} && \
python3 setup.py install && \
cd ../ && \
rm -rf torchvision
# note: this was used on older torchvision versions (~0.4) to workaround a bug,
# but has since started causing another bug as of torchvision 0.11.1
# ARG PILLOW_VERSION=pillow<7
# pip3 install --no-cache-dir "${PILLOW_VERSION}"
#
# upgrade cmake - https://stackoverflow.com/a/56690743
# this is needed for newer versions of torchaudio (>= v0.10)
#
RUN apt-get update && \
apt-get install -y --no-install-recommends \
software-properties-common \
apt-transport-https \
ca-certificates \
gnupg \
lsb-release \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# typically --only-upgrade is used in the apt install, but cmake wasn't previously installed in this container
# note: skipping this way for now, because having trouble pinning it to specific version (see below)
#RUN wget -qO - https://apt.kitware.com/keys/kitware-archive-latest.asc | apt-key add - && \
# apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" && \
# apt-get update && \
# apt-cache policy cmake && \
# apt-get install -y --no-install-recommends \
# cmake \
# && rm -rf /var/lib/apt/lists/* \
# && apt-get clean
# note: cmake is currently pinned to 3.22.3 because of https://github.com/pytorch/pytorch/issues/74955
RUN pip3 install --upgrade --no-cache-dir --verbose cmake==3.22.3
RUN cmake --version
# patch for https://github.com/pytorch/pytorch/issues/45323
RUN PYTHON_ROOT=`pip3 show torch | grep Location: | cut -d' ' -f2` && \
TORCH_CMAKE_CONFIG=$PYTHON_ROOT/torch/share/cmake/Torch/TorchConfig.cmake && \
echo "patching _GLIBCXX_USE_CXX11_ABI in ${TORCH_CMAKE_CONFIG}" && \
sed -i 's/ set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=")/ set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=0")/g' ${TORCH_CMAKE_CONFIG}
#
# torchaudio
#
ARG TORCHAUDIO_VERSION
RUN apt-get update && \
apt-get install -y --no-install-recommends \
pkg-config \
libffi-dev \
libsndfile1 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
RUN pip3 install --no-cache-dir scikit-build && \
pip3 install --no-cache-dir ninja && \
pip3 install --no-cache-dir --verbose pysoundfile
# note: see https://github.com/pytorch/audio/issues/2295 for the reason for the sed commands
RUN git clone --recursive -b ${TORCHAUDIO_VERSION} https://github.com/pytorch/audio torchaudio && \
cd torchaudio && \
sed -i 's# URL https://zlib.net/zlib-1.2.11.tar.gz# URL https://zlib.net/zlib-1.2.12.tar.gz#g' third_party/zlib/CMakeLists.txt || echo "failed to patch torchaudio/third_party/zlib/CMakeLists.txt" && \
sed -i 's# URL_HASH SHA256=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1# URL_HASH SHA256=91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9#g' third_party/zlib/CMakeLists.txt || echo "failed to patch torchaudio/third_party/zlib/CMakeLists.txt" && \
BUILD_SOX=1 python3 setup.py install && \
cd ../ && \
rm -rf torchaudio
#
# install OpenCV (with CUDA)
#
ARG OPENCV_URL=https://nvidia.box.com/shared/static/5v89u6g5rb62fpz4lh0rz531ajo2t5ef.gz
ARG OPENCV_DEB=OpenCV-4.5.0-aarch64.tar.gz
COPY scripts/opencv_install.sh /tmp/opencv_install.sh
RUN cd /tmp && ./opencv_install.sh ${OPENCV_URL} ${OPENCV_DEB}
#
# PyCUDA
#
ENV PATH="/usr/local/cuda/bin:${PATH}"
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
RUN echo "$PATH" && echo "$LD_LIBRARY_PATH"
RUN pip3 install --no-cache-dir --verbose pycuda six