Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'container_abcs' from 'torch._six' #420

Closed
aboutmedicine opened this issue Feb 10, 2021 · 5 comments
Closed

cannot import name 'container_abcs' from 'torch._six' #420

aboutmedicine opened this issue Feb 10, 2021 · 5 comments

Comments

@aboutmedicine
Copy link

aboutmedicine commented Feb 10, 2021

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-37004d024db3> in <module>()
     26 
     27 get_ipython().system('pip install -U git+https://github.com/rwightman/pytorch-image-models')
---> 28 import timm
     29 
     30 import torch_xla.core.xla_model as xm

6 frames
/usr/local/lib/python3.6/dist-packages/timm/models/layers/helpers.py in <module>()
      4 """
      5 from itertools import repeat
----> 6 from torch._six import container_abcs
      7 
      8 

ImportError: cannot import name 'container_abcs'
@aboutmedicine
Copy link
Author

I'm away from my computer at the moment, but will create a pull request later for the code:

TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])

if TORCH_MAJOR == 1 and TORCH_MINOR < 8:
    from torch._six import container_abcs
else:
    import collections.abc as container_abcs

To be added to timm/models/layers/helpers.py

@rwightman
Copy link
Collaborator

@aboutmedicine thanks for the report, I've been burned by doing version checks like that in the past, how about a try / except ImportError ? I'll take a look tomorrow if I don't see a PR from you as I have a bunch of other changes about to merge.

@rwightman
Copy link
Collaborator

On second thought should probably just use the proper Python import as I'm pretty sure collections.abc is in any Python3 version that'd be used with this. The ._six code just came from a cut & paste.

@aboutmedicine
Copy link
Author

Thanks for your help, and sounds like a good plan #421

@sebasmos
Copy link

I'm away from my computer at the moment, but will create a pull request later for the code:

TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])

if TORCH_MAJOR == 1 and TORCH_MINOR < 8:
    from torch._six import container_abcs
else:
    import collections.abc as container_abcs

To be added to timm/models/layers/helpers.py

This might be silly but its also missing a torch import:

import torch
TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])

if TORCH_MAJOR == 1 and TORCH_MINOR < 8:
    from torch._six import container_abcs
else:
    import collections.abc as container_abcs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants