为什么TensorFlow可以看到Keras看不到我的GPU?

时间:2018-12-09 21:02:06

标签: python tensorflow keras gpu

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给出:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

nvidia-smi也可以。

list_local_devices()提供:

  

[名称:“ / device:CPU:0” device_type:“ CPU” memory_limit:268435456   化身{}化身:459307207819325532,名称:   “ / device:XLA_GPU:0” device_type:“ XLA_GPU” memory_limit:17179869184   位置{}化身:9054555249843627113 physical_device_desc:   “设备:XLA_GPU设备”,名称:“ /设备:XLA_CPU:0” device_type:   “ XLA_CPU” memory_limit:17179869184位置{}化身:   5902450771458744885 physical_device_desc:“设备:XLA_CPU设备”]

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 返回:

  

设备映射:   / job:本地主机/副本:0 /任务:0 /设备:XLA_GPU:0->设备:XLA_GPU设备   / job:本地主机/副本:0 /任务:0 /设备:XLA_CPU:0->设备:XLA_CPU设备

为什么Keras和PyTorch无法在我的GPU上运行? (RTX 2070)

2 个答案:

答案 0 :(得分:0)

我很难找到问题。实际上,运行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*

答案 1 :(得分:0)

我最近遇到了这个问题。事实证明,pip安装的必需软件包(例如keras)不包含与XLA相关的标志。如果我更改为必需的软件包的完整miniconda或anaconda安装,则可以运行我的代码。就我而言,我正在运行facebook AI代码。

运行中出现问题的早期指示:

nvidia-smi

,发现您的深网没有使用千兆字节的数据,而是在使用千字节。这样,即使没有警告(有时也很难在日志中找到警告),您仍然知道问题出在如何编译必需的软件。您之所以知道这一点,是因为GPU的设备类型不匹配,因此默认为CPU。然后将代码卸载到CPU上。

就我而言,我使用miniconda安装了tensorflow-gpu,ipython,imutils,imgaug和其他一些软件包。如果发现conda中缺少必需的软件包,请使用:

conda -c conda-forge <package-name>

拾起丢失的物品,例如imutils和imgaug。