You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cpu_offload vRAM memory consumption large than 4GB #1934
importtorchfromdiffusersimportStableDiffusionPipelinepipe=StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
torch_dtype=torch.float16,
)
pipe=pipe.to("cuda")
prompt="a photo of an astronaut riding a horse on mars"pipe.enable_sequential_cpu_offload()
image=pipe(prompt).images[0]
Thanks a lot for the super clean bug report. When running your code-snippet in combination with:
nvidia-smi
I can observe the same numbers as in your table.
I think the problem is that we move all modules to GPU in the very beginning. We shouldn't do this. When setting:
pipe.enable_sequential_cpu_offload()
It's important to previously not run .to("cuda"). E.g. the following should give much better memory numbers:
importtorchfromdiffusersimportStableDiffusionPipelinepipe=StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
torch_dtype=torch.float16,
safety_checker=None,
)
prompt="a photo of an astronaut riding a horse on mars"pipe.enable_sequential_cpu_offload()
image=pipe(prompt, num_inference_steps=4).images[0]
When running the above I'm getting <3GB memory usage.
In this example here, I'm not using the safety_checker since there is a bug with cpu_offload + safety checker at the moment that should however be corrected in this PR: #1968 along-side the incorrect documentation as spotted by you. Thanks a lot ❤️
It's an interesting use case here since by it might not be super intuitive to have to remove.to("cuda") when using enable_sequential_cpu_offload(...).
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Activity
patrickvonplaten commentedon Jan 10, 2023
Hey @Sanster,
Thanks a lot for the super clean bug report. When running your code-snippet in combination with:
I can observe the same numbers as in your table.
I think the problem is that we move all modules to GPU in the very beginning. We shouldn't do this. When setting:
It's important to previously not run
.to("cuda"). E.g. the following should give much better memory numbers:When running the above I'm getting <3GB memory usage.
In this example here, I'm not using the
safety_checkersince there is a bug with cpu_offload + safety checker at the moment that should however be corrected in this PR: #1968 along-side the incorrect documentation as spotted by you. Thanks a lot ❤️It's an interesting use case here since by it might not be super intuitive to have to remove
.to("cuda")when usingenable_sequential_cpu_offload(...).cc @pcuenca @patil-suraj @anton-l and maybe also @sgugger @muellerzr just FYI since it might be a common problem people run into.
github-actions commentedon Feb 5, 2023
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.