[MiniMax-H3] Block-level group offloading of the Qwen3-VL text encoder fails: the encoder step bypasses its top-level forward

未关闭
#15,399 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Shan2L 已经在做这个了。

开始于 2026年11月25日。

  • #15395 来自 @Shan2L —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
18/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python, pytorch

调研方向

Start with get_qwen3vl_prompt_embeds in the MiniMax-H3 and Pika-H3-Flex pipeline modules, where text_encoder.model(...) and the manual _hf_hook.pre_forward call bypass the top-level forward. Reproduce with block_level group offloading on the text encoder to see the device mismatch on the token embedding. Done means encoding succeeds under block_level offloading and matches the existing output; the linked pull request #15395 already proposes the change, so this is not open for a fresh attempt.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

get_qwen3vl_prompt_embeds (MiniMax-H3, MiniMax-H3-Image, and its copy in Pika-H3-Flex) calls text_encoder.model(...) and fires accelerate's _hf_hook.pre_forward by hand; the code carries a TODO about it. Hooks that wrap only the top-level forward therefore never fire. With offload_type="block_level" group offloading on the text encoder, the modules outside the decoder blocks (the token embedding) are never onloaded and encoding fails:

RuntimeError: Expected all tensors to be on the same device, but got index is on cuda:0, different from other tensors on cpu
Reproduction
import torch
from diffusers import ModularPipeline
from diffusers.hooks import apply_group_offloading

pipe = ModularPipeline.from_pretrained("<MiniMax-H3-Image diffusers checkpoint>")
pipe.load_components(dtype=torch.bfloat16)
dev = torch.device("cuda")
pipe.transformer.enable_group_offload(dev, offload_device=torch.device("cpu"), offload_type="block_level", num_blocks_per_group=1, use_stream=True)
apply_group_offloading(pipe.text_encoder, dev, offload_device=torch.device("cpu"), offload_type="block_level", num_blocks_per_group=1, use_stream=True)
pipe.vae.to(dev)
pipe(prompt="a garden", height=1024, width=1024, output="images")  # fails in the text encoder step

leaf_level on the text encoder works, because it hooks every leaf module.

Context

Offloading is the only way to run MiniMax-H3-Image on one 32 GB GPU: the documented ComponentsManager auto offload moves the ~62 GB text encoder as a whole and does not fit.

System Info

diffusers main (e3f8451), torch 2.14 (ROCm 10.1), Radeon AI PRO R9600D / R9700 (gfx1201).

Fix

#15395 calls text_encoder(...) with logits_to_keep=1 instead, so the top-level hooks fire; hidden_states[50] is bitwise identical to the current call.

主要语言
Python
星标
35k
派生
7.5k
平均合并
2 天 22 小时
30 天内合并 PR
58

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

huggingface/diffusers 的其他 Issue

查看 huggingface/diffusers 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。