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 'gpu' from partially initialized module 'encoding' #403

Open
Yforestafe opened this issue Jul 18, 2021 · 8 comments
Open

Comments

@Yforestafe
Copy link

When I run the following code:
python test.py --dataset ADE20K --model-zoo EncNet_ResNet50s_ADE --eval
I miss the error and i can't fix it :
ImportError: cannot import name 'gpu' from partially initialized module 'encoding' (most likely due to a circular import) (/home/aleymane/anaconda3/lib/python3.8/site-packages/torch_encoding-1.2.2b20210718-py3.8-linux-x86_64.egg/encoding/init.py)
2021-07-18 21-47-45 的屏幕截图

@Yforestafe
Copy link
Author

(base) aleymane@aleymane-To-be-filled-by-O-E-M:~/下载/PyTorch-Encoding-master/experiments/segmentation$ python test.py --dataset ADE20K --model-zoo EncNet_ResNet50s_ADE --eval
Traceback (most recent call last):
File "test.py", line 17, in
import encoding.utils as utils
File "/home/aleymane/anaconda3/lib/python3.8/site-packages/torch_encoding-1.2.2b20210718-py3.8-linux-x86_64.egg/encoding/init.py", line 13, in
from . import nn, functions, parallel, utils, models, datasets, transforms
File "/home/aleymane/anaconda3/lib/python3.8/site-packages/torch_encoding-1.2.2b20210718-py3.8-linux-x86_64.egg/encoding/nn/init.py", line 12, in
from .encoding import *
File "/home/aleymane/anaconda3/lib/python3.8/site-packages/torch_encoding-1.2.2b20210718-py3.8-linux-x86_64.egg/encoding/nn/encoding.py", line 18, in
from ..functions import scaled_l2, aggregate, pairwise_cosine
File "/home/aleymane/anaconda3/lib/python3.8/site-packages/torch_encoding-1.2.2b20210718-py3.8-linux-x86_64.egg/encoding/functions/init.py", line 2, in
from .encoding import *
File "/home/aleymane/anaconda3/lib/python3.8/site-packages/torch_encoding-1.2.2b20210718-py3.8-linux-x86_64.egg/encoding/functions/encoding.py", line 17, in
from encoding import gpu
ImportError: cannot import name 'gpu' from partially initialized module 'encoding' (most likely due to a circular import) (/home/aleymane/anaconda3/lib/python3.8/site-packages/torch_encoding-1.2.2b20210718-py3.8-linux-x86_64.egg/encoding/init.py)

@XiaozhuLove
Copy link

hello,i encountered the same problem, how did you solve this problem finally。thank you very much

@zhanghang1989
Copy link
Owner

Did you compile the library with GPU?

@XiaozhuLove
Copy link

Did you compile the library with GPU?

i used this command,

conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1 -c pytorch , and the pytorch-gpu is true.

import encoding
Traceback (most recent call last):
File "", line 1, in
File "/home/lab/anaconda3/lib/python3.8/site-packages/encoding/init.py", line 13, in
from . import nn, functions, parallel, utils, models, datasets, transforms
File "/home/lab/anaconda3/lib/python3.8/site-packages/encoding/nn/init.py", line 12, in
from .encoding import *
File "/home/lab/anaconda3/lib/python3.8/site-packages/encoding/nn/encoding.py", line 18, in
from ..functions import scaled_l2, aggregate, pairwise_cosine
File "/home/lab/anaconda3/lib/python3.8/site-packages/encoding/functions/init.py", line 2, in
from .encoding import *
File "/home/lab/anaconda3/lib/python3.8/site-packages/encoding/functions/encoding.py", line 17, in
from encoding import gpu
ImportError: cannot import name 'gpu' from partially initialized module 'encoding' (most likely due to a circular import) (/home/lab/anaconda3/lib/python3.8/site-packages/encoding/init.py)
import torch
print(torch.version.cuda)
10.0
print(torch.cuda.is_available())
True


Requirement already satisfied: scipy in ./anaconda3/lib/python3.8/site-packages (from torch-encoding==1.2.2b20210831) (1.6.2)
Requirement already satisfied: requests in ./anaconda3/lib/python3.8/site-packages (from torch-encoding==1.2.2b20210831) (2.25.1)
Requirement already satisfied: six in ./anaconda3/lib/python3.8/site-packages (from torchvision>=0.5.0->torch-encoding==1.2.2b20210831) (1.15.0)
Requirement already satisfied: idna<3,>=2.5 in ./anaconda3/lib/python3.8/site-packages (from requests->torch-encoding==1.2.2b20210831) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in ./anaconda3/lib/python3.8/site-packages (from requests->torch-encoding==1.2.2b20210831) (1.26.4)
Requirement already satisfied: chardet<5,>=3.0.2 in ./anaconda3/lib/python3.8/site-packages (from requests->torch-encoding==1.2.2b20210831) (4.0.0)
Requirement already satisfied: certifi>=2017.4.17 in ./anaconda3/lib/python3.8/site-packages (from requests->torch-encoding==1.2.2b20210831) (2020.12.5)
Building wheels for collected packages: torch-encoding
Building wheel for torch-encoding (setup.py) ... done
Created wheel for torch-encoding: filename=torch_encoding-1.2.2b20210831-cp38-cp38-linux_x86_64.whl size=5356502 sha256=6aab71bcd65bc6c722b2d19d5e0d5ab1606a8c2e3790f8eafa632db992682fcd
Stored in directory: /tmp/pip-ephem-wheel-cache-0rnvwebf/wheels/3b/0d/65/569ac6f956a08c129f6d709db05728cb4cd3bd426ef9aea13b
Successfully built torch-encoding
Installing collected packages: torch-encoding
Successfully installed torch-encoding-1.2.2b20210831

and i tried several times. also reinstalled the ubuntu system,but still not work. thank you very much
看起来好像是有多个 torch-encoding 的版本在本地,可以多run几次 pip uninstall -y torch-encoding
然后再重装试试 pip install git+https://github.com/zhanghang1989/PyTorch-Encoding/

@tommyjqliu
Copy link

tommyjqliu commented Feb 8, 2022

I met the same problem and found out it is because I forgot to install CUDA. After the installation problem should be solved. You can use "nvcc --version" to check out whether CUDA is installed correctly.

@XAVILLA
Copy link

XAVILLA commented Feb 10, 2022

@hentaitommy can you explain what you mean by installing CUDA? I have the same problem. Thanks!

@melissah14
Copy link

@XAVILLA @hentaitommy, did either of you figure this out? I have confirmed that I have CUDA installed with the following:

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_May__3_18:49:52_PDT_2022
Cuda compilation tools, release 11.7, V11.7.64
Build cuda_11.7.r11.7/compiler.31294372_0

But I still get the error:
File "/private/home/[]/.conda/envs/env_pytorch/lib/python3.6/site-packages/encoding/functions/encoding.py", line 17, in
from encoding import gpu
ImportError: cannot import name 'gpu'

@zhanghang1989
Copy link
Owner

A possible reason could be that you've installed an older version of this package. You may try pip uninstall torch-encoding multiple times and then follow the instructions to re-install

https://hangzhang.org/PyTorch-Encoding/notes/compile.html

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

6 participants