diff --git a/tests/__init__.py b/tests/__init__.py index 58422f803e..1e97f89407 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -8,32 +8,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -from __future__ import annotations - -import sys -import unittest -import warnings - - -def _enter_pr_4800(self): - """ - code from https://github.com/python/cpython/pull/4800 - """ - # The __warningregistry__'s need to be in a pristine state for tests - # to work properly. - for v in list(sys.modules.values()): - if getattr(v, "__warningregistry__", None): - v.__warningregistry__ = {} - self.warnings_manager = warnings.catch_warnings(record=True) - self.warnings = self.warnings_manager.__enter__() - warnings.simplefilter("always", self.expected) - return self - - -# FIXME: workaround for https://bugs.python.org/issue29620 -try: - # Suppression for issue #494: tests/__init__.py:34: error: Cannot assign to a method - unittest.case._AssertWarnsContext.__enter__ = _enter_pr_4800 # type: ignore -except AttributeError: - pass diff --git a/tests/apps/detection/networks/test_retinanet.py b/tests/apps/detection/networks/test_retinanet.py index 9def63c1d3..cb4129f7ed 100644 --- a/tests/apps/detection/networks/test_retinanet.py +++ b/tests/apps/detection/networks/test_retinanet.py @@ -20,7 +20,7 @@ from monai.networks import eval_mode from monai.networks.nets import resnet10, resnet18, resnet34, resnet50, resnet101, resnet152, resnet200 from monai.utils import ensure_tuple, optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, dict_product, skip_if_quick, test_onnx_save, test_script_save +from tests.test_utils import dict_product, skip_if_quick, test_onnx_save, test_script_save _, has_torchvision = optional_import("torchvision") @@ -94,7 +94,6 @@ TEST_CASES_TS = [[params["model"], *params["case"]] for params in dict_product(model=MODEL_LIST, case=[TEST_CASE_1])] -@SkipIfBeforePyTorchVersion((1, 12)) @unittest.skipUnless(has_torchvision, "Requires torchvision") @skip_if_quick class TestRetinaNet(unittest.TestCase): diff --git a/tests/apps/detection/networks/test_retinanet_detector.py b/tests/apps/detection/networks/test_retinanet_detector.py index b91ea46b4b..6ac1efd734 100644 --- a/tests/apps/detection/networks/test_retinanet_detector.py +++ b/tests/apps/detection/networks/test_retinanet_detector.py @@ -21,7 +21,7 @@ from monai.apps.detection.utils.anchor_utils import AnchorGeneratorWithAnchorShape from monai.networks import eval_mode, train_mode from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save +from tests.test_utils import skip_if_quick, test_script_save _, has_torchvision = optional_import("torchvision") @@ -110,7 +110,6 @@ def forward(self, images): return {self.cls_key: [torch.randn(out_cls_shape)], self.box_reg_key: [torch.randn(out_box_reg_shape)]} -@SkipIfBeforePyTorchVersion((1, 11)) @unittest.skipUnless(has_torchvision, "Requires torchvision") @skip_if_quick class TestRetinaNetDetector(unittest.TestCase): diff --git a/tests/apps/detection/utils/test_anchor_box.py b/tests/apps/detection/utils/test_anchor_box.py index 7543c84ed9..b537c2533c 100644 --- a/tests/apps/detection/utils/test_anchor_box.py +++ b/tests/apps/detection/utils/test_anchor_box.py @@ -18,7 +18,7 @@ from monai.apps.detection.utils.anchor_utils import AnchorGenerator, AnchorGeneratorWithAnchorShape from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, assert_allclose, test_script_save +from tests.test_utils import assert_allclose, test_script_save _, has_torchvision = optional_import("torchvision") @@ -39,7 +39,6 @@ ] -@SkipIfBeforePyTorchVersion((1, 11)) @unittest.skipUnless(has_torchvision, "Requires torchvision") class TestAnchorGenerator(unittest.TestCase): @parameterized.expand(TEST_CASES_2D) diff --git a/tests/apps/maisi/networks/test_autoencoderkl_maisi.py b/tests/apps/maisi/networks/test_autoencoderkl_maisi.py index 6b9aae1d17..1470cb853a 100644 --- a/tests/apps/maisi/networks/test_autoencoderkl_maisi.py +++ b/tests/apps/maisi/networks/test_autoencoderkl_maisi.py @@ -19,7 +19,6 @@ from monai.apps.generation.maisi.networks.autoencoderkl_maisi import AutoencoderKlMaisi from monai.networks import eval_mode from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion tqdm, has_tqdm = optional_import("tqdm", name="tqdm") _, has_einops = optional_import("einops") @@ -87,7 +86,6 @@ def test_shape(self, input_param, input_shape, expected_shape, expected_latent_s self.assertEqual(result[2].shape, expected_latent_shape) @parameterized.expand(CASES) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_with_convtranspose_and_checkpointing( self, input_param, input_shape, expected_shape, expected_latent_shape ): @@ -152,7 +150,6 @@ def test_shape_reconstruction(self): result = net.reconstruct(torch.randn(input_shape).to(device)) self.assertEqual(result.shape, expected_shape) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_reconstruction_with_convtranspose_and_checkpointing(self): input_param, input_shape, expected_shape, _ = CASES[0] input_param = input_param.copy() @@ -170,7 +167,6 @@ def test_shape_encode(self): self.assertEqual(result[0].shape, expected_latent_shape) self.assertEqual(result[1].shape, expected_latent_shape) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_encode_with_convtranspose_and_checkpointing(self): input_param, input_shape, _, expected_latent_shape = CASES[0] input_param = input_param.copy() @@ -190,7 +186,6 @@ def test_shape_sampling(self): ) self.assertEqual(result.shape, expected_latent_shape) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_sampling_convtranspose_and_checkpointing(self): input_param, _, _, expected_latent_shape = CASES[0] input_param = input_param.copy() @@ -209,7 +204,6 @@ def test_shape_decode(self): result = net.decode(torch.randn(latent_shape).to(device)) self.assertEqual(result.shape, expected_input_shape) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_decode_convtranspose_and_checkpointing(self): input_param, expected_input_shape, _, latent_shape = CASES[0] input_param = input_param.copy() diff --git a/tests/apps/maisi/networks/test_controlnet_maisi.py b/tests/apps/maisi/networks/test_controlnet_maisi.py index 2668398350..5868d1e308 100644 --- a/tests/apps/maisi/networks/test_controlnet_maisi.py +++ b/tests/apps/maisi/networks/test_controlnet_maisi.py @@ -20,7 +20,6 @@ from monai.apps.generation.maisi.networks.controlnet_maisi import ControlNetMaisi from monai.networks import eval_mode from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion _, has_einops = optional_import("einops") @@ -127,7 +126,6 @@ ] -@SkipIfBeforePyTorchVersion((2, 0)) class TestControlNet(unittest.TestCase): @parameterized.expand(TEST_CASES) @skipUnless(has_einops, "Requires einops") diff --git a/tests/test_auto3dseg.py b/tests/apps/test_auto3dseg.py similarity index 100% rename from tests/test_auto3dseg.py rename to tests/apps/test_auto3dseg.py diff --git a/tests/apps/test_auto3dseg_bundlegen.py b/tests/apps/test_auto3dseg_bundlegen.py index f82782c21f..6098d991fc 100644 --- a/tests/apps/test_auto3dseg_bundlegen.py +++ b/tests/apps/test_auto3dseg_bundlegen.py @@ -26,13 +26,7 @@ from monai.bundle.config_parser import ConfigParser from monai.data import create_test_image_3d from monai.utils import set_determinism -from tests.test_utils import ( - SkipIfBeforePyTorchVersion, - get_testing_algo_template_path, - skip_if_downloading_fails, - skip_if_no_cuda, - skip_if_quick, -) +from tests.test_utils import get_testing_algo_template_path, skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick num_images_perfold = max(torch.cuda.device_count(), 4) num_images_per_batch = 2 @@ -104,7 +98,6 @@ def run_auto3dseg_before_bundlegen(test_path, work_dir): @skip_if_no_cuda -@SkipIfBeforePyTorchVersion((1, 11, 1)) @skip_if_quick class TestBundleGen(unittest.TestCase): def setUp(self) -> None: diff --git a/tests/apps/vista3d/test_point_based_window_inferer.py b/tests/apps/vista3d/test_point_based_window_inferer.py index de57d39606..8e13a4cefb 100644 --- a/tests/apps/vista3d/test_point_based_window_inferer.py +++ b/tests/apps/vista3d/test_point_based_window_inferer.py @@ -20,7 +20,7 @@ from monai.networks import eval_mode from monai.networks.nets.vista3d import vista3d132 from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_quick +from tests.test_utils import skip_if_quick device = "cuda" if torch.cuda.is_available() else "cpu" @@ -60,7 +60,6 @@ ] -@SkipIfBeforePyTorchVersion((1, 11)) @skip_if_quick class TestPointBasedWindowInferer(unittest.TestCase): @parameterized.expand(TEST_CASES) diff --git a/tests/bundle/test_bundle_download.py b/tests/bundle/test_bundle_download.py index c8adb966b0..650b0d7930 100644 --- a/tests/bundle/test_bundle_download.py +++ b/tests/bundle/test_bundle_download.py @@ -28,12 +28,12 @@ from monai.bundle.scripts import _examine_monai_version, _list_latest_versions, download from monai.utils import optional_import from tests.test_utils import ( - SkipIfBeforePyTorchVersion, assert_allclose, command_line_tests, skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick, + skip_if_windows, ) _, has_huggingface_hub = optional_import("huggingface_hub") @@ -95,6 +95,47 @@ {"model.pt": "27952767e2e154e3b0ee65defc5aed38", "model.ts": "97746870fe591f69ac09827175b00675"}, ] +TEST_CASE_NGC_1 = [ + "spleen_ct_segmentation", + "0.3.7", + None, + "monai_spleen_ct_segmentation", + "models/model.pt", + "b418a2dc8672ce2fd98dc255036e7a3d", +] +TEST_CASE_NGC_2 = [ + "monai_spleen_ct_segmentation", + "0.3.7", + "monai_", + "spleen_ct_segmentation", + "models/model.pt", + "b418a2dc8672ce2fd98dc255036e7a3d", +] + +TESTCASE_NGC_WEIGHTS = { + "key": "model.0.conv.unit0.adn.N.bias", + "value": torch.tensor( + [ + -0.0705, + -0.0937, + -0.0422, + -0.2068, + 0.1023, + -0.2007, + -0.0883, + 0.0018, + -0.1719, + 0.0116, + 0.0285, + -0.0044, + 0.1223, + -0.1287, + -0.1858, + 0.0460, + ] + ), +} + class TestDownload(unittest.TestCase): @parameterized.expand([TEST_CASE_1, TEST_CASE_2]) @@ -356,7 +397,6 @@ def test_load_weights_with_net_override(self, bundle_name, device, net_override) @parameterized.expand([TEST_CASE_9]) @skip_if_quick - @SkipIfBeforePyTorchVersion((1, 7, 1)) def test_load_ts_module(self, bundle_files, bundle_name, version, repo, device, model_file): with skip_if_downloading_fails(): # load ts module @@ -419,5 +459,31 @@ def test_url_download_large_files(self, bundle_files, bundle_name, url, hash_val self.assertTrue(check_hash(filepath=file_path, val=hash_val[file])) +@skip_if_windows +class TestNgcBundleDownload(unittest.TestCase): + @parameterized.expand([TEST_CASE_NGC_1, TEST_CASE_NGC_2]) + @skip_if_quick + def test_ngc_download_bundle(self, bundle_name, version, remove_prefix, download_name, file_path, hash_val): + with skip_if_downloading_fails(): + with tempfile.TemporaryDirectory() as tempdir: + download( + name=bundle_name, source="ngc", version=version, bundle_dir=tempdir, remove_prefix=remove_prefix + ) + full_file_path = os.path.join(tempdir, download_name, file_path) + self.assertTrue(os.path.exists(full_file_path)) + self.assertTrue(check_hash(filepath=full_file_path, val=hash_val)) + + model = load( + name=bundle_name, source="ngc", version=version, bundle_dir=tempdir, remove_prefix=remove_prefix + ) + assert_allclose( + model.state_dict()[TESTCASE_NGC_WEIGHTS["key"]], + TESTCASE_NGC_WEIGHTS["value"], + atol=1e-4, + rtol=1e-4, + type_test=False, + ) + + if __name__ == "__main__": unittest.main() diff --git a/tests/test_print_info.py b/tests/config/test_print_info.py similarity index 100% rename from tests/test_print_info.py rename to tests/config/test_print_info.py diff --git a/tests/data/meta_tensor/test_meta_tensor.py b/tests/data/meta_tensor/test_meta_tensor.py index 1ee5531b76..c0e53fd24c 100644 --- a/tests/data/meta_tensor/test_meta_tensor.py +++ b/tests/data/meta_tensor/test_meta_tensor.py @@ -32,7 +32,7 @@ from monai.data.utils import decollate_batch, list_data_collate from monai.transforms import BorderPadd, Compose, DivisiblePadd, FromMetaTensord, ToMetaTensord from monai.utils.enums import PostFix -from tests.test_utils import TEST_DEVICES, SkipIfBeforePyTorchVersion, assert_allclose, dict_product, skip_if_no_cuda +from tests.test_utils import TEST_DEVICES, assert_allclose, dict_product, skip_if_no_cuda DTYPES = [[torch.float32], [torch.float64], [torch.float16], [torch.int64], [torch.int32], [None]] @@ -297,7 +297,6 @@ def test_dataset(self, device, dtype): self.check(im, ims[i], ids=True) @parameterized.expand(DTYPES) - @SkipIfBeforePyTorchVersion((1, 8)) def test_dataloader(self, dtype): batch_size = 5 ims = [self.get_im(dtype=dtype)[0] for _ in range(batch_size * 2)] @@ -314,7 +313,6 @@ def test_dataloader(self, dtype): self.assertTupleEqual(tuple(batch.affine.shape), expected_affine_shape) self.assertEqual(len(batch.applied_operations), batch_size) - @SkipIfBeforePyTorchVersion((1, 9)) def test_indexing(self): """ Check the metadata is returned in the expected format depending on whether @@ -406,7 +404,6 @@ def test_slicing(self): self.assertEqual(x[[True, False, True]].shape, (2, 3, 4)) @parameterized.expand(DTYPES) - @SkipIfBeforePyTorchVersion((1, 8)) def test_decollate(self, dtype): batch_size = 3 ims = [self.get_im(dtype=dtype)[0] for _ in range(batch_size * 2)] diff --git a/tests/data/test_shuffle_buffer.py b/tests/data/test_shuffle_buffer.py index ee0ce9e2d1..274121ec77 100644 --- a/tests/data/test_shuffle_buffer.py +++ b/tests/data/test_shuffle_buffer.py @@ -18,10 +18,8 @@ from monai.data import DataLoader, ShuffleBuffer from monai.utils import convert_data_type -from tests.test_utils import SkipIfBeforePyTorchVersion -@SkipIfBeforePyTorchVersion((1, 12)) class TestShuffleBuffer(unittest.TestCase): def test_shape(self): buffer = ShuffleBuffer([1, 2, 3, 4], seed=0) diff --git a/tests/fl/monai_algo/test_fl_monai_algo_dist.py b/tests/fl/monai_algo/test_fl_monai_algo_dist.py index 744169e10d..c198ee5431 100644 --- a/tests/fl/monai_algo/test_fl_monai_algo_dist.py +++ b/tests/fl/monai_algo/test_fl_monai_algo_dist.py @@ -23,7 +23,7 @@ from monai.fl.utils.constants import ExtraItems from monai.fl.utils.exchange_object import ExchangeObject from monai.networks import get_state_dict -from tests.test_utils import DistCall, DistTestCase, SkipIfBeforePyTorchVersion, SkipIfNoModule, skip_if_no_cuda +from tests.test_utils import DistCall, DistTestCase, SkipIfNoModule, skip_if_no_cuda TESTS_PATH = TESTS_PATH = Path(__file__).parents[2].as_posix() _root_dir = os.path.abspath(pathjoin(TESTS_PATH)) @@ -32,7 +32,6 @@ @SkipIfNoModule("ignite") -@SkipIfBeforePyTorchVersion((1, 11, 1)) class TestFLMonaiAlgo(DistTestCase): @DistCall(nnodes=1, nproc_per_node=2, init_method="no_init") @skip_if_no_cuda diff --git a/tests/handlers/test_handler_tb_image.py b/tests/handlers/test_handler_tb_image.py index 2ed37bdbc7..8657e552f1 100644 --- a/tests/handlers/test_handler_tb_image.py +++ b/tests/handlers/test_handler_tb_image.py @@ -23,7 +23,6 @@ from monai.data import decollate_batch from monai.handlers import TensorBoardImageHandler from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") @@ -31,7 +30,6 @@ @unittest.skipUnless(has_tb, "Requires SummaryWriter installation") -@SkipIfBeforePyTorchVersion((1, 13)) # issue 6683 class TestHandlerTBImage(unittest.TestCase): @parameterized.expand(TEST_CASES) def test_tb_image_shape(self, shape): diff --git a/tests/inferers/test_zarr_avg_merger.py b/tests/inferers/test_zarr_avg_merger.py index 8dfd4cd96b..b4e26d6beb 100644 --- a/tests/inferers/test_zarr_avg_merger.py +++ b/tests/inferers/test_zarr_avg_merger.py @@ -11,7 +11,9 @@ from __future__ import annotations +import os import unittest +from tempfile import TemporaryDirectory import numpy as np import torch @@ -22,16 +24,7 @@ from monai.utils import get_package_version, optional_import, version_geq from tests.test_utils import assert_allclose -np.seterr(divide="ignore", invalid="ignore") zarr, has_zarr = optional_import("zarr") -print(version_geq(get_package_version("zarr"), "3.0.0")) -if has_zarr: - if version_geq(get_package_version("zarr"), "3.0.0"): - directory_store = zarr.storage.LocalStore("test.zarr") - else: - directory_store = zarr.storage.DirectoryStore("test.zarr") -else: - directory_store = None numcodecs, has_numcodecs = optional_import("numcodecs") TENSOR_4x4 = torch.randint(low=0, high=255, size=(2, 3, 4, 4), dtype=torch.float32) @@ -160,9 +153,9 @@ pad(TENSOR_4x4, (0, 2), value=float("nan")), ] -# explicit directory store +# explicit directory store, defer creating the store until test time by using the placeholder value "directory_store" TEST_CASE_10_DIRECTORY_STORE = [ - dict(merged_shape=TENSOR_4x4.shape, store=directory_store), + dict(merged_shape=TENSOR_4x4.shape, store="directory_store"), [ (TENSOR_4x4[..., :2, :2], (0, 0)), (TENSOR_4x4[..., :2, 2:], (0, 2)), @@ -352,10 +345,30 @@ @unittest.skipUnless(has_zarr and has_numcodecs, "Requires zarr (and numcodecs) packages.)") class ZarrAvgMergerTests(unittest.TestCase): + def setUp(self): + self.orig_settings = np.seterr(divide="ignore", invalid="ignore") + self.temp_dir = TemporaryDirectory() + self.merged_name = os.path.join(self.temp_dir.name, "merged.zarr") + + def tearDown(self): + np.seterr(**self.orig_settings) + self.temp_dir.cleanup() + + def _get_directory_store(self, base_dir): + zarr_path = os.path.join(base_dir, "test.zarr") + + if version_geq(get_package_version("zarr"), "3.0.0"): + directory_store = zarr.storage.LocalStore(zarr_path) + else: + directory_store = zarr.storage.DirectoryStore(zarr_path) + + return directory_store + @parameterized.expand(ALL_TESTS) def test_zarr_avg_merger_patches(self, arguments, patch_locations, expected): is_zarr_v3 = version_geq(get_package_version("zarr"), "3.0.0") codec_reg = numcodecs.registry.codec_registry + arguments = dict(arguments) # Handle compressor/codecs based on zarr version if "compressor" in arguments and is_zarr_v3: @@ -405,7 +418,15 @@ def test_zarr_avg_merger_patches(self, arguments, patch_locations, expected): if arguments["count_compressor"] != "default" and arguments["count_compressor"] is not None: arguments["count_compressor"] = codec_reg[arguments["count_compressor"].lower()]() + # ensure the merged directory is in the temporary directory and not the current directory + + if "store" not in arguments: + arguments["store"] = self.merged_name + elif arguments["store"] == "directory_store": + arguments["store"] = self._get_directory_store(self.temp_dir.name) # get store object now + merger = ZarrAvgMerger(**arguments) + for pl in patch_locations: merger.aggregate(pl[0], pl[1]) output = merger.finalize() @@ -420,10 +441,14 @@ def test_zarr_avg_merger_patches(self, arguments, patch_locations, expected): def test_zarr_avg_merger_finalized_error(self): with self.assertRaises(ValueError): - merger = ZarrAvgMerger(merged_shape=(1, 3, 2, 3)) + merger = ZarrAvgMerger(merged_shape=(1, 3, 2, 3), store=self.merged_name) merger.finalize() merger.aggregate(torch.zeros(1, 3, 2, 2), (3, 3)) def test_zarr_avg_merge_none_merged_shape_error(self): with self.assertRaises(ValueError): - ZarrAvgMerger(merged_shape=None) + ZarrAvgMerger(merged_shape=None, store=self.merged_name) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/integration/test_auto3dseg_ensemble.py b/tests/integration/test_auto3dseg_ensemble.py index 08b059e3f7..e2aa566e53 100644 --- a/tests/integration/test_auto3dseg_ensemble.py +++ b/tests/integration/test_auto3dseg_ensemble.py @@ -32,13 +32,7 @@ from monai.transforms import SaveImage from monai.utils import check_parent_dir, optional_import, set_determinism from monai.utils.enums import AlgoKeys -from tests.test_utils import ( - SkipIfBeforePyTorchVersion, - get_testing_algo_template_path, - skip_if_downloading_fails, - skip_if_no_cuda, - skip_if_quick, -) +from tests.test_utils import get_testing_algo_template_path, skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") @@ -109,7 +103,6 @@ def create_sim_data(dataroot, sim_datalist, sim_dim, **kwargs): @skip_if_quick @skip_if_no_cuda -@SkipIfBeforePyTorchVersion((1, 11, 1)) @unittest.skipIf(not has_tb, "no tensorboard summary writer") class TestEnsembleBuilder(unittest.TestCase): def setUp(self) -> None: diff --git a/tests/integration/test_auto3dseg_hpo.py b/tests/integration/test_auto3dseg_hpo.py index f0d3492004..149d1c2157 100644 --- a/tests/integration/test_auto3dseg_hpo.py +++ b/tests/integration/test_auto3dseg_hpo.py @@ -25,12 +25,7 @@ from monai.data import create_test_image_3d from monai.utils import optional_import from monai.utils.enums import AlgoKeys -from tests.test_utils import ( - SkipIfBeforePyTorchVersion, - get_testing_algo_template_path, - skip_if_downloading_fails, - skip_if_no_cuda, -) +from tests.test_utils import get_testing_algo_template_path, skip_if_downloading_fails, skip_if_no_cuda _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") optuna, has_optuna = optional_import("optuna") @@ -76,7 +71,6 @@ def skip_if_no_optuna(obj): } -@SkipIfBeforePyTorchVersion((1, 11, 1)) @unittest.skipIf(not has_tb, "no tensorboard summary writer") class TestHPO(unittest.TestCase): def setUp(self) -> None: diff --git a/tests/integration/test_integration_autorunner.py b/tests/integration/test_integration_autorunner.py index 52906bde05..fed0ceabd0 100644 --- a/tests/integration/test_integration_autorunner.py +++ b/tests/integration/test_integration_autorunner.py @@ -23,13 +23,7 @@ from monai.bundle.config_parser import ConfigParser from monai.data import create_test_image_3d from monai.utils import optional_import -from tests.test_utils import ( - SkipIfBeforePyTorchVersion, - get_testing_algo_template_path, - skip_if_downloading_fails, - skip_if_no_cuda, - skip_if_quick, -) +from tests.test_utils import get_testing_algo_template_path, skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") _, has_nni = optional_import("nni") @@ -68,7 +62,6 @@ @skip_if_quick -@SkipIfBeforePyTorchVersion((1, 11, 1)) # for mem_get_info @unittest.skipIf(not has_tb, "no tensorboard summary writer") class TestAutoRunner(unittest.TestCase): def setUp(self) -> None: diff --git a/tests/integration/test_integration_gpu_customization.py b/tests/integration/test_integration_gpu_customization.py index 42f7d52e21..4bec96c198 100644 --- a/tests/integration/test_integration_gpu_customization.py +++ b/tests/integration/test_integration_gpu_customization.py @@ -24,13 +24,7 @@ from monai.data import create_test_image_3d from monai.utils import optional_import from monai.utils.enums import AlgoKeys -from tests.test_utils import ( - SkipIfBeforePyTorchVersion, - get_testing_algo_template_path, - skip_if_downloading_fails, - skip_if_no_cuda, - skip_if_quick, -) +from tests.test_utils import get_testing_algo_template_path, skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") @@ -67,7 +61,6 @@ @skip_if_quick -@SkipIfBeforePyTorchVersion((1, 11, 1)) # module 'torch.cuda' has no attribute 'mem_get_info' @unittest.skipIf(not has_tb, "no tensorboard summary writer") class TestEnsembleGpuCustomization(unittest.TestCase): def setUp(self) -> None: diff --git a/tests/integration/test_integration_lazy_samples.py b/tests/integration/test_integration_lazy_samples.py index 834e9ccb2a..63d6b8f9d9 100644 --- a/tests/integration/test_integration_lazy_samples.py +++ b/tests/integration/test_integration_lazy_samples.py @@ -26,7 +26,7 @@ from monai.data import create_test_image_3d, decollate_batch from monai.transforms.utils import has_status_keys from monai.utils import TraceStatusKeys, set_determinism -from tests.test_utils import HAS_CUPY, DistTestCase, SkipIfBeforePyTorchVersion, skip_if_quick +from tests.test_utils import HAS_CUPY, DistTestCase, skip_if_quick def _no_op(x): @@ -158,7 +158,6 @@ def run_training_test(root_dir, device="cuda:0", cachedataset=0, readers=(None, @skip_if_quick -@SkipIfBeforePyTorchVersion((1, 11)) class IntegrationLazyResampling(DistTestCase): def setUp(self): monai.config.print_config() diff --git a/tests/integration/test_integration_nnunet_bundle.py b/tests/integration/test_integration_nnunet_bundle.py index 1e117aeffe..cd17df7f64 100644 --- a/tests/integration/test_integration_nnunet_bundle.py +++ b/tests/integration/test_integration_nnunet_bundle.py @@ -28,7 +28,7 @@ from monai.data import DataLoader, Dataset, create_test_image_3d from monai.transforms import Compose, Decollated, EnsureChannelFirstd, LoadImaged, SaveImaged from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick +from tests.test_utils import skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") _, has_nnunet = optional_import("nnunetv2") @@ -51,7 +51,6 @@ @skip_if_quick -@SkipIfBeforePyTorchVersion((1, 13, 0)) @unittest.skipIf(not has_tb, "no tensorboard summary writer") @unittest.skipIf(not has_nnunet, "no nnunetv2") class TestnnUNetBundle(unittest.TestCase): diff --git a/tests/integration/test_integration_nnunetv2_runner.py b/tests/integration/test_integration_nnunetv2_runner.py index 9717e06170..44291e5722 100644 --- a/tests/integration/test_integration_nnunetv2_runner.py +++ b/tests/integration/test_integration_nnunetv2_runner.py @@ -22,7 +22,7 @@ from monai.bundle.config_parser import ConfigParser from monai.data import create_test_image_3d from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick +from tests.test_utils import skip_if_downloading_fails, skip_if_no_cuda, skip_if_quick _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") _, has_nnunet = optional_import("nnunetv2") @@ -45,7 +45,6 @@ @skip_if_quick -@SkipIfBeforePyTorchVersion((1, 13, 0)) @unittest.skipIf(not has_tb, "no tensorboard summary writer") @unittest.skipIf(not has_nnunet, "no nnunetv2") class TestnnUNetV2Runner(unittest.TestCase): diff --git a/tests/integration/test_integration_workers.py b/tests/integration/test_integration_workers.py index 6b6ee057f5..e3803a8ca1 100644 --- a/tests/integration/test_integration_workers.py +++ b/tests/integration/test_integration_workers.py @@ -18,7 +18,7 @@ from monai.data import DataLoader from monai.utils import set_determinism -from tests.test_utils import DistTestCase, SkipIfBeforePyTorchVersion, TimedCall, skip_if_no_cuda, skip_if_quick +from tests.test_utils import DistTestCase, TimedCall, skip_if_no_cuda, skip_if_quick def run_loading_test(num_workers=50, device=None, pw=False): @@ -42,7 +42,6 @@ def run_loading_test(num_workers=50, device=None, pw=False): @skip_if_quick @skip_if_no_cuda -@SkipIfBeforePyTorchVersion((1, 9)) class IntegrationLoading(DistTestCase): def tearDown(self): set_determinism(seed=None) diff --git a/tests/integration/test_reg_loss_integration.py b/tests/integration/test_reg_loss_integration.py index 6a759b036d..cdc174ddd0 100644 --- a/tests/integration/test_reg_loss_integration.py +++ b/tests/integration/test_reg_loss_integration.py @@ -20,7 +20,6 @@ from monai.losses import BendingEnergyLoss, GlobalMutualInformationLoss, LocalNormalizedCrossCorrelationLoss from monai.utils import set_determinism -from tests.test_utils import SkipIfBeforePyTorchVersion TEST_CASES = [ [BendingEnergyLoss, {}, ["pred"], 3], @@ -41,7 +40,6 @@ def tearDown(self): set_determinism(None) @parameterized.expand(TEST_CASES) - @SkipIfBeforePyTorchVersion((1, 9)) def test_convergence(self, loss_type, loss_args, forward_args, pred_channels=1): """ The goal of this test is to assess if the gradient of the loss function diff --git a/tests/losses/image_dissimilarity/test_global_mutual_information_loss.py b/tests/losses/image_dissimilarity/test_global_mutual_information_loss.py index 44e73a477c..ff7851ed1c 100644 --- a/tests/losses/image_dissimilarity/test_global_mutual_information_loss.py +++ b/tests/losses/image_dissimilarity/test_global_mutual_information_loss.py @@ -20,7 +20,7 @@ from monai import transforms from monai.losses.image_dissimilarity import GlobalMutualInformationLoss -from tests.test_utils import SkipIfBeforePyTorchVersion, download_url_or_skip_test, skip_if_quick, testing_data_config +from tests.test_utils import download_url_or_skip_test, skip_if_quick, testing_data_config device = "cuda:0" if torch.cuda.is_available() else "cpu" @@ -66,7 +66,6 @@ def setUp(self): hash_type=config.get("hash_type", "sha256"), ) - @SkipIfBeforePyTorchVersion((1, 9)) def test_bspline(self): loss_fn = GlobalMutualInformationLoss(kernel_type="b-spline", num_bins=32, sigma_ratio=0.015) diff --git a/tests/losses/test_ds_loss.py b/tests/losses/test_ds_loss.py index 6b91dff17a..586826aafe 100644 --- a/tests/losses/test_ds_loss.py +++ b/tests/losses/test_ds_loss.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.losses import DeepSupervisionLoss, DiceCELoss, DiceFocalLoss, DiceLoss -from tests.test_utils import SkipIfBeforePyTorchVersion, test_script_save +from tests.test_utils import test_script_save TEST_CASES_DICECE = [ [ @@ -151,14 +151,12 @@ def test_ill_reduction(self): loss = DeepSupervisionLoss(DiceCELoss(reduction="none")) loss(torch.ones((1, 2, 3)), torch.ones((1, 1, 2, 3))) - @SkipIfBeforePyTorchVersion((1, 10)) def test_script(self): loss = DeepSupervisionLoss(DiceCELoss()) test_input = torch.ones(2, 2, 8, 8) test_script_save(loss, test_input, test_input) -@SkipIfBeforePyTorchVersion((1, 11)) class TestDSLossDiceCE2(unittest.TestCase): @parameterized.expand(TEST_CASES_DICECE2) def test_result(self, input_param, input_param2, input_data, expected_val): @@ -167,7 +165,6 @@ def test_result(self, input_param, input_param2, input_data, expected_val): np.testing.assert_allclose(result.detach().cpu().numpy(), expected_val, atol=1e-4, rtol=1e-4) -@SkipIfBeforePyTorchVersion((1, 11)) class TestDSLossDice(unittest.TestCase): @parameterized.expand(TEST_CASES_DICE) def test_result(self, input_param, input_data, expected_val): @@ -176,7 +173,6 @@ def test_result(self, input_param, input_data, expected_val): np.testing.assert_allclose(result.detach().cpu().numpy(), expected_val, atol=1e-4, rtol=1e-4) -@SkipIfBeforePyTorchVersion((1, 11)) class TestDSLossDiceFocal(unittest.TestCase): @parameterized.expand(TEST_CASES_DICEFOCAL) def test_result(self, input_param, input_data, expected_val): diff --git a/tests/losses/test_perceptual_loss.py b/tests/losses/test_perceptual_loss.py index 2d11d41bee..b406bd3c69 100644 --- a/tests/losses/test_perceptual_loss.py +++ b/tests/losses/test_perceptual_loss.py @@ -18,7 +18,7 @@ from monai.losses import PerceptualLoss from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, assert_allclose, skip_if_downloading_fails, skip_if_quick +from tests.test_utils import assert_allclose, skip_if_downloading_fails, skip_if_quick _, has_torchvision = optional_import("torchvision") TEST_CASES = [ @@ -73,7 +73,6 @@ ] -@SkipIfBeforePyTorchVersion((1, 11)) @unittest.skipUnless(has_torchvision, "Requires torchvision") @skip_if_quick class TestPerceptualLoss(unittest.TestCase): diff --git a/tests/metrics/test_cumulative_average_dist.py b/tests/metrics/test_cumulative_average_dist.py index 53e81b7d86..30b308866c 100644 --- a/tests/metrics/test_cumulative_average_dist.py +++ b/tests/metrics/test_cumulative_average_dist.py @@ -18,10 +18,9 @@ import torch.distributed as dist from monai.metrics import CumulativeAverage -from tests.test_utils import DistCall, DistTestCase, SkipIfBeforePyTorchVersion +from tests.test_utils import DistCall, DistTestCase -@SkipIfBeforePyTorchVersion((1, 8)) class DistributedCumulativeAverage(DistTestCase): @DistCall(nnodes=1, nproc_per_node=2) def test_value(self): diff --git a/tests/networks/blocks/test_CABlock.py b/tests/networks/blocks/test_CABlock.py index 132910504b..28fdee3dca 100644 --- a/tests/networks/blocks/test_CABlock.py +++ b/tests/networks/blocks/test_CABlock.py @@ -20,7 +20,7 @@ from monai.networks import eval_mode from monai.networks.blocks.cablock import CABlock, FeedForward from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, assert_allclose, dict_product +from tests.test_utils import assert_allclose, dict_product einops, has_einops = optional_import("einops") @@ -71,7 +71,6 @@ def test_invalid_spatial_dims(self): with self.assertRaises(ValueError): CABlock(spatial_dims=4, dim=64, num_heads=4, bias=True) - @SkipIfBeforePyTorchVersion((2, 0)) @skipUnless(has_einops, "Requires einops") def test_flash_attention(self): device = "cuda" if torch.cuda.is_available() else "cpu" @@ -100,7 +99,6 @@ def test_qkv_transformation_3d(self): qkv = block.qkv(x) self.assertEqual(qkv.shape, (2, 192, 16, 16, 16)) - @SkipIfBeforePyTorchVersion((2, 0)) @skipUnless(has_einops, "Requires einops") def test_flash_vs_normal_attention(self): device = "cuda" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/blocks/test_crossattention.py b/tests/networks/blocks/test_crossattention.py index 741d5e3b53..50d6245016 100644 --- a/tests/networks/blocks/test_crossattention.py +++ b/tests/networks/blocks/test_crossattention.py @@ -22,7 +22,7 @@ from monai.networks.blocks.crossattention import CrossAttentionBlock from monai.networks.layers.factories import RelPosEmbedding from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, assert_allclose, dict_product +from tests.test_utils import assert_allclose, dict_product einops, has_einops = optional_import("einops") @@ -49,7 +49,6 @@ class TestResBlock(unittest.TestCase): @parameterized.expand(TEST_CASE_CABLOCK) @skipUnless(has_einops, "Requires einops") - @SkipIfBeforePyTorchVersion((2, 0)) def test_shape(self, input_param, input_shape, expected_shape): # Without flash attention net = CrossAttentionBlock(**input_param) @@ -64,14 +63,12 @@ def test_ill_arg(self): with self.assertRaises(ValueError): CrossAttentionBlock(hidden_size=620, num_heads=8, dropout_rate=0.4) - @SkipIfBeforePyTorchVersion((2, 0)) def test_save_attn_with_flash_attention(self): with self.assertRaises(ValueError): CrossAttentionBlock( hidden_size=128, num_heads=3, dropout_rate=0.1, use_flash_attention=True, save_attn=True ) - @SkipIfBeforePyTorchVersion((2, 0)) def test_rel_pos_embedding_with_flash_attention(self): with self.assertRaises(ValueError): CrossAttentionBlock( @@ -97,7 +94,6 @@ def test_causal_no_sequence_length(self): CrossAttentionBlock(hidden_size=128, num_heads=4, dropout_rate=0.1, causal=True) @skipUnless(has_einops, "Requires einops") - @SkipIfBeforePyTorchVersion((2, 0)) def test_causal_flash_attention(self): block = CrossAttentionBlock( hidden_size=128, @@ -165,7 +161,6 @@ def test_access_attn_matrix(self): @parameterized.expand([[True], [False]]) @skipUnless(has_einops, "Requires einops") - @SkipIfBeforePyTorchVersion((2, 0)) def test_flash_attention(self, causal): input_param = {"hidden_size": 128, "num_heads": 1, "causal": causal, "sequence_length": 16 if causal else None} device = "cuda:0" if torch.cuda.is_available() else "cpu" diff --git a/tests/networks/blocks/test_fpn_block.py b/tests/networks/blocks/test_fpn_block.py index 6980889433..4b45850159 100644 --- a/tests/networks/blocks/test_fpn_block.py +++ b/tests/networks/blocks/test_fpn_block.py @@ -21,7 +21,7 @@ from monai.networks.blocks.feature_pyramid_network import FeaturePyramidNetwork from monai.networks.nets.resnet import resnet50 from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, test_script_save +from tests.test_utils import test_script_save _, has_torchvision = optional_import("torchvision") @@ -55,7 +55,6 @@ def test_fpn_block(self, input_param, input_shape, expected_shape): self.assertEqual(result["feat1"].shape, expected_shape[1]) @parameterized.expand(TEST_CASES) - @SkipIfBeforePyTorchVersion((1, 9, 1)) def test_script(self, input_param, input_shape, expected_shape): # test whether support torchscript net = FeaturePyramidNetwork(**input_param) @@ -76,7 +75,6 @@ def test_fpn(self, input_param, input_shape, expected_shape): self.assertEqual(result["pool"].shape, expected_shape[1]) @parameterized.expand(TEST_CASES2) - @SkipIfBeforePyTorchVersion((1, 9, 1)) def test_script(self, input_param, input_shape, expected_shape): # test whether support torchscript net = _resnet_fpn_extractor(backbone=resnet50(), spatial_dims=input_param["spatial_dims"], returned_layers=[1]) diff --git a/tests/networks/blocks/test_patchembedding.py b/tests/networks/blocks/test_patchembedding.py index de6b486279..2945482649 100644 --- a/tests/networks/blocks/test_patchembedding.py +++ b/tests/networks/blocks/test_patchembedding.py @@ -21,7 +21,7 @@ from monai.networks import eval_mode from monai.networks.blocks.patchembedding import PatchEmbed, PatchEmbeddingBlock from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, dict_product +from tests.test_utils import dict_product einops, has_einops = optional_import("einops") @@ -58,7 +58,6 @@ ] -@SkipIfBeforePyTorchVersion((1, 11, 1)) class TestPatchEmbeddingBlock(unittest.TestCase): def setUp(self): self.threads = torch.get_num_threads() diff --git a/tests/networks/blocks/test_selfattention.py b/tests/networks/blocks/test_selfattention.py index 7d209659b9..af52918612 100644 --- a/tests/networks/blocks/test_selfattention.py +++ b/tests/networks/blocks/test_selfattention.py @@ -22,7 +22,7 @@ from monai.networks.blocks.selfattention import SABlock from monai.networks.layers.factories import RelPosEmbedding from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, assert_allclose, test_script_save +from tests.test_utils import assert_allclose, test_script_save einops, has_einops = optional_import("einops") @@ -54,7 +54,6 @@ class TestResBlock(unittest.TestCase): @parameterized.expand(TEST_CASE_SABLOCK) @skipUnless(has_einops, "Requires einops") - @SkipIfBeforePyTorchVersion((2, 0)) def test_shape(self, input_param, input_shape, expected_shape): net = SABlock(**input_param) with eval_mode(net): @@ -68,7 +67,6 @@ def test_ill_arg(self): with self.assertRaises(ValueError): SABlock(hidden_size=620, num_heads=8, dropout_rate=0.4) - @SkipIfBeforePyTorchVersion((2, 0)) def test_rel_pos_embedding_with_flash_attention(self): with self.assertRaises(ValueError): SABlock( @@ -80,7 +78,6 @@ def test_rel_pos_embedding_with_flash_attention(self): rel_pos_embedding=RelPosEmbedding.DECOMPOSED, ) - @SkipIfBeforePyTorchVersion((1, 13)) def test_save_attn_with_flash_attention(self): with self.assertRaises(ValueError): SABlock(hidden_size=128, num_heads=3, dropout_rate=0.1, use_flash_attention=True, save_attn=True) @@ -98,7 +95,6 @@ def test_causal_no_sequence_length(self): SABlock(hidden_size=128, num_heads=4, dropout_rate=0.1, causal=True) @skipUnless(has_einops, "Requires einops") - @SkipIfBeforePyTorchVersion((2, 0)) def test_causal_flash_attention(self): block = SABlock( hidden_size=128, @@ -196,7 +192,6 @@ def count_sablock_params(*args, **kwargs): @parameterized.expand([[True, False], [True, True], [False, True], [False, False]]) @skipUnless(has_einops, "Requires einops") - @SkipIfBeforePyTorchVersion((2, 0)) def test_script(self, include_fc, use_combined_linear): input_param = { "hidden_size": 360, @@ -213,7 +208,6 @@ def test_script(self, include_fc, use_combined_linear): test_script_save(net, test_data) @skipUnless(has_einops, "Requires einops") - @SkipIfBeforePyTorchVersion((2, 0)) def test_flash_attention(self): for causal in [True, False]: input_param = {"hidden_size": 360, "num_heads": 4, "input_size": (16, 32), "causal": causal} diff --git a/tests/networks/blocks/test_subpixel_upsample.py b/tests/networks/blocks/test_subpixel_upsample.py index 9300ff2b43..f4075f5099 100644 --- a/tests/networks/blocks/test_subpixel_upsample.py +++ b/tests/networks/blocks/test_subpixel_upsample.py @@ -20,7 +20,7 @@ from monai.networks import eval_mode from monai.networks.blocks import SubpixelUpsample from monai.networks.layers.factories import Conv -from tests.test_utils import SkipIfBeforePyTorchVersion, test_script_save +from tests.test_utils import test_script_save TEST_CASE_SUBPIXEL = [] for inch in range(1, 5): @@ -75,7 +75,6 @@ def test_subpixel_shape(self, input_param, input_shape, expected_shape): result = net.forward(torch.randn(input_shape)) self.assertEqual(result.shape, expected_shape) - @SkipIfBeforePyTorchVersion((1, 8, 1)) def test_script(self): input_param, input_shape, _ = TEST_CASE_SUBPIXEL[0] net = SubpixelUpsample(**input_param) diff --git a/tests/networks/blocks/warp/test_warp.py b/tests/networks/blocks/warp/test_warp.py index 452ca5d890..93af559790 100644 --- a/tests/networks/blocks/warp/test_warp.py +++ b/tests/networks/blocks/warp/test_warp.py @@ -22,13 +22,7 @@ from monai.networks.blocks.warp import Warp from monai.transforms import LoadImaged from monai.utils import GridSampleMode, GridSamplePadMode -from tests.test_utils import ( - SkipIfBeforePyTorchVersion, - SkipIfNoModule, - download_url_or_skip_test, - skip_if_quick, - testing_data_config, -) +from tests.test_utils import SkipIfNoModule, download_url_or_skip_test, skip_if_quick, testing_data_config LOW_POWER_TEST_CASES = [ # run with BUILD_MONAI=1 to test csrc/resample, BUILD_MONAI=0 to test native grid_sample [ @@ -144,7 +138,6 @@ def test_ill_shape(self): with self.assertRaisesRegex(ValueError, ""): warp_layer(image=torch.arange(4).reshape((1, 1, 2, 2)).to(dtype=torch.float), ddf=torch.zeros(1, 2, 3, 3)) - @SkipIfBeforePyTorchVersion((1, 8)) def test_grad(self): for b in GridSampleMode: for p in GridSamplePadMode: diff --git a/tests/networks/layers/test_gaussian_filter.py b/tests/networks/layers/test_gaussian_filter.py index 7ed99c3ed7..9a0267284f 100644 --- a/tests/networks/layers/test_gaussian_filter.py +++ b/tests/networks/layers/test_gaussian_filter.py @@ -18,11 +18,13 @@ from parameterized import parameterized from monai.networks.layers import GaussianFilter -from tests.test_utils import SkipIfAtLeastPyTorchVersion, skip_if_quick +from monai.utils import unsqueeze_left +from tests.test_utils import TEST_DEVICES, test_is_quick +# trainable test cases TEST_CASES = [[{"type": "erf", "gt": 2.0}], [{"type": "scalespace", "gt": 3.0}], [{"type": "sampled", "gt": 5.0}]] TEST_CASES_GPU = [[{"type": "erf", "gt": 0.8, "device": "cuda"}], [{"type": "sampled", "gt": 5.0, "device": "cuda"}]] -TEST_CASES_3d = [ +TEST_CASES_3D = [ [{"type": "scalespace", "gt": 0.5, "dims": (2, 3, 8, 9, 10), "lr": 0.01, "device": "cuda"}], [{"type": "erf", "gt": 3.8, "dims": (2, 3, 8, 9, 10), "lr": 0.1, "device": "cuda"}], ] @@ -33,26 +35,101 @@ [{"type": "scalespace", "gt": 3.0, "device": "cuda"}], ] +TEST_CASES_BP = TEST_CASES + TEST_CASES_GPU + TEST_CASES_3D + +if not test_is_quick(): + TEST_CASES_BP += TEST_CASES_SLOW + + +EXPECTED_1D = np.array( + [0.5654129, 0.68915915, 0.79146194, 0.8631974, 0.8998163, 0.8998163, 0.8631973, 0.79146194, 0.6891592, 0.5654129] +) + +EXPECTED_2D = np.array( + [[0.13239081, 0.13932934, 0.13239081], [0.13932936, 0.14663152, 0.13932936], [0.13239081, 0.13932934, 0.13239081]] +) + +EXPECTED_3D = np.array( + [ + [ + [0.07189433, 0.07911152, 0.07911152, 0.07189433], + [0.07566228, 0.08325771, 0.08325771, 0.07566228], + [0.07189433, 0.07911152, 0.07911152, 0.07189433], + ], + [ + [0.07911152, 0.08705322, 0.08705322, 0.07911152], + [0.08325771, 0.09161563, 0.09161563, 0.08325771], + [0.07911152, 0.08705322, 0.08705322, 0.07911152], + ], + [ + [0.07911152, 0.08705322, 0.08705322, 0.07911152], + [0.08325771, 0.09161563, 0.09161563, 0.08325771], + [0.07911152, 0.08705322, 0.08705322, 0.07911152], + ], + [ + [0.07189433, 0.07911152, 0.07911152, 0.07189433], + [0.07566228, 0.08325771, 0.08325771, 0.07566228], + [0.07189433, 0.07911152, 0.07911152, 0.07189433], + ], + ] +) + +EXPECTED_3D_SIGMAS = np.array( + [ + [[0.13690521, 0.13690521], [0.15181276, 0.15181276], [0.13690521, 0.13690521]], + [[0.1506486, 0.15064861], [0.16705267, 0.16705267], [0.1506486, 0.15064861]], + [[0.1506486, 0.15064861], [0.16705267, 0.16705267], [0.1506486, 0.15064861]], + [[0.13690521, 0.13690521], [0.15181276, 0.15181276], [0.13690521, 0.13690521]], + ] +) + +DEVICE_RTOL = [d + [rtol] for d, rtol in zip(TEST_DEVICES, (1e-5, 1e-2))] # device/tolerance pairs +TEST_CASES_2D_3D = [[(1, 1, 4, 3, 4), (3, 3, 3), EXPECTED_3D] + d for d in DEVICE_RTOL] +TEST_CASES_2D_3D += [[(1, 1, 4, 3, 2), (3, [3, 2, 1], 3), EXPECTED_3D_SIGMAS] + d for d in DEVICE_RTOL] + +if not test_is_quick(): + TEST_CASES_2D_3D += [[(1, 1, 3, 3), (2, 3, 3), EXPECTED_2D] + d for d in DEVICE_RTOL] + + +class GaussianFilterTestCase(unittest.TestCase): + def test_wrong_args(self): + with self.assertRaisesRegex(ValueError, ""): + GaussianFilter(3, [3, 2], 3) + GaussianFilter(3, [3, 2, 1], 3) # test init + + def test_1d(self): + a = torch.ones(1, 8, 10) + g = GaussianFilter(1, 3, 3) + + expected = np.tile(unsqueeze_left(EXPECTED_1D, 3), (1, 8, 1)) + np.testing.assert_allclose(g(a).cpu().numpy(), expected, rtol=1e-5) + + @parameterized.expand(TEST_CASES_2D_3D) + def test_2d_3d(self, oargs, gargs, expected, device, rtol): + a = torch.ones(*oargs).to(device) + g = GaussianFilter(*gargs).to(device) + + np.testing.assert_allclose(g(a).cpu().numpy(), unsqueeze_left(expected, len(oargs)), rtol=rtol) + -@SkipIfAtLeastPyTorchVersion((2, 2, 0)) # https://github.com/Project-MONAI/MONAI/issues/7445 class TestGaussianFilterBackprop(unittest.TestCase): - def code_to_run(self, input_args): + @parameterized.expand(TEST_CASES_BP) + def test_training(self, input_args): input_dims = input_args.get("dims", (2, 3, 8)) - device = ( - torch.device("cuda") - if (input_args.get("device") == "cuda" and torch.cuda.is_available()) - else torch.device("cpu:0") - ) + + device = torch.device("cpu") + if input_args.get("device") == "cuda" and torch.cuda.is_available(): + device = torch.device("cuda:0") base = torch.ones(*input_dims).to(device) - gt = torch.tensor(input_args["gt"], requires_grad=False).to(device) + gt = torch.tensor(input_args["gt"], requires_grad=False) g_type = input_args["type"] lr = input_args.get("lr", 0.1) init_sigma = input_args.get("init", 1.0) # static filter to generate a target spatial_dims = len(base.shape) - 2 - filtering = GaussianFilter(spatial_dims=spatial_dims, sigma=gt, approx=g_type, requires_grad=False) + filtering = GaussianFilter(spatial_dims=spatial_dims, sigma=gt.to(device), approx=g_type, requires_grad=False) filtering.to(device) target = filtering(base) self.assertFalse(filtering.sigma[0].requires_grad) @@ -65,141 +142,17 @@ def code_to_run(self, input_args): # train optimizer = torch.optim.Adam(trainable.parameters(), lr=lr) - for s in range(1000): + for _ in range(1000): optimizer.zero_grad() pred = trainable(base) loss = torch.pow(pred - target, 2).mean() loss.backward() - if (s + 1) % 50 == 0: - var = list(trainable.parameters())[0] - print(f"step {s} loss {loss}") - print(var, var.grad) if loss.item() < 1e-7: break optimizer.step() - # check the result - print(s, gt) - for idx, s in enumerate(trainable.sigma): - np.testing.assert_allclose( - s.cpu().item(), gt.cpu() if len(gt.shape) == 0 else gt[idx].cpu().item(), rtol=1e-2 - ) - - @parameterized.expand(TEST_CASES + TEST_CASES_GPU + TEST_CASES_3d) - def test_train_quick(self, input_args): - self.code_to_run(input_args) - @parameterized.expand(TEST_CASES_SLOW) - @skip_if_quick - def test_train_slow(self, input_args): - self.code_to_run(input_args) - - -@SkipIfAtLeastPyTorchVersion((2, 2, 0)) # https://github.com/Project-MONAI/MONAI/issues/7445 -class GaussianFilterTestCase(unittest.TestCase): - def test_1d(self): - a = torch.ones(1, 8, 10) - g = GaussianFilter(1, 3, 3).to(torch.device("cpu:0")) - expected = np.array( - [ - [ - [ - 0.5654129, - 0.68915915, - 0.79146194, - 0.8631974, - 0.8998163, - 0.8998163, - 0.8631973, - 0.79146194, - 0.6891592, - 0.5654129, - ] - ] - ] - ) - expected = np.tile(expected, (1, 8, 1)) - np.testing.assert_allclose(g(a).cpu().numpy(), expected, rtol=1e-5) - - @skip_if_quick - def test_2d(self): - a = torch.ones(1, 1, 3, 3) - g = GaussianFilter(2, 3, 3).to(torch.device("cpu:0")) - expected = np.array( - [ - [ - [ - [0.13239081, 0.13932934, 0.13239081], - [0.13932936, 0.14663152, 0.13932936], - [0.13239081, 0.13932934, 0.13239081], - ] - ] - ] - ) - - np.testing.assert_allclose(g(a).cpu().numpy(), expected, rtol=1e-5) - if torch.cuda.is_available(): - g = GaussianFilter(2, 3, 3).to(torch.device("cuda:0")) - np.testing.assert_allclose(g(a.cuda()).cpu().numpy(), expected, rtol=1e-2) - - def test_3d(self): - a = torch.ones(1, 1, 4, 3, 4) - g = GaussianFilter(3, 3, 3).to(torch.device("cpu:0")) - - expected = np.array( - [ - [ - [ - [ - [0.07189433, 0.07911152, 0.07911152, 0.07189433], - [0.07566228, 0.08325771, 0.08325771, 0.07566228], - [0.07189433, 0.07911152, 0.07911152, 0.07189433], - ], - [ - [0.07911152, 0.08705322, 0.08705322, 0.07911152], - [0.08325771, 0.09161563, 0.09161563, 0.08325771], - [0.07911152, 0.08705322, 0.08705322, 0.07911152], - ], - [ - [0.07911152, 0.08705322, 0.08705322, 0.07911152], - [0.08325771, 0.09161563, 0.09161563, 0.08325771], - [0.07911152, 0.08705322, 0.08705322, 0.07911152], - ], - [ - [0.07189433, 0.07911152, 0.07911152, 0.07189433], - [0.07566228, 0.08325771, 0.08325771, 0.07566228], - [0.07189433, 0.07911152, 0.07911152, 0.07189433], - ], - ] - ] - ] - ) - np.testing.assert_allclose(g(a).cpu().numpy(), expected, rtol=1e-5) - - def test_3d_sigmas(self): - a = torch.ones(1, 1, 4, 3, 2) - g = GaussianFilter(3, [3, 2, 1], 3).to(torch.device("cpu:0")) - - expected = np.array( - [ - [ - [ - [[0.13690521, 0.13690521], [0.15181276, 0.15181276], [0.13690521, 0.13690521]], - [[0.1506486, 0.15064861], [0.16705267, 0.16705267], [0.1506486, 0.15064861]], - [[0.1506486, 0.15064861], [0.16705267, 0.16705267], [0.1506486, 0.15064861]], - [[0.13690521, 0.13690521], [0.15181276, 0.15181276], [0.13690521, 0.13690521]], - ] - ] - ] - ) - np.testing.assert_allclose(g(a).cpu().numpy(), expected, rtol=1e-5) - if torch.cuda.is_available(): - g = GaussianFilter(3, [3, 2, 1], 3).to(torch.device("cuda:0")) - np.testing.assert_allclose(g(a.cuda()).cpu().numpy(), expected, rtol=1e-2) - - def test_wrong_args(self): - with self.assertRaisesRegex(ValueError, ""): - GaussianFilter(3, [3, 2], 3).to(torch.device("cpu:0")) - GaussianFilter(3, [3, 2, 1], 3).to(torch.device("cpu:0")) # test init + for idx, s in enumerate(trainable.sigma): + np.testing.assert_allclose(s.cpu().item(), gt if len(gt.shape) == 0 else gt[idx].item(), rtol=1e-2) if __name__ == "__main__": diff --git a/tests/networks/layers/test_hilbert_transform.py b/tests/networks/layers/test_hilbert_transform.py index c12136aecf..733ae9ba85 100644 --- a/tests/networks/layers/test_hilbert_transform.py +++ b/tests/networks/layers/test_hilbert_transform.py @@ -18,8 +18,6 @@ from parameterized import parameterized from monai.networks.layers import HilbertTransform -from monai.utils import OptionalImportError -from tests.test_utils import SkipIfModule, SkipIfNoModule def create_expected_numpy_output(input_datum, **kwargs): @@ -112,7 +110,6 @@ def create_expected_numpy_output(input_datum, **kwargs): # TESTS CHECKING PADDING, AXIS SELECTION ETC ARE COVERED BY test_detect_envelope.py -@SkipIfNoModule("torch.fft") class TestHilbertTransformCPU(unittest.TestCase): @parameterized.expand(TEST_CASES_CPU + TEST_CASES_GPU) def test_value(self, arguments, image, expected_data, atol): @@ -121,11 +118,5 @@ def test_value(self, arguments, image, expected_data, atol): np.testing.assert_allclose(result, expected_data.squeeze(), atol=atol) -@SkipIfModule("torch.fft") -class TestHilbertTransformNoFFTMod(unittest.TestCase): - def test_no_fft_module_error(self): - self.assertRaises(OptionalImportError, HilbertTransform(), torch.randn(1, 1, 10)) - - if __name__ == "__main__": unittest.main() diff --git a/tests/networks/nets/test_autoencoderkl.py b/tests/networks/nets/test_autoencoderkl.py index 2d4c5b66ca..bbe2840164 100644 --- a/tests/networks/nets/test_autoencoderkl.py +++ b/tests/networks/nets/test_autoencoderkl.py @@ -23,7 +23,7 @@ from monai.networks import eval_mode from monai.networks.nets import AutoencoderKL from monai.utils import optional_import -from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_downloading_fails, testing_data_config +from tests.test_utils import skip_if_downloading_fails, testing_data_config tqdm, has_tqdm = optional_import("tqdm", name="tqdm") _, has_einops = optional_import("einops") @@ -179,7 +179,6 @@ def test_shape(self, input_param, input_shape, expected_shape, expected_latent_s self.assertEqual(result[2].shape, expected_latent_shape) @parameterized.expand(CASES) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_with_convtranspose_and_checkpointing( self, input_param, input_shape, expected_shape, expected_latent_shape ): @@ -238,7 +237,6 @@ def test_shape_reconstruction(self): result = net.reconstruct(torch.randn(input_shape).to(device)) self.assertEqual(result.shape, expected_shape) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_reconstruction_with_convtranspose_and_checkpointing(self): input_param, input_shape, expected_shape, _ = CASES[0] input_param = input_param.copy() @@ -256,7 +254,6 @@ def test_shape_encode(self): self.assertEqual(result[0].shape, expected_latent_shape) self.assertEqual(result[1].shape, expected_latent_shape) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_encode_with_convtranspose_and_checkpointing(self): input_param, input_shape, _, expected_latent_shape = CASES[0] input_param = input_param.copy() @@ -276,7 +273,6 @@ def test_shape_sampling(self): ) self.assertEqual(result.shape, expected_latent_shape) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_sampling_convtranspose_and_checkpointing(self): input_param, _, _, expected_latent_shape = CASES[0] input_param = input_param.copy() @@ -295,7 +291,6 @@ def test_shape_decode(self): result = net.decode(torch.randn(latent_shape).to(device)) self.assertEqual(result.shape, expected_input_shape) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_decode_convtranspose_and_checkpointing(self): input_param, expected_input_shape, _, latent_shape = CASES[0] input_param = input_param.copy() diff --git a/tests/networks/nets/test_dints_network.py b/tests/networks/nets/test_dints_network.py index 449d5045fe..80ade00db7 100644 --- a/tests/networks/nets/test_dints_network.py +++ b/tests/networks/nets/test_dints_network.py @@ -19,7 +19,7 @@ from monai.networks.nets import DiNTS, TopologyInstance, TopologySearch from monai.networks.nets.dints import Cell -from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_quick, test_script_save +from tests.test_utils import skip_if_quick, test_script_save TEST_CASES_3D = [ [ @@ -153,7 +153,6 @@ def test_dints_search(self, dints_grid_params, dints_params, input_shape, expect self.assertTrue(isinstance(net.weight_parameters(), list)) -@SkipIfBeforePyTorchVersion((1, 9)) class TestDintsTS(unittest.TestCase): @parameterized.expand(TEST_CASES_3D + TEST_CASES_2D) def test_script(self, dints_grid_params, dints_params, input_shape, _): diff --git a/tests/test_masked_autoencoder_vit.py b/tests/networks/nets/test_masked_autoencoder_vit.py similarity index 100% rename from tests/test_masked_autoencoder_vit.py rename to tests/networks/nets/test_masked_autoencoder_vit.py diff --git a/tests/networks/nets/test_segresnet_ds.py b/tests/networks/nets/test_segresnet_ds.py index ad97829f76..4a2cf40e6f 100644 --- a/tests/networks/nets/test_segresnet_ds.py +++ b/tests/networks/nets/test_segresnet_ds.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets import SegResNetDS, SegResNetDS2 -from tests.test_utils import SkipIfBeforePyTorchVersion, dict_product, test_script_save +from tests.test_utils import dict_product, test_script_save device = "cuda" if torch.cuda.is_available() else "cpu" @@ -135,7 +135,6 @@ def test_ill_arg(self): with self.assertRaises(ValueError): SegResNetDS2(spatial_dims=4) - @SkipIfBeforePyTorchVersion((1, 10)) def test_script(self): input_param, input_shape, _ = TEST_CASE_SEGRESNET_DS[0] net = SegResNetDS(**input_param) diff --git a/tests/networks/nets/test_unetr.py b/tests/networks/nets/test_unetr.py index 76ac3a7439..5d4faa3979 100644 --- a/tests/networks/nets/test_unetr.py +++ b/tests/networks/nets/test_unetr.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets.unetr import UNETR -from tests.test_utils import SkipIfBeforePyTorchVersion, dict_product, skip_if_quick, test_script_save +from tests.test_utils import dict_product, skip_if_quick, test_script_save TEST_CASE_UNETR = [ [ @@ -115,7 +115,6 @@ def test_ill_arg(self): ) @parameterized.expand(TEST_CASE_UNETR) - @SkipIfBeforePyTorchVersion((2, 0)) def test_script(self, input_param, input_shape, _): net = UNETR(**(input_param)) net.eval() diff --git a/tests/networks/nets/test_vista3d.py b/tests/networks/nets/test_vista3d.py index bdf424f69e..8a1207604c 100644 --- a/tests/networks/nets/test_vista3d.py +++ b/tests/networks/nets/test_vista3d.py @@ -19,7 +19,7 @@ from monai.networks import eval_mode from monai.networks.nets import VISTA3D, SegResNetDS2 from monai.networks.nets.vista3d import ClassMappingClassify, PointMappingSAM -from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_quick +from tests.test_utils import skip_if_quick device = "cuda" if torch.cuda.is_available() else "cpu" @@ -54,7 +54,6 @@ ] -@SkipIfBeforePyTorchVersion((1, 11)) @skip_if_quick class TestVista3d(unittest.TestCase): @parameterized.expand(TEST_CASES) diff --git a/tests/networks/nets/test_vit.py b/tests/networks/nets/test_vit.py index e7290f89d4..54ad3f863e 100644 --- a/tests/networks/nets/test_vit.py +++ b/tests/networks/nets/test_vit.py @@ -18,7 +18,7 @@ from monai.networks import eval_mode from monai.networks.nets.vit import ViT -from tests.test_utils import SkipIfBeforePyTorchVersion, dict_product, skip_if_quick, test_script_save +from tests.test_utils import dict_product, skip_if_quick, test_script_save TEST_CASE_Vit = [ ( @@ -99,7 +99,6 @@ def test_ill_arg( ) @parameterized.expand(TEST_CASE_Vit[:1]) - @SkipIfBeforePyTorchVersion((2, 0)) def test_script(self, input_param, input_shape, _): net = ViT(**(input_param)) net.eval() diff --git a/tests/networks/nets/test_vqvae.py b/tests/networks/nets/test_vqvae.py index 624fb37930..13a34f9657 100644 --- a/tests/networks/nets/test_vqvae.py +++ b/tests/networks/nets/test_vqvae.py @@ -18,7 +18,6 @@ from monai.networks import eval_mode from monai.networks.nets.vqvae import VQVAE -from tests.test_utils import SkipIfBeforePyTorchVersion TEST_CASES = [ [ @@ -114,7 +113,6 @@ def test_shape(self, input_param, input_shape, expected_shape): self.assertEqual(result.shape, expected_shape) @parameterized.expand(TEST_CASES) - @SkipIfBeforePyTorchVersion((1, 11)) def test_shape_with_checkpoint(self, input_param, input_shape, expected_shape): device = "cuda" if torch.cuda.is_available() else "cpu" input_param = input_param.copy() diff --git a/tests/networks/test_bundle_onnx_export.py b/tests/networks/test_bundle_onnx_export.py index 85f908c185..33c1f4cc8c 100644 --- a/tests/networks/test_bundle_onnx_export.py +++ b/tests/networks/test_bundle_onnx_export.py @@ -20,7 +20,7 @@ from monai.bundle import ConfigParser from monai.networks import save_state -from tests.test_utils import SkipIfBeforePyTorchVersion, SkipIfNoModule, command_line_tests, skip_if_windows +from tests.test_utils import SkipIfNoModule, command_line_tests, skip_if_windows TEST_CASE_1 = ["True"] TEST_CASE_2 = ["False"] @@ -28,7 +28,6 @@ @skip_if_windows @SkipIfNoModule("onnx") -@SkipIfBeforePyTorchVersion((1, 10)) class TestONNXExport(unittest.TestCase): def setUp(self): self.device = os.environ.get("CUDA_VISIBLE_DEVICES") diff --git a/tests/networks/test_convert_to_onnx.py b/tests/networks/test_convert_to_onnx.py index 106f15dc9d..1d4cd6b071 100644 --- a/tests/networks/test_convert_to_onnx.py +++ b/tests/networks/test_convert_to_onnx.py @@ -20,7 +20,7 @@ from monai.networks import convert_to_onnx from monai.networks.nets import SegResNet, UNet -from tests.test_utils import SkipIfBeforePyTorchVersion, SkipIfNoModule, optional_import, skip_if_quick +from tests.test_utils import SkipIfNoModule, optional_import, skip_if_quick if torch.cuda.is_available(): TORCH_DEVICE_OPTIONS = ["cpu", "cuda"] @@ -39,7 +39,6 @@ @SkipIfNoModule("onnx") -@SkipIfBeforePyTorchVersion((1, 9)) @skip_if_quick class TestConvertToOnnx(unittest.TestCase): @parameterized.expand(TESTS) @@ -67,7 +66,6 @@ def test_unet(self, device, use_trace, use_ort): self.assertTrue(isinstance(onnx_model, onnx.ModelProto)) @parameterized.expand(TESTS_ORT) - @SkipIfBeforePyTorchVersion((1, 12)) def test_seg_res_net(self, device, use_ort): if use_ort: _, has_onnxruntime = optional_import("onnxruntime") diff --git a/tests/networks/test_varnet.py b/tests/networks/test_varnet.py index 23e2ff5a36..9cadf15ce5 100644 --- a/tests/networks/test_varnet.py +++ b/tests/networks/test_varnet.py @@ -20,7 +20,7 @@ from monai.apps.reconstruction.networks.nets.complex_unet import ComplexUnet from monai.apps.reconstruction.networks.nets.varnet import VariationalNetworkModel from monai.networks import eval_mode -from tests.test_utils import SkipIfBeforePyTorchVersion, test_script_save +from tests.test_utils import test_script_save device = torch.device("cuda" if torch.cuda.is_available() else "cpu") coil_sens_model = CoilSensitivityModel(spatial_dims=2, features=[8, 16, 32, 64, 128, 8]) @@ -45,7 +45,6 @@ def test_shape(self, coil_sens_model, refinement_model, num_cascades, input_shap self.assertEqual(result.shape, expected_shape) @parameterized.expand(TESTS) - @SkipIfBeforePyTorchVersion((1, 9, 1)) def test_script(self, coil_sens_model, refinement_model, num_cascades, input_shape, expected_shape): net = VariationalNetworkModel(coil_sens_model, refinement_model, num_cascades) diff --git a/tests/ngc_bundle_download.py b/tests/ngc_bundle_download.py deleted file mode 100644 index 612397b5a1..0000000000 --- a/tests/ngc_bundle_download.py +++ /dev/null @@ -1,144 +0,0 @@ -# Copyright (c) MONAI Consortium -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import annotations - -import os -import sys -import tempfile -import unittest - -import torch -from parameterized import parameterized - -from monai.apps import check_hash -from monai.apps.mmars import MODEL_DESC, load_from_mmar -from monai.bundle import download, load -from monai.config import print_debug_info -from monai.networks.utils import copy_model_state -from tests.test_utils import assert_allclose, skip_if_downloading_fails, skip_if_quick, skip_if_windows - -TEST_CASE_NGC_1 = [ - "spleen_ct_segmentation", - "0.3.7", - None, - "monai_spleen_ct_segmentation", - "models/model.pt", - "b418a2dc8672ce2fd98dc255036e7a3d", -] -TEST_CASE_NGC_2 = [ - "monai_spleen_ct_segmentation", - "0.3.7", - "monai_", - "spleen_ct_segmentation", - "models/model.pt", - "b418a2dc8672ce2fd98dc255036e7a3d", -] - -TESTCASE_WEIGHTS = { - "key": "model.0.conv.unit0.adn.N.bias", - "value": torch.tensor( - [ - -0.0705, - -0.0937, - -0.0422, - -0.2068, - 0.1023, - -0.2007, - -0.0883, - 0.0018, - -0.1719, - 0.0116, - 0.0285, - -0.0044, - 0.1223, - -0.1287, - -0.1858, - 0.0460, - ] - ), -} - - -@skip_if_windows -class TestNgcBundleDownload(unittest.TestCase): - @parameterized.expand([TEST_CASE_NGC_1, TEST_CASE_NGC_2]) - @skip_if_quick - def test_ngc_download_bundle(self, bundle_name, version, remove_prefix, download_name, file_path, hash_val): - with skip_if_downloading_fails(): - with tempfile.TemporaryDirectory() as tempdir: - download( - name=bundle_name, source="ngc", version=version, bundle_dir=tempdir, remove_prefix=remove_prefix - ) - full_file_path = os.path.join(tempdir, download_name, file_path) - self.assertTrue(os.path.exists(full_file_path)) - self.assertTrue(check_hash(filepath=full_file_path, val=hash_val)) - - model = load( - name=bundle_name, source="ngc", version=version, bundle_dir=tempdir, remove_prefix=remove_prefix - ) - assert_allclose( - model.state_dict()[TESTCASE_WEIGHTS["key"]], - TESTCASE_WEIGHTS["value"], - atol=1e-4, - rtol=1e-4, - type_test=False, - ) - - -@unittest.skip("deprecating mmar tests") -class TestAllDownloadingMMAR(unittest.TestCase): - def setUp(self): - print_debug_info() - self.test_dir = "./" - - @parameterized.expand((item,) for item in MODEL_DESC) - def test_loading_mmar(self, item): - if item["name"] == "clara_pt_self_supervised_learning_segmentation": # test the byow model - default_model_file = os.path.join("ssl_models_2gpu", "best_metric_model.pt") - pretrained_weights = load_from_mmar( - item=item["name"], - mmar_dir="./", - map_location="cpu", - api=True, - model_file=default_model_file, - weights_only=True, - ) - pretrained_weights = {k.split(".", 1)[1]: v for k, v in pretrained_weights["state_dict"].items()} - sys.path.append(os.path.join(f"{item['name']}", "custom")) # custom model folder - from vit_network import ViTAutoEnc # pylint: disable=E0401 - - model = ViTAutoEnc( - in_channels=1, - img_size=(96, 96, 96), - patch_size=(16, 16, 16), - proj_type="conv", - hidden_size=768, - mlp_dim=3072, - ) - _, loaded, not_loaded = copy_model_state(model, pretrained_weights) - self.assertTrue(len(loaded) > 0 and len(not_loaded) == 0) - return - if item["name"] == "clara_pt_fed_learning_brain_tumor_mri_segmentation": - default_model_file = os.path.join("models", "server", "best_FL_global_model.pt") - else: - default_model_file = None - pretrained_model = load_from_mmar( - item=item["name"], mmar_dir="./", map_location="cpu", api=True, model_file=default_model_file - ) - self.assertTrue(isinstance(pretrained_model, torch.nn.Module)) - - def tearDown(self): - print(os.listdir(self.test_dir)) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_set_visible_devices.py b/tests/test_set_visible_devices.py deleted file mode 100644 index f02f3f690f..0000000000 --- a/tests/test_set_visible_devices.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) MONAI Consortium -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# http://www.apache.org/licenses/LICENSE-2.0 -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import annotations - -import os -import unittest - -from tests.test_utils import SkipIfAtLeastPyTorchVersion, skip_if_no_cuda - - -class TestVisibleDevices(unittest.TestCase): - @staticmethod - def run_process_and_get_exit_code(code_to_execute): - value = os.system(code_to_execute) - return int(bin(value).replace("0b", "").rjust(16, "0")[:8], 2) - - @skip_if_no_cuda - @SkipIfAtLeastPyTorchVersion((2, 2, 1)) - def test_visible_devices(self): - num_gpus_before = self.run_process_and_get_exit_code( - 'python -c "import os; import torch; ' - + "os.environ['CUDA_VISIBLE_DEVICES'] = ''; exit(torch.cuda.device_count())\"" - ) - num_gpus_after = self.run_process_and_get_exit_code( - 'python -c "import os; import monai; import torch; ' - + "os.environ['CUDA_VISIBLE_DEVICES'] = ''; exit(torch.cuda.device_count())\"" - ) - self.assertEqual(num_gpus_before, num_gpus_after) - - # test import monai won't affect setting CUDA_VISIBLE_DEVICES - num_gpus_after_monai = self.run_process_and_get_exit_code( - 'python -c "import os; import torch; import monai; ' - + "os.environ['CUDA_VISIBLE_DEVICES'] = '0'; exit(torch.cuda.device_count())\"" - ) - self.assertEqual(num_gpus_after_monai, 1) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/transforms/spatial/test_grid_patch.py b/tests/transforms/spatial/test_grid_patch.py index f6edea4d54..b6fb9168a5 100644 --- a/tests/transforms/spatial/test_grid_patch.py +++ b/tests/transforms/spatial/test_grid_patch.py @@ -19,7 +19,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms.spatial.array import GridPatch -from tests.test_utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose +from tests.test_utils import TEST_NDARRAYS, assert_allclose A = np.arange(16).repeat(3).reshape(4, 4, 3).transpose(2, 0, 1) A11 = A[:, :2, :2] @@ -98,7 +98,6 @@ class TestGridPatch(unittest.TestCase): @parameterized.expand(TEST_CASES) - @SkipIfBeforePyTorchVersion((1, 11, 1)) def test_grid_patch(self, in_type, input_parameters, image, expected): input_image = in_type(image) splitter = GridPatch(**input_parameters) @@ -113,7 +112,6 @@ def test_grid_patch(self, in_type, input_parameters, image, expected): ) @parameterized.expand([TEST_CASE_META_0, TEST_CASE_META_1]) - @SkipIfBeforePyTorchVersion((1, 9, 1)) def test_grid_patch_meta(self, input_parameters, image, expected, expected_meta): set_track_meta(True) splitter = GridPatch(**input_parameters) diff --git a/tests/transforms/spatial/test_grid_patchd.py b/tests/transforms/spatial/test_grid_patchd.py index 859a5a3890..81e1da8b5b 100644 --- a/tests/transforms/spatial/test_grid_patchd.py +++ b/tests/transforms/spatial/test_grid_patchd.py @@ -18,7 +18,7 @@ from parameterized import parameterized from monai.transforms.spatial.dictionary import GridPatchd -from tests.test_utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose +from tests.test_utils import TEST_NDARRAYS, assert_allclose A = np.arange(16).repeat(3).reshape(4, 4, 3).transpose(2, 0, 1) A11 = A[:, :2, :2] @@ -78,7 +78,6 @@ class TestGridPatchd(unittest.TestCase): @parameterized.expand(TEST_SINGLE) - @SkipIfBeforePyTorchVersion((1, 11, 1)) def test_grid_patchd(self, in_type, input_parameters, image_dict, expected): image_key = "image" input_dict = {} diff --git a/tests/transforms/spatial/test_rand_grid_patch.py b/tests/transforms/spatial/test_rand_grid_patch.py index b148f46c97..884c7269f1 100644 --- a/tests/transforms/spatial/test_rand_grid_patch.py +++ b/tests/transforms/spatial/test_rand_grid_patch.py @@ -20,7 +20,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms.spatial.array import RandGridPatch from monai.utils import set_determinism -from tests.test_utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose +from tests.test_utils import TEST_NDARRAYS, assert_allclose A = np.arange(16).repeat(3).reshape(4, 4, 3).transpose(2, 0, 1) A11 = A[:, :2, :2] @@ -112,7 +112,6 @@ def tearDown(self): set_determinism(None) @parameterized.expand(TEST_SINGLE) - @SkipIfBeforePyTorchVersion((1, 11, 1)) def test_rand_grid_patch(self, in_type, input_parameters, image, expected): input_image = in_type(image) splitter = RandGridPatch(**input_parameters) @@ -128,7 +127,6 @@ def test_rand_grid_patch(self, in_type, input_parameters, image, expected): ) @parameterized.expand([TEST_CASE_META_0, TEST_CASE_META_1]) - @SkipIfBeforePyTorchVersion((1, 9, 1)) def test_rand_grid_patch_meta(self, input_parameters, image, expected, expected_meta): set_track_meta(True) splitter = RandGridPatch(**input_parameters) diff --git a/tests/transforms/spatial/test_rand_grid_patchd.py b/tests/transforms/spatial/test_rand_grid_patchd.py index b9e9589e6d..6b0f9d6eb3 100644 --- a/tests/transforms/spatial/test_rand_grid_patchd.py +++ b/tests/transforms/spatial/test_rand_grid_patchd.py @@ -19,7 +19,7 @@ from monai.transforms.spatial.dictionary import RandGridPatchd from monai.utils import set_determinism -from tests.test_utils import TEST_NDARRAYS, SkipIfBeforePyTorchVersion, assert_allclose +from tests.test_utils import TEST_NDARRAYS, assert_allclose A = np.arange(16).repeat(3).reshape(4, 4, 3).transpose(2, 0, 1) A11 = A[:, :2, :2] @@ -92,7 +92,6 @@ def tearDown(self): set_determinism(None) @parameterized.expand(TEST_SINGLE) - @SkipIfBeforePyTorchVersion((1, 11, 1)) def test_rand_grid_patchd(self, in_type, input_parameters, image_dict, expected): image_key = "image" input_dict = {} diff --git a/tests/transforms/test_detect_envelope.py b/tests/transforms/test_detect_envelope.py index 821c6ad947..2c7eeeceb4 100644 --- a/tests/transforms/test_detect_envelope.py +++ b/tests/transforms/test_detect_envelope.py @@ -18,8 +18,7 @@ from parameterized import parameterized from monai.transforms import DetectEnvelope -from monai.utils import OptionalImportError -from tests.test_utils import TEST_NDARRAYS, SkipIfModule, SkipIfNoModule, assert_allclose +from tests.test_utils import TEST_NDARRAYS, assert_allclose n_samples = 500 hann_windowed_sine = np.sin(2 * np.pi * 10 * np.linspace(0, 1, n_samples)) * np.hanning(n_samples) @@ -53,7 +52,7 @@ ] TEST_CASE_2D_SINE_AXIS_1 = [ - {"axis": 2}, # set axis argument to 1 + {"axis": 2}, # set axis argument to 2 # Create 10 identical windowed sine waves as a 2D numpy array np.expand_dims(np.stack([hann_windowed_sine] * 10, axis=1), 0), # Expected output: absolute value of each sample of the waveform, repeated (i.e. flat envelopes) @@ -114,7 +113,6 @@ TEST_CASE_INVALID_OBJ = [{}, "a string", "__call__"] # method expected to raise exception -@SkipIfNoModule("torch.fft") class TestDetectEnvelope(unittest.TestCase): @parameterized.expand( [ @@ -149,11 +147,5 @@ def test_value_error(self, arguments, image, method): self.fail("Expected raising method invalid. Should be __init__ or __call__.") -@SkipIfModule("torch.fft") -class TestHilbertTransformNoFFTMod(unittest.TestCase): - def test_no_fft_module_error(self): - self.assertRaises(OptionalImportError, DetectEnvelope(), np.random.rand(1, 10)) - - if __name__ == "__main__": unittest.main() diff --git a/tests/transforms/test_fourier.py b/tests/transforms/test_fourier.py index f9685030d4..396cc9f1ff 100644 --- a/tests/transforms/test_fourier.py +++ b/tests/transforms/test_fourier.py @@ -20,13 +20,10 @@ from monai.data.synthetic import create_test_image_2d, create_test_image_3d from monai.transforms import Fourier from monai.utils.misc import set_determinism -from tests.test_utils import SkipIfBeforePyTorchVersion, SkipIfNoModule TEST_CASES = [((128, 64),), ((64, 48, 80),)] -@SkipIfBeforePyTorchVersion((1, 8)) -@SkipIfNoModule("torch.fft") class TestFourier(unittest.TestCase): def setUp(self): set_determinism(0) diff --git a/tests/test_rand_torchio.py b/tests/transforms/test_rand_torchio.py similarity index 100% rename from tests/test_rand_torchio.py rename to tests/transforms/test_rand_torchio.py diff --git a/tests/test_rand_torchiod.py b/tests/transforms/test_rand_torchiod.py similarity index 100% rename from tests/test_rand_torchiod.py rename to tests/transforms/test_rand_torchiod.py diff --git a/tests/transforms/test_resample_backends.py b/tests/transforms/test_resample_backends.py index e4ca3edc19..80dca55d23 100644 --- a/tests/transforms/test_resample_backends.py +++ b/tests/transforms/test_resample_backends.py @@ -22,7 +22,7 @@ from monai.transforms import Resample from monai.transforms.utils import create_grid from monai.utils import GridSampleMode, GridSamplePadMode, NdimageMode, SplineMode, convert_to_numpy -from tests.test_utils import SkipIfBeforePyTorchVersion, assert_allclose, is_tf32_env +from tests.test_utils import assert_allclose, is_tf32_env _rtol = 1e-3 if is_tf32_env() else 1e-4 @@ -42,7 +42,6 @@ TEST_IDENTITY.append([dict(device=device), p_s, interp_s, pad_s, (1, 21, 23, 24)]) -@SkipIfBeforePyTorchVersion((1, 9, 1)) class TestResampleBackends(unittest.TestCase): @parameterized.expand(TEST_IDENTITY) def test_resample_identity(self, input_param, im_type, interp, padding, input_shape): diff --git a/tests/transforms/test_resize.py b/tests/transforms/test_resize.py index 2b9014c3a3..1a1eb4553f 100644 --- a/tests/transforms/test_resize.py +++ b/tests/transforms/test_resize.py @@ -21,13 +21,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import Resize from tests.lazy_transforms_utils import test_resampler_lazy -from tests.test_utils import ( - TEST_NDARRAYS_ALL, - NumpyImageTestCase2D, - SkipIfAtLeastPyTorchVersion, - assert_allclose, - is_tf32_env, -) +from tests.test_utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, is_tf32_env TEST_CASE_0 = [{"spatial_size": 15}, (6, 10, 15)] @@ -117,7 +111,6 @@ def test_correct_results(self, spatial_size, mode, anti_aliasing): ) @parameterized.expand([TEST_CASE_0, TEST_CASE_1, TEST_CASE_2, TEST_CASE_2_1, TEST_CASE_3, TEST_CASE_4]) - @SkipIfAtLeastPyTorchVersion((2, 2, 0)) # https://github.com/Project-MONAI/MONAI/issues/7445 def test_longest_shape(self, input_param, expected_shape): input_data = np.random.randint(0, 2, size=[3, 4, 7, 10]) input_param["size_mode"] = "longest" diff --git a/tests/transforms/test_resized.py b/tests/transforms/test_resized.py index 926e0fa58a..7acef3fe46 100644 --- a/tests/transforms/test_resized.py +++ b/tests/transforms/test_resized.py @@ -21,13 +21,7 @@ from monai.data import MetaTensor, set_track_meta from monai.transforms import Invertd, Resize, Resized from tests.lazy_transforms_utils import test_resampler_lazy -from tests.test_utils import ( - TEST_NDARRAYS_ALL, - NumpyImageTestCase2D, - SkipIfAtLeastPyTorchVersion, - assert_allclose, - test_local_inversion, -) +from tests.test_utils import TEST_NDARRAYS_ALL, NumpyImageTestCase2D, assert_allclose, test_local_inversion TEST_CASE_0 = [{"keys": "img", "spatial_size": 15}, (6, 10, 15)] @@ -64,7 +58,6 @@ ] -@SkipIfAtLeastPyTorchVersion((2, 2, 0)) # https://github.com/Project-MONAI/MONAI/issues/7445 class TestResized(NumpyImageTestCase2D): def test_invalid_inputs(self): with self.assertRaises(ValueError): diff --git a/tests/transforms/test_signal_fillempty.py b/tests/transforms/test_signal_fillempty.py index d9166db986..716d9fb278 100644 --- a/tests/transforms/test_signal_fillempty.py +++ b/tests/transforms/test_signal_fillempty.py @@ -20,13 +20,11 @@ from monai.transforms import SignalFillEmpty from monai.utils.type_conversion import convert_to_tensor -from tests.test_utils import SkipIfBeforePyTorchVersion TESTS_PATH = Path(__file__).parents[1] TEST_SIGNAL = os.path.join(TESTS_PATH, "testing_data", "signal.npy") -@SkipIfBeforePyTorchVersion((1, 9)) class TestSignalFillEmptyNumpy(unittest.TestCase): def test_correct_parameters_multi_channels(self): self.assertIsInstance(SignalFillEmpty(replacement=0.0), SignalFillEmpty) @@ -37,7 +35,6 @@ def test_correct_parameters_multi_channels(self): self.assertTrue(not np.isnan(fillemptysignal).any()) -@SkipIfBeforePyTorchVersion((1, 9)) class TestSignalFillEmptyTorch(unittest.TestCase): def test_correct_parameters_multi_channels(self): self.assertIsInstance(SignalFillEmpty(replacement=0.0), SignalFillEmpty) diff --git a/tests/transforms/test_signal_fillemptyd.py b/tests/transforms/test_signal_fillemptyd.py index 01ab135eb0..3ed66c98f2 100644 --- a/tests/transforms/test_signal_fillemptyd.py +++ b/tests/transforms/test_signal_fillemptyd.py @@ -20,13 +20,11 @@ from monai.transforms import SignalFillEmptyd from monai.utils.type_conversion import convert_to_tensor -from tests.test_utils import SkipIfBeforePyTorchVersion TESTS_PATH = Path(__file__).parents[1] TEST_SIGNAL = os.path.join(TESTS_PATH, "testing_data", "signal.npy") -@SkipIfBeforePyTorchVersion((1, 9)) class TestSignalFillEmptyNumpy(unittest.TestCase): def test_correct_parameters_multi_channels(self): self.assertIsInstance(SignalFillEmptyd(replacement=0.0), SignalFillEmptyd) @@ -41,7 +39,6 @@ def test_correct_parameters_multi_channels(self): self.assertTrue(not np.isnan(data_["signal"]).any()) -@SkipIfBeforePyTorchVersion((1, 9)) class TestSignalFillEmptyTorch(unittest.TestCase): def test_correct_parameters_multi_channels(self): self.assertIsInstance(SignalFillEmptyd(replacement=0.0), SignalFillEmptyd) diff --git a/tests/transforms/test_signal_rand_add_squarepulse.py b/tests/transforms/test_signal_rand_add_squarepulse.py index da3fe44a75..3dd3822d62 100644 --- a/tests/transforms/test_signal_rand_add_squarepulse.py +++ b/tests/transforms/test_signal_rand_add_squarepulse.py @@ -22,7 +22,6 @@ from monai.transforms import SignalRandAddSquarePulse from monai.utils import optional_import from monai.utils.type_conversion import convert_to_tensor -from tests.test_utils import SkipIfBeforePyTorchVersion _, has_scipy = optional_import("scipy") TESTS_PATH = Path(__file__).parents[1] @@ -31,7 +30,6 @@ @skipUnless(has_scipy, "scipy required") -@SkipIfBeforePyTorchVersion((1, 10, 1)) class TestSignalRandAddSquarePulseNumpy(unittest.TestCase): @parameterized.expand(VALID_CASES) def test_correct_parameters_multi_channels(self, boundaries, frequencies): @@ -43,7 +41,6 @@ def test_correct_parameters_multi_channels(self, boundaries, frequencies): @skipUnless(has_scipy, "scipy required") -@SkipIfBeforePyTorchVersion((1, 10, 1)) class TestSignalRandAddSquarePulseTorch(unittest.TestCase): @parameterized.expand(VALID_CASES) def test_correct_parameters_multi_channels(self, boundaries, frequencies): diff --git a/tests/transforms/test_signal_rand_add_squarepulse_partial.py b/tests/transforms/test_signal_rand_add_squarepulse_partial.py index c5c53b602f..68659a3663 100644 --- a/tests/transforms/test_signal_rand_add_squarepulse_partial.py +++ b/tests/transforms/test_signal_rand_add_squarepulse_partial.py @@ -22,7 +22,6 @@ from monai.transforms import SignalRandAddSquarePulsePartial from monai.utils import optional_import from monai.utils.type_conversion import convert_to_tensor -from tests.test_utils import SkipIfBeforePyTorchVersion _, has_scipy = optional_import("scipy") TESTS_PATH = Path(__file__).parents[1] @@ -31,7 +30,6 @@ @skipUnless(has_scipy, "scipy required") -@SkipIfBeforePyTorchVersion((1, 10, 1)) class TestSignalRandAddSquarePulsePartialNumpy(unittest.TestCase): @parameterized.expand(VALID_CASES) def test_correct_parameters_multi_channels(self, boundaries, frequencies, fraction): @@ -45,7 +43,6 @@ def test_correct_parameters_multi_channels(self, boundaries, frequencies, fracti @skipUnless(has_scipy, "scipy required") -@SkipIfBeforePyTorchVersion((1, 10, 1)) class TestSignalRandAddSquarePulsePartialTorch(unittest.TestCase): @parameterized.expand(VALID_CASES) def test_correct_parameters_multi_channels(self, boundaries, frequencies, fraction): diff --git a/tests/test_torchio.py b/tests/transforms/test_torchio.py similarity index 100% rename from tests/test_torchio.py rename to tests/transforms/test_torchio.py diff --git a/tests/test_torchiod.py b/tests/transforms/test_torchiod.py similarity index 100% rename from tests/test_torchiod.py rename to tests/transforms/test_torchiod.py diff --git a/tests/utils/test_pad_mode.py b/tests/utils/test_pad_mode.py index e13ec8aacd..aafe2796bc 100644 --- a/tests/utils/test_pad_mode.py +++ b/tests/utils/test_pad_mode.py @@ -18,10 +18,9 @@ from monai.transforms import CastToType, Pad from monai.utils import NumpyPadMode, PytorchPadMode -from tests.test_utils import SkipIfBeforePyTorchVersion, dict_product +from tests.test_utils import dict_product -@SkipIfBeforePyTorchVersion((1, 10, 1)) class TestPadMode(unittest.TestCase): def test_pad(self): expected_shapes = {3: (1, 15, 10), 4: (1, 10, 6, 7)} diff --git a/tests/utils/test_set_determinism.py b/tests/utils/test_set_determinism.py index 76564fb0f2..c5648e031f 100644 --- a/tests/utils/test_set_determinism.py +++ b/tests/utils/test_set_determinism.py @@ -17,7 +17,7 @@ import torch from monai.utils import get_seed, set_determinism -from tests.test_utils import SkipIfBeforePyTorchVersion, skip_if_no_cuda +from tests.test_utils import skip_if_no_cuda class TestSetDeterminism(unittest.TestCase): @@ -59,7 +59,6 @@ class TestSetFlag(unittest.TestCase): def setUp(self): set_determinism(1, use_deterministic_algorithms=True) - @SkipIfBeforePyTorchVersion((1, 8)) # beta feature @skip_if_no_cuda def test_algo_not_deterministic(self): """ diff --git a/tests/visualize/test_plot_2d_or_3d_image.py b/tests/visualize/test_plot_2d_or_3d_image.py index b9ced3953c..7343a77774 100644 --- a/tests/visualize/test_plot_2d_or_3d_image.py +++ b/tests/visualize/test_plot_2d_or_3d_image.py @@ -20,7 +20,7 @@ from monai.utils import optional_import from monai.visualize import plot_2d_or_3d_image -from tests.test_utils import SkipIfBeforePyTorchVersion, SkipIfNoModule +from tests.test_utils import SkipIfNoModule SummaryWriter, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") @@ -38,7 +38,6 @@ @unittest.skipUnless(has_tb, "Requires SummaryWriter installation") -@SkipIfBeforePyTorchVersion((1, 13)) # issue 6683 class TestPlot2dOr3dImage(unittest.TestCase): @parameterized.expand([TEST_CASE_1, TEST_CASE_2, TEST_CASE_3, TEST_CASE_4, TEST_CASE_5]) def test_tb_image(self, shape):