AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'

See original GitHub issue

How 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:closed
  • Created 2 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
simonschoecommented, Jul 21, 2021

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:

python -m venv .venv
.\.venv\Scripts\activate
python -m pip install -U pip setuptools wheel
python -m pip install torch==1.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
python -m pip install -U spacy[transformers,cuda111]
python -m spacy download en_core_web_trf

I believe the cudnn error was mainly due to me trying to install cupy from source instead of using the cupy-cuda111 wheel. (Note that the torch install step is crucial since spacy[transformers] does only load the CPU-only version of torch as far as I am concerned)

0reactions
github-actions[bot]commented, Oct 21, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found