zhanghang1989 / PyTorch-Encoding

A CV toolkit for my papers.
https://hangzhang.org/PyTorch-Encoding/
MIT License
2.04k stars 450 forks source link

Cannot import encoding #70

Open OasisYang opened 6 years ago

OasisYang commented 6 years ago

Hi, I can run "python setup.py install" with no errors, but when i try to "import encoding". I got the error like this. Could you help me with that, thanks. image

zhanghang1989 commented 6 years ago

Please install ninja 1.8.2 by following the instructions https://www.claudiokuenzler.com/blog/756/install-newer-ninja-build-tools-ubuntu-14.04-trusty#.WxYrvFMvzJw

OasisYang commented 6 years ago

I installed the ninja 1.8.2 by the instructions you mentioned, but got the same error @zhanghang1989.

liyingying05 commented 6 years ago

I have got the same error, and I changed ['ninja', '-v'] to ['ninja', '--v'],but the main error also exists, when I try "import encoding", I got error " ImportError: No module named 'enclib_cpu' ", it seems must have one of this

image

but I have none. I have run "python setup.py install" with no errors and my ninja version is 1.8.2. @zhanghang1989 @OasisYang Have you solved it?

zhanghang1989 commented 6 years ago

Are you using the PyTorch master branch?

vribeiro1 commented 6 years ago

@zhanghang1989 I am having the same issues described above. At first I had the RuntimeError: Error building extension 'enclib_cpu' just like @OasisYang described. Then I tried replacing ['ninja', '-v'] by ['ninja', '--v'] like @liyingying05 did, and also had the ImportError: No module named 'enclib_cpu'.

I have ninja 1.8.2 installed. I pip-installed torch-encoding with no errors. Also tried installing via setup.py, which worked fine. I'm working on the Pytorch master branch. Do any of you have solved it?

liyingying05 commented 6 years ago

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

XindyTT commented 6 years ago

I have successful installed pytorch 0.5 and ninja 1.8.2,however when I import encoding, there has also problems.

`Traceback (most recent call last): File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 742, in _build_extension_module ['ninja', '-v'], stderr=subprocess.STDOUT, cwd=build_directory) File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/subprocess.py", line 376, in check_output **kwargs).stdout File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/subprocess.py", line 468, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/init.py", line 13, in from . import nn, functions, dilated, parallel, utils, models, datasets File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/nn/init.py", line 12, in from .encoding import File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/nn/encoding.py", line 18, in from ..functions import scaledL2, aggregate, pairwise_cosine File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/functions/init.py", line 2, in from .encoding import File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/functions/encoding.py", line 14, in from .. import lib File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/init.py", line 20, in ], build_directory=gpu_path, verbose=False) File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 496, in load with_cuda=with_cuda) File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 664, in _jit_compile _build_extension_module(name, build_directory) File "/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 748, in _build_extension_module name, error.output.decode())) RuntimeError: Error building extension 'enclib_gpu': [1/4] /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu -o encoding_kernel.cuda.o FAILED: encoding_kernel.cuda.o /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu -o encoding_kernel.cuda.o /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu(315): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu(341): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu(364): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/encoding_kernel.cu(391): error: class "at::Context" has no member "getCurrentCUDAStream"

4 errors detected in the compilation of "/tmp/tmpxft_00005f49_00000000-6_encoding_kernel.cpp1.ii". [2/4] /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu -o syncbn_kernel.cuda.o FAILED: syncbn_kernel.cuda.o /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu -o syncbn_kernel.cuda.o /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu(183): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu(217): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu(249): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/syncbn_kernel.cu(272): error: class "at::Context" has no member "getCurrentCUDAStream"

4 errors detected in the compilation of "/tmp/tmpxft_00005f4a_00000000-6_syncbn_kernel.cpp1.ii". [3/4] /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu -o roi_align_kernel.cuda.o FAILED: roi_align_kernel.cuda.o /usr/local/cuda/bin/nvcc -DTORCH_EXTENSION_NAME=enclib_gpu -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/TH -I/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/torch/lib/include/THC -I/usr/local/cuda/include -I/home/wuxinting/anaconda3/envs/pytorch-master/include/python3.7m --compiler-options '-fPIC' -std=c++11 -c /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu -o roi_align_kernel.cuda.o /home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu(373): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu(373): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu(420): error: class "at::Context" has no member "getCurrentCUDAStream"

/home/wuxinting/anaconda3/envs/pytorch-master/lib/python3.7/site-packages/encoding/lib/gpu/roi_align_kernel.cu(420): error: class "at::Context" has no member "getCurrentCUDAStream"

4 errors detected in the compilation of "/tmp/tmpxft_00005f4b_00000000-6_roi_align_kernel.cpp1.ii". ninja: build stopped: subcommand failed.`

zhanghang1989 commented 6 years ago

Please install ninja 1.8.2 by following the instructions https://www.claudiokuenzler.com/blog/756/install-newer-ninja-build-tools-ubuntu-14.04-trusty#.WxYrvFMvzJw

XindyTT commented 6 years ago

@zhanghang1989 Thank you for your reply, I tried in this way, but it doesn't work for me. The main problem for me is enclib_gpu cannot be installed, class "at::Context" has no member "getCurrentCUDAStream". Then I search for the sorece code in pytorch-master, finding that the API has been change to at::cuda::getCurrentCUDAStream, so I replace all the at::globalContext.getCurrentCUDAStream() to at::cuda::getCurrentCUDAStream and edd the header file #include "ATen/cuda/CUDAContext.h" , it is work for me. I think maybe the master branch of pytorch has make some change with the version before?

zhanghang1989 commented 6 years ago

Thanks a lot @XindyTT ! I will update the repo in next release.

fanglw commented 5 years ago

use pytorch=0.4.1 will be ok. My python version is 3.6.7.

zhanghang1989 commented 5 years ago

This issue should have been fixed by previous PR.

thompa2 commented 5 years ago

I'm also getting this error: ImportError: No module named 'enclib_cpu'. I did a source install from the Pytorch master branch and installed ninja 1.8.2 as per the link above. Any suggestions?

zhanghang1989 commented 5 years ago

Maybe it is related to this https://github.com/zhanghang1989/PyTorch-Encoding/issues/140#issuecomment-438373706

chauhochow commented 5 years ago

i have met the same problem. i have try it on pytorch0.4.1 and pytorch1.0, and also rename torch.h to extension.h, but i still cannot solve it. if anyone solve it?

henanjun commented 5 years ago

@zhanghang1989 Thank you for your reply, I tried in this way, but it doesn't work for me. The main problem for me is enclib_gpu cannot be installed, class "at::Context" has no member "getCurrentCUDAStream". Then I search for the sorece code in pytorch-master, finding that the API has been change to at::cuda::getCurrentCUDAStream, so I replace all the at::globalContext.getCurrentCUDAStream() to at::cuda::getCurrentCUDAStream and edd the header file #include "ATen/cuda/CUDAContext.h" , it is work for me. I think maybe the master branch of pytorch has make some change with the version b

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

Hello. What do you mean by using Pytroch master? Do I need uninstall the current Pytorch and install a new version?

XindyTT commented 5 years ago

@zhanghang1989 Thank you for your reply, I tried in this way, but it doesn't work for me. The main problem for me is enclib_gpu cannot be installed, class "at::Context" has no member "getCurrentCUDAStream". Then I search for the sorece code in pytorch-master, finding that the API has been change to at::cuda::getCurrentCUDAStream, so I replace all the at::globalContext.getCurrentCUDAStream() to at::cuda::getCurrentCUDAStream and edd the header file #include "ATen/cuda/CUDAContext.h" , it is work for me. I think maybe the master branch of pytorch has make some change with the version b

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

Hello. What do you mean by using Pytroch master? Do I need uninstall the current Pytorch and install a new version?

master is the branch of Pytorch in git. However, the API and variable may change if pytorch's version update. I tried the repo in June, where the master of pytorch is version 0.5. And now the version may be higher.

henanjun commented 5 years ago

@zhanghang1989 Thank you for your reply, I tried in this way, but it doesn't work for me. The main problem for me is enclib_gpu cannot be installed, class "at::Context" has no member "getCurrentCUDAStream". Then I search for the sorece code in pytorch-master, finding that the API has been change to at::cuda::getCurrentCUDAStream, so I replace all the at::globalContext.getCurrentCUDAStream() to at::cuda::getCurrentCUDAStream and edd the header file #include "ATen/cuda/CUDAContext.h" , it is work for me. I think maybe the master branch of pytorch has make some change with the version b

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

