AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'
See original GitHub issueHow to reproduce the behaviour
I followed the official spacy-transformers documentation and run in a clean venv:
pip install spacy[transformers,cuda112]
spacy download en_core_web_trf
The GPU is properly detected via !nvidia-smi
, however, spacy
is returning an error when running:
from thinc.api import set_gpu_allocator, require_gpu
set_gpu_allocator('pytorch')
require_gpu(0)
AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_8948/4226459810.py in <module>
2
3 set_gpu_allocator('pytorch')
----> 4 require_gpu(0)
c:\Users\...\Desktop\L09_Desktop\stratTransf\.venv\lib\site-packages\thinc\util.py in require_gpu(gpu_id)
188
189 set_current_ops(CupyOps())
--> 190 set_active_gpu(gpu_id)
191 return True
192
c:\Users\...\Desktop\L09_Desktop\stratTransf\.venv\lib\site-packages\thinc\util.py in set_active_gpu(gpu_id)
149 import torch
150
--> 151 torch.cuda.set_device(gpu_id)
152 torch.set_default_tensor_type("torch.cuda.FloatTensor")
153 except ImportError:
c:\Users\...\Desktop\L09_Desktop\stratTransf\.venv\lib\site-packages\torch\cuda\__init__.py in set_device(device)
262 device = _get_device_index(device)
263 if device >= 0:
--> 264 torch._C._cuda_setDevice(device)
265
266
AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'
Any idea what might cause the problem? I would be super grateful for any help!
Info about spaCy
- spaCy version: 3.1.0
- Platform: Windows-10-10.0.19041-SP0
- Python version: 3.8.5
- Pipelines: en_core_web_trf (3.1.0)
Edit
As per #7123, I added another line when setting up the environment and changed to cuda111
(since pytroch
stable does not yet support cu112
):
pip install torch==1.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
pip install spacy[transformers, cuda111]
spacy download en_core_web_trf
Afterwards, I am not able to load the transformer model any longer, i.e. running spacy download en_core_web_trf
yields the following error:
OSError: [WinError 127] The specified procedure could not be found. Error loading "C:\Users\...\Desktop\L09_Desktop\stratTransf\.venv\lib\site-packages\torch\lib\cublas64_11.dll" or one of its dependencies.
However,
from thinc.api import set_gpu_allocator, require_gpu
set_gpu_allocator('pytorch')
require_gpu(0)
now returns True
… I am pretty much clueless. 😆
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (10 by maintainers)
Top Results From Across the Web
Still get this error--module 'torch._C' has no attribute ... - GitHub
the main error is "AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'". I tried to fix this problems by refering ...
Read more >'torch._c' has no attribute '_cuda_setdevice' - You.com - You.com
I have been following your direction to run model with Cityscape datasets and faced with "AttributeError: module 'torch.C' has no attribute 'cuda_setDevice'".
Read more >AttributeError: module 'torch' has no attribute 'device'
I just checked that, it's strange it's 0.1.12_1. Yesterday I installed Pytorch with "conda install pytorch torchvision -c pytorch". Shouldn't ...
Read more >module 'torch.cuda' has no attribute '_UntypedStorage'
With the more extensive dataset, I receive the AttributeError in the subject header and RuntimeError: Pin memory threat exited unexpectedly ...
Read more >CuPy Documentation - Read the Docs
CuPy is a NumPy/SciPy-compatible array library for GPU-accelerated computing with Python. CuPy acts as a drop-in.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, so I was finally able to fix it, thanks for all your help! Downgrading to CUDA 11.1 eventually did the trick. For all coming after me, this was the order of installations:
I believe the
cudnn
error was mainly due to me trying to installcupy
from source instead of using thecupy-cuda111
wheel. (Note that thetorch
install step is crucial sincespacy[transformers]
does only load the CPU-only version oftorch
as far as I am concerned)This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.