Repository: Project-MONAI/MONAI

Issue:
tests.test_spatial_resample error
**Describe the bug**
randomly run into this issue:
```
[2022-06-01T14:46:36.804Z] ======================================================================
[2022-06-01T14:46:36.804Z] ERROR: test_ill_affine_1 (tests.test_spatial_resample.TestSpatialResample)
[2022-06-01T14:46:36.804Z] ----------------------------------------------------------------------
[2022-06-01T14:46:36.804Z] Traceback (most recent call last):
[2022-06-01T14:46:36.804Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/transforms/spatial/array.py", line 274, in __call__
[2022-06-01T14:46:36.804Z]     if pytorch_after(1, 8, 0)
[2022-06-01T14:46:36.804Z] RuntimeError: CUDA error: an illegal memory access was encountered
[2022-06-01T14:46:36.804Z] CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
[2022-06-01T14:46:36.804Z] For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
[2022-06-01T14:46:36.804Z] 
[2022-06-01T14:46:36.804Z] During handling of the above exception, another exception occurred:
[2022-06-01T14:46:36.804Z] 
[2022-06-01T14:46:36.804Z] Traceback (most recent call last):
[2022-06-01T14:46:36.804Z]   File "/usr/local/lib/python3.7/dist-packages/parameterized/parameterized.py", line 533, in standalone_func
[2022-06-01T14:46:36.804Z]     return func(*(a + p.args), **p.kwargs)
[2022-06-01T14:46:36.804Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/tests/test_spatial_resample.py", line 161, in test_ill_affine
[2022-06-01T14:46:36.804Z]     SpatialResample()(img=img, dst_affine=dst_affine)
[2022-06-01T14:46:36.804Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/utils/deprecate_utils.py", line 217, in _wrapper
[2022-06-01T14:46:36.804Z]     return func(*args, **kwargs)
[2022-06-01T14:46:36.804Z]   File "/home/jenkins/agent/workspace/MONAI-premerge/monai/monai/transforms/spatial/array.py", line 278, in __call__
[2022-06-01T14:46:36.804Z]     raise ValueError(f"src affine is not invertible: {src_affine_}") from e
[2022-06-01T14:46:36.804Z]   File "/usr/local/lib/python3.7/dist-packages/torch/_tensor.py", line 628, in __format__
[2022-06-01T14:46:36.804Z]     return object.__format__(self, format_spec)
[2022-06-01T14:46:36.804Z]   File "/usr/local/lib/python3.7/dist-packages/torch/_tensor.py", line 305, in __repr__
[2022-06-01T14:46:36.804Z]     return torch._tensor_str._str(self)
[2022-06-01T14:46:36.804Z]   File "/usr/local/lib/python3.7/dist-packages/torch/_tensor_str.py", line 434, in _str
[2022-06-01T14:46:36.804Z]     return _str_intern(self)
[2022-06-01T14:46:36.804Z]   File "/usr/local/lib/python3.7/dist-packages/torch/_tensor_str.py", line 409, in _str_intern
[2022-06-01T14:46:36.804Z]     tensor_str = _tensor_str(self, indent)
[2022-06-01T14:46:36.804Z]   File "/usr/local/lib/python3.7/dist-packages/torch/_tensor_str.py", line 264, in _tensor_str
[2022-06-01T14:46:36.804Z]     formatter = _Formatter(get_summarized_data(self) if summarize else self)
[2022-06-01T14:46:36.804Z]   File "/usr/local/lib/python3.7/dist-packages/torch/_tensor_str.py", line 100, in __init__
[2022-06-01T14:46:36.804Z]     nonzero_finite_vals = torch.masked_select(tensor_view, torch.isfinite(tensor_view) & tensor_view.ne(0))
[2022-06-01T14:46:36.804Z] RuntimeError: CUDA error: an illegal memory access was encountered
[2022-06-01T14:46:36.804Z] CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
[2022-06-01T14:46:36.804Z] For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
[2022-06-01T14:46:36.804Z] 
```

