ast icon indicating copy to clipboard operation
ast copied to clipboard

[Bug] ModuleNotFoundError: No module named 'torch.ao'

Open almostimplemented opened this issue 2 years ago • 7 comments

Following setup instructions at present will lead to an error on the model import. Specifically, torchvision needs to be pinned to a version. Otherwise, pip may install (e.g.) 0.12.0, which expects torch==1.11.0 when it imports torch.ao.

 from models import AASTModel
/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: /homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/torchvision/image.so: undefined symbol: _ZNK3c106IValue23reportToTensorTypeErrorEv
  warn(f"Failed to load image Python extension: {e}")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/homes/ace01/non_forks/ast/src/models/__init__.py", line 8, in <module>
    from .ast_models import *
  File "/homes/ace01/non_forks/ast/src/models/ast_models.py", line 14, in <module>
    import timm
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/timm/__init__.py", line 2, in <module>
    from .models import create_model, list_models, is_model, list_modules, model_entrypoint, \
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/timm/models/__init__.py", line 1, in <module>
    from .byobnet import *
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/timm/models/byobnet.py", line 36, in <module>
    from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/timm/data/__init__.py", line 7, in <module>
    from .loader import create_loader
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/timm/data/loader.py", line 12, in <module>
    from .transforms_factory import create_transform
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/timm/data/transforms_factory.py", line 9, in <module>
    from torchvision import transforms
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/torchvision/__init__.py", line 7, in <module>
    from torchvision import models
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/torchvision/models/__init__.py", line 18, in <module>
    from . import quantization
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/torchvision/models/quantization/__init__.py", line 1, in <module>
    from .mobilenet import *
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/torchvision/models/quantization/mobilenet.py", line 1, in <module>
    from .mobilenetv2 import QuantizableMobileNetV2, mobilenet_v2, __all__ as mv2_all
  File "/homes/ace01/non_forks/ast/venvast/lib/python3.7/site-packages/torchvision/models/quantization/mobilenetv2.py", line 5, in <module>
    from torch.ao.quantization import QuantStub, DeQuantStub
ModuleNotFoundError: No module named 'torch.ao'

almostimplemented avatar Jun 13 '22 12:06 almostimplemented

Hi there,

Did we use torchvision somewhere in the repo? Could you point me to that?

Thanks!

-Yuan

YuanGongND avatar Jun 13 '22 17:06 YuanGongND

Hi there,

Did we use torchvision somewhere in the repo? Could you point me to that?

Thanks!

-Yuan

Hi Yuan,

If you follow the call stack you can see the dependency arises from import timm from ast_models.py

almostimplemented avatar Jun 13 '22 19:06 almostimplemented

Thanks! I just checked, it seems we use torchvision==0.10.0+cu102

>>> torch.__version__
'1.8.1+cu102'
>>> torchaudio.__version__
'0.8.1'
>>> torchvision.__version__
'0.10.0+cu102'

It's weird that no one has complained about this issue. I assume the order you install these three packages also matters.

YuanGongND avatar Jun 13 '22 19:06 YuanGongND

I suspect it is more to do with when the user installed the dependencies rather than the order -- I think the breaking change came only in the 0.12.0 release:

https://github.com/pytorch/vision/releases/tag/v0.12.0

Without pinning the version in the requirements file, pip will get the latest. So anyone who set up before that point would have avoided the issue -- or perhaps anyone who installed into a Python environment with torchvision already installed / cached at a lower version.

almostimplemented avatar Jun 13 '22 20:06 almostimplemented

Would you like the version changed to 0.10.0?

almostimplemented avatar Jun 13 '22 20:06 almostimplemented

Yes, but I will need to test it before changing it.

Thanks again for pointing this out.

YuanGongND avatar Jun 13 '22 20:06 YuanGongND

A regular check on the traffic of this repo shows that many people are searching this issue - which means this bug affects many people. Follow your suggestion I have pinned torchvision to 0.10.0. I don't have time to make a test but hope that would makes things better.

If anyone still experience this bug, please leave a message in this thread and I will take another look.

-Yuan

YuanGongND avatar Nov 25 '22 01:11 YuanGongND