Repository: Project-MONAI/MONAI

Issue:
drop pytorch 1.4 support
**Is your feature request related to a problem? Please describe.**
this ticket is to propose to drop the pytorch 1.4 support, this will reduce the dev/CI/CD burdens and encourage the use of the newer pytorch features such as AMP


Discussion:
@wyli thanks for raising this ticket and your related PR.
AMP is still not supported in PyTorch 1.5 BTW.

Resolving patch:
diff --git a/monai/networks/blocks/fcn.py b/monai/networks/blocks/fcn.py
--- a/monai/networks/blocks/fcn.py
+++ b/monai/networks/blocks/fcn.py
@@ -20,7 +20,7 @@
 from monai.networks.layers.factories import Act, Conv, Norm
 from monai.utils import optional_import
 
-models, _ = optional_import("torchvision", "0.5.0", name="models")
+models, _ = optional_import("torchvision", name="models")
 
 
 class GCN(nn.Module):
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
@@ -14,12 +14,12 @@
 """
 
 import warnings
-from typing import Any, Callable, List, Optional, Sequence, Tuple, Union
+from typing import Any, List, Optional, Sequence, Tuple, Union
 
 import numpy as np
 import torch
 
-from monai.config import USE_COMPILED, get_torch_version_tuple
+from monai.config import USE_COMPILED
 from monai.data.utils import compute_shape_offset, to_affine_nd, zoom_affine
 from monai.networks.layers import AffineTransform, GaussianFilter, grid_pull
 from monai.transforms.compose import Randomizable, Transform
@@ -46,17 +46,6 @@
 
 nib, _ = optional_import("nibabel")
 
-_torch_interp: Callable[..., torch.Tensor]
-
-if get_torch_version_tuple() >= (1, 5):
-    # additional argument since torch 1.5 (to avoid warnings)
-    def _torch_interp(**kwargs):
-        return torch.nn.functional.interpolate(recompute_scale_factor=True, **kwargs)
-
-
-else:
-    _torch_interp = torch.nn.functional.interpolate
-
 
 class Spacing(Transform):
     """
@@ -353,7 +342,8 @@ def __call__(
                 f"got spatial_size={output_ndim} img={input_ndim}."
             )
         spatial_size = fall_back_tuple(self.spatial_size, img.shape[1:])
-        resized = _torch_interp(
+        resized = torch.nn.functional.interpolate(  # type: ignore
+            recompute_scale_factor=True,
             input=torch.as_tensor(np.ascontiguousarray(img), dtype=torch.float).unsqueeze(0),
             size=spatial_size,
             mode=self.mode.value if mode is None else InterpolateMode(mode).value,
@@ -528,7 +518,8 @@ def __call__(
 
         """
         _zoom = ensure_tuple_rep(self.zoom, img.ndim - 1)  # match the spatial image dim
-        zoomed = _torch_interp(
+        zoomed = torch.nn.functional.interpolate(  # type: ignore
+            recompute_scale_factor=True,
             input=torch.as_tensor(np.ascontiguousarray(img), dtype=torch.float).unsqueeze(0),
             scale_factor=list(_zoom),
             mode=self.mode.value if mode is None else InterpolateMode(mode).value,
@@ -1475,7 +1466,8 @@ def __call__(
         if self.do_transform:
             grid = self.deform_grid(spatial_size=sp_size)
             grid = self.rand_affine_grid(grid=grid)
-            grid = _torch_interp(
+            grid = torch.nn.functional.interpolate(  # type: ignore
+                recompute_scale_factor=True,
                 input=grid.unsqueeze(0),
                 scale_factor=list(ensure_tuple(self.deform_grid.spacing)),
                 mode=InterpolateMode.BICUBIC.value,
diff --git a/monai/transforms/spatial/dictionary.py b/monai/transforms/spatial/dictionary.py
--- a/monai/transforms/spatial/dictionary.py
+++ b/monai/transforms/spatial/dictionary.py
@@ -35,7 +35,6 @@
     Rotate90,
     Spacing,
     Zoom,
-    _torch_interp,
 )
 from monai.transforms.utils import create_grid
 from monai.utils import (
@@ -522,7 +521,8 @@ def __call__(
         if self.rand_2d_elastic.do_transform:
             grid = self.rand_2d_elastic.deform_grid(spatial_size=sp_size)
             grid = self.rand_2d_elastic.rand_affine_grid(grid=grid)
-            grid = _torch_interp(
+            grid = torch.nn.functional.interpolate(  # type: ignore
+                recompute_scale_factor=True,
                 input=grid.unsqueeze(0),
                 scale_factor=ensure_tuple_rep(self.rand_2d_elastic.deform_grid.spacing, 2),
                 mode=InterpolateMode.BICUBIC.value,


Test patch: