-
Notifications
You must be signed in to change notification settings - Fork 971
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
Add cpu_offload_with_hook
#1045
Conversation
The documentation is not available anymore as the PR was closed or merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very nice! If possible we were also envisioning the possibility to pass a previous user_hook to the CpuOffload hook so that the previous model can be offloaded at forward. E.g. so that the following could be possible:
hook_1 = cpu_offload_with_hook(model_1, cuda_device)
hook_2 = cpu_offload_with_hook(model_2, cuda_device, user_hook=hook_1)
hook_3 = cpu_offload_with_hook(model_3, cuda_device, user_hook=hook_2)
so that the following would automatically work:
hid_1 = model_1(input)
for i in range(50):
hid_2 = model_2(hid_1)
hid_3 = model_3(hid_3)
Alternatively, we could also call the hooks ourselves if preferred, but if we could directly pass the hooks as shown in the code review that would make diffusers code much nicer I think :-)
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Really Cool! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks a mille for the super fast PR ❤️
This is a feature request for Diffusers. This PR adds a new
cpu_offload_with_hook
function that will offload the model to CPU, then put it back on the GPU once executed, but without offloading it just after the forward likecpu_offload
does. Instead, it's up to the user to call thehook.offload()
to offload it again.Example:
cc @pcuenca @patrickvonplaten