Skip to content

Group offloading (block_level): non-block modules are copied to the device and back on every forward #15400

In review

Description

@Shan2L

Is your feature request related to a problem? Please describe.

With offload_type="block_level", every module, parameter and buffer outside the block groups (embedders, norms, refiners, ...) goes into one top-level group that is copied to the device and back synchronously on every forward pass. The streamed blocks overlap with compute, but this group does not. For MiniMax-H3-Image these modules (token refiner and embedders) total 1.72 GB: about 0.23 s host-to-device plus 0.54 s device-to-host per forward, on one Radeon AI PRO R9600D. Over a request that is ~4 s of a ~32 s total.

Describe the solution you'd like.

Two opt-in arguments for block_level in apply_group_offloading / ModelMixin.enable_group_offload:

  • keep_non_block_modules_resident: bool = False: place the non-block modules on onload_device once and never offload them.
  • num_resident_blocks: int = 0: keep the first N block groups on the device permanently, for users with spare device memory.

Measured with a prototype on MiniMax-H3-Image 1024x1024 (transformer block_level, use_stream=True): 32.22 -> 28.09 s per request with keep_non_block_modules_resident=True, same peak memory (6.23 GiB), bitwise identical output.

Additional context.

Non-block parameter size of other models (from their configs): HunyuanVideo 0.67 GiB, Wan2.1-14B 0.43 GiB, Qwen-Image 0.075 GiB, so the gain is mainly for large video DiTs. Implemented in #15394.

Activity

  1. yiyixuxu commented on Nov 30, 2026

    @yiyixuxu
    Collaborator

    thanks for the issue!
    i'd like to support the use case, however, I wonder if we should have a more flexible option instead of the 2 flags added in the PR, e.g.

    model.enable_group_offload(..., resident_modules = [...])

    cc @DN6 here, would like to hear your thoughts on this

  2. Shan2L commented on Dec 2, 2026

    @Shan2L
    ContributorAuthor

    Thanks @yiyixuxu, a single resident_modules argument sounds better to me than the two flags. A proposal, happy to adjust:

    model.enable_group_offload(
        onload_device, offload_type="block_level", num_blocks_per_group=1, use_stream=True,
        resident_modules=["time_text_embed", "context_embedder", "token_refiner", "transformer_blocks.0"],
    )
    • Entries are qualified names of submodules, matched as name prefixes. They are moved to onload_device once and excluded from all offload groups, so they are never copied back.
    • A name inside a block ModuleList (e.g. transformer_blocks.0) makes that block resident. This covers what num_resident_blocks did, without a second argument.
    • Parameters and buffers registered directly on the root model (e.g. a scale_shift_table) are not submodules. I would accept their names too, so a user can keep everything outside the blocks resident.
    • Unknown names raise ValueError, like the existing argument checks.

    For leaf_level the same list can mean "do not offload these modules". I would start with block_level only and raise for leaf_level, unless you prefer both now.

    If this looks right to you and @DN6, I will rework #15394 to this API and drop keep_non_block_modules_resident and num_resident_blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions