You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Group offloading (block_level): non-block modules are copied to the device and back on every forward #15400
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.
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.
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.
Activity
yiyixuxu commentedon Nov 30, 2026
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.
cc @DN6 here, would like to hear your thoughts on this
Shan2L commentedon Dec 2, 2026
Thanks @yiyixuxu, a single
resident_modulesargument sounds better to me than the two flags. A proposal, happy to adjust:onload_deviceonce and excluded from all offload groups, so they are never copied back.ModuleList(e.g.transformer_blocks.0) makes that block resident. This covers whatnum_resident_blocksdid, without a second argument.scale_shift_table) are not submodules. I would accept their names too, so a user can keep everything outside the blocks resident.ValueError, like the existing argument checks.For
leaf_levelthe same list can mean "do not offload these modules". I would start withblock_levelonly and raise forleaf_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_residentandnum_resident_blocks.