Skip to content

Allow for using CPU if no CUDA device is detected - #123

Open
Urcra wants to merge 3 commits into
CompVis:mainfrom
Urcra:main
Open

Allow for using CPU if no CUDA device is detected#123
Urcra wants to merge 3 commits into
CompVis:mainfrom
Urcra:main

Conversation

@Urcra

@UrcraUrcra commented Aug 17, 2022

Copy link
Copy Markdown

Allows for running on the CPU if no CUDA device is detected instead of just giving a runtime error.

This should allow for more people to experiment even without owning an nvidia GPU

Solves:

@leszekhanuszleszekhanusz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it works!

It is my understanding that by default, pytorch puts everything on the cpu and you have to specify .cuda() or .to(torch.device("cuda") to move things to the gpu.

So I think that maybe all the model.cpu() calls are not needed. Same for .to(torch.device("cpu"))

Comment threadldm/models/diffusion/ddim.py Outdated
Comment threadldm/models/diffusion/plms.py Outdated
Comment threadldm/modules/encoders/modules.py Outdated
Comment threadldm/modules/encoders/modules.py Outdated
Comment threadldm/modules/encoders/modules.py Outdated
Comment threadscripts/knn2img.py Outdated
Comment threadscripts/knn2img.py Outdated
Comment threadscripts/knn2img.py Outdated
Comment threadscripts/sample_diffusion.py Outdated
Comment threadscripts/txt2img.py Outdated
@leszekhanusz

leszekhanusz commented Aug 18, 2022

Copy link
Copy Markdown

Currently I am using export CUDA_VISIBLE_DEVICES="" to test using the only the cpu with your code.

It would be neat if we could use a --disable-cuda flag as described in pytorch device-agnostic example to use the cpu explicitely without having to mess with environment variables.

This would be useful for example when you have a GPU but not not enough VRAM to put the model on it.

@Urcra

Copy link
Copy Markdown
Author

Thanks, it works!

It is my understanding that by default, pytorch puts everything on the cpu and you have to specify .cuda() or .to(torch.device("cuda") to move things to the gpu.

So I think that maybe all the model.cpu() calls are not needed. Same for .to(torch.device("cpu"))

👍 Yeah you are right, just didn't think about that when I first made the PR, but I fixed it now, so it's a bit cleaner

@Urcra

Copy link
Copy Markdown
Author

Currently I am using export CUDA_VISIBLE_DEVICES="" to test using the only the cpu with your code.

It would be neat if we could use a --disable-cuda flag as described in pytorch device-agnostic example to use the cpu explicitely without having to mess with environment variables.

This would be useful for example when you have a GPU but not not enough VRAM to put the model on it.

Wanted to also do this, but it's pretty annoying to pass new arguments into the classes from encoder/modules.py and I wasn't really sure if I wanted to create a global variable for it or how it could best be solved, open to any ideas though

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Urcra@leszekhanusz