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

AssertionError: Torch not compiled with CUDA enabled #30664

Closed
Testin1234 opened this issue Dec 3, 2019 · 96 comments
Closed

AssertionError: Torch not compiled with CUDA enabled #30664

Testin1234 opened this issue Dec 3, 2019 · 96 comments
Labels
module: binaries Anything related to official binaries that we release to users triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@Testin1234
Copy link

Testin1234 commented Dec 3, 2019

I'm trying to do neural style swapping, and for some reason, I keep getting the following errors.
AssertionError: Torch not compiled with CUDA enabled
File "c:\apps\Miniconda3\lib\site-packages\torch\nn\modules\module.py", line 260, in cuda
return self._apply(lambda t: t.cuda(device))
File "c:\apps\Miniconda3\lib\site-packages\torch\nn\modules\module.py", line 187, in _apply
module._apply(fn)
File "c:\apps\Miniconda3\lib\site-packages\torch\nn\modules\module.py", line 187, in _apply
module._apply(fn)
File "c:\apps\Miniconda3\lib\site-packages\torch\nn\modules\module.py", line 193, in _apply
param.data = fn(param.data)
File "c:\apps\Miniconda3\lib\site-packages\torch\nn\modules\module.py", line 260, in
return self.apply(lambda t: t.cuda(device))
File "c:\apps\Miniconda3\lib\site-packages\torch\cuda_init
.py", line 161, in _lazy_init
check_driver()
File "c:\apps\Miniconda3\lib\site-packages\torch\cuda_init
.py", line 75, in _check_driver
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

I recently reinstalled conda and this has just been completely broken for me.

cc @ezyang

@zou3519
Copy link
Contributor

zou3519 commented Dec 3, 2019

How did you install pytorch? It sounds like you installed pytorch without CUDA support. https://pytorch.org/ has instructions for how to install pytorch with cuda support.

@zou3519 zou3519 added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: binaries Anything related to official binaries that we release to users labels Dec 4, 2019
@Gailsunset
Copy link

Shalom!

I am new to pytorch, and already installed pytorch in my Mac laptop.

trying to run the wsi_bert.py code, and get this error.
"""
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
"""
Please help.
Thx a lot!

@swj0418
Copy link

swj0418 commented Jan 1, 2020

Try this.
conda install -c pytorch torchvision cudatoolkit=10.1 pytorch
Depending on what cuda version you have.

@ezyang
Copy link
Contributor

ezyang commented Jan 2, 2020

Note that unless you know otherwise, your Mac probably doesn't have an NVIDIA GPU on it.

For further support questions related to installation, please follow up on the forums https://discuss.pytorch.org/

@ezyang ezyang closed this as completed Jan 2, 2020
ulrikah added a commit to ulrikah/TDT4265-StarterCode that referenced this issue Mar 21, 2020
Some CUDA functions seem to result in AssertionError for MacOS users that haven't installed Pytorch with CUDA support. More info: pytorch/pytorch#30664
@AchinthyaBhat
Copy link

I don't know where to raise an issue, but this continues to be a problem on Windows when Pytorch is installed without CUDA support even though it has been recently fixed for MacOS. Can someone help me?

@dzhoshkun
Copy link

Experiencing this problem on Windows as well.

@jpryne
Copy link

jpryne commented Apr 3, 2020

I tried re-installing pytorch as per @swj0418 above,
conda install -c pytorch torchvision cudatoolkit=10.1 pytorch
yet to no avail. Running this from with a Jupyter notebook under Anaconda on Windows 10 with an Nvidia1060 6GB & Intel i7.

@YuanYingtao
Copy link

Experiencing this problem on Windows as well.

I have the same question too. I think i need to modify the code, but i don't what to do.

@benzhi
Copy link

benzhi commented Jun 12, 2020

Same here, installing as described on pytorch site (conda install pytorch torchvision cudatoolkit=10.1 -c pytorch) yields (during installation):

  cudatoolkit        pkgs/main/win-64::cudatoolkit-10.1.243-h74a9793_0
  pytorch            pytorch/win-64::pytorch-1.5.0-py3.7_cpu_0
  torchvision        pytorch/win-64::torchvision-0.6.0-py37_cpu

Where there's clearly cpu already in the package names, which can be confirmed after installation:

pytorch                   1.5.0               py3.7_cpu_0  [cpuonly]  pytorch

p.s. CUDA 10.1 was completely installed before creating the env and installing pytorch

@kimcdata
Copy link

kimcdata commented Jun 16, 2020

I had the same problem (Win10, CUDA installed prior to making conda env)

The option to install using pip worked for me (inside a miniconda env, python 3.7.7)

From the pytorch website:

