Skip to content

UnboundLocalError: noise_pred_neg referenced before assignment when cfg=1.0 (distilled mode) #458

Description

Bug

When using MultimodalGuider with cfg=1.0 (required for the distilled LoRA workflow), SamplerCustomAdvanced crashes with:

UnboundLocalError: local variable 'noise_pred_neg' referenced before assignment

File: guiders/multimodal_guider.py, line 269
Triggered by: euler_ancestral_cfg_pp and euler_cfg_pp samplers, which register a sampler_post_cfg_function hook that references noise_pred_neg.

Root Cause

In MultimodalGuider.predict_noise, noise_pred_neg is only assigned inside the if any(params.do_uncond() for params in [...]) block (line ~167). When cfg=1.0, do_uncond() returns False (not math.isclose(cfg_scale, 1.0)), so the block is skipped entirely. However, line 269 unconditionally references noise_pred_neg when iterating sampler_post_cfg_function hooks:

for fn in model_options.get("sampler_post_cfg_function", []):
    args = {
        ...
        "uncond_denoised": noise_pred_neg,  # ← crashes here when cfg=1.0
        ...
    }

Note that v_noise_pred_neg and a_noise_pred_neg are correctly initialized to 0 before the block, but noise_pred_neg (the packed form) is not.

Reproduction

  1. Use the LTX-2.3 22B NVFP4 model with distilled LoRA (ltx-2.3-22b-distilled-lora-384.safetensors)
  2. Set GuiderParameters cfg=1.0 for both VIDEO and VIDEO modalities (correct for distilled)
  3. Use KSamplerSelect with euler_ancestral_cfg_pp or euler_cfg_pp
  4. Queue — crashes immediately on first denoising step

Fix

Initialize noise_pred_neg (and noise_pred_perturbed for the same reason) before the conditional blocks:

# Before the if do_uncond() block, add:
noise_pred_neg = noise_pred_pos      # fallback when cfg=1.0 (do_uncond skipped)
noise_pred_perturbed = noise_pred_pos  # fallback when stg=0.0 (do_perturbed skipped)

This matches the behavior of the already-initialized v_noise_pred_neg = 0 / a_noise_pred_neg = 0 variables and is the correct semantic for distilled inference (no negative guidance correction needed).

Environment

  • LTX-2.3 22B NVFP4 (ltx-2.3-22b-dev-nvfp4.safetensors)
  • Distilled LoRA: ltx-2.3-22b-distilled-lora-384.safetensors
  • ComfyUI-LTXVideo (latest main)
  • Sampler: euler_ancestral_cfg_pp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions