Fix operator precedence bug in VLBO loss weights#107
Open
Mr-Neutr0n wants to merge 1 commit intoAILab-CVC:mainfrom
Open
Fix operator precedence bug in VLBO loss weights#107Mr-Neutr0n wants to merge 1 commit intoAILab-CVC:mainfrom
Mr-Neutr0n wants to merge 1 commit intoAILab-CVC:mainfrom
Conversation
…uard The x0-parameterized lvlb_weights computation had a missing pair of parentheses that caused incorrect evaluation: (2. * 1 - torch.Tensor(alphas_cumprod)) Due to operator precedence, this evaluates as (2.0 - alphas_cumprod) instead of the intended 2.0 * (1 - alphas_cumprod). This produces wrong loss weighting across timesteps when training with x0 parameterization. Also tighten the NaN assertion from .all() to .any() so that partially-NaN weight tensors are caught instead of silently passing.
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
lvlb_weightscomputation forx0parameterization (lvdm/models/ddpm3d.py, line 159). The expression(2. * 1 - torch.Tensor(alphas_cumprod))evaluates as(2.0 - alphas_cumprod)due to multiplication binding tighter than subtraction. The correct denominator is2.0 * (1 - alphas_cumprod)..all()to.any()so that partially-NaN weight tensors are caught immediately instead of silently passing validation.Details
The VLBO (variational lower bound objective) loss weighting formula for the
x0parameterization branch is:Without the parentheses around
(1 - alphas_cumprod), the denominator becomes(2 - alphas_cumprod)which distorts the relative loss weights across timesteps. This matters for any training run that usesparameterization="x0"with the VLBO loss term.The NaN guard
assert not torch.isnan(x).all()only triggers when every element is NaN. Changing to.any()ensures the assertion catches even a single NaN, which is the expected safety check behavior.Test plan
lvlb_weightsvalues match the expected VLBO formula for bothepsandx0parameterizationslvlb_weightsafter initialization with standard schedules