From torch._six import container_abcs, string_classes, int_classes ImportError: cannot import name 'container_abcs' from 'torch._six' (/home/mona/anaconda3/envs/zephyr/lib/python3.9/site-packages/torch/_six.py)

username: Mona_Jalal
cooked: <p>I get this error:</p>
<pre><code class="lang-auto">(zephyr) mona@ard-gpu-01:~/zephyr/python/zephyr$ python test.py     --model_name pn2     --dataset_root ./data/ycb/matches_data_test/     --dataset_name ycbv     --dataset HSVD_diff_uv_norm     --no_valid_proj --no_valid_depth     --loss_cutoff log     --exp_name final     --resume_path ./ckpts/final_ycbv.ckpt
Traceback (most recent call last):
  File "/home/mona/zephyr/python/zephyr/test.py", line 10, in &lt;module&gt;
    from zephyr.datasets import getDataloader
  File "/home/mona/zephyr/python/zephyr/datasets/__init__.py", line 8, in &lt;module&gt;
    from zephyr.datasets.collate import default_collate
  File "/home/mona/zephyr/python/zephyr/datasets/collate.py", line 9, in &lt;module&gt;
    from torch._six import container_abcs, string_classes, int_classes
ImportError: cannot import name 'container_abcs' from 'torch._six' (/home/mona/anaconda3/envs/zephyr/lib/python3.9/site-packages/torch/_six.py)

</code></pre>
<p>I saw this answer:</p><aside class="onebox githubissue" data-onebox-src="https://github.com/NVIDIA/apex/issues/1048#issuecomment-877851575">
  <header class="source">

      <a href="https://github.com/NVIDIA/apex/issues/1048#issuecomment-877851575" target="_blank" rel="noopener nofollow ugc">github.com/NVIDIA/apex</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/NVIDIA/apex/issues/1048#issuecomment-877851575" target="_blank" rel="noopener nofollow ugc">cannot import name 'container_abcs' from 'torch._six'</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2021-02-09" data-time="16:53:41" data-timezone="UTC">04:53PM - 09 Feb 21 UTC</span>
      </div>

        <div class="date">
          closed <span class="discourse-local-date" data-format="ll" data-date="2021-02-10" data-time="06:12:42" data-timezone="UTC">06:12AM - 10 Feb 21 UTC</span>
        </div>

      <div class="user">
        <a href="https://github.com/ShoufaChen" target="_blank" rel="noopener nofollow ugc">
          <img alt="ShoufaChen" src="https://avatars.githubusercontent.com/u/28682908?v=4" class="onebox-avatar-inline" width="20" height="20">
          ShoufaChen
        </a>
      </div>
    </div>

    <div class="labels">
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">```
&gt;&gt;&gt; from apex import amp
Traceback (most recent call last):
  File "&lt;stdi<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">n&gt;", line 1, in &lt;module&gt;
  File "/mnt/lustre/chenshoufa/anaconda3/envs/pytorch18/lib/python3.8/site-packages/apex/__init__.py", line 8, in &lt;module&gt;
    from . import amp
  File "/mnt/lustre/chenshoufa/anaconda3/envs/pytorch18/lib/python3.8/site-packages/apex/amp/__init__.py", line 1, in &lt;module&gt;
    from .amp import init, half_function, float_function, promote_function,\
  File "/mnt/lustre/chenshoufa/anaconda3/envs/pytorch18/lib/python3.8/site-packages/apex/amp/amp.py", line 1, in &lt;module&gt;
    from . import compat, rnn_compat, utils, wrap
  File "/mnt/lustre/chenshoufa/anaconda3/envs/pytorch18/lib/python3.8/site-packages/apex/amp/rnn_compat.py", line 1, in &lt;module&gt;
    from . import utils, wrap
  File "/mnt/lustre/chenshoufa/anaconda3/envs/pytorch18/lib/python3.8/site-packages/apex/amp/wrap.py", line 3, in &lt;module&gt;
    from ._amp_state import _amp_state
  File "/mnt/lustre/chenshoufa/anaconda3/envs/pytorch18/lib/python3.8/site-packages/apex/amp/_amp_state.py", line 14, in &lt;module&gt;
    from torch._six import container_abcs
