Use pre-norm text features for Qwen-Image 2.1 (#7765)

Signed-off-by: Tianyu Guo <guoty9@mail2.sysu.edu.cn>
This commit is contained in:
Tianyu Guo authored and GitHub committed 2026-09-18 13:50:36 +08:00
1 parent eb54a3186b
commit 93d7a06e7f
1 file changed
+6 -1
@@ -541,7 +541,12 @@ class QwenImage21Pipeline(
if getattr(model_inputs, "mm_token_type_ids", None) is not None:
forward_kwargs["mm_token_type_ids"] = model_inputs.mm_token_type_ids
outputs = self.text_encoder(**forward_kwargs)
text_model = getattr(self.text_encoder.model, "language_model", self.text_encoder.model)
handle = text_model.norm.register_forward_hook(lambda module, args, output: args[0])
try:
outputs = self.text_encoder(**forward_kwargs)
finally:
handle.remove()
hidden_states = outputs.hidden_states[-1]
split_hidden_states = list(self._extract_masked_hidden(hidden_states, model_inputs.attention_mask))