Skip to content

feature: CpuOffload pre_forward don't attempt to move if already on device #3695

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JoeGaffney
Copy link

@JoeGaffney JoeGaffney commented Jul 26, 2025

What does this PR do?

Added optimisation to not attempt to move devices if already on that the device. This is more noticeable in large step iterations on diffusion loops when the pre_forward can get called many times

Possibly the there is a better way than using next() and noticed it's possibly to set the prev_module_hook to invalid object so added an additional check. Glad for any feedback to improve. Or perhaps there's an even better way.

Fixes # (issue)

Issue was not as bad as I initially thought. But from speaking with maintainers there was some smaller gains found. Mainly noticeable in large loops

huggingface/diffusers#11872

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

…y on that the device. This is more noticiable in large step itterations on diffusion loops when the pre_froward can get called many times
@JoeGaffney JoeGaffney marked this pull request as ready for review July 26, 2025 14:29
@S1ro1
Copy link
Member

S1ro1 commented Aug 2, 2025

cc @SunMarc

Sign up for free to 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.

3 participants