From 0d9973b5dbfb9b7dba0a6457f4e50ec768436828 Mon Sep 17 00:00:00 2001 From: "ChanFu, Hsu" <228416682+IvenHsu01@users.noreply.github.com> Date: Fri, 4 Dec 2026 22:25:18 +0800 Subject: [PATCH] [Kandinsky 6] Onload the text encoder before generate in expand_prompts under model CPU offload --- .../pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py b/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py index 6226855c31bf..932e8beb7553 100644 --- a/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py +++ b/src/diffusers/pipelines/kandinsky6/pipeline_kandinsky6_ti2va.py @@ -480,6 +480,9 @@ def expand_prompts( ).to(device) if generator is not None: torch.manual_seed(generator.initial_seed()) + hook = getattr(text_encoder, "_hf_hook", None) + if hook is not None and hasattr(hook, "pre_forward"): + hook.pre_forward(text_encoder) generated = text_encoder.generate(**inputs, max_new_tokens=max_sequence_length) generated = generated[:, inputs["input_ids"].shape[1] :] return tokenizer.batch_decode(generated, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]