Repository: pytorch/vision

Issue:
PyTorch 1.13 release breaks torchvision 0.14.0 - bad python import from maxvit
### 🐛 Describe the bug

Bad import in TorchVision > Models > maxvit.py

```python
from torchvision import models
```

```
  File "py3.7\lib\site-packages\torchvision\__init__.py", line 5, in <module>
    from torchvision import datasets, io, models, ops, transforms, utils
  File "py3.7\lib\site-packages\torchvision\models\__init__.py", line 16, in <module>
    from .maxvit import *
  File "py3.7\lib\site-packages\torchvision\models\maxvit.py", line 3, in <module>

    from typing import Any, Callable, List, Optional, OrderedDict, Sequence, Tuple

ImportError: cannot import name 'OrderedDict' from 'typing'
```

### Versions

Collecting environment information...
PyTorch version: 1.13.0+cu116
Is debug build: False
CUDA used to build PyTorch: 11.6
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 Pro
GCC version: Could not collect
Clang version: Could not collect
CMake version: Could not collect
Libc version: N/A

Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.19041-SP0
Is CUDA available: True
CUDA runtime version: 11.1.74
CUDA_MODULE_LOADING set to:
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 2080 Ti
Nvidia driver version: 512.15
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.19.5
[pip3] pytorch-fid==0.2.1
[pip3] pytorch-lightning==1.5.10
[pip3] pytorch-wavelets==1.3.0
[pip3] torch==1.13.0+cu116
[pip3] torchaudio==0.12.1
[pip3] torchfile==0.1.0
[pip3] torchmetrics==0.8.2
[pip3] torchsummary==1.5.1
[pip3] torchvision==0.14.0+cu116
[conda] Could not collect

cc @peterjc123 @mszhanyi @skyline75489 @nbcsm


Discussion:
Oh, it looks like this is due to a change in python standard library (e.g. moving the location of OrderedDict)

Note that I'm using Python 3.7
According to the install page, 3.7 is supported:
![image](https://user-images.githubusercontent.com/1510114/198738694-3eaa8c65-25aa-467b-8b55-5548cc38689e.png)

<img width="1145" alt="Screenshot 2022-10-31 at 12 10 48 PM" src="https://user-images.githubusercontent.com/5326909/198947029-5d7aae38-df6a-483b-84fb-3b60799ec0f0.png">


Working perfectly fine with the python 3.9

True to upgrade your python version 
Sounds like this is expected since we no longer support 3.7, but adding triage review label to determine if we want to do anything about this (perhaps there is an easy fix)
[OrderedDict](https://docs.python.org/3/library/typing.html#typing.OrderedDict) has been added in Python-3.7.2. Is there a reason why one needs to use 3.7.0 here?

Also, moving to TorchVision, as this is not really a core issue, but again, I don't think the goal is to support Python-3.7.0
As noted above, the PyTorch install page says Python 3.7 is still supported.

Its fine to change that, but the official install page should reflect the accurate minimum supported python version.
@jcowles I think the best solution would be probably to update to the latest Python 3.7.x minor. Perhaps it's worth changing the documentation to indicate that 3.7.2 and above is supported.
> Is there a reason why one needs to use 3.7.0 here?
>  I don't think the goal is to support Python-3.7.0

@malfet the current lower bound is set to `3.7`

https://github.com/pytorch/vision/blob/bf58902b2fd881c760cd2eeacfae2d7c468ebf1f/setup.py#L549

so depending on the users environment, it's seems possible to install torchvision with `3.7.0` (even from a clean env) and observe the original failure here.

Do you know if we're planning on a bugfix release soon? If we are, we might want to either:
- a) bump our lower bound to `3.7.2` (https://github.com/pytorch/vision/pull/6926). But that would be deviating from torch core's requirements.
- b) fix the failure in some other way: we might not even need an `OrderedDict` in this case, since all dicts are guaranteed to preserve insertion order from 3.7.


I have a preference for b) since it's less restrictive, and because `typing.OrderedDict` is [already deprecated in 3.9](https://docs.python.org/3/library/typing.html#typing.OrderedDict) so we'll have to update that eventually anyway.

Resolving patch:
diff --git a/torchvision/models/maxvit.py b/torchvision/models/maxvit.py
--- a/torchvision/models/maxvit.py
+++ b/torchvision/models/maxvit.py
@@ -1,6 +1,7 @@
 import math
+from collections import OrderedDict
 from functools import partial
-from typing import Any, Callable, List, Optional, OrderedDict, Sequence, Tuple
+from typing import Any, Callable, List, Optional, Sequence, Tuple
 
 import numpy as np
 import torch
@@ -426,7 +427,7 @@ def __init__(
     ) -> None:
         super().__init__()
 
-        layers: OrderedDict[str, Any] = OrderedDict()  # type: ignore
+        layers: OrderedDict = OrderedDict()
 
         # convolutional layer
         layers["MBconv"] = MBConv(


Test patch: