fix: UnboundLocalError for noise_pred_neg/perturbed when cfg=1.0#460
Open
Frank Greico (codeman101) wants to merge 1 commit intoLightricks:masterfrom
Open
fix: UnboundLocalError for noise_pred_neg/perturbed when cfg=1.0#460Frank Greico (codeman101) wants to merge 1 commit intoLightricks:masterfrom
Frank Greico (codeman101) wants to merge 1 commit intoLightricks:masterfrom
Conversation
…ional 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 Lightricks#458
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
UnboundLocalErrorinMultimodalGuider.predict_noise()when using cfg=1.0 (distilled mode) withsampler_post_cfg_functionhooks active.Fixes #458
Bug
In
predict_noise(), the variablesnoise_pred_negandnoise_pred_perturbedare only assigned inside conditional blocks:noise_pred_negis assigned insideif any(params.do_uncond() ...)-- skipped when cfg=1.0noise_pred_perturbedis assigned insideif any(params.do_perturbed() ...)-- skipped when STG is disabledHowever, both variables are unconditionally referenced later in the
sampler_post_cfg_functionhooks loop:This causes an
UnboundLocalErrorcrash when any post-CFG hook is registered (e.g. from other custom nodes) and the model runs in distilled mode (cfg=1.0).Fix
Initialize both variables to
noise_pred_posas safe fallbacks before the conditional blocks:When cfg=1.0 and no perturbation is applied, the unconditional and perturbed predictions are semantically equivalent to the positive prediction, so
noise_pred_posis the correct fallback value.