Windows10系统RTX3080显卡下TensorFlow、Keras运行报错且速度极慢
RTX3080 TensorFlow GPU运行异常解决方案
核心问题原因
- RTX3080属于安培架构显卡,最低要求TensorFlow 2.4及以上版本才能支持GPU运算,你安装的TensorFlow 2.2.1仅适配CUDA10.1,无法识别30系显卡,代码会自动降级到CPU运行,导致耗时极长
- 你使用的
device:XLA_GPU:0设备命名规则已在TensorFlow 2.x版本废弃,会直接触发设备不存在的报错 - 单独安装的Keras 2.3.1在高版本TensorFlow中已经内置,无需额外安装,容易引发依赖冲突
修复步骤
- 卸载现有不兼容依赖
pip uninstall -y tensorflow keras conda remove -y cudnn cudatoolkit
- 安装适配30系显卡的CUDA、cuDNN版本
conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1
- 安装对应版本TensorFlow(2.6版本适配CUDA11.2,且内置Keras无需单独安装)
pip install tensorflow==2.6.0
- 使用适配2.x版本的GPU测试代码
import tensorflow as tf # 打印可用GPU设备,正常会输出RTX3080相关信息 print(tf.config.list_physical_devices('GPU')) # 矩阵乘法测试 a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]) c = tf.linalg.matmul(a, b) print(c)
内容的提问来源于stack exchange,提问作者KFK
相关产品推荐
相关产品推荐

