如何在不重新启动机器的情况下修复 torch.cuda.is_available() False 问题?

Mon*_*lal 2 python ubuntu pytorch

我有:

$ python
Python 3.7.6 (default, Jan  8 2020, 19:59:22) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
False
>>> quit()

$ nvidia-smi
Wed Oct 14 21:28:50 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 450.51.06    Driver Version: 450.51.06    CUDA Version: 11.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce RTX 2070    Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   47C    P8     9W /  N/A |   1257MiB /  7982MiB |     11%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1424      G   /usr/lib/xorg/Xorg                823MiB |
|    0   N/A  N/A      1767      G   /usr/bin/gnome-shell              407MiB |
|    0   N/A  N/A      6420      G   /usr/lib/firefox/firefox            2MiB |
|    0   N/A  N/A      6949      G   /usr/lib/firefox/firefox            2MiB |
|    0   N/A  N/A      7447      G   /usr/lib/firefox/firefox            2MiB |
|    0   N/A  N/A      8888      G   /usr/lib/firefox/firefox            2MiB |
|    0   N/A  N/A      9218      G   /usr/lib/firefox/firefox            2MiB |
|    0   N/A  N/A      9282      G   /usr/lib/firefox/firefox            2MiB |
|    0   N/A  N/A     65854      G   /usr/lib/firefox/firefox            2MiB |
|    0   N/A  N/A     70801      G   /usr/lib/firefox/firefox            2MiB |
+-----------------------------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以解决这个问题而无需重新启动我的机器?

我有 Ubuntu 20.04 和 PyTorch 1.6.0

重新启动机器后,我得到的是: 在此输入图像描述

Ath*_*bey 6

这种情况经常发生在 ubuntu 用户身上(我不太确定其他发行版)。我注意到这种行为,尤其是当我让机器处于睡眠状态时。无需重新启动,您就可以运行此线程中提到的以下命令

sudo rmmod nvidia_uvm
sudo modprobe nvidia_uvm