Possible causes and solutions of RuntimeError: torch.cuda.FloatTensor is not enabled.

created at 11-03-2021 views: 11

When using pytorch, an error 

RuntimeError: torch.cuda.FloatTensor is not enabled. 

is reported. The specific information is as follows:

Possible cause 1

This error may occur because your computer does not have an Invida graphics card, does not support GPU acceleration, and you are using a GPU in your code. The solution is to change the gpu version of the code to the cpu version, that is, change all the places where .cuda() appears in the code to .cpu().

Possible cause 2

There is another reason, which happens to be the reverse of the above. Of course, it's not because the computer doesn't have a cpu, but the pytorch you downloaded and installed is the cpu version. And the reason for this error is exactly the same.

The solution is to uninstall and reinstall the installed pytorch. Since I downloaded the whl file and installed it with pip when I installed it, the uninstallation is also relatively simple, just a one-line command pip3 uninstall torch, a confirmation message will appear after running, remember to check whether the version to be uninstalled is correct (here I made a mistake again at the beginning, because I used conda to manage two virtual environments. At the beginning, I didn’t pay attention to the confirmation message. I uninstalled my 1.6.0 version of torch. After I uninstalled it, it didn’t seem to be right. I found that I didn't switch the running environment of the terminal, so I still have to be careful).

After the uninstallation is complete, execute the command conda list, you can see that there is no torch package, which indicates that the uninstallation was successful. Then re-download and install torch. The download link of each version of torch contains many versions. Pay attention to careful identification. Don't download the torch starting with cpu, which is the cpu version of torch. For the `torch0.4.0` I want to download, its name is cu90/torch-0.4.0-cp36-cp36m-linux_x86_64.whl.

After downloading the whl file, open the terminal in this directory and execute the command pip3 install torch-0.4.0-cp36-cp36m-linux_x86_64.whl to install it.

created at:11-03-2021
edited at: 11-03-2021: