Skip to content

Commit bc09a1e

Browse files
committed
Address review feedback on ROCm support
- Add ARG PYTHON_VERSION; the rocm-sdk site-packages paths were hardcoded to python3.12 and broke silently on a different BASE_IMAGE. - Build the extensions with BUILD_MONAI=1 FORCE_CUDA=1 (the build host has no GPU, so setup.py would otherwise skip them) and set ENV BUILD_MONAI=1, which deviceconfig needs at runtime to gate USE_COMPILED. - Drop the test_densenet skipTest that duplicated its @skipIf decorator. Assisted-by: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Patel, Nilaykumar K <NilaykumarKantibhai.Patel@amd.com>
1 parent 459d9cc commit bc09a1e

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎Dockerfile.rocm‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ LABEL maintainer="monai.contact@gmail.com"
2828
ARG AMDGPU_TARGETS="gfx942"
2929
ARG ROCM_SERIES="10.0"
3030
ARG ROCM_INDEX_URL="https://stable.repo.amd.com/rocm/whl-next/"
31+
# Must match the python3 in BASE_IMAGE: it determines the venv's site-packages path below.
32+
ARG PYTHON_VERSION=3.12
3133

3234
ENV DEBIAN_FRONTEND=noninteractive
3335

@@ -53,10 +55,10 @@ RUN pip install --no-cache-dir --index-url ${ROCM_INDEX_URL} \
5355
torchaudio \
5456
&& rocm-sdk init
5557

56-
ENV ROCM_PATH="/opt/venv/lib/python3.12/site-packages/_rocm_sdk_core"
58+
ENV ROCM_PATH="/opt/venv/lib/python${PYTHON_VERSION}/site-packages/_rocm_sdk_core"
5759
ENV ROCM_HOME="${ROCM_PATH}"
58-
ENV ROCM_DEVEL_PATH="/opt/venv/lib/python3.12/site-packages/_rocm_sdk_devel"
59-
ENV ROCM_LIBRARIES_PATH="/opt/venv/lib/python3.12/site-packages/_rocm_sdk_libraries"
60+
ENV ROCM_DEVEL_PATH="/opt/venv/lib/python${PYTHON_VERSION}/site-packages/_rocm_sdk_devel"
61+
ENV ROCM_LIBRARIES_PATH="/opt/venv/lib/python${PYTHON_VERSION}/site-packages/_rocm_sdk_libraries"
6062
ENV PATH="${ROCM_PATH}/bin:${PATH}"
6163
ENV LD_LIBRARY_PATH="${ROCM_PATH}/lib:${ROCM_PATH}/lib/rocm_sysdeps/lib:${ROCM_PATH}/lib/llvm/lib:${ROCM_LIBRARIES_PATH}/lib"
6264
ENV CPATH="${ROCM_DEVEL_PATH}/include:/usr/lib/gcc/x86_64-linux-gnu/13/include"
@@ -79,16 +81,22 @@ COPY monai ./monai
7981

8082
# Use print_dependencies.py rather than -e .[all,testing] to filter CUDA-only packages:
8183
# cucim-cu* pulls in cuda-toolkit (~1.2 GB); nvidia-ml-py fails at import on ROCm; nni depends on it.
82-
# BUILD_MONAI is not set: docker build has no GPU, so extensions JIT-compile at container runtime.
84+
# BUILD_MONAI=1 builds the C++/HIP extensions ahead of time; FORCE_CUDA=1 is required because the
85+
# build host has no GPU, so setup.py's `torch.cuda.is_available()` check would otherwise skip them.
86+
# Compilation itself needs only the toolkit and PYTORCH_ROCM_ARCH (set above), not a device.
8387
# pytest is not in the "testing" extra; it is added explicitly for running tests by hand.
8488
RUN python monai/config/print_dependencies.py build-system \
8589
| xargs -d '\n' pip install --no-cache-dir --no-build-isolation \
8690
&& python monai/config/print_dependencies.py all testing \
8791
| grep -vE '^cucim-cu|^nvidia-ml-py|^nni' > /tmp/rocm-requirements-$$.txt \
88-
&& pip install --no-cache-dir --no-build-isolation \
92+
&& BUILD_MONAI=1 FORCE_CUDA=1 pip install --no-cache-dir --no-build-isolation \
8993
-r /tmp/rocm-requirements-$$.txt pytest -e . \
9094
&& rm -f /tmp/rocm-requirements-$$.txt
9195

96+
# Required at runtime too: monai.config.deviceconfig gates USE_COMPILED on this variable, so
97+
# without it the extensions built above would be present but never used.
98+
ENV BUILD_MONAI=1
99+
92100
# Set HIPCIM_INDEX_URL="" to build without WSI/cucim support.
93101
# CuImage is imported (not just cucim) because cucim uses lazy_loader -- a bare import
94102
# succeeds even when the native library is unresolvable. Failing here is deliberate: if

‎tests/networks/nets/test_densenet.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ def test_121_2d_shape_pretrain(self, model, input_param, input_shape, expected_s
9595
"ROCm may select different conv algorithms per graph; bit-exactness not guaranteed.",
9696
)
9797
def test_pretrain_consistency(self, model, input_param, input_shape):
98-
if torch.version.hip is not None:
99-
self.skipTest("ROCm may select different conv algorithms per graph; bit-exactness not guaranteed.")
10098
example = torch.randn(input_shape).to(device)
10199
with skip_if_downloading_fails():
102100
net = model(**input_param).to(device)

0 commit comments

Comments
 (0)