简体   繁体   English

Anaconda 更新的时候总想把我的GPU Pytorch版本换成CPU Pytorch版本

[英]Anaconda always want to replace my GPU Pytorch version to CPU Pytorch version when updating

I have a newly installed Anaconda3 (version 2020.02) environment, and I have installed Pytorch GPU version by the command conda install pytorch torchvision cudatoolkit=10.2 -c pytorch . I have a newly installed Anaconda3 (version 2020.02) environment, and I have installed Pytorch GPU version by the command conda install pytorch torchvision cudatoolkit=10.2 -c pytorch . I have verified that my Pytorch indeed runs fine on GPU.我已经验证我的 Pytorch 确实在 GPU 上运行良好。

However, whenever I update Anaconda by conda update --all , the following messages always shows:但是,每当我通过 conda conda update --all更新 Anaconda 时,总是会显示以下消息:

The following packages will be SUPERSEDED by a higher-priority channel:

  pytorch            pytorch::pytorch-1.5.0-py3.7_cuda102_~ --> pkgs/main::pytorch-1.5.0-cpu_py37h9f948e0_0

In other words, it always want to replace my GPU version Pytorch to CPU version.也就是说,它总想把我的GPU版本Pytorch换成CPU版本。 I have tried that if continue the update, it will install the CPU version Pytorch and my previous Pytorch code on GPU could not run anymore.我已经尝试过,如果继续更新,它将安装 CPU 版本 Pytorch,而我之前在 GPU 上的 Pytorch 代码无法运行。 I have also tried the command conda update --all --no-channel-priority but the message still shows.我也尝试了命令conda update --all --no-channel-priority但消息仍然显示。

To my knowledge I have never modified Anaconda channels or add custom channels.据我所知,我从未修改过 Anaconda 通道或添加自定义通道。 How can I get rid of this message?我怎样才能摆脱这个消息?

It's happening because, by default, conda prefers packages from a higher priority channel over any version from a lower priority channel.这是因为默认情况下,conda 更喜欢来自较高优先级通道的包,而不是来自较低优先级通道的任何版本。 -- conda docs -- 康达文档

You can solve this problem by setting the priority of pytorch channel higher than the default channel by changing the order in .condarc -- more here您可以通过更改.condarc中的顺序将pytorch通道的优先级设置为高于默认通道来解决此问题——更多在这里

channels:
  - pytorch
  - defaults
  - conda-forge

channel_priority: true

or you can upgrade it by specifying as option:或者您可以通过指定选项来升级它:

conda update --all -c pytorch

In my case, the problem was coming from conda trying to update cudatoolkit from 11.3 to 11.5 (these numbers will vary depending on when you read this).就我而言,问题来自 conda 试图将cudatoolkit从 11.3 更新到 11.5(这些数字会因您阅读本文的时间而异)。

However, if you go here: https://pytorch.org/get-started/locally/ , you will see which CUDA version is compatible with the current PyTorch version (right now PyTorch version is Stable (1.10.1) ). However, if you go here: https://pytorch.org/get-started/locally/ , you will see which CUDA version is compatible with the current PyTorch version (right now PyTorch version is Stable (1.10.1) ). It appears, from that link, that this version of PyTorch requires CUDA 11.3 .从该链接看来,此版本的 PyTorch 需要CUDA 11.3

This is confirmed by the proposed one-liner to install PyTorch that fixes cudatoolkit's version to 11.3:建议的单线安装 PyTorch 证实了这一点,将 cudatoolkit 的版本修复为 11.3:

# (this is not the solution - unless you're doing a fresh install)
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

Solution for mamba update --all : pin cudatookit version mamba update --all的解决方案:pin cudatookit版本

Use conda's pinned file: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html#preventing-packages-from-updating-pinning使用 conda 的pinned文件: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html#preventing-packages-from-updating-pinning

vi /YOUR_PATH_TO/miniconda3/envs/YOUR_ENV_NAME/conda-meta/pinned

# And add a line to limit coodatookit version to 11.3
#        (or higher, depending on when you read this - see above)
cudatoolkit<11.4

Now mamba update --all doesn't try to update cudatookit and consequently doesn't try to replace GPU PyTorch with CPU PyTorch, because the dependency to cudatookit 11.3 is satisfied.现在mamba update --all不会尝试更新 cudatookit,因此不会尝试将 GPU PyTorch 替换为 CPU PyTorch,因为对 cudatookit 的依赖已满足。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM