AutoDL中tensorflow【未找到GPU / 可用的GPU数量:0】

一、问题检查

1. 在终端使用命令nvidia-smi查看设备中是否有GPU:

结果显示系统识别到了一块 NVIDIA GeForce RTX 3090 GPU。

2. 用下述代码中的任一个测试能否检测到GPU:

(1)查看tensorflow的版本和可用的GPU数量

         输出结果显示tensorflow的版本为2.10.0,

         虽然系统中有GPU,但并没有被识别,因此可用的GPU数量为0

import tensorflow as tf

print("TensorFlow 版本:", tf.__version__)
print("可用的 GPU 数量:", len(tf.config.experimental.list_physical_devices('GPU')))

【输出结果】
TensorFlow 版本: 2.10.0
可用的 GPU 数量: 0

(2)查看可用的GPU数量及能否使用CPU

         输出结果显示第一个列表为0,说明没有可用的GPU,但能够使用CPU

import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
print(gpus, cpus)

【输出结果】
[] [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]

二、问题解决

解决方法大致概述为:

tensorflow最好安装在2.10.0版本,并与cuda和cudnn的版本匹配

1. 在终端使用命令nvcc --version查看cuda的版本为11.3

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0
(shap) root@autodl-container-07ff4facf2-59e98f64:~# 

2. 安装8.2.1版本的cudnn

conda install cudnn=8.2.1

3. 测试能否检测到GPU

import tensorflow as tf

print("TensorFlow 版本:", tf.__version__)
print("可用的 GPU 数量:", len(tf.config.experimental.list_physical_devices('GPU')))

【输出结果】
TensorFlow 版本: 2.10.0
可用的 GPU 数量: 1

4. 主要的解决方法就是使各种库的版本匹配,我用的版本如下:

python:3.8
tensorflow:2.10.0
cuda:11.3
cudnn:8.2.1

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值