BenjaminFranklinGates
BenjaminFranklinGates

Reputation: 115

Colab Notebook: Cannot import name 'container_abcs' from 'torch._six'

I'm trying to run the deit colab notebook found here:

https://colab.research.google.com/github/facebookresearch/deit/blob/colab/notebooks/deit_inference.ipynb

but I'm running into an issue in the second cell, specifically the import timm line, which returns this:

ImportError: cannot import name 'container_abcs' from 'torch._six'

Upvotes: 5

Views: 22025

Answers (4)

Jeethesh
Jeethesh

Reputation: 39

I encountered this problem when I was working on PyTorch 1.12 version with a code base developed on PyTorch 1.6.

You should replace

from torch._six import container_abcs 

with

import collections.abc as container_abcs 

as per this issue on GitHub.

Upvotes: 0

loretoparisi
loretoparisi

Reputation: 16271

In my case it worked with

pip install timm==0.4.12

Upvotes: 3

user11717481
user11717481

Reputation: 1602

  • Issue related to this error here:

Try a specific version of timm library:

!pip install timm==0.3.2

Upvotes: 3

Jeffrey Hu
Jeffrey Hu

Reputation: 21

when I install torch==1.9.0 and torch-geometric, the old code has the errors.

here is my solution:

   TORCH_MAJOR = int(torch.__version__.split('.')[0])
   TORCH_MINOR = int(torch.__version__.split('.')[1])
   if TORCH_MAJOR == 0:
      import collections.abc as container_abcs
   else:
      from torch._six import container_abcs

change to:

    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,int_classes
    else:
        import collections.abc as container_abcs
        int_classes = int

Upvotes: 2

Related Questions