在WSL中通过Conda配置TensorFlow GPU加速遇阻求助
在WSL(Windows 11)中通过Conda配置TensorFlow GPU加速的问题
无Conda的WSL操作尝试
- 安装CUDA,执行
nvcc -V显示版本为11.5.r11.5 - 创建并激活虚拟环境
- 安装TensorFlow
- 运行测试代码后检测不到GPU(设备实际配备GPU),测试代码如下:
import tensorflow as tf from tensorflow.python.platform import build_info as build # 检查TensorFlow能否访问GPU physical_devices = tf.config.list_physical_devices('GPU') print("Num GPUs Available: ", len(physical_devices)) if physical_devices: print("TensorFlow GPU details:") for gpu in physical_devices: print(gpu) else: print("No GPUs detected by TensorFlow.") print(tf.test.is_built_with_cuda()) print(build.build_info['cuda_version'])
基于Conda安装CUDA和cuDNN的WSL操作尝试
参考Anaconda Linux安装文档及cuDNN Conda安装指南,执行以下步骤:
curl -O https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.shbash ~/Downloads/Anaconda3-2024.02-1-Linux-x86_64.sh- 创建conda环境:
conda create --name cudnn_env python=3.8 - 激活环境:
conda activate cudnn_env - 安装cuDNN:
conda install -c conda-forge cudnn - 运行测试代码
python TfGpuTest.py,输出如下:
2024-05-27 17:23:19.552732: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. Num GPUs Available: 0 No GPUs detected by TensorFlow. False Traceback (most recent call last): File "TfGpuTest.py", line 18, in <module> print(build.build_info['cuda_version']) KeyError: 'cuda_version'
补充尝试
原环境Python3.8对应的TensorFlow版本较旧,于是创建Python3.12的新环境,执行conda install tensorflow时出现版本兼容错误,无匹配版本(未找到TensorFlow 2.15);降级至Python3.11.9后成功安装TensorFlow 2.12.0,但GPU检测问题仍未解决。
内容的提问来源于stack exchange,提问作者plutownium
相关产品推荐
相关产品推荐

