Add unconditional lora support so Ideogram 4 inference will more closely resemble the full pipeline results. I pushed a finetuned unconditional lora to the hub as an adapter.

This commit is contained in:
Jaret Burkett
2026-06-16 13:27:43 -06:00
parent f6c0104f25
commit 178eb5fbbe
7 changed files with 139 additions and 6 deletions

View File

@@ -325,15 +325,28 @@ class Ideogram4Pipeline:
)
uncond_mask = torch.zeros(batch_size, 0, dtype=torch.long, device=device)
# The unconditional LoRA (if present) must be active *only* on the
# unconditional pass. We force it off before each conditional pass since the
# outer sampling context (``with network:``) may switch it on globally.
uncond_lora = getattr(model, "unconditional_lora", None)
for t in timesteps:
t01 = (t / 1000.0).to(device).expand(latents.shape[0])
if uncond_lora is not None:
uncond_lora.is_active = False
v_cond = predict_velocity(
transformer, latents.to(dtype), t01, cond_feats, cond_mask
)
if do_cfg:
v_uncond = predict_velocity(
transformer, latents.to(dtype), t01, uncond_feats, uncond_mask
)
if uncond_lora is not None:
uncond_lora.is_active = True
try:
v_uncond = predict_velocity(
transformer, latents.to(dtype), t01, uncond_feats, uncond_mask
)
finally:
if uncond_lora is not None:
uncond_lora.is_active = False
v = v_uncond + guidance_scale * (v_cond - v_uncond)
else:
v = v_cond