Fix operator precedence in x0 LVLB weights and NaN assertion#404
Open
Mr-Neutr0n wants to merge 1 commit intoCompVis:mainfrom
Open
Fix operator precedence in x0 LVLB weights and NaN assertion#404Mr-Neutr0n wants to merge 1 commit intoCompVis:mainfrom
Mr-Neutr0n wants to merge 1 commit intoCompVis:mainfrom
Conversation
Two bugs in DDPM.register_schedule(): 1. The x0 parameterization formula `2. * 1 - torch.Tensor(alphas_cumprod)` is evaluated as `(2. * 1) - torch.Tensor(alphas_cumprod)` due to operator precedence, yielding `2.0 - alphas_cumprod` instead of the intended `2.0 * (1 - alphas_cumprod)`. This produces incorrect LVLB weights that silently degrade training when using x0 parameterization. 2. The NaN guard `assert not isnan(...).all()` only fires when *every* element is NaN. A single NaN — which is enough to corrupt the loss — passes undetected. Changed to `.any()` so any NaN triggers the assertion.
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 two related bugs in
DDPM.register_schedule()(ldm/models/diffusion/ddpm.py):Operator precedence bug in x0 LVLB weights (line 163): The expression
2. * 1 - torch.Tensor(alphas_cumprod)is parsed as(2.0) - alphas_cumprodinstead of2.0 * (1 - alphas_cumprod). This silently produces incorrect variational lower bound weights when usingx0parameterization, degrading training quality. Added parentheses to enforce the correct grouping.NaN assertion uses
.all()instead of.any()(line 169):assert not torch.isnan(...).all()only triggers if every element is NaN. A single NaN value — which is sufficient to corrupt the loss and propagate through the model — passes undetected. Changed to.any()so the assertion catches any NaN.Test plan
parameterization="x0"and confirm LVLB weights match the expected formula