为什么Keras看不到我的GPU而TensorFlow能看到?

2024-10-02 02:44:12 发布

您现在位置:Python中文网/ 问答频道 /正文

answer from SO之后,我运行了:

# confirm TensorFlow sees the GPU
from tensorflow.python.client import device_lib
assert 'GPU' in str(device_lib.list_local_devices())

# confirm Keras sees the GPU
from keras import backend
assert len(backend.tensorflow_backend._get_available_gpus()) > 0

# confirm PyTorch sees the GPU
from torch import cuda
assert cuda.is_available()
assert cuda.device_count() > 0
print(cuda.get_device_name(cuda.current_device()))

第一个测试有效,而其他测试没有。在

运行nvcc --version可以得到:

^{pr2}$

英伟达smi也可以。在

list_local_devices()提供:

[name: "/device:CPU:0" device_type: "CPU" memory_limit: 268435456 locality { } incarnation: 459307207819325532, name: "/device:XLA_GPU:0" device_type: "XLA_GPU" memory_limit: 17179869184 locality { } incarnation: 9054555249843627113 physical_device_desc: "device: XLA_GPU device", name: "/device:XLA_CPU:0" device_type: "XLA_CPU" memory_limit: 17179869184 locality { } incarnation: 5902450771458744885 physical_device_desc: "device: XLA_CPU device"]

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 退货:

Device mapping: /job:localhost/replica:0/task:0/device:XLA_GPU:0 -> device: XLA_GPU device /job:localhost/replica:0/task:0/device:XLA_CPU:0 -> device: XLA_CPU device

为什么Keras和Pythorch不能在我的GPU上运行?(RTX 2070)


Tags: thenamefromimportbackendgpudevicetype
2条回答

我最近遇到了这个问题。结果发现pip安装的必需软件包(比如keras)没有包含与XLA相关的标志。如果我改为一个完整的miniconda或anaconda安装必要的软件包,那么我就可以运行我的代码了。在我的例子中,我运行的是facebook的人工智能代码。在

出现问题的早期指标正在运行:

nvidia-smi

你的deepnet没有使用千兆位的数据,而是使用了千字节。然后,即使没有警告(有时在日志中很难找到警告),问题在于所需软件是如何编译的。你知道这一点是因为GPU在设备类型上没有得到匹配,结果默认为CPU。然后将代码卸载到CPU上。在

在我的例子中,我使用miniconda安装了tensorflowgpu、ipython、imutils、imgaug和其他一些包。如果您发现conda中缺少必需的软件包,请使用:

^{pr2}$

捡起丢失的物品,如imutils和imgauge。在

我很难找到这个问题。实际上,运行CUDA样本给了我很好的见解:

CUDA error at ../../common/inc/helper_cuda.h:1162 code=30(cudaErrorUnknown) "cudaGetDeviceCount(&device_count)"

使用sudo时: MapSMtoCores for SM 7.5 is undefined. Default to use 64 Cores/SM GPU Device 0: "GeForce RTX 2070" with compute capability 7.5

所以问题是我的lib不是每个人都能读的。在

我的错误被修复为:

sudo chmod -R a+r /usr/local/cuda*

相关问题 更多 >

    热门问题