Google Colab:torch cuda为true但没有可用的CUDA GPU。

4
我使用Google Colab来训练模型,但是像图片所示,当我输入'torch.cuda.is_available()'时,输出为'true'。然后我运行代码,但出现以下错误:RuntimeError: No CUDA GPUs are available.
2个回答

1

我猜我已经找到了一个可以修复我的问题的解决方案。我曾经遇到过同样的错误。 当你运行这个时:

import tensorflow as tf
tf.test.gpu_device_name()

它会给你GPU编号,在我的情况下是

/device:GPU:0

我意识到我传递的代码是:

parser.add_argument('--gpu', type=str, default="1", help='choose GPU')

所以我用 Colab 给我的 GPU 数量替换了 "1",改成了 "0",然后它就可以工作了。

希望这也能解决你的问题。


我必须在不同的环境之间切换,直到tf.test.gpu_device_name()返回一个设备名称。 - undefined

1
尝试安装您想要使用的cudatoolkit版本 "conda install pytorch torchvision cudatoolkit=10.1 -c pytorch"

/bin/bash: 第一行:conda:找不到命令 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接