Skip to content

Commit ed49fab

Browse files
fix(flux2): strip reference-image tokens from Heun preview latents (invoke-ai#9274)
The Heun (2nd order) branch of the FLUX.2 Klein denoise loop passed the full preview latent to step_callback without removing the concatenated reference-image tokens. With ref images the sequence length is doubled, so unpack_flux2 failed with "Shape mismatch, 8192 != 4096". Slice the preview to original_seq_len before the callback, matching the behavior already present in the Euler branch. Co-authored-by: Lincoln Stein <lincoln.stein@gmail.com>
1 parent 5c464f8 commit ed49fab

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

invokeai/backend/flux2/denoise.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,17 @@ def denoise(
195195
preview_img = inpaint_extension.merge_intermediate_latents_with_init_latents(
196196
preview_img, 0.0
197197
)
198+
# Extract only the generated image portion for preview (exclude reference images)
199+
callback_latents = (
200+
preview_img[:, :original_seq_len, :] if img_cond_seq is not None else preview_img
201+
)
198202
step_callback(
199203
PipelineIntermediateState(
200204
step=user_step,
201205
order=2,
202206
total_steps=total_steps,
203207
timestep=int(t_curr * 1000),
204-
latents=preview_img,
208+
latents=callback_latents,
205209
),
206210
)
207211
else:

0 commit comments

Comments
 (0)