conda临时换源 & conda安装pytorch

conda临时换源安装pytorch

参照pytorch官方教程在conda中安装时,发现下载速度很慢,因为官网提供的命令使用-c参数指定了pytorch的源来安装:

conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch

如果添加了中科大的channel,并删除上面的-c pytorch,安装pytorch时会报错:
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
(猜测:无法在中科大的channel中找到pytorch)

为提高速度,可以使用清华源:

  • 参数-c临时使用,这样其他包会使用全局设定的其他源,仅pytorch使用清华源:
conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  • 也可以直接添加到channels:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

# 删除指定channels
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# 查看所有channels
conda config --show channels
# 换回conda的默认源
conda config --remove-key channels

关于conda

conda可以构建多个虚拟环境,这些环境与本地环境分开。

比如,创建一个使用python3.7的env,那么无论是否activate该env,本地环境如cmd都不会受到任何影响。该环境只在使用Anaconda进入的命令行中生效。

因此如果使用conda,就不需要像网上一些教程,额外在本地纠结安装什么版本的CUDA和cuDNN了,因为最终使用的版本都是conda中安装的。

并且,无需使用conda安装cuDNN,conda中使用自己的cuDNN

Conda did not install cudnn for pytorch? - PyTorch Forums

Hi,
I use the following command to install pytorch:
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch

then I use the command conda list to list the packages that have been installed with pytorch, I found the cudatoolkit but I did not found the cudnn, why? the pytorch do not need the cudnn ?
when I install tensorflow gpu version using the conda install command , the cudnn and cudatoolkit are both installed. Why pytorch only need cudatoolkit?

pytorch comes with it’s own cudnn, so you don’t have to install it specifically.

# Use this to check if pytorch is using cudnn
torch.backends.cudnn.enabled
文章作者: Yihan
文章链接: https://crushonu.top/conda临时换源-conda安装pytorch-10/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Yihan's Blog