Hello. What do you mean by using Pytroch master? Do I need uninstall the current Pytorch and install a new version?

master is the branch of Pytorch in git. However, the API and variable may change if pytorch's version update. I tried the repo in June, where the master of pytorch is version 0.5. And now the version may be higher.

I see. Thanks for your kind reply.

andrewwyl commented 4 years ago

@vribeiro1 I have solved it using the PyTorch master branch, and the ['ninja', '-v'] should not be changed.

hi,Could you tell me how you solved this problem?ubuntu==16.04,python==3.5,gcc==5.4.0 cuda==9.0 torch-encoding Version is 1.0.0

chenerg commented 4 years ago

same problem with torchvision-0.5.0 pytorch-1.4.0 and ninjia 1.8.2

zhanghang1989 commented 4 years ago

Hi, did you follow the instructions at https://hangzhang.org/PyTorch-Encoding/notes/compile.html

I suggest using the latest anaconda with CUDA 10.0 on ubuntu 16.04.

qiaoyaya2011 commented 4 years ago

it doesn't work ,i have tried No module named 'enclib_gpu' @zhanghang1989

qiaoyaya2011 commented 4 years ago

do you have saved this problem? @OasisYang

qiaoyaya2011 commented 4 years ago

@zhanghang1989 I am having the same issues described above. At first I had the RuntimeError: Error building extension 'enclib_cpu' just like @OasisYang described. Then I tried replacing ['ninja', '-v'] by ['ninja', '--v'] like @liyingying05 did, and also had the ImportError: No module named 'enclib_cpu'.

I have ninja 1.8.2 installed. I pip-installed torch-encoding with no errors. Also tried installing via setup.py, which worked fine. I'm working on the Pytorch master branch. Do any of you have solved it?

i also meet this problem,have you solved it

qiaoyaya2011 commented 4 years ago

what's the mean of PR @zhanghang1989

qiaoyaya2011 commented 4 years ago

same problem with torchvision-0.5.0 pytorch-1.4.0 and ninjia 1.8.2

me too

qiaoyaya2011 commented 4 years ago

Hi, did you follow the instructions at https://hangzhang.org/PyTorch-Encoding/notes/compile.html

I suggest using the latest anaconda with CUDA 10.0 on ubuntu 16.04.

it doesn't work

zhanghang1989 commented 4 years ago

Please use pytorch 1.4.0. PyTorch 1.5 is not supported yet.

diwamanic commented 3 years ago

I am facing an issue like this during my installation of Pytorch_Encoding. I am trying to run this module in Windows. And I am using Anaconda for this purpose. Could someone of you please give me a detailed set of instructions as to how I properly install it and resolve the issue that I captured below:

This is the error I am getting for the installation:

INFO: pip is looking at multiple versions of to determine which version is compatible with other requirements. This could take a while. INFO: pip is looking at multiple versions of torch-encoding to determine which version is compatible with other requirements. This could take a while. ERROR: Cannot install torch-encoding and torch-encoding==1.2.2b20210226 because these package versions have conflicting dependencies.

The conflict is caused by: torch-encoding 1.2.2b20210226 depends on torch>=1.4.0 torchvision 0.5.0 depends on torch==1.4.0

To fix this you could try to:

  1. loosen the range of package versions you've specified
  2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies

zhanghang1989 commented 3 years ago

Please uninstall all the existing versions torch-encoding library in your machine. Then follow the instructions: https://hangzhang.org/PyTorch-Encoding/notes/compile.html

diwamanic commented 3 years ago

Hey thanks, I have sorted out that issue. But, at the moment, I am trying to train the model with cpu. I could not do it with pip install method. Because it throws some big chunk of error: I have scoured through the whole error lines and found the place where it makes an issue.

This following is the issue: c:\users\dmanicka\appdata\local\programs\python\python36\lib\site-packages\torch\utils\cpp_extension.py:209: UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the file specified

can you please help me get through this error?

zhanghang1989 commented 3 years ago

I haven't used window system. Could you try using the docker option? https://hangzhang.org/PyTorch-Encoding/notes/compile.html#using-docker