Repository: Project-MONAI/MONAI

Issue:
module 'torch.hub' has no attribute 'get_dir' in pytorch 1.5
**Describe the bug**
from the nightly tests with PyTorch 1.5 https://github.com/Project-MONAI/MONAI/runs/2779850136?check_suite_focus=true:
```
======================================================================
ERROR: test_load_ckpt_2 (tests.test_mmar_download.TestMMMARDownload)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.6/site-packages/parameterized/parameterized.py", line 533, in standalone_func
    return func(*(a + p.args), **p.kwargs)
  File "/__w/MONAI/MONAI/tests/test_mmar_download.py", line 97, in test_load_ckpt
    output = load_from_mmar(**input_args)
  File "/__w/MONAI/MONAI/monai/apps/mmars/mmars.py", line 109, in load_from_mmar
    model_dir = download_mmar(item=item, mmar_dir=mmar_dir, progress=progress)
  File "/__w/MONAI/MONAI/monai/apps/mmars/mmars.py", line 72, in download_mmar
    mmar_dir = os.path.join(torch.hub.get_dir(), "mmars")
AttributeError: module 'torch.hub' has no attribute 'get_dir'

----------------------------------------------------------------------
```
module 'torch.hub' has no attribute 'get_dir' in pytorch 1.5
**Describe the bug**
from the nightly tests with PyTorch 1.5 https://github.com/Project-MONAI/MONAI/runs/2779850136?check_suite_focus=true:
```
======================================================================
ERROR: test_load_ckpt_2 (tests.test_mmar_download.TestMMMARDownload)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/conda/lib/python3.6/site-packages/parameterized/parameterized.py", line 533, in standalone_func
    return func(*(a + p.args), **p.kwargs)
  File "/__w/MONAI/MONAI/tests/test_mmar_download.py", line 97, in test_load_ckpt
    output = load_from_mmar(**input_args)
  File "/__w/MONAI/MONAI/monai/apps/mmars/mmars.py", line 109, in load_from_mmar
    model_dir = download_mmar(item=item, mmar_dir=mmar_dir, progress=progress)
  File "/__w/MONAI/MONAI/monai/apps/mmars/mmars.py", line 72, in download_mmar
    mmar_dir = os.path.join(torch.hub.get_dir(), "mmars")
AttributeError: module 'torch.hub' has no attribute 'get_dir'

----------------------------------------------------------------------
```


Discussion:

Resolving patch:
diff --git a/monai/apps/mmars/mmars.py b/monai/apps/mmars/mmars.py
--- a/monai/apps/mmars/mmars.py
+++ b/monai/apps/mmars/mmars.py
@@ -69,7 +69,12 @@ def download_mmar(item, mmar_dir=None, progress: bool = True):
     if not isinstance(item, Mapping):
         item = _get_model_spec(item)
     if not mmar_dir:
-        mmar_dir = os.path.join(torch.hub.get_dir(), "mmars")
+        get_dir, has_home = optional_import("torch.hub", name="get_dir")
+        if has_home:
+            mmar_dir = os.path.join(get_dir(), "mmars")
+        else:
+            raise ValueError("mmar_dir=None, but no suitable default directory computed. Upgrade Pytorch to 1.6+ ?")
+
     model_dir = os.path.join(mmar_dir, item[Keys.ID])
     download_and_extract(
         url=item[Keys.URL],


Test patch:
diff --git a/tests/test_mmar_download.py b/tests/test_mmar_download.py
--- a/tests/test_mmar_download.py
+++ b/tests/test_mmar_download.py
@@ -19,7 +19,7 @@
 
 from monai.apps import download_mmar, load_from_mmar
 from monai.apps.mmars import MODEL_DESC
-from tests.utils import skip_if_quick
+from tests.utils import SkipIfAtLeastPyTorchVersion, SkipIfBeforePyTorchVersion, skip_if_quick
 
 TEST_CASES = [["clara_pt_prostate_mri_segmentation_1"], ["clara_pt_covid19_ct_lesion_segmentation_1"]]
 TEST_EXTRACT_CASES = [
@@ -83,6 +83,7 @@
 class TestMMMARDownload(unittest.TestCase):
     @parameterized.expand(TEST_CASES)
     @skip_if_quick
+    @SkipIfBeforePyTorchVersion((1, 6))
     def test_download(self, idx):
         download_mmar(idx)
         download_mmar(idx, progress=False)  # repeated to check caching
@@ -93,6 +94,7 @@ def test_download(self, idx):
 
     @parameterized.expand(TEST_EXTRACT_CASES)
     @skip_if_quick
+    @SkipIfBeforePyTorchVersion((1, 6))
     def test_load_ckpt(self, input_args, expected_name, expected_val):
         output = load_from_mmar(**input_args)
         self.assertEqual(output.__class__.__name__, expected_name)
@@ -104,6 +106,11 @@ def test_unique(self):
         keys = sorted([m["id"] for m in MODEL_DESC])
         self.assertTrue(keys == sorted(set(keys)))
 
+    @SkipIfAtLeastPyTorchVersion((1, 6))
+    def test_no_default(self):
+        with self.assertRaises(ValueError):
+            download_mmar(0)
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tests/utils.py b/tests/utils.py
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -126,7 +126,7 @@ def __call__(self, obj):
 
 class SkipIfAtLeastPyTorchVersion:
     """Decorator to be used if test should be skipped
-    with PyTorch versions newer than that given."""
+    with PyTorch versions newer than or equal to that given."""
 
     def __init__(self, pytorch_version_tuple):
         self.max_version = pytorch_version_tuple