Skip to content

Commit c85f67f

Browse files
authored
Merge pull request #3863 from karttikjangid/feat/gsoc7-optimize-docker-image-remove-pytorch
replace PyTorch with minimal CUDA runtime wheels, reduce image by ~4.7 GB
2 parents 37160ce + 9cc555a commit c85f67f

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

scripts/RADI/Dockerfile.dependencies_humble

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ ENV PYTHONPATH=/opt/ros/${ROS_DISTRO}/lib/python3.10/site-packages
2828
ENV ROS_PYTHON_VERSION=3
2929
ENV ROS_VERSION=2
3030

31+
# gz.msgs10 Python bindings (installed by gz-harmonic apt package) are compiled
32+
# with protoc 3.x and cannot create descriptors under protobuf 4.x / 5.x C++
33+
# extension. Force pure-Python protobuf parser (backward-compatible with all
34+
# .pb2 files) so gz.msgs10 and onnxruntime-gpu coexist without version pinning.
35+
ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
36+
3137
# Install common tools
3238
RUN apt-get update && apt-get install -y \
3339
software-properties-common \
@@ -162,9 +168,42 @@ RUN python3.10 -m pip install --no-cache-dir \
162168
pyulog==1.0.1 pyyaml==5.4.1 requests==2.31.0 serial==0.0.97 six==1.16.0 toml==0.10.2 psutil==5.9.0 \
163169
onnxruntime-gpu==1.22.0 Pillow==9.0.1 opencv-python==4.5.5.64 watchdog==2.1.5 utm==0.7.0 psycopg2 jedi pyapriltags
164170

165-
# install pytorch with CUDA 12.8 support
166-
RUN python3.10 -m pip install --no-cache-dir --ignore-installed sympy==1.13.3
167-
RUN python3.10 -m pip install --no-cache-dir torch --extra-index-url https://download.pytorch.org/whl/cu128
171+
# CUDA runtime wheels for onnxruntime-gpu==1.22.0 CUDA Execution Provider.
172+
#
173+
# All seven packages below must be upgraded together whenever onnxruntime-gpu
174+
# is bumped. Compatibility ranges declared by the wheel (via ~= operator):
175+
# nvidia-cuda-runtime-cu12 ~= 12.0 nvidia-cuda-nvrtc-cu12 ~= 12.0
176+
# nvidia-cublas-cu12 (runtime dep of cudnn)
177+
# nvidia-cudnn-cu12 ~= 9.0
178+
# nvidia-curand-cu12 ~= 10.0 nvidia-cufft-cu12 ~= 11.0
179+
#
180+
# Upgrade checklist:
181+
# 1. Check the new ORT release notes for CUDA / cuDNN major version changes.
182+
# 2. Run: pip show onnxruntime-gpu | grep Requires — to see declared ~= ranges.
183+
# 3. Pick PyPI versions whose MAJOR matches those ranges (stay on CUDA 12.x,
184+
# cuDNN 9.x, curand 10.x, cufft 11.x until ORT itself changes the range).
185+
# 4. After build, verify inside the container:
186+
# python3 -c "import onnxruntime as ort; print(ort.get_available_providers())"
187+
# CUDAExecutionProvider must appear first.
188+
# 5. Run: ldd $(python3 -c "import onnxruntime, os; print(os.path.dirname(onnxruntime.__file__))")/capi/libonnxruntime_providers_cuda.so
189+
# Every .so must resolve (no "not found" lines).
190+
RUN python3.10 -m pip install --no-cache-dir \
191+
nvidia-cuda-runtime-cu12==12.8.90 \
192+
nvidia-cublas-cu12==12.8.4.1 \
193+
nvidia-cudnn-cu12==9.10.2.21 \
194+
nvidia-nvjitlink-cu12==12.8.93 \
195+
nvidia-cuda-nvrtc-cu12==12.8.93 \
196+
nvidia-curand-cu12==10.3.10.19 \
197+
nvidia-cufft-cu12==11.4.1.4
198+
199+
# Register all pip-installed nvidia .so files with ldconfig so onnxruntime-gpu
200+
# finds them regardless of whether pip used site-packages or dist-packages
201+
RUN python3.10 -c "\
202+
import sysconfig, pathlib; \
203+
site = pathlib.Path(sysconfig.get_path('purelib')); \
204+
conf = '\n'.join(str(d) for d in site.glob('nvidia/*/lib') if d.is_dir()); \
205+
pathlib.Path('/etc/ld.so.conf.d/nvidia-pip.conf').write_text(conf + '\n')" \
206+
&& ldconfig
168207

169208
# monaco editor
170209
RUN python3.10 -m pip install --no-cache-dir black==24.10.0

0 commit comments

Comments
 (0)