Conda Pytorch keeps downgrading itself from cuda -> cpu

I know it is a silly question and probably I’m not the only one experiencing this problem.
But I really get frustrated by the fact that once I have a working PyTorch installation, that uses CUDA, then any change in my conda environment leads to an unwanted downgrade of PyTorch from cuda to cpu.

Now it happened again: I was using Pytorch since month. Then I needed scipy and installed it using the following command:

$conda install scipy

and then during the installation process it did the following:

pytorch pytorch::pytorch-2.5.1-py3.12_cuda12.~ --> pkgs/main::pytorch-2.3.1-cpu_py312h4f03144_0

So, cuda is not recognized anymore. I have to reinstall my system from scratch again.

Why?
How prevent such problems in the future?
It happens 7 times of 10 when I need to install another package in my environment.

Any suggestion to fix it once for all?

Before confirming the updates (in this case scipy) your package manager should show which dependencies would be changed and you should check which packages are downgraded.
These chains of dependency can be annoying if too many packages use strict requirements. PyTorch itself does not depend on scipy and would not care if you change its version.

Ok, but how to stop the downgrade of a package?
Why should conda downgrade a package (in this case pytorch) from cuda to cpu version?

I don’t know as you didn’t show any logs, which would indicate what kind of dependencies you are changing.
I can only speculate that e.g. scipy downgraded numpy that downgraded transformers that downgraded PyTorch (I don’t know if this dependency chain exists, so use this as a pure theoretical example).

The conda install command for PyTorch binaries needed the pytorch-cuda==version metapackage defining all CUDA runtime libraries.
If you don’t specify this, the default will be used which might be CPU-only.
conda binaries are also deprecated, so you might want to consider switching to pip wheels (which use CUDA as the default when running pip install torch).