From f6c0104f256f30c291278b3e2911ef3e4d759134 Mon Sep 17 00:00:00 2001 From: Jaret Burkett Date: Tue, 16 Jun 2026 10:23:08 -0600 Subject: [PATCH] Handle unconditional conditioning for ideogram 4 more in line with example code. --- .../diffusion_models/ideogram4/src/pipeline.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/extensions_built_in/diffusion_models/ideogram4/src/pipeline.py b/extensions_built_in/diffusion_models/ideogram4/src/pipeline.py index c68e2d4..5798f94 100644 --- a/extensions_built_in/diffusion_models/ideogram4/src/pipeline.py +++ b/extensions_built_in/diffusion_models/ideogram4/src/pipeline.py @@ -297,7 +297,11 @@ class Ideogram4Pipeline: gw = width // (ae_scale * patch) latent_channels = transformer.config.in_channels - do_cfg = unconditional_embeds is not None and guidance_scale != 1.0 + # Ideogram uses asymmetric CFG: the unconditional branch is image-only + # (no text tokens) with zeroed text features -- it does NOT run a negative + # prompt through the text encoder. So we ignore unconditional_embeds and + # build an empty (0-length) text sequence for the uncond pass below. + do_cfg = guidance_scale > 1.0 if latents is None: shape = (1, latent_channels, gh, gw) @@ -311,9 +315,15 @@ class Ideogram4Pipeline: conditional_embeds.text_embeds, device, dtype ) if do_cfg: - uncond_feats, uncond_mask = pad_text_features( - unconditional_embeds.text_embeds, device, dtype + # Image-only unconditional: zero-length text sequence. predict_velocity + # then produces an image-token-only forward pass with zeroed llm + # features, matching the reference's asymmetric CFG. + batch_size = latents.shape[0] + text_dim = cond_feats.shape[-1] + uncond_feats = torch.zeros( + batch_size, 0, text_dim, device=device, dtype=dtype ) + uncond_mask = torch.zeros(batch_size, 0, dtype=torch.long, device=device) for t in timesteps: t01 = (t / 1000.0).to(device).expand(latents.shape[0])