[tests] Add Config to Exclude Modules from Leaf-Level Group Offloading - #14564
[tests] Add Config to Exclude Modules from Leaf-Level Group Offloading#14564dg845 wants to merge 3 commits into
Conversation
`test_pipeline_level_group_offloading_inference` was skipped outright for HunyuanVideoFramepack because `image_encoder` is a `SiglipVisionModel`, whose attention pooling head wraps a `torch.nn.MultiheadAttention`. That hands `self.out_proj.weight` to `torch.nn.functional.multi_head_attention_forward` instead of calling `self.out_proj`, so the leaf-level onload hook on `out_proj` never fires and its weights stay on the offload device. Add a `group_offloading_leaf_level_exclude_modules` knob to the old-style `PipelineTesterMixin` and the new-style `BasePipelineTesterConfig` (empty by default, so no behavior change elsewhere), pass it through to `enable_group_offload(exclude_modules=...)` in both implementations of the test, and set it to `["image_encoder"]` for framepack instead of skipping. Block-level offloading is unaffected — the whole head is onloaded as one unmatched module — hence the level in the name. The test now passes and covers leaf-level offloading of the transformer, VAE and both text encoders. The VAE is coverage nothing else provided: `test_group_offloading_inference` deliberately excludes `vae` and `image_encoder`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Records the rule behind `group_offloading_leaf_level_exclude_modules`: leaf-level offloading hooks only the supported leaf types and onloads each on its own forward, so any code that reads a leaf's `.weight` instead of calling the leaf bypasses that hook. Routes the fix by who owns the component. A diffusers model declares the gap with `_supports_group_offloading = False` on the `ModelMixin` subclass, which both offload mixins honor. A third-party component that can't be annotated goes in `group_offloading_leaf_level_exclude_modules`, which keeps offload coverage for every other component — where a hand-written skip would drop it for the whole pipeline, the VAE included, since the component-scoped `test_group_offloading_inference` deliberately excludes it. `torch.nn.MultiheadAttention` is called out as the common instance rather than as the definition, with `HunyuanDiTAttentionPool` as a case that fails the same way with no MHA module involved, so the guidance still applies when a future component fails for a different reason. Also notes that a failure should be reproduced before a skip or exclusion is added: of the five pipelines currently skipping the pipeline-level test, only framepack and motif_video still fail. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Self-Review ReportSelf-review — Diff: 2 commits, 5 files, +27/−8 Blocking issuesNone. Non-blocking issues
Both are house-style calls; neither is obviously correct enough to settle without the reviewer. VerificationCode commit, re-confirmed: attribute resolves for every new-style user (AST scan of Tests: Dead CodeNot applicable — no source changes. SummaryREADY. Nothing left to fix before submitting; the two non-blocking items above are the only things that should reach the reviewer unresolved. |
What does this PR do?
This PR adds a
group_offloading_leaf_level_exclude_modulespipeline test config attribute, which allows leaf-level group offloading tests such astest_pipeline_level_group_offloading_inferenceto exclude particular modules which are not leaf-level offloadable while still covering other modules which are. In practice, modules which are not offloadable at the leaf level tend to still be offloadable at the block level (such as thetransformersSiglipVisionModelused by the Hunyuan Video Framepack pipeline which motivated this PR), which is why we focus on leaf-level offloading here.The new
group_offloading_leaf_level_exclude_modulesattribute can potentially be used by the following test files, but is only used for the motivating Hunyuan Video Framepack case in this PR:tests/pipelines/hunyuan_video/test_hunyuan_video_framepack.py(this PR)tests/pipelines/glm_image/test_glm_image.pytests/pipelines/joyimage/test_joyimage_edit.pytests/pipelines/joyimage/test_joyimage_edit_plus.pytests/pipelines/motif_video/test_motif_video_image2video.pyCan open up a follow-up PR to address the other tests.
Based on PR #14551.
Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
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.
@sayakpaul
@DN6