pip install torch===1.5.0 torchvision===0.6.0 -f https://download.pytorch.org/whl/torch_stable.html

@yick2232
Copy link

I don't know where to raise an issue, but this continues to be a problem on Windows when Pytorch is installed without CUDA support even though it has been recently fixed for MacOS. Can someone help me?

Change code device = torch.device("cpu") to device = torch.device("cuda")

@sathvikn
Copy link

Shalom!

I am new to pytorch, and already installed pytorch in my Mac laptop.

trying to run the wsi_bert.py code, and get this error.
"""
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
"""
Please help.
Thx a lot!

@Gailsunset I was running the same code from wsi_bert.py, and although conda install -c pytorch torchvision cudatoolkit=10.1 pytorch from the reply right after didn't end up working out, just conda install cudatoolkit led me to get past that issue.

@tejasvi
Copy link

tejasvi commented Jul 31, 2020

In my case, I had cpuonly package installed which needs to be removed.

@bnymnsntrk
Copy link

In my case, I had cpuonly package installed which needs to be removed.

how did you delete it?

@amgaweda
Copy link

amgaweda commented Sep 17, 2020

I had the same problem (Win10, CUDA installed prior to making conda env)

The option to install using pip worked for me (inside a miniconda env, python 3.7.7)

From the pytorch website:

pip install torch===1.5.0 torchvision===0.6.0 -f https://download.pytorch.org/whl/torch_stable.html

Just confirming this approach worked for me; Windows 10, using Anaconda's CMD Terminal; CUDA v10

@zm-m
Copy link

zm-m commented Nov 5, 2020

I don't know where to raise an issue, but this continues to be a problem on Windows when Pytorch is installed without CUDA support even though it has been recently fixed for MacOS. Can someone help me?

I'm having the same problem on an Ubuntu VM. No CUDA installed (because no GPU), and I am 100% sure it is the cpu-only version. I know because I have uninstalled and reinstalled many times (each time making sure all previous files are removed), trying pytorch 1.4, 1.5, and 1.6, all with corresponding torchvision versions. I've also tried editing the code to specify the whole torch.device="cpu" thing but the issue persists. I currently have torch=1.5 with cpu only and torchvision 0.6 installed and would be really grateful to anyone with suggestions.

@OGmenas
Copy link

OGmenas commented Dec 15, 2020

Try this.
conda install -c pytorch torchvision cudatoolkit=10.1 pytorch
Depending on what cuda version you have.

i have a rtx 2060 and it worked fine with this toolkit.

@Malithi-gif
Copy link

@Testin1234 are you resolve this one?

@Mwni
Copy link

Mwni commented Jan 10, 2021

If you've ever ran pip install torch without the -f https://download.pytorch.org/whl/torch_stable.html argument, chances are, you have the corrupt cpu only version in your pip cache. whatever reinstall you do, doesn't matter because pip will just pull the same bad version from cache. to solve:

pip uninstall torch
pip cache purge
pip install torch -f https://download.pytorch.org/whl/torch_stable.html

@BotMichael
Copy link

I had the same problem (Win10, CUDA installed prior to making conda env)

The option to install using pip worked for me (inside a miniconda env, python 3.7.7)

From the pytorch website:

pip install torch===1.5.0 torchvision===0.6.0 -f https://download.pytorch.org/whl/torch_stable.html

Thank you so much!!!!!!!!

@lingxuan0520
Copy link

I encountered the same problem, I think you should uninstall the cpu version of torch, and change it to the gpu version to solve it

@SharonPeled
Copy link

I had the same issue on Linux. I tried almost all the solutions proposed here, but none worked. Finally, I could solve my problem by first uninstalling Torch with pip uninstall torch, and then reinstalling it with Wheel:

pip install torch==1.12.1+cu102 torchvision==0.13.1+cu102 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu102

Then, I got the following, which confirmed that Torch was successfully compiled with CUDA enabled:

>>> import torch
>>> torch.__version__
'1.12.1+cu102'
>>> torch.zeros(1).cuda()
tensor([0.], device='cuda:0')
>>> torch.cuda.is_available()
True

Many thanks for the solution, that's the only solution that worked on my linux machine as well.
Although I'm getting RuntimeError: CUDA error: invalid device function when using nn.parallel.DistributedDataParallel, does anyone else had it? any ideas?

@fengyx8
Copy link

fengyx8 commented Sep 5, 2023 via email

@meetrais
Copy link

meetrais commented Sep 5, 2023

If you've ever ran pip install torch without the -f https://download.pytorch.org/whl/torch_stable.html argument, chances are, you have the corrupt cpu only version in your pip cache. whatever reinstall you do, doesn't matter because pip will just pull the same bad version from cache. to solve:

