From 16ea44a37981e1d8e44c48f84ced7abef39559b3 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:08:03 +0800 Subject: [PATCH 1/9] add arm support Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- tests/test_convert_to_onnx.py | 19 +++++++++++++------ tests/test_dynunet.py | 9 ++++++++- tests/test_rand_affine.py | 2 +- tests/test_rand_affined.py | 10 +++++++++- tests/test_spatial_resampled.py | 9 ++++++++- 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/tests/test_convert_to_onnx.py b/tests/test_convert_to_onnx.py index 398d260c52..bbde8c346b 100644 --- a/tests/test_convert_to_onnx.py +++ b/tests/test_convert_to_onnx.py @@ -11,6 +11,7 @@ from __future__ import annotations +import platform import itertools import unittest @@ -29,6 +30,12 @@ TESTS = list(itertools.product(TORCH_DEVICE_OPTIONS, [True, False], [True, False])) TESTS_ORT = list(itertools.product(TORCH_DEVICE_OPTIONS, [True])) +ON_AARCH64 = platform.machine() == "aarch64" +if ON_AARCH64: + rtol, atol=1e-1, 1e-2 +else: + rtol, atol=1e-3, 1e-4 + onnx, _ = optional_import("onnx") @@ -56,8 +63,8 @@ def test_unet(self, device, use_trace, use_ort): device=device, use_ort=use_ort, use_trace=use_trace, - rtol=1e-3, - atol=1e-4, + rtol=rtol, + atol=atol, ) else: # https://github.com/pytorch/pytorch/blob/release/1.9/torch/onnx/__init__.py#L182 @@ -72,8 +79,8 @@ def test_unet(self, device, use_trace, use_ort): device=device, use_ort=use_ort, use_trace=use_trace, - rtol=1e-3, - atol=1e-4, + rtol=rtol, + atol=atol, ) self.assertTrue(isinstance(onnx_model, onnx.ModelProto)) @@ -107,8 +114,8 @@ def test_seg_res_net(self, device, use_ort): device=device, use_ort=use_ort, use_trace=True, - rtol=1e-3, - atol=1e-4, + rtol=rtol, + atol=atol, ) self.assertTrue(isinstance(onnx_model, onnx.ModelProto)) diff --git a/tests/test_dynunet.py b/tests/test_dynunet.py index b0137ae245..008e2f0b95 100644 --- a/tests/test_dynunet.py +++ b/tests/test_dynunet.py @@ -11,6 +11,7 @@ from __future__ import annotations +import platform import unittest from typing import Any, Sequence @@ -24,6 +25,12 @@ InstanceNorm3dNVFuser, _ = optional_import("apex.normalization", name="InstanceNorm3dNVFuser") +ON_AARCH64 = platform.machine() == "aarch64" +if ON_AARCH64: + rtol, atol=1e-2, 1e-2 +else: + rtol, atol=1e-4, 1e-4 + device = "cuda" if torch.cuda.is_available() else "cpu" strides: Sequence[Sequence[int] | int] @@ -159,7 +166,7 @@ def test_consistency(self, input_param, input_shape, _): with eval_mode(net_fuser): result_fuser = net_fuser(input_tensor) - assert_allclose(result, result_fuser, rtol=1e-4, atol=1e-4) + assert_allclose(result, result_fuser, rtol=rtol, atol=atol) class TestDynUNetDeepSupervision(unittest.TestCase): diff --git a/tests/test_rand_affine.py b/tests/test_rand_affine.py index f37f7827bb..23e3fd148c 100644 --- a/tests/test_rand_affine.py +++ b/tests/test_rand_affine.py @@ -147,7 +147,7 @@ def test_rand_affine(self, input_param, input_data, expected_val): g.set_random_state(123) result = g(**input_data) g.rand_affine_grid.affine = torch.eye(4, dtype=torch.float64) # reset affine - test_resampler_lazy(g, result, input_param, input_data, seed=123) + test_resampler_lazy(g, result, input_param, input_data, seed=123, rtol=_rtol) if input_param.get("cache_grid", False): self.assertTrue(g._cached_grid is not None) assert_allclose(result, expected_val, rtol=_rtol, atol=1e-4, type_test="tensor") diff --git a/tests/test_rand_affined.py b/tests/test_rand_affined.py index 20c50954e2..777239718e 100644 --- a/tests/test_rand_affined.py +++ b/tests/test_rand_affined.py @@ -234,7 +234,15 @@ def test_rand_affined(self, input_param, input_data, expected_val, track_meta): lazy_init_param["keys"], lazy_init_param["mode"] = key, mode resampler = RandAffined(**lazy_init_param).set_random_state(123) expected_output = resampler(**call_param) - test_resampler_lazy(resampler, expected_output, lazy_init_param, call_param, seed=123, output_key=key) + test_resampler_lazy( + resampler, + expected_output, + lazy_init_param, + call_param, + seed=123, + output_key=key, + rtol=_rtol + ) resampler.lazy = False if input_param.get("cache_grid", False): diff --git a/tests/test_spatial_resampled.py b/tests/test_spatial_resampled.py index 541015cc34..a44cd4d910 100644 --- a/tests/test_spatial_resampled.py +++ b/tests/test_spatial_resampled.py @@ -11,6 +11,7 @@ from __future__ import annotations +import platform import unittest import numpy as np @@ -23,6 +24,12 @@ from tests.lazy_transforms_utils import test_resampler_lazy from tests.utils import TEST_DEVICES, assert_allclose +ON_AARCH64 = platform.machine() == "aarch64" +if ON_AARCH64: + rtol, atol=1e-1, 1e-2 +else: + rtol, atol=1e-3, 1e-4 + TESTS = [] destinations_3d = [ @@ -104,7 +111,7 @@ def test_flips_inverse(self, img, device, dst_affine, kwargs, expected_output): # check lazy lazy_xform = SpatialResampled(**init_param) - test_resampler_lazy(lazy_xform, output_data, init_param, call_param, output_key="img") + test_resampler_lazy(lazy_xform, output_data, init_param, call_param, output_key="img", rtol=rtol, atol=atol) # check inverse inverted = xform.inverse(output_data)["img"] From 3699d5fe8eca44aedb9a8ac78cc8a4016500ca30 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:12:53 +0800 Subject: [PATCH 2/9] modify dockerfile Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index cb1300ea90..742aa5efe2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,12 @@ FROM ${PYTORCH_IMAGE} LABEL maintainer="monai.contact@gmail.com" +# TODO: remark for issue [revise the dockerfile](https://github.com/zarr-developers/numcodecs/issues/431) +WORKDIR /opt +RUN git clone --recursive https://github.com/zarr-developers/numcodecs.git +WORKDIR /opt/numcodecs +RUN pip wheel . + WORKDIR /opt/monai # install full deps From 4c528425500323d155e4ec1390a6ae9196acb7dc Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:15:28 +0800 Subject: [PATCH 3/9] change cucim to cucim-cu12 Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- requirements-dev.txt | 2 +- setup.cfg | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index b08fef874b..9c61baf866 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -26,7 +26,7 @@ mypy>=1.5.0 ninja torchvision psutil -cucim>=23.2.0; platform_system == "Linux" +cucim-cu12; platform_system == "Linux" openslide-python imagecodecs; platform_system == "Linux" or platform_system == "Darwin" tifffile; platform_system == "Linux" or platform_system == "Darwin" diff --git a/setup.cfg b/setup.cfg index 229e2ace56..d17f86307f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -59,7 +59,7 @@ all = tqdm>=4.47.0 lmdb psutil - cucim>=23.2.0 + cucim-cu12 openslide-python tifffile imagecodecs @@ -111,7 +111,7 @@ lmdb = psutil = psutil cucim = - cucim>=23.2.0 + cucim-cu12 openslide = openslide-python tifffile = From 5b0fcb2104df2a70041b4b8d17fe46abdd76e4d1 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:17:37 +0800 Subject: [PATCH 4/9] fix flake8 Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- tests/test_convert_to_onnx.py | 6 +++--- tests/test_dynunet.py | 4 ++-- tests/test_rand_affined.py | 8 +------- tests/test_spatial_resampled.py | 4 ++-- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/tests/test_convert_to_onnx.py b/tests/test_convert_to_onnx.py index bbde8c346b..798c510800 100644 --- a/tests/test_convert_to_onnx.py +++ b/tests/test_convert_to_onnx.py @@ -11,8 +11,8 @@ from __future__ import annotations -import platform import itertools +import platform import unittest import torch @@ -32,9 +32,9 @@ ON_AARCH64 = platform.machine() == "aarch64" if ON_AARCH64: - rtol, atol=1e-1, 1e-2 + rtol, atol = 1e-1, 1e-2 else: - rtol, atol=1e-3, 1e-4 + rtol, atol = 1e-3, 1e-4 onnx, _ = optional_import("onnx") diff --git a/tests/test_dynunet.py b/tests/test_dynunet.py index 008e2f0b95..f3c982056c 100644 --- a/tests/test_dynunet.py +++ b/tests/test_dynunet.py @@ -27,9 +27,9 @@ ON_AARCH64 = platform.machine() == "aarch64" if ON_AARCH64: - rtol, atol=1e-2, 1e-2 + rtol, atol = 1e-2, 1e-2 else: - rtol, atol=1e-4, 1e-4 + rtol, atol = 1e-4, 1e-4 device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/test_rand_affined.py b/tests/test_rand_affined.py index 777239718e..32fde8dc0f 100644 --- a/tests/test_rand_affined.py +++ b/tests/test_rand_affined.py @@ -235,13 +235,7 @@ def test_rand_affined(self, input_param, input_data, expected_val, track_meta): resampler = RandAffined(**lazy_init_param).set_random_state(123) expected_output = resampler(**call_param) test_resampler_lazy( - resampler, - expected_output, - lazy_init_param, - call_param, - seed=123, - output_key=key, - rtol=_rtol + resampler, expected_output, lazy_init_param, call_param, seed=123, output_key=key, rtol=_rtol ) resampler.lazy = False diff --git a/tests/test_spatial_resampled.py b/tests/test_spatial_resampled.py index a44cd4d910..d5c86258d7 100644 --- a/tests/test_spatial_resampled.py +++ b/tests/test_spatial_resampled.py @@ -26,9 +26,9 @@ ON_AARCH64 = platform.machine() == "aarch64" if ON_AARCH64: - rtol, atol=1e-1, 1e-2 + rtol, atol = 1e-1, 1e-2 else: - rtol, atol=1e-3, 1e-4 + rtol, atol = 1e-3, 1e-4 TESTS = [] From cb17ed788cee6ae888c53c6afb07c49b9933f4cf Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Tue, 27 Feb 2024 22:35:27 +0800 Subject: [PATCH 5/9] add python limit for cucim Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 9c61baf866..8f5feb3e60 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -26,7 +26,7 @@ mypy>=1.5.0 ninja torchvision psutil -cucim-cu12; platform_system == "Linux" +cucim-cu12; platform_system == "Linux"; '3.9' <= python_version <= '3.10' openslide-python imagecodecs; platform_system == "Linux" or platform_system == "Darwin" tifffile; platform_system == "Linux" or platform_system == "Darwin" From bd30cad6af53d8b7d5a095c587b4be6d961a24ec Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Tue, 27 Feb 2024 22:45:52 +0800 Subject: [PATCH 6/9] add python limit for cucim Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- requirements-dev.txt | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 8f5feb3e60..7c2f31135b 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -26,7 +26,7 @@ mypy>=1.5.0 ninja torchvision psutil -cucim-cu12; platform_system == "Linux"; '3.9' <= python_version <= '3.10' +cucim-cu12; platform_system == "Linux"; python_version >= '3.9' and python_version <= '3.10' openslide-python imagecodecs; platform_system == "Linux" or platform_system == "Darwin" tifffile; platform_system == "Linux" or platform_system == "Darwin" diff --git a/setup.cfg b/setup.cfg index d17f86307f..d7cb703d25 100644 --- a/setup.cfg +++ b/setup.cfg @@ -59,7 +59,7 @@ all = tqdm>=4.47.0 lmdb psutil - cucim-cu12 + cucim-cu12; python_version >= '3.9' and python_version <= '3.10' openslide-python tifffile imagecodecs From 2e1f75b268f8433b5d390c36e835dfff0a8a1295 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Tue, 27 Feb 2024 22:49:02 +0800 Subject: [PATCH 7/9] minor fix Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7c2f31135b..ff9df6e9b4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -26,7 +26,7 @@ mypy>=1.5.0 ninja torchvision psutil -cucim-cu12; platform_system == "Linux"; python_version >= '3.9' and python_version <= '3.10' +cucim-cu12; platform_system == "Linux" and python_version >= "3.9" and python_version <= "3.10" openslide-python imagecodecs; platform_system == "Linux" or platform_system == "Darwin" tifffile; platform_system == "Linux" or platform_system == "Darwin" From 345c342a6cc57d145819d0f2586bd2e6ecece65b Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:07:39 +0800 Subject: [PATCH 8/9] Update Dockerfile Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 742aa5efe2..7383837585 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,9 +18,7 @@ LABEL maintainer="monai.contact@gmail.com" # TODO: remark for issue [revise the dockerfile](https://github.com/zarr-developers/numcodecs/issues/431) WORKDIR /opt -RUN git clone --recursive https://github.com/zarr-developers/numcodecs.git -WORKDIR /opt/numcodecs -RUN pip wheel . +RUN git clone --recursive https://github.com/zarr-developers/numcodecs.git && pip wheel numcodecs WORKDIR /opt/monai From 773424e506c9b231c92b534f073a6c10aee06f4b Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 1 Mar 2024 00:26:51 +0800 Subject: [PATCH 9/9] address comments Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index ff9df6e9b4..af1b8b89d5 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -46,7 +46,7 @@ pynrrd pre-commit pydicom h5py -nni; platform_system == "Linux" +nni; platform_system == "Linux" and "arm" not in platform_machine and "aarch" not in platform_machine optuna git+https://github.com/Project-MONAI/MetricsReloaded@monai-support#egg=MetricsReloaded onnx>=1.13.0