You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7c06ec6
Browse filesBrowse the repository at this point in the historyBrowse files
committed
Resolve accelerator-vendor dependency variants from pyproject.toml
MONAI's dependency lists name the packages published for NVIDIA hardware
(cucim-cu*, cupy-cuda*, nvidia-*). None of them install or import on AMD ROCm,
so monai[all] and monai[cucim] are unusable there, and Dockerfile.rocm had to
grep them back out of the requirements it generated.
Rather than add a ROCm-specific escape hatch, introduce a general
accelerator-vendor mechanism: when MONAI is built or installed against a given
vendor's PyTorch, that vendor's plugin rewrites the dependency lists. The extras
keep their upstream names and meanings, and pyproject.toml stays the single,
statically readable source of truth.
monai/config/vendor_deps.py holds the generic engine -- requirement parsing,
substitution, de-duplication, the vendor registry and active_vendor(). It
carries no vendor knowledge beyond a one-line detection probe per registry
entry. monai/config/vendor_rocm.py is the first plugin, supplying the AMD
substitution table, the device extras and the rocm requirement. Supporting
another vendor means adding a registry entry and a vendor_<name>.py; setup.py
does not change. MONAI_VENDOR forces a vendor by name or disables rewriting
with `none`.
On a ROCm torch, cucim-cu12/cucim-cu13 become amd-hipcim, cupy-cuda* becomes
amd-cupy, and nvidia-ml-py, nni and nvidia-nvimgcodec-cu* are dropped.
amd-hipcim ships the cucim namespace and amd-cupy ships cupy, so every
optional_import call site works unchanged -- no runtime code changes.
Isolation is the point of the design, and is enforced rather than assumed:
- setup.py passes distclass only when a vendor is active, so an NVIDIA or CPU
build calls setup() exactly as upstream does.
- A plugin module is imported only after its registry probe matches, so a build
for one vendor never executes another vendor's code.
- monai/__init__.py eagerly imports every submodule, which pulled the packaging
modules -- and with them a vendor plugin -- into every `import monai` on every
machine. They are now excluded. This predates the vendor work.
- A vendor that is detected but whose plugin cannot be loaded, or whose contract
is malformed, fails the build. Falling back to the unmodified lists would ship
NVIDIA packages in a ROCm wheel, which is worse than failing. The contract is
checked on load because neither mistake raises where it would be used:
`key in substitutions` is a substring test on a string, so a SUBSTITUTIONS
that is not a mapping quietly matches nothing, and lookups are canonicalised,
so a key that is not already a PEP 503 name can never match either.
- pip build isolation resolves torch afresh, and a plain PyPI wheel outranks a
vendor build of the same release under PEP 440, so a source install on an AMD
machine can be handed a CUDA torch, detect no vendor, and emit CUDA
dependencies at exit 0. MONAI now warns when it finds an AMD GPU but no ROCm
torch; MONAI_VENDOR=none keeps a deliberate CPU build on that hardware quiet.
The rocm requirement pins the ROCm *release*, never the HIP version. These are
different numbers: ROCm 10.0 ships HIP 7.15 and ROCm 10.1 ships HIP 7.16, while
the rocm package is versioned by the release, so torch.version.hip or
hipcc --version yield a requirement no index can satisfy. Detection reads the
release from the tree ROCM_PATH/ROCM_HOME point at, then the rocm package
installed here, then `rocm-sdk version`, and only then a system install, so an
unrelated /opt/rocm cannot shadow the SDK being built against. Reading files
rather than probing PATH also keeps detection working under pip build
isolation.
The requirement requests the libraries, devel and per-arch device features and
spans ROCM_SERIES_SPAN minor series. devel is needed after install, not only to
build: rocm-sdk-core ships libamdhip64.so.7 but not the unversioned
libamdhip64.so, so only the devel tree can satisfy a link, and monai/_extensions
JIT-compiles its HIP sources through torch.utils.cpp_extension.load() on first
use. The span reflects measurement: amd-cupy, amd-hipcim and a MONAI wheel built
for ROCm 10.0 all run on a 10.1 runtime, and a one-minor ceiling made pip
backtrack off the real wheel onto a 0.0.2 PyPI placeholder stub -- a silent
downgrade rather than an error.
Also report the HIP toolkit version in get_gpu_info() on ROCm builds, where
torch.version.cuda is None and print_config() showed "CUDA version: None". Only
the key name changes; it stays behind the existing Has CUDA guard.
Dockerfile.rocm drops the grep filter and the separate amd-hipcim install step,
both now redundant, and passes AMD's index to the main install.
docs/source/installation.md documents the vendor mechanism and gives the full
ROCm recipe, including the two ways to install from source under build
isolation.
Verified end to end on an AMD Instinct MI355X: a clean environment installing
monai[cucim] from this branch resolves amd-hipcim, amd-cupy and a ROCm torch
with zero CUDA packages, and cupy, cucim and MONAI transforms, losses and
metrics all run on the GPU. Across isolated CPU-only, NVIDIA and ROCm build
environments on a host carrying both a system /opt/rocm and /usr/local/cuda,
non-vendor builds are unaffected: generated metadata and print_dependencies.py
output are identical to dev, no vendor module is imported, and no distclass is
passed. Faults injected into the ROCm plugin -- a SyntaxError, raising at
import, raising while computing the requirement, and a malformed substitution
table -- each fail the ROCm build and leave the CPU and NVIDIA builds
byte-identical. Also verified on an NVIDIA H100.
Signed-off-by: Prateek Chokse <prateek.chokse@amd.com>
Signed-off-by: Nilaykumar K Patel <NilaykumarKantibhai.Patel@amd.com>
Co-authored-by: Vikas C Sajjan <Vikas.CSajjan@amd.com>
Co-authored-by: Soumitra Chatterjee <Soumitra.Chatterjee@amd.com>
Co-authored-by: Nilaykumar K Patel <NilaykumarKantibhai.Patel@amd.com>
Co-authored-by: Anik Chaudhuri <Anik.Chaudhuri@amd.com>
0 commit comments