pip uninstall torch
pip cache purge
pip install torch -f https://download.pytorch.org/whl/torch_stable.html

This worked like a charm, Thank you !!!

@geeker-smallwhite
Copy link

Hi, I have M2 max chip MacOS with 12 CPU, 38 GPU. I am getting this error :“Torch not compiled with CUDA enabled”. May I ask your help please? Thanks

I heve the same issue in same pc

@fengyx8
Copy link

fengyx8 commented Sep 28, 2023 via email

@geeker-smallwhite
Copy link

Hi, I have M2 max chip MacOS with 12 CPU, 38 GPU. I am getting this error :“Torch not compiled with CUDA enabled”. May I ask your help please? Thanks

I heve the same issue in same pc

you can set runtime mode to resolve this issue

@peterhchen
Copy link

peterhchen commented Sep 29, 2023 via email

@maraujo
Copy link

maraujo commented Oct 23, 2023

You need to make sure that your cuda driver (downloaded at https://developer.nvidia.com/cuda-downloads) matches with the pytorch-cuda library version that you install with python.

For example, the current snippet at the official pytorch site is:
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

So, you need to have the 11.8 version of cuda downloaded from nvidia official website and installed.

@fengyx8
Copy link

fengyx8 commented Oct 23, 2023 via email

@StantheBrain
Copy link

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

@liwenyi666
Copy link

如果您曾经在pip install torch没有-f https://download.pytorch.org/whl/torch_stable.html参数的情况下运行过,那么您的 pip 缓存中很可能有损坏的仅 cpu 版本。无论你做什么重新安装,都没关系,因为 pip 只会从缓存中提取相同的错误版本。解决:

pip uninstall torch
pip cache purge
pip install torch -f https://download.pytorch.org/whl/torch_stable.html

thank you!!!!!

@fengyx8
Copy link

fengyx8 commented Nov 26, 2023 via email

@ATkouti
Copy link

ATkouti commented Dec 21, 2023

pip uninstall torch pip cache purge pip install torch -f https://download.pytorch.org/whl/torch_stable.html

I had the same problem and the issue is fixed with the above solution. Just run each command separately and it should solve your problem if it is the same as my problem. 👍 😃 Thank you @Mwni

thank you so much it works for me :)

@fengyx8
Copy link

fengyx8 commented Dec 21, 2023 via email

@roopeshsn
Copy link

I am getting the same error. My laptop doesn't have a dedicated Nvidia GPU. How can I resolve this? Is there any solution?

@fengyx8
Copy link

fengyx8 commented Feb 4, 2024 via email

@alpaca-farm
Copy link

If you've ever ran pip install torch without the -f https://download.pytorch.org/whl/torch_stable.html argument, chances are, you have the corrupt cpu only version in your pip cache. whatever reinstall you do, doesn't matter because pip will just pull the same bad version from cache. to solve:

pip uninstall torch
pip cache purge
pip install torch -f https://download.pytorch.org/whl/torch_stable.html

This one worked for me too! Thanks

@covalspace
Copy link

If you've ever ran pip install torch without the -f https://download.pytorch.org/whl/torch_stable.html argument, chances are, you have the corrupt cpu only version in your pip cache. whatever reinstall you do, doesn't matter because pip will just pull the same bad version from cache. to solve:

pip uninstall torch
pip cache purge
pip install torch -f https://download.pytorch.org/whl/torch_stable.html

this didn't work on my mac and now my torch is broken saying module not found but already satisfied so thanks a lot for this

@fengyx8
Copy link

fengyx8 commented Apr 12, 2024 via email

@1458763783
Copy link

How did you install pytorch? It sounds like you installed pytorch without CUDA support. https://pytorch.org/ has instructions for how to install pytorch with cuda support.

I also encountered the same error, this method is worked..

@fengyx8
Copy link

fengyx8 commented Jun 9, 2024 via email

@StinkyKittyKiss
Copy link

If you've ever ran pip install torch without the -f https://download.pytorch.org/whl/torch_stable.html argument, chances are, you have the corrupt cpu only version in your pip cache. whatever reinstall you do, doesn't matter because pip will just pull the same bad version from cache. to solve:

pip uninstall torch
pip cache purge
pip install torch -f https://download.pytorch.org/whl/torch_stable.html

This fixed my problem when encountering this issue while using DeepLabCut (DLC).

@gtimk6
Copy link

gtimk6 commented Jul 2, 2024

I use in conda env., reinstall it by commands and solved it.
e.g: conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
pytorch-cuda depends you version.

@Abbsalehi
Copy link

device = torch.device("cuda")

This happens once you install pytorch using conda. Instead, install it using:
pip install torch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: binaries Anything related to official binaries that we release to users triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests