Skip to content

Commit 89653fc

Browse files
authored
Merge branch 'dev' into 9069-py312-full-dep-observability
2 parents 486e75b + 657f098 commit 89653fc

21 files changed

Lines changed: 265 additions & 251 deletions

‎.github/workflows/ci_tests_gpu.yml‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: tests
2+
3+
on:
4+
schedule:
5+
- cron: "0 2 * * 3" # at 02:00 UTC Wednesday
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
# automatically cancel the previously triggered workflows when there's a newer version
13+
group: cicd-tests-gpu-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
# Supported versions of Python and PyTorch are listed here for use below and as documentation
17+
env:
18+
# supported versions of Python, copied from ci_tests.yml and should be synced where appropriate with that file
19+
PYTHON_VER1: '3.11'
20+
PYTORCH_VER1: '2.12.1'
21+
PYTORCH_VER3: '2.14.1' # for hyena tests, should be updated when possible
22+
TORCHVISION_VER1: '0.27.1' # used for testing with lowest PyTorch version (PYTORCH_VER1), update as needed
23+
24+
TQDM_DISABLE: 1 # squelch TQDM output to reduce log file size
25+
26+
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: python # https://github.com/Project-MONAI/MONAI/issues/4354
27+
28+
BUILD_MONAI: 1 # always build MONAI and ensure it tries to use the compiled extensions
29+
FORCE_CUDA: 1 # ensure CUDA code is built
30+
31+
jobs:
32+
33+
full-dep-gpu:
34+
runs-on: [self-hosted, linux, gpu]
35+
strategy:
36+
fail-fast: false
37+
timeout-minutes: 360
38+
steps:
39+
- uses: actions/checkout@v7
40+
- name: Set up Python ${{ env.PYTHON_VER1 }}
41+
uses: actions/setup-python@v6
42+
with:
43+
python-version: ${{ env.PYTHON_VER1 }}
44+
cache: 'pip'
45+
- name: Install the complete dependencies
46+
run: |
47+
python -m pip install --upgrade pip wheel wheel_stub
48+
python -m pip install torch==${PYTORCH_VER1} torchvision==${TORCHVISION_VER1}
49+
python -m pip install --pre -U itk # TODO: needed?
50+
python monai/config/print_dependencies.py build-system | xargs pip install --no-build-isolation
51+
# tests below use the MONAI in the current directory, -e ensures the compiled code stays there and is found
52+
python -m pip install --no-build-isolation torch==${PYTORCH_VER1} torchvision==${TORCHVISION_VER1} -e .[all,testing,nvimgcodec]
53+
shell: bash
54+
- name: Run (almost) all tests
55+
run: |
56+
python -c 'import monai._C; cap=monai._C.max_compute_capability(); assert cap > 0, f"Capabilities too low: {cap}"'
57+
nvidia-smi || true
58+
python monai/config/check_env.py --env --monai
59+
./runtests.sh -u --net
60+
# env: # FIXME: NGC test failing with "RuntimeError: NGC API response is not ok. Failed to get token." Need to fix key?
61+
# NGC_API_KEY: ${{ secrets.NGC_API_KEY }}
62+
# NGC_ORG: ${{ secrets.NGC_ORG }}
63+
# NGC_TEAM: ${{ secrets.NGC_TEAM }}
64+
65+
full-dep-gpu-hyena:
66+
runs-on: [self-hosted, linux, gpu]
67+
strategy:
68+
fail-fast: false
69+
timeout-minutes: 30
70+
steps:
71+
- uses: actions/checkout@v7
72+
- name: Set up Python ${{ env.PYTHON_VER1 }}
73+
uses: actions/setup-python@v6
74+
with:
75+
python-version: ${{ env.PYTHON_VER1 }}
76+
cache: 'pip'
77+
- name: Install the complete dependencies
78+
run: |
79+
python -m pip install --upgrade pip wheel wheel_stub
80+
python -m pip install torch==${PYTORCH_VER3} torchvision
81+
python monai/config/print_dependencies.py build-system | xargs pip install --no-build-isolation
82+
# tests below use the MONAI in the current directory, -e ensures the compiled code stays there and is found
83+
python -m pip install --no-build-isolation -e .[testing,hyena]
84+
shell: bash
85+
- name: Run Hyena tests
86+
run: |
87+
python -c "import torch; from monai.networks.blocks.hyena import is_nvsubquadratic_available; \
88+
assert torch.cuda.is_available(), 'No CUDA devices found.'; \
89+
assert is_nvsubquadratic_available(), 'nvsubquadratic must be importable.'"
90+
python -m unittest tests.networks.blocks.test_hyena_block tests.networks.nets.test_hyena_nd_unetr tests.networks.nets.test_swin_unetr

‎Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ RUN wget -q ${NGC_CLI_URI} && unzip ngccli_linux.zip && chmod u+x ngc-cli/ngc &&
3434
rm -rf ngccli_linux.zip ngc-cli.md5
3535
ENV PATH=${PATH}:/opt/tools:/opt/tools/ngc-cli
3636
RUN apt-get update \
37-
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y libopenslide0 \
37+
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y libopenslide0 libopenmpi3 \
3838
&& rm -rf /var/lib/apt/lists/*
3939
# append /opt/tools to runtime path for NGC CLI to be accessible from all file system locations
4040
ENV PATH=${PATH}:/opt/tools

‎Dockerfile.slim‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ FROM ${IMAGE} AS build2
6161
ENV DEBIAN_FRONTEND=noninteractive
6262
ENV APT_INSTALL="apt install -y --no-install-recommends"
6363

64+
# install the necessary libraries for running Python and for Triton to build kernels when needed
6465
RUN apt update && apt upgrade -y && \
65-
${APT_INSTALL} ca-certificates python-is-python3 git libopenslide0 && \
66+
${APT_INSTALL} ca-certificates python-is-python3 python3-dev git libopenslide0 build-essential && \
6667
apt clean && \
6768
rm -rf /usr/lib/python*/EXTERNALLY-MANAGED /var/lib/apt/lists/*
6869

‎monai/config/deviceconfig.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ def print_config(file=sys.stdout):
114114
fprint(f"MONAI flags: {HAS_EXT=}, {USE_COMPILED=}, {USE_META_DICT=}", file=file)
115115
fprint(f"MONAI rev id: {monai.__revision_id__}", file=file)
116116
fprint(f"MONAI __file__: {monai.__file__}", file=file)
117+
118+
if HAS_EXT:
119+
fprint(f"monai._C.max_compute_capability: {monai._C.max_compute_capability()}", file=file)
120+
fprint(f"monai._C.compiled_with_cuda: {monai._C.compiled_with_cuda()}", file=file)
121+
fprint(f"monai._C.monai_torch_version: {monai._C.monai_torch_version()}", file=file)
122+
117123
fprint("\nOptional dependencies:", file=file)
118124
for k, v in get_optional_config_values().items():
119125
fprint(f"{k} version: {v}", file=file)

‎monai/csrc/ext.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
7272
#endif
7373
}, "Maximum compute capability (major*100+minor) the extension was compiled for, or 0 if unknown");
7474

75+
m.def("compiled_with_cuda", []() {
76+
#ifdef WITH_CUDA
77+
return 1;
78+
#else
79+
return 0;
80+
#endif
81+
}, "Returns 1 if compiled with WITH_CUDA set, 0 otherwise");
82+
83+
m.def("monai_torch_version", []() { return MONAI_TORCH_VERSION; }, "PyTorch version used for compilation");
84+
7585
// resample
7686
m.def("grid_pull", &monai::grid_pull, "GridPull");
7787
m.def("grid_pull_backward", &monai::grid_pull_backward, "GridPull backward");

‎monai/data/nvimgcodec_pydicom_plugin.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ def register_as_decoder_plugin(module_path: str | None = None) -> bool:
6767
"""Register the nvImageCodec pydicom decoder plugin."""
6868
if not is_nvimgcodec_available():
6969
_logger.debug("nvImageCodec is not available; skipping pydicom decoder plugin registration.")
70-
return False
71-
if not has_pydicom_plugin:
72-
return False
73-
return bool(pydicom_plugin.register(module_path))
70+
elif not has_pydicom_plugin:
71+
_logger.debug("nvImageCodec does not have pydicom_plugin; skipping pydicom decoder plugin registration.")
72+
elif not bool(pydicom_plugin.register(module_path)):
73+
_logger.debug("nvImageCodec pydicom_plugin failed to register; skipping pydicom decoder plugin registration.")
74+
else:
75+
return True # every check and register() succeeded
76+
77+
return False
7478

7579

7680
def unregister_as_decoder_plugin() -> bool:

‎monai/engines/trainer.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def run(self) -> None: # type: ignore[override]
5151
If call this function multiple times, it will continuously run from the previous state.
5252
5353
"""
54-
self.scaler = torch.cuda.amp.GradScaler() if self.amp else None
54+
self.scaler = torch.amp.GradScaler() if self.amp else None
5555
super().run()
5656

5757
def get_stats(self, *vars):
@@ -613,8 +613,8 @@ def __init__(
613613
self.g_inferer = SimpleInferer() if g_inferer is None else g_inferer
614614
self.d_inferer = SimpleInferer() if d_inferer is None else d_inferer
615615

616-
self.state.g_scaler = torch.cuda.amp.GradScaler() if self.amp else None
617-
self.state.d_scaler = torch.cuda.amp.GradScaler() if self.amp else None
616+
self.state.g_scaler = torch.amp.GradScaler() if self.amp else None
617+
self.state.d_scaler = torch.amp.GradScaler() if self.amp else None
618618

619619
self.optim_set_to_none = optim_set_to_none
620620
self._complete_state_dict_user_keys()

‎monai/engines/workflow.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def set_sampler_epoch(engine: Engine) -> None:
165165
self.amp = amp
166166
self.to_kwargs = {} if to_kwargs is None else to_kwargs
167167
self.amp_kwargs = {} if amp_kwargs is None else amp_kwargs
168-
self.scaler: torch.cuda.amp.GradScaler | None = None
168+
self.scaler: torch.amp.GradScaler | None = None
169169

170170
if event_names is None:
171171
event_names = [IterationEvents]

‎monai/losses/image_dissimilarity.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ def forward(self, pred: torch.Tensor, target: torch.Tensor) -> torch.Tensor:
361361
wa, pa, wb, pb = self.parzen_windowing(pred, target) # (batch, num_sample, num_bin), (batch, 1, num_bin)
362362

363363
pab = torch.bmm(wa.permute(0, 2, 1), wb.to(wa)).div(wa.shape[1]) # (batch, num_bins, num_bins)
364-
papb = torch.bmm(pa.permute(0, 2, 1), pb.to(pa)) # (batch, num_bins, num_bins)
364+
# FIXME: in CI tests bmm raises "RuntimeError: Failed to find C compiler." when it tries to compile a kernel,
365+
# using permite here instead of bmm gets around this as there are no means of forcing native ops.
366+
papb = pa.permute(0, 2, 1).to(pb).mul(pb).to(pab) # (batch, num_bins, num_bins)
367+
365368
mi = torch.sum(
366369
pab * torch.log((pab + self.smooth_nr) / (papb + self.smooth_dr) + self.smooth_dr), dim=(1, 2)
367370
) # (batch)

‎monai/networks/nets/senet.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
]
3939

4040
SE_NET_MODELS = {
41-
"senet154": "http://data.lip6.fr/cadene/pretrainedmodels/senet154-c7b49a05.pth",
42-
"se_resnet50": "http://data.lip6.fr/cadene/pretrainedmodels/se_resnet50-ce0d4300.pth",
43-
"se_resnet101": "http://data.lip6.fr/cadene/pretrainedmodels/se_resnet101-7e38fcc6.pth",
44-
"se_resnet152": "http://data.lip6.fr/cadene/pretrainedmodels/se_resnet152-d17c99b7.pth",
45-
"se_resnext50_32x4d": "http://data.lip6.fr/cadene/pretrainedmodels/se_resnext50_32x4d-a260b3a4.pth",
46-
"se_resnext101_32x4d": "http://data.lip6.fr/cadene/pretrainedmodels/se_resnext101_32x4d-3b2fe3d8.pth",
41+
"senet154": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/senet154-c7b49a05.pth",
42+
"se_resnet50": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnet50-ce0d4300.pth",
43+
"se_resnet101": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnet101-7e38fcc6.pth",
44+
"se_resnet152": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnet152-d17c99b7.pth",
45+
"se_resnext50_32x4d": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnext50_32x4d-a260b3a4.pth",
46+
"se_resnext101_32x4d": "https://huggingface.co/datasets/MONAI/testing_data/resolve/main/se_resnext101_32x4d-3b2fe3d8.pth",
4747
}
4848

4949

0 commit comments

Comments
 (0)