Repository navigation
Conversation
…ts under model CPU offload
This branch has not been deployed
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.
What does this PR do?
Fixes #15503
expand_promptscallstext_encoder.generate(...). Since huggingface/transformers#45783 (v5.18.0),generate()runsget_image_featuresbefore the first top-levelforward, the only callenable_model_cpu_offload()hooks, so withimage=the vision tower runs with its weights still oncpu.This PR fires the text encoder's accelerate hook before
generate(), in the same form as #15456 andapply_forward_hook(utils/accelerate_utils.py).Results
mainat facc812 + this diff, the #15503 snippet (released weights), NVIDIA GeForce RTX 5090, torch 2.14.1+cu130, accelerate 1.9.0:mainraises the device-mismatch error inexpand_prompts; with this PR the error is gone andexpand_promptsreturns a prompt.mainand this PR.main(RTX 5090 and AMD Radeon 8060S): offload output equalspipe.to("cuda")(max abs diff 0) on 5.16.1 and raises on 5.21.0. This PR was not run on them.Outside the reported case:
expand_prompts=False: the added lines are not reached.expand_prompts=Truewithoutimage=under model offload: the hook fires beforegenerate()instead of at its firstforward. Not measured.pipe.to(...), group offloading): the lines do nothing. Not run.device_map="balanced"): one extrapre_forward(text_encoder)call per prompt. Not measured.Self-review notes (
self-reviewskill): blocking none. Left for review: hand-fired hook (pipelines.md gotcha 8);hasattr(hook, "pre_forward")is always true, kept to matchapply_forward_hook; no test, asMemoryTesterMixinoffloads withoutimage=/expand_prompts=True.ruffcheck / format pass.Before submitting
self-reviewskill on the diff?image=+expand_prompts=Truefails withenable_model_cpu_offload()on transformers >= 5.18 (device mismatch inget_image_features) #15503, no maintainer reply yet.documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@yiyixuxu @sayakpaul