PyTorch 国内源无法指定 cuda 版本的优雅解决

baba 发布于 2024-04-12 2175 次阅读


前言

在国内不方便代理的机器上,我们一般采用换源加速 PyPI 仓库下载,但是除了安装 PyTorch 的时候(无奈...)

PyTorch 官方的安装方法是通过

Run this Command:

`pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121`

https://pytorch.org/

这就和其中 -i--index-url 参数会覆盖我们设置的镜像源,若是直接删除 -i--index-url 参数,换源就不起作用。

此时我们需要的是 https://download.pytorch.org/whl/ 的反相代理而不是常规的 https://pypi.org/simple 的反相代理

搜索到的反代有 https://mirror.sjtu.edu.cn/pytorch-wheels (上交大) https://mirrors.aliyun.com/pytorch-wheels (阿里云)

`pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

pip3 install torch torchvision torchaudio --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121
`

2024年11月22日更新

配置了--index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu124 但是没有生效是正常的,原因是

pytorch-wheel 4个月没有同步了,https://mirror.sjtu.edu.cn/pytorch-wheels/cu124 重定向到了 https://download.pytorch.org/whl/cu124

2025年3月21日 更新

目前

https://mirror.sjtu.edu.cn/pytorch-wheels (上交大)

https://mirrors.aliyun.com/pytorch-wheels (阿里云)

均无最新版本!!!

可尝试使用南京大学的镜像,用法同上

https://mirror.nju.edu.cn/pytorch/whl

此作者没有提供个人介绍
最后更新于 2025-03-21