You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

搭载AMD Radeon(TM)显卡的联想笔记本TensorFlow安装报错解决

AMD Radeon显卡安装TensorFlow的正确步骤

报错原因

你遇到的IndexError: list index out of range是因为原生TensorFlow不支持AMD Radeon显卡,调用tf.config.list_physical_devices("GPU")返回空列表,无法通过索引0获取设备。

针对Windows系统(多数笔记本场景)

1. 清理现有TensorFlow(如果已安装)

在PyCharm的终端中执行:

pip uninstall tensorflow -y

2. 安装TensorFlow-DirectML插件

这是微软和AMD合作的方案,专门支持Windows上的AMD GPU加速:

pip install tensorflow-directml-plugin

注意:Python版本需符合插件要求(当前支持3.8~3.11版本)

3. 验证安装的测试代码

替换你原来的代码,避免空列表索引错误:

import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
import tensorflow as tf

# 检测GPU设备
physical_devices = tf.config.list_physical_devices('GPU')
if physical_devices:
    print(f"已识别AMD GPU设备: {physical_devices}")
    tf.config.experimental.set_memory_growth(physical_devices[0], True)
else:
    print("未识别到GPU,将使用CPU运行")

# 简单验证计算
print(f"TensorFlow版本: {tf.__version__}")
print("测试计算结果:", tf.reduce_sum(tf.random.normal([1000, 1000])).numpy())

针对Linux系统

如果你的笔记本使用Linux系统,需通过ROCm框架实现AMD GPU加速:

  1. 先安装对应显卡型号的ROCm驱动及依赖(要求显卡为GCN 3架构及以上)
  2. 安装适配ROCm的TensorFlow:
pip install tensorflow-rocm
  1. 用上述测试代码验证GPU是否被识别

PyCharm环境配置提示

在PyCharm中,确保当前项目使用的虚拟环境已安装上述TensorFlow版本:

  • 打开File > Settings > Project: [你的项目名] > Python Interpreter
  • 查看已安装包列表,确认tensorflow-directml-plugin或tensorflow-rocm存在,若没有可直接在该界面搜索安装

内容的提问来源于stack exchange,提问作者Josue Oliva

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 19:16:01