简体   繁体   中英

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 verified that my Pytorch indeed runs fine on GPU.

However, whenever I update Anaconda by conda update --all , the following messages always shows:

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. 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. I have also tried the command conda update --all --no-channel-priority but the message still shows.

To my knowledge I have never modified Anaconda channels or add custom channels. 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 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

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).

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 .

This is confirmed by the proposed one-liner to install PyTorch that fixes cudatoolkit's version to 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

Use conda's pinned file: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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