恒美微站
首页
关于我们
建站服务
主题模板
案例展示
资讯中心
联系我们
AMD 7800xt + WSL2 + ROCm7.2.1 配置AI开发环境
首页
资讯中心
/
AMD 7800xt + WSL2 + ROCm7.2.1 配置AI开发环境
AMD 7800xt + WSL2 + ROCm7.2.1 配置AI开发环境
发布时间:2026/10/18 23:47:55
WSL2 Ubuntu 22.04 ROCm 7.2.1 Conda AI 开发环境配置环境Windows 11 WSL2 AMD Radeon RX 7800 XTAdrenalin 26.2.2 ROCm 7.2.1 PyTorch 2.9.1前置条件项目要求Windows 版本Windows 11WSL2 必需AMD 显卡驱动Adrenalin Edition 26.2.2WSL2已启用发行版Ubuntu 22.04 LTS第1步安装 Ubuntu 22.04 WSL在Windows PowerShell / Terminal中执行wsl--install-d Ubuntu-22.04安装完成后设置用户名和密码然后进入 WSLwsl-d Ubuntu-22.04第2步配置 apt 清华镜像源# 备份原配置sudocp/etc/apt/sources.list /etc/apt/sources.list.bak.$(date%Y%m%d)# 写入清华镜像源sudotee/etc/apt/sources.listEOF deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse EOFsudoaptupdate第3步安装基础依赖sudoaptinstall-y\build-essential\cmake\git\wget\curl\gnupg2\software-properties-common\libjpeg-dev\python3-dev\python3-pip\pkg-config\libnuma-dev\libdrm-dev\aria2第4步添加 ROCm 7.2.1 仓库# 添加 AMD GPG 密钥wget-qO- https://repo.radeon.com/rocm/rocm.gpg.key|sudoapt-keyadd-# 添加 ROCm 7.2.1 仓库echodeb [archamd64] https://repo.radeon.com/rocm/apt/7.2.1 jammy main|sudotee/etc/apt/sources.list.d/rocm.list# 关键设置 apt 优先级强制使用 AMD 官方仓库# 解决 Ubuntu universe 中旧版 ROCm 5.0.0 包冲突sudotee/etc/apt/preferences.d/rocm-pin-1001EOF Package: * Pin: origin repo.radeon.com Pin-Priority: 1001 EOFsudoaptupdate第5步安装 ROCm 7.2.1sudoaptinstall-yrocm-dev rocm-libs如果提示依赖冲突如rocm-cmake 5.0.0-1冲突使用显式版本安装sudoaptinstall-y\rocm-cmake0.14.0.70201-81~22.04\rocm-device-libs1.0.0.70201-81~22.04\rocm-utils7.2.1.70201-81~22.04\rocm-dev\rocm-libs第6步安装 librocdxgWSL GPU 支持核心组件安装预编译 deb 包cd/tmp# 下载预编译 deb 包wgethttps://github.com/ROCm/librocdxg/releases/download/v1.1.2/rocdxg-roct_1.1.2_amd64.deb# 安装sudodpkg-irocdxg-roct_1.1.2_amd64.deb# 修复可能的依赖sudoapt--fix-brokeninstall-y第7步配置环境变量将以下内容追加到~/.bashrccat~/.bashrcEOF # ROCm export PATH/opt/rocm/bin:/opt/rocm/hip/bin:$PATH export HSA_ENABLE_DXG_DETECTION1 EOFsource~/.bashrcHSA_ENABLE_DXG_DETECTION1是 WSL2 下 ROCm 识别 GPU 的必需变量。第8步验证 ROCm 安装rocminfo|grepMarketing Name预期输出能看到你的 AMD GPU 型号如Radeon RX 7800 XTX。注意rocm-smi在 WSL2 下会报错Driver not initialized (amdgpu not found)这是正常现象因为 WSL2 没有 Linux 内核 amdgpu 模块。GPU 状态请在Windows 主机上通过 Adrenalin 软件或任务管理器查看。第9步安装 Miniconda 配置国内镜像# 下载 Miniconda清华镜像wgethttps://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh-Ominiconda.sh# 安装bashminiconda.sh-b-p$HOME/miniconda3# 初始化~/miniconda3/bin/conda initbashsource~/.bashrc配置 Conda 清华镜像conda config--addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main conda config--addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free conda config--addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config--addchannels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch conda config--setshow_channel_urlsyes配置 pip 清华镜像mkdir-p~/.config/pipcat~/.config/pip/pip.confEOF [global] index-url https://pypi.tuna.tsinghua.edu.cn/simple trusted-host pypi.tuna.tsinghua.edu.cn EOF第10步创建 Conda 环境conda create-nmyenvpython3.10-yconda activate myenvPython 3.10 是 PyTorch 2.9.1 官方支持的版本无需更换。第11步安装 PyTorch 2.9.1 for ROCm 7.2重要PyPI (download.pytorch.org/whl/rocm7.2) 上没有 PyTorch 2.9.1只有 2.11.0/2.12.0 nightly。必须从AMD 官方仓库下载预编译 whl。下载 whl 包使用 aria2c 多线程加速mkdir-p~/pytorch_whlcd~/pytorch_whl# 下载 torch 2.9.1约 1.6GBwgethttps://repo.radeon.com/rocm/manylinux/rocm-rel-7.2/torch-2.9.1%2Brocm7.2.0.lw.git7e1940d4-cp310-cp310-linux_x86_64.whl# 下载 torchvision 0.24.0约 2.9MBwgethttps://repo.radeon.com/rocm/manylinux/rocm-rel-7.2/torchvision-0.24.0%2Brocm7.2.0.gitb919bd0c-cp310-cp310-linux_x86_64.whl# 下载 torchaudio 2.9.0约 487KBwgethttps://repo.radeon.com/rocm/manylinux/rocm-rel-7.2/torchaudio-2.9.0%2Brocm7.2.0.gite3c6ee2b-cp310-cp310-linux_x86_64.whl# 下载 tritonPyTorch 需要约 287MBwgethttps://repo.radeon.com/rocm/manylinux/rocm-rel-7.2/triton-3.5.1%2Brocm7.2.0.gita272dfa8-cp310-cp310-linux_x86_64.whl本地安装cd~/pytorch_whl pipinstall./*.whl版本对应关系AMD 官方仓库包版本说明torch2.9.1核心框架torchvision0.24.0图像处理torchaudio2.9.0音频处理triton3.5.1PyTorch 编译优化必需第12步验证 PyTorch GPUpython-c import torch print(fPyTorch版本: {torch.__version__}) print(fROCm/HIP版本: {torch.version.hip}) print(fGPU可用: {torch.cuda.is_available()}) print(fGPU数量: {torch.cuda.device_count()}) if torch.cuda.is_available(): print(fGPU名称: {torch.cuda.get_device_name(0)}) x torch.rand(1000, 1000).cuda() y torch.rand(1000, 1000).cuda() z x y print(GPU 矩阵乘法测试通过) 预期输出PyTorch版本: 2.9.1rocm7.2.0.lw.git7e1940d4 ROCm/HIP版本: 7.2.xxxx GPU可用: True GPU数量: 1 GPU名称: AMD Radeon RX 7800 XT GPU 矩阵乘法测试通过第13步安装常用 AI 开发包可选pipinstallnumpy pandas matplotlib scikit-learn\transformers accelerate huggingface-hub safetensors\pillow opencv-python sentencepiece protobuf附录 AWSL 环境备份与恢复备份导出为 tar# 停止 WSL确保数据一致性wsl--shutdown# 导出为 tar 文件wsl--export Ubuntu-22.04 D:\WSL_Backups\ubuntu2204_rocm_backup.tar恢复从 tar 导入# 导入为新发行版wsl--import Ubuntu-22.04-Restore D:\WSL\Ubuntu-22.04-Restore D:\WSL_Backups\ubuntu2204_rocm_backup.tar# 设置默认用户否则进入是 root# 在 Windows PowerShell / CMD 中执行wsl-d Ubuntu-22.04-Restore-u root# 创建 /etc/wsl.conf如果不存在sudotee/etc/wsl.conf EOF[user]defaultxlrong EOF# 退出 WSLexit# 然后在 Windows 侧重启 WSLwsl--shutdown wsl-d Ubuntu-22.04-RestoreD:\WSL\Ubuntu-22.04-Restore是新虚拟磁盘的存放目录不是工作路径可自定义为任意有空间的目录。快速克隆同一台机器wsl--export Ubuntu-22.04 D:\WSL_Backups\base.tar wsl--import Ubuntu-22.04-Clone D:\WSL\Clone D:\WSL_Backups\base.tar附录 B常见问题速查Q1:apt install rocm-dev报错依赖冲突rocm-cmake 5.0.0-1原因Ubuntu 22.04 universe 仓库自带旧版 ROCm 5.0.0与 AMD 官方 7.2.1 冲突。解决添加 apt 优先级配置见第4步强制使用repo.radeon.com源。Q2:pip install torch2.9.1在 PyPI 上找不到原因PyPI 的whl/rocm7.2索引只有 2.11.0/2.12.0 nightly没有 2.9.1。解决从 AMD 官方仓库下载 whl见第11步。Q3:rocm-smi报错amdgpu not found原因WSL2 是虚拟机没有 Linux amdgpu 内核模块。解决这是正常的用rocminfo和 PyTorch 验证 GPU 即可。参考文档AMD WSL How to GuideROCm/librocdxg GitHubAMD Radeon 兼容性矩阵Adrenalin Edition 26.2.2 版本说明