TensorFlow GPU安装指南
创始人
2025-05-28 17:10:15

测试你当前的环境是否已经支持:

import tensorflow as tfif tf.test.gpu_device_name():print(f"Default GPU device: {tf.test.gpu_device_name()}")
else:print("GPU device not found. Please check your settings.")

如果正确配置了GPU,就有会有:

Default GPU device: /device:GPU:0

使用 pip 安装 TensorFlow

注意:TensorFlow 2.10 是最后一个 TensorFlow 版本。 原生 Windows 上支持的 GPU。 从TensorFlow 2.11 开始,您需要在 WSL2 中安装 TensorFlow, 或者安装 TensorFlow-cpu

默认已经按照好了: Miniconda

创建新的conda 环境

conda create --name tfGPU python=3.9

GPU 安装

先要安装 NVIDIA GPU 驱动,

然后用 conda 安装 CUDA, cuDNN

conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0

安装TensorFlow

先升级 最新的 pip

pip install --upgrade pip

TensorFlow 2.10 是最后一个 TensorFlow 版本。 原生 Windows 上支持的 GPU。
所以安装2.11以前的版本


pip install "tensorflow<2.11" 

验证TensorFlow CPU的安装

python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

输出 tensor 张量的数据,就是安装好了。

在这里插入图片描述

验证TensorFlow GPU的安装

python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

在这里插入图片描述

在这里插入图片描述

相关内容

热门资讯

牛市早报|国常会:研究推进银发... 【市场数据】至24日收盘,上证综指涨0.87%,报4117.41点;科创50指数跌0.34%,报14...
算力订单22亿、定增10亿,郭... 文丨郭小兴编辑丨杜海来源丨新商悟(本文约为900字)2月下旬,平治信息拟定增募资不超过10亿元押注国...
盘前必读丨国常会重磅定调银发经... 【财经日历】央行在香港发行500亿元人民币央票新股申购:固德电材►►国务院总理李强2月24日主持召开...
当人形机器人闹完春晚:马年具身... 马年春晚有个细节耐人寻味,开场不到半小时,三个节目里具身智能机器人频繁出镜。2025年的机器人还像颤...
6年前2459元买入,现在涨到... 相机涨价实在是太离谱了,都快和黄金一样了!据钱江晚报,近日,天气逐渐转暖,不少人纷纷出门赏花、遛娃、...