Repository: Project-MONAI/MONAI

Issue:
compatibility with torch 1.9
**Is your feature request related to a problem? Please describe.**
pytorch 1.9 is available, there're some compatibility issues such as https://github.com/Project-MONAI/MONAI/runs/2831507688?check_suite_focus=true#step:8:4236


Discussion:

Resolving patch:
diff --git a/monai/data/dataset.py b/monai/data/dataset.py
--- a/monai/data/dataset.py
+++ b/monai/data/dataset.py
@@ -243,7 +243,13 @@ def _cachecheck(self, item_transformed):
             hashfile = self.cache_dir / f"{data_item_md5}.pt"
 
         if hashfile is not None and hashfile.is_file():  # cache hit
-            return torch.load(hashfile)
+            try:
+                return torch.load(hashfile)
+            except PermissionError as e:
+                if sys.platform == "win32":
+                    pass  # windows machine multiprocessing not efficiently supported
+                else:
+                    raise e
 
         _item_transformed = self._pre_transform(deepcopy(item_transformed))  # keep the original hashed
         if hashfile is not None:


Test patch:
diff --git a/tests/test_basic_unet.py b/tests/test_basic_unet.py
--- a/tests/test_basic_unet.py
+++ b/tests/test_basic_unet.py
@@ -30,15 +30,15 @@
     CASES_1D.append(
         [
             kwargs,
-            (10, 5, 17),
-            (10, 8, 17),
+            (10, 5, 33),
+            (10, 8, 33),
         ]
     )
 
 CASES_2D = []
 for mode in ["pixelshuffle", "nontrainable", "deconv"]:
-    for d1 in range(17, 64, 14):
-        for d2 in range(63, 18, -21):
+    for d1 in range(33, 64, 14):
+        for d2 in range(63, 33, -21):
             in_channels, out_channels = 2, 3
             CASES_2D.append(
                 [
@@ -62,8 +62,8 @@
             "features": (16, 20, 21, 22, 23, 11),
             "upsample": "pixelshuffle",
         },
-        (2, 1, 16, 17, 18),
-        (2, 2, 16, 17, 18),
+        (2, 1, 33, 34, 35),
+        (2, 2, 33, 34, 35),
     ],
     [  # 2-channel 3D, batch 3
         {
@@ -73,8 +73,8 @@
             "features": (14, 15, 16, 17, 18, 11),
             "upsample": "deconv",
         },
-        (3, 2, 16, 17, 18),
-        (3, 7, 16, 17, 18),
+        (3, 2, 33, 37, 34),
+        (3, 7, 33, 37, 34),
     ],
     [  # 4-channel 3D, batch 5
         {
@@ -84,8 +84,8 @@
             "features": (14, 15, 16, 17, 18, 10),
             "upsample": "nontrainable",
         },
-        (5, 4, 19, 84, 16),
-        (5, 2, 19, 84, 16),
+        (5, 4, 34, 35, 37),
+        (5, 2, 34, 35, 37),
     ],
 ]
 
diff --git a/tests/testing_data/integration_answers.py b/tests/testing_data/integration_answers.py
--- a/tests/testing_data/integration_answers.py
+++ b/tests/testing_data/integration_answers.py
@@ -375,6 +375,52 @@
             ],
         },
     },
+    {  # test answers for PyTorch 1.9
+        "integration_workflows": {
+            "output_sums_2": [
+                0.14213180541992188,
+                0.15153264999389648,
+                0.13801145553588867,
+                0.1338348388671875,
+                0.18515968322753906,
+                0.16404008865356445,
+                0.14110612869262695,
+                0.16686391830444336,
+                0.15673542022705078,
+                0.1772594451904297,
+                0.16174745559692383,
+                0.16518878936767578,
+                0.1440296173095703,
+                0.11033201217651367,
+                0.1611781120300293,
+                0.19660568237304688,
+                0.17468547821044922,
+                0.053053855895996094,
+                0.1909656524658203,
+                0.19952869415283203,
+                0.1957845687866211,
+                0.2034916877746582,
+                0.16042661666870117,
+                0.13193607330322266,
+                0.15104389190673828,
+                0.13695430755615234,
+                0.22720861434936523,
+                0.16157913208007812,
+                0.14759159088134766,
+                0.10379791259765625,
+                0.11937189102172852,
+                0.1306462287902832,
+                0.11205482482910156,
+                0.15182113647460938,
+                0.16006708145141602,
+                0.19011592864990234,
+                0.21713829040527344,
+                0.17794132232666016,
+                0.18584394454956055,
+                0.03577899932861328,
+            ],
+        },
+    },
 ]