Cannot import name 'int_classes' from 'torch._six'

I’m using pytorch 1.9. I know that using 1.8 would solve it but I absolutely have to use 1.9.
I have the same error but with “container_abcs” solved with “import collections.abc as container_abcs” the problem remains with “int_classes”. Does anyone have any solution to solve this problem besides pytorch downgrade.

5 Likes

Easiest solution would be to just set int_classes = int instead of importing it from _six.

6 Likes

Confirming that I get the same error in PyTorch 1.9:

(proxy) [jalal@goku proxynca_pp]$ CUDA_VISIBLE_DEVICES=0,1 python train.py --dataset cub  --config config/cub.json --mode train --apex --seed 0
Traceback (most recent call last):
  File "train.py", line 3, in <module>
    import dataset
  File "/scratch3/research/code/fashion/proxynca_pp/dataset/__init__.py", line 6, in <module>
    from . import utils
  File "/scratch3/research/code/fashion/proxynca_pp/dataset/utils.py", line 8, in <module>
    from torch._six import int_classes as _int_classes
ImportError: cannot import name 'int_classes' from 'torch._six' (/scratch3/venv/proxy/lib/python3.8/site-packages/torch/_six.py)
(proxy) [jalal@goku proxynca_pp]$ pip freeze
h5py==3.4.0
numpy==1.21.2
Pillow==8.3.2
scipy==1.7.1
torch==1.9.0+cu111
torchaudio==0.9.0
torchvision==0.10.0+cu111
tqdm==4.62.2
typing-extensions==3.10.0.2

for this code repo: GitHub - euwern/proxynca_pp: The implementation of ProxyNCA++.

#from torch._six import int_classes as _int_classes
int_classes = int

^ worked for me.