From 3f144d7d385f44bc4b0c12d320129f267276722a Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 2 Jan 2026 17:58:09 +0900 Subject: [PATCH] Fix Issue #43: Prevent ComfyUI-nunchaku bug by forcing guidance=None after conversion to additional_t_cond - Force guidance to None in forward() and _execute_model() to prevent ComfyUI-nunchaku's buggy code path (line 726) from executing - Preserve legacy guidance values from kwargs/transformer_options and convert to additional_t_cond when needed (backward compatibility) - This prevents TypeError: QwenTimestepProjEmbeddings.forward() takes 3 positional arguments but 4 were given - Similar defensive approach to v2.0.2-v2.0.8 guidance duplication fixes --- wrappers/qwenimage.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wrappers/qwenimage.py b/wrappers/qwenimage.py index 7a94d66..3a58022 100644 --- a/wrappers/qwenimage.py +++ b/wrappers/qwenimage.py @@ -96,7 +96,10 @@ class ComfyQwenImageWrapper(nn.Module): # which could cause issues when passing to _execute_model # Note: ref_latents is NOT a parameter of forward(), so we keep it in kwargs for _execute_model to use if "guidance" in kwargs: - # Remove guidance from kwargs to avoid duplication (explicit parameter takes precedence) + # Preserve legacy guidance if it only arrives via kwargs (environment-dependent), + # then remove it to avoid duplication downstream. + if guidance is None: + guidance = kwargs.get("guidance") kwargs.pop("guidance") if "transformer_options" in kwargs: # Merge transformer_options from kwargs into the parameter if needed @@ -104,6 +107,10 @@ class ComfyQwenImageWrapper(nn.Module): transformer_options = {**transformer_options, **kwargs.pop("transformer_options")} else: kwargs.pop("transformer_options") + # Preserve legacy guidance if it only arrives via transformer_options (environment-dependent). + # We will later remove it from transformer_options when actually calling the model. + if guidance is None and isinstance(transformer_options, dict) and "guidance" in transformer_options: + guidance = transformer_options.get("guidance") if "attention_mask" in kwargs: kwargs.pop("attention_mask") if isinstance(timestep, torch.Tensor):