Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conda installs a cpu version of pytorch and torchvision #529

Closed
remtav opened this issue May 3, 2022 · 12 comments · Fixed by #545
Closed

Conda installs a cpu version of pytorch and torchvision #529

remtav opened this issue May 3, 2022 · 12 comments · Fixed by #545

Comments

@remtav
Copy link
Contributor

remtav commented May 3, 2022

Conda installation (tested on Ubuntu 20.04) installs a cpu version of pytorch and torchvision. In my own project, the only remedy I've found was to hardcode the pytorch package to use. Poor solution. Hoping to find an alternative.

Related to #527

result from conda list in torchgeo environment:
ksnip_20220503-162044
ksnip_20220503-162055

@adamjstewart
Copy link
Collaborator

@ashnair1 @calebrob6 this relates to #295. I believe both pytorch-cpu and pytorch-gpu satisfy pytorch, but it's always been unclear to me how to decide which conda actually uses. I wonder if running conda install pytorch-gpu explicitly after installing the environment would help.

@remtav
Copy link
Contributor Author

remtav commented May 4, 2022

@ashnair1 @calebrob6 this relates to #295. I believe both pytorch-cpu and pytorch-gpu satisfy pytorch, but it's always been unclear to me how to decide which conda actually uses. I wonder if running conda install pytorch-gpu explicitly after installing the environment would help.

Just tried installing pytorch-gpu (conda install pytorch-gpu -c pytorch) on top on my pre-existing conda environment (on Ubuntu 20.04 again), and it seems to be working. Don't know how this could be elegantly done without having to add a step in the installation process. Ideally, conda could check if there's a gpu or not and install accordingly, but I don't think we're close to having that feature.

@adamjstewart
Copy link
Collaborator

With Spack this would look like:

$ spack install py-torchgeo ^py-torch+cuda cuda_arch=...

I don't know of any other package managers that have that level of flexibility. But we can certainly add this advice to the installation instructions!

@ashnair1
Copy link
Collaborator

ashnair1 commented May 4, 2022

For what it's worth I've opened conda-forge/pytorch-cpu-feedstock#102 to look into this. I didn't observe this when I pushed #295 so I'm not sure if it's a new development but I can reproduce this now.

@ashnair1
Copy link
Collaborator

ashnair1 commented May 4, 2022

@ashnair1 @calebrob6 this relates to #295. I believe both pytorch-cpu and pytorch-gpu satisfy pytorch, but it's always been unclear to me how to decide which conda actually uses. I wonder if running conda install pytorch-gpu explicitly after installing the environment would help.

Just tried installing pytorch-gpu (conda install pytorch-gpu -c pytorch) on top on my pre-existing conda environment (on Ubuntu 20.04 again), and it seems to be working. Don't know how this could be elegantly done without having to add a step in the installation process. Ideally, conda could check if there's a gpu or not and install accordingly, but I don't think we're close to having that feature.

I believe conda does have a way to determine if your device has a gpu or not via virtual packages. Refer here. But I'm still not clear on the details.

@adamjstewart
Copy link
Collaborator

@remtav was this issue fixed by #528? From the discussion in conda-forge/pytorch-cpu-feedstock#102 it seems like this issue only affects the pytorch package from conda-forge, it shouldn't affect the pytorch package from the pytorch channel.

@remtav
Copy link
Contributor Author

remtav commented May 24, 2022

@remtav was this issue fixed by #528? From the discussion in conda-forge/pytorch-cpu-feedstock#102 it seems like this issue only affects the pytorch package from conda-forge, it shouldn't affect the pytorch package from the pytorch channel.

Unfortunately, no. Even the pytorch channel chooses the cpu version:
image

A quick solution would be to specify pytorch-gpu. I can open the PR if this solution is ok.

However, for a more permanent solution, we'd have to dig further into what @ashnair1 shared. Maybe conda can validate the presence of a GPU or not and choose the package based on that.

@ashnair1
Copy link
Collaborator

ashnair1 commented May 24, 2022

Could you try installing by pegging the cudatoolkit to one of the following (10.2, 11.1, 11.3, 11.5)? pytorch does not ship a whl compiled with cudatoolkit 11.7 which is the latest cudatoolkit and the one that gets installed by default.

Talked about this in the linked conda-forge issue here -> conda-forge/pytorch-cpu-feedstock/issues/102#issuecomment-1133948416

@remtav
Copy link
Contributor Author

remtav commented May 24, 2022

Could you try installing by pegging the cudatoolkit to one of the following (10.2, 11.1, 11.3, 11.5)? pytorch does not ship a whl compiled with cudatoolkit 11.7 which is the latest cudatoolkit and the one that gets installed by default.

Talked about this in the linked conda-forge issue here -> conda-forge/pytorch-cpu-feedstock/issues/102#issuecomment-1133948416

Works! I simply changed :

dependencies:
  - cudatoolkit

to

dependencies:
  - cudatoolkit<=11.5

and conda installed pytorch with gpu support:
image

@adamjstewart I'd be pushing a tiny PR for this tomorrow if that's fine on your side.

@adamjstewart
Copy link
Collaborator

I'm surprised we even have cudatoolkit in there, isn't that only needed for pytorch-gpu? Btw, I'm fine with whatever, I don't use conda.

@vivienneprince
Copy link

check out https://pytorch.org/get-started/locally/
try:
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

@jerrytamchiho
Copy link

check out https://pytorch.org/get-started/locally/ try: conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

This installs the cpu version by default again now. (21/06/2024 RTX4090)
Solve: Just use pip install instead of conda install or add the -gpu flag into the command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants