Cannot import name 'QuantStub' from 'torch.ao.quantization'

Hi I am new to pytorch.

I encounter an issue when I run the below. Can someone assist ?
from torchvision import datasets, transforms

Error message:
ImportError: cannot import name ‘QuantStub’ from ‘torch.ao.quantization’

Are you seeing this error while just running from torchvision import datasets, transforms or any other imports?
Could you post the versions reported by pip list | grep torch and/or conda list | grep torch?

Hi ptrblck,
Thanks for reply. Someone suggested that I take away the .ao from all the error message files. So i just took away .ao from the below files and now there is no error message. Hope it really resolve the issue.

init
mobilenetv2
mobilenetv3

1 Like

you probably have an older version of pytorch? we are deprecating the torch.quantization namespace, and torch.ao.quantization is the recommended one

1 Like

Hi Jerry,
Oh I see. May I know what version of pytorch & python should I install so that I can run pytorch smoothly?

2 Likes

Updating pytorch fixes the problem:

pip install --upgrade torch torchvision