使用国内镜像源加速安装PyTorch

2024-05-10

使用默认 conda 源或者 pip 源安装 PyTorch 时,经常会下载很慢,这里我是用上海交大的 https://mirror.sjtu.edu.cn/docs/pytorch-wheels 源来进行加速。

pytorch-wheels 是 PyTorch pip 源的镜像。直接将 https://pytorch.org/get-started/locally/ 中的 https://download.pytorch.org/whl 替换为 https://mirror.sjtu.edu.cn/pytorch-wheels 即可。

使用前最好先把 pip 镜像源也设置一下

pip config set global.index-url https://mirrors.cernet.edu.cn/pypi/web/simple

这里提供几个版本的 PyTorch 对应的安装命令

# 2.3.0+cu118
pip install torch==2.3.0+cu118 torchvision==0.18.0+cu118 torchaudio==2.3.0+cu118 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html
# 2.3.0+cu121
pip install torch==2.3.0+cu121 torchvision==0.18.0+cu121 torchaudio==2.3.0+cu121 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html

# 2.2.0+cu118
pip install torch==2.2.0+cu118 torchvision==0.17.0+cu118 torchaudio==2.2.0+cu118 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html
# 2.2.0+cu121
pip install torch==2.2.0+cu121 torchvision==0.17.0+cu121 torchaudio==2.2.0+cu121 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html

# 2.1.0+cu118
pip install torch==2.1.0+cu118 torchvision==0.16.0+cu118 torchaudio==2.1.0+cu118 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html
# 2.1.0+cu121
pip install torch==2.1.0+cu121 torchvision==0.16.0+cu121 torchaudio==2.1.0+cu121 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html

# 2.0.0+cu118
pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 torchaudio==2.0.1+cu118 -f https://mirror.sjtu.edu.cn/pytorch-wheels/torch_stable.html