Hotfix: tolerate new ComfyUI Krea2 forward signature (fixes #1)

Newer ComfyUI cores insert ref_latents positionally into the Krea2
diffusion forward, crashing our replaced _forward with "takes 4 to 6
positional arguments but 7 were given" - even for stock generation.
Accept both call shapes (dict tail = transformer_options), and use the
natively-passed ref_latents when present.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Boss
2026-07-22 13:17:08 +09:00
co-authored by Claude Fable 5
parent 9b024304fa
commit f911223c20
+13 -2
View File
@@ -154,8 +154,19 @@ def _krea2_extra_conds_shapes(self, **kwargs):
# are returned. Sources are resized to the target latent size in latent space.
# --------------------------------------------------------------------------
def _krea2_forward(self, x, timesteps, context, attention_mask=None, transformer_options={}, **kwargs):
ref_latents = kwargs.get("ref_latents", None) or []
def _krea2_forward(self, x, timesteps, context, attention_mask=None, *_drift, transformer_options=None, **kwargs):
# ComfyUI signature-drift guard: older cores call (..., attention_mask, transformer_options);
# newer cores insert ref_latents positionally: (..., attention_mask, ref_latents,
# transformer_options). Accept both so stock Krea 2 generation never breaks on update.
native_ref = None
drift = list(_drift)
if drift and isinstance(drift[-1], dict) and transformer_options is None:
transformer_options = drift.pop()
if drift:
native_ref = drift.pop(0)
if transformer_options is None:
transformer_options = {}
ref_latents = kwargs.get("ref_latents", None) or native_ref or []
ref_boosts = list(kwargs.get("ref_boosts", None) or [])
ref_fit = list(kwargs.get("ref_fit", None) or [])
# Defensive alignment: pad from the LEFT so attached values always map to the LAST refs