Repository: Project-MONAI/MONAI

Issue:
Random CI errors may related to out of memory
**Is your feature request related to a problem? Please describe.**
https://github.com/Project-MONAI/MONAI/runs/6567755462?check_suite_focus=true
```
======================================================================
ERROR: test_verify_0____w_MONAI_MONAI_tests_testing_data_metadata_json (tests.test_bundle_verify_net.TestVerifyNetwork)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/parameterized/parameterized.py", line 533, in standalone_func
    return func(*(a + p.args), **p.kwargs)
  File "/__w/MONAI/MONAI/tests/test_bundle_verify_net.py", line 43, in test_verify
    subprocess.check_call(cmd, env=test_env)
  File "/opt/conda/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['coverage', 'run', '-m', 'monai.bundle', 'verify_net_in_out', 'network_def', '--meta_file', '/__w/MONAI/MONAI/tests/testing_data/metadata.json', '--config_file', '/__w/MONAI/MONAI/tests/testing_data/inference.json', '-n', '2', '--any', '32', '--args_file', '/tmp/tmp7y1u_zw9/def_args.json', '--_meta_#network_data_format#inputs#image#spatial_shape', "[32,'*','4**p*n']"]' returned non-zero exit status 1.

======================================================================
ERROR: test_bspline (tests.test_global_mutual_information_loss.TestGlobalMutualInformationLoss)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/__w/MONAI/MONAI/tests/test_global_mutual_information_loss.py", line 106, in test_bspline
    result = loss_fn(a2, a1).detach().cpu().numpy()
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
tests finished, printing completed times >10.0s in ascending order...

test_read_patches_cucim_0 (tests.test_masked_inference_wsi_dataset.TestMaskedInferenceWSIDataset) (10.2s)
test_script_0 (tests.test_senet.TestSENET) (10.4s)
test_invert (tests.test_invertd.TestInvertd) (10.6s)
  File "/__w/MONAI/MONAI/monai/losses/image_dissimilarity.py", line 319, in forward
    wa, pa, wb, pb = self.parzen_windowing(pred, target)  # (batch, num_sample, num_bin), (batch, 1, num_bin)
  File "/__w/MONAI/MONAI/monai/losses/image_dissimilarity.py", line 233, in parzen_windowing
    pred_weight, pred_probability = self.parzen_windowing_b_spline(pred, order=3)
  File "/__w/MONAI/MONAI/monai/losses/image_dissimilarity.py", line 283, in parzen_windowing_b_spline
    weight + (4 - 6 * sample_bin_matrix**2 + 3 * sample_bin_matrix**3) * (sample_bin_matrix < 1) / 6
RuntimeError: CUDA out of memory. Tried to allocate 736.00 MiB (GPU 0; 14.76 GiB total capacity; 5.73 GiB already allocated; 94.00 MiB free; 5.75 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF
```
Would be nice to enhance the test logic.



Discussion:

Resolving patch:
diff --git a/monai/apps/detection/transforms/array.py b/monai/apps/detection/transforms/array.py
--- a/monai/apps/detection/transforms/array.py
+++ b/monai/apps/detection/transforms/array.py
@@ -237,7 +237,7 @@ def __init__(self, spatial_size: Union[Sequence[int], int], size_mode: str = "al
         self.spatial_size = spatial_size
 
     def __call__(  # type: ignore
-        self, boxes: NdarrayOrTensor, src_spatial_size: Union[Sequence[int], int]  # type: ignore
+        self, boxes: NdarrayOrTensor, src_spatial_size: Union[Sequence[int], int]
     ) -> NdarrayOrTensor:
         """
         Args:


Test patch:
diff --git a/tests/test_bundle_verify_net.py b/tests/test_bundle_verify_net.py
--- a/tests/test_bundle_verify_net.py
+++ b/tests/test_bundle_verify_net.py
@@ -35,8 +35,8 @@ def test_verify(self, meta_file, config_file):
             ConfigParser.export_config_file(config=def_args, filepath=def_args_file)
 
             cmd = ["coverage", "run", "-m", "monai.bundle", "verify_net_in_out", "network_def", "--meta_file"]
-            cmd += [meta_file, "--config_file", config_file, "-n", "2", "--any", "32", "--args_file", def_args_file]
-            cmd += ["--_meta_#network_data_format#inputs#image#spatial_shape", "[32,'*','4**p*n']"]
+            cmd += [meta_file, "--config_file", config_file, "-n", "4", "--any", "16", "--args_file", def_args_file]
+            cmd += ["--_meta_#network_data_format#inputs#image#spatial_shape", "[16,'*','2**p*n']"]
 
             test_env = os.environ.copy()
             print(f"CUDA_VISIBLE_DEVICES in {__file__}", test_env.get("CUDA_VISIBLE_DEVICES"))
diff --git a/tests/test_global_mutual_information_loss.py b/tests/test_global_mutual_information_loss.py
--- a/tests/test_global_mutual_information_loss.py
+++ b/tests/test_global_mutual_information_loss.py
@@ -18,7 +18,7 @@
 from monai.losses.image_dissimilarity import GlobalMutualInformationLoss
 from tests.utils import SkipIfBeforePyTorchVersion, download_url_or_skip_test, skip_if_quick, testing_data_config
 
-device = "cuda" if torch.cuda.is_available() else "cpu"
+device = "cuda:0" if torch.cuda.is_available() else "cpu"
 
 FILE_PATH = os.path.join(os.path.dirname(__file__), "testing_data", "temp_" + "mri.nii")