From c6d2387ac445ea7f049248424323f7ca712dcb0a Mon Sep 17 00:00:00 2001 From: Frank Greico Date: Wed, 8 Apr 2026 00:39:30 -0700 Subject: [PATCH] fix: initialize noise_pred_neg and noise_pred_perturbed before conditional blocks When cfg=1.0 (distilled mode), do_uncond() returns False so the block that assigns noise_pred_neg is skipped. Similarly when STG is disabled, noise_pred_perturbed is never assigned. But both variables are unconditionally referenced in the sampler_post_cfg_function hooks, causing an UnboundLocalError. Initialize both to noise_pred_pos as safe fallbacks before the conditional blocks. Fixes #458 --- guiders/multimodal_guider.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/guiders/multimodal_guider.py b/guiders/multimodal_guider.py index 0d964e4..9ac5e6f 100644 --- a/guiders/multimodal_guider.py +++ b/guiders/multimodal_guider.py @@ -158,6 +158,12 @@ def predict_noise( a_noise_pred_perturbed, v_noise_pred_perturbed = 0, 0 a_noise_pred_modality, v_noise_pred_modality = 0, 0 + # Initialize to noise_pred_pos as fallback for sampler_post_cfg_function hooks, + # which reference these unconditionally even when the conditional blocks below + # are skipped (e.g. cfg=1.0 distilled mode skips do_uncond, no STG skips do_perturbed). + noise_pred_neg = noise_pred_pos + noise_pred_perturbed = noise_pred_pos + if any(params.do_uncond() for params in [audio_params, video_params]): try: model_options["transformer_options"]["run_vx"] = run_vx