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

Ouverte
#15,400 1 commentaire 0 réactions 1 personne assignée Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@DN6 y travaille déjà.

Depuis le 30/11/2026.

  • #15394 par @Shan2L — ouverte

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
18/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python, pytorch
Domaine
ai-infra-agents

Piste de recherche

The work sits in the group offloading path of apply_group_offloading and ModelMixin.enable_group_offload, specifically the top-level group that holds non-block modules under block_level. Start by reading how that group is built and how it is moved to and from the device on each forward. Done means the two proposed arguments exist, keep_non_block_modules_resident and num_resident_blocks, with tests showing the non-block modules stay on device and output is unchanged. Note that a prototype is already linked as PR #15394, so check that PR before starting.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Python
Étoiles
35k
Forks
7.5k
Merge moyen
2 j 22 h
PR mergées (30 j)
58

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de huggingface/diffusers

Toutes les issues de huggingface/diffusers

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.