support group offloading under auto offloading - #14358
Merged
Merged
Conversation
`ComponentsManager.enable_auto_cpu_offload` and `enable_group_offload` are two independent hook systems — accelerate's `_hf_hook` and diffusers' `HookRegistry` — and neither noticed the other. Enabling both raised nothing and appeared to work, but auto offloading frees memory by calling `.to()`, which a group offloaded module refuses and only warns about. Every offload the manager thought it performed was a no-op: it recorded memory as freed that never was, and it charged a group offloaded model's whole weight against the device although only one group is ever resident. A group offloaded model now takes part but places itself. It still makes room by moving other models aside, since its `pre_forward` consults the strategy as before; it is never chosen as the thing to move, because moving it does nothing; and the manager no longer pretends to offload it. Either order works, group offload before or after enabling. Deciding *what* to move then has to come from somewhere other than memory estimates, so `enable_auto_cpu_offload` takes an `offload_strategy` and `set_offload_strategy` can replace it later. The default `AutoOffloadStrategy` sizes its decisions from model memory footprints, which do not describe a model holding one group at a time, so it warns when it meets group offloading — only when no strategy was passed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
related to #14346
with this PR, we now support the use case where a group offloaded model now takes part in auto offloading but places itself:
pre_forwardconsults the strategy as before)Either order works — group offload before or after
enable_auto_cpu_offload.Also here, because it is what makes the combination useful:
enable_auto_cpu_offload(..., offload_strategy=...)andset_offload_strategy(...),AutoOffloadStrategy, it is not meaningful to use AutoOffloadStrategy with group offloading because the default strategy make its decisions from model memory footprints — a number that does not describe a model holding one group at a time.Demo
Tongyi-MAI/Z-Image-Turbo(11.5GB transformer, 3.7GB text encoder in bf16) on one H100, 4 steps:The whole custom strategy is:
automatchingon gpuis the point: on an 80GB card the default strategy never fires, becausenothing is ever short of memory. Deciding from the workflow ("the text encoder is done") buys 7.5GB,
and group offloading the transformer buys another 6.4GB — 64% off the resident case.
Not in this PR
offloading itself when everything else is already offloaded. The guards here hold for that: when the
manager group offloads a model it has already hooked, the hook stops moving it from that point on, so no extra bookkeeping is needed.