ImportError: cannot import name 'container_abcs' from 'torch._six' (/mnt/lustre/chenshoufa/anaconda3/envs/pytorch18/lib/python3.8/site-packages/torch/_six.py)
```</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/1/21efe557962585d3b3ff91d9556091a3321afb28.png" data-download-href="https://discuss.pytorch.org/uploads/default/21efe557962585d3b3ff91d9556091a3321afb28" title="Screenshot from 2023-05-31 14-12-40"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/1/21efe557962585d3b3ff91d9556091a3321afb28_2_690x153.png" alt="Screenshot from 2023-05-31 14-12-40" data-base62-sha1="4QdJk9UMtJH8ccH8X7TJEGc8iBG" width="690" height="153" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/1/21efe557962585d3b3ff91d9556091a3321afb28_2_690x153.png, https://discuss.pytorch.org/uploads/default/original/3X/2/1/21efe557962585d3b3ff91d9556091a3321afb28.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/2/1/21efe557962585d3b3ff91d9556091a3321afb28.png 2x" data-dominant-color="F5F6F7"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot from 2023-05-31 14-12-40</span><span class="informations">868×193 25 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I was not sure where exactly I should add it so I added it here:<br>
(zephyr) mona@ard-gpu-01:~/zephyr/python/zephyr$ vi /home/mona/zephyr/python/zephyr/test.py</p>
<pre><code class="lang-auto">$ cat /home/mona/zephyr/python/zephyr/test.py
import os
import numpy as np
import torch
import torch.cuda
import random

from pytorch_lightning import Trainer

from zephyr.models import getModel
from zephyr.datasets import getDataloader
from zephyr.options import getOptions, checkArgs

import collections.abc as container_abcs
</code></pre>
<p>But it didn’t resolve the error. Do you know how I can fix it?</p>
<p>Here’s my env information:</p>
<pre><code class="lang-auto">(zephyr) mona@ard-gpu-01:~/zephyr$ python -m torch.utils.collect_env
Collecting environment information...
PyTorch version: 1.13.0+cu117
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
Clang version: 14.0.0-1ubuntu1
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.9.16 (main, Mar  8 2023, 14:00:05)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.19.0-42-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.7.99
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3080 Laptop GPU
Nvidia driver version: 530.30.02
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.24.3
[pip3] pytorch-lightning==0.7.6
[pip3] torch==1.13.0+cu117
[pip3] torchmetrics==0.11.4
[pip3] torchtext==0.14.0
[pip3] torchvision==0.14.0+cu117
[conda] numpy                     1.24.3                   pypi_0    pypi
[conda] pytorch-lightning         0.7.6                    pypi_0    pypi
[conda] torch                     1.13.0+cu117             pypi_0    pypi
[conda] torchmetrics              0.11.4                   pypi_0    pypi
[conda] torchtext                 0.14.0                   pypi_0    pypi
[conda] torchvision               0.14.0+cu117             pypi_0    pypi

</code></pre>
<p>Here’s zephyr git repo: <a href="https://github.com/r-pad/zephyr" class="inline-onebox" rel="noopener nofollow ugc">GitHub - r-pad/zephyr: Source code for ZePHyR: Zero-shot Pose Hypothesis Rating @ ICRA 2021</a><br>
and the command I ran belongs to <code>Test on YCB-V dataset</code></p>

username: Mona_Jalal
cooked: <pre><code class="lang-auto">import torch
import re
#from torch._six import container_abcs, string_classes, int_classes
import collections.abc as container_abcs
</code></pre>
<p>^^ the fix</p>
<p>(zephyr) mona@ard-gpu-01:~/zephyr/python/zephyr$ vi datasets/collate.py</p>