https://github.com/Project-MONAI/MONAI/blob/8ed38fd5a0ae53dc0ede72674770733857969952/monai/transforms/spatial/array.py#L272-L276

torch 1.10.2, cuda 10.2


Discussion:

Resolving patch:
diff --git a/monai/apps/utils.py b/monai/apps/utils.py
--- a/monai/apps/utils.py
+++ b/monai/apps/utils.py
@@ -27,7 +27,7 @@
 from monai.config.type_definitions import PathLike
 from monai.utils import look_up_option, min_version, optional_import
 
-gdown, has_gdown = optional_import("gdown", "3.6")
+gdown, has_gdown = optional_import("gdown", "4.4")
 
 if TYPE_CHECKING:
     from tqdm import tqdm
@@ -147,7 +147,12 @@ def check_hash(filepath: PathLike, val: Optional[str] = None, hash_type: str = "
 
 
 def download_url(
-    url: str, filepath: PathLike = "", hash_val: Optional[str] = None, hash_type: str = "md5", progress: bool = True
+    url: str,
+    filepath: PathLike = "",
+    hash_val: Optional[str] = None,
+    hash_type: str = "md5",
+    progress: bool = True,
+    **gdown_kwargs,
 ) -> None:
     """
     Download file from specified URL link, support process bar and hash check.
@@ -160,6 +165,10 @@ def download_url(
             if None, skip hash validation.
         hash_type: 'md5' or 'sha1', defaults to 'md5'.
         progress: whether to display a progress bar.
+        gdown_kwargs: other args for `gdown` except for the `url`, `output` and `quiet`.
+            these args will only be used if download from google drive.
+            details of the args of it:
+            https://github.com/wkentaro/gdown/blob/main/gdown/download.py
 
     Raises:
         RuntimeError: When the hash validation of the ``filepath`` existing file fails.
@@ -189,7 +198,7 @@ def download_url(
             if urlparse(url).netloc == "drive.google.com":
                 if not has_gdown:
                     raise RuntimeError("To download files from Google Drive, please install the gdown dependency.")
-                gdown.download(url, f"{tmp_name}", quiet=not progress)
+                gdown.download(url, f"{tmp_name}", quiet=not progress, **gdown_kwargs)
             else:
                 _download_with_progress(url, tmp_name, progress=progress)
             if not tmp_name.exists():
diff --git a/monai/networks/utils.py b/monai/networks/utils.py
--- a/monai/networks/utils.py
+++ b/monai/networks/utils.py
@@ -486,7 +486,7 @@ def save_state(src: Union[torch.nn.Module, Dict], path: PathLike, **kwargs):
         src: input data to save, can be `nn.Module`, `state_dict`, a dictionary of `nn.Module` or `state_dict`.
         path: target file path to save the input object.
         kwargs: other args for the `save_obj` except for the `obj` and `path`.
-            default `func` is `torch.save()`, details of the args of it:
+            default `func` is `torch.save()`, details of the args:
             https://pytorch.org/docs/stable/generated/torch.save.html.
 
     """
diff --git a/monai/transforms/spatial/array.py b/monai/transforms/spatial/array.py
--- a/monai/transforms/spatial/array.py
+++ b/monai/transforms/spatial/array.py
@@ -234,7 +234,7 @@ def __call__(
                     else torch.solve(dst_affine, src_affine).solution  # type: ignore
                 )
         except (np.linalg.LinAlgError, RuntimeError) as e:
-            raise ValueError(f"src affine is not invertible: {src_affine}") from e
+            raise ValueError("src affine is not invertible.") from e
         xform = to_affine_nd(spatial_rank, xform)
         # no resampling if it's identity transform
         if allclose(xform, np.diag(np.ones(len(xform))), atol=AFFINE_TOL) and allclose(spatial_size, in_spatial_size):


Test patch: