安装了torch发现是cpu版本怎么办?

 安装了torch发现是cpu版本怎么办?_第1张图片

1卸载旧版本(CPU 版)


pip uninstall torch torchvision torchaudio -y

 

 直接在 base 环境操作的优点

  • 省事:无需额外创建环境,适合快速测试或短期项目。

  • 全局可用:安装的包对所有项目可见(适合常用工具如 numpypandas

 

 可以省略以下步骤(防止污染环境)

创建并激活环境
conda create -n pytorch_gpu python=3.10 -y
conda activate pytorch_gpu

 

 2使用国内镜像源加速下载

 pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 -i https://pypi.tuna.tsinghua.edu.cn/simple --extra-index-url https://download.pytorch.org/whl/cu121

 

3验证安装 

 import torch
print("CUDA 可用:", torch.cuda.is_available())  # 应输出 True
print("PyTorch CUDA 版本:", torch.version.cuda)  # 应显示 12.1
print("GPU 设备名称:", torch.cuda.get_device_name(0))  # 打印显卡型号

安装了torch发现是cpu版本怎么办?_第2张图片

你可能感兴趣的:(安装了torch发现是cpu版本怎么办?)