Skip to content

fix: align denoising score target with energy gradient - #333

Merged
soran-ghaderi merged 1 commit into
soran-ghaderi:nightlyfrom
LucasLeao18:fix/dsm-score-sign
Sep 15, 2026
Merged

soran-ghaderi merged 1 commit into
soran-ghaderi:nightlyfrom
LucasLeao18:fix/dsm-score-sign

Conversation

@LucasLeao18

Copy link
Copy Markdown
Contributor

Problem

BaseScoreMatching.compute_score() returns grad E, but denoising score matching compared it with the conditional log-density score -noise / sigma^2. The opposite conventions make DSM train a quadratic energy in the wrong direction.

Solution

Match the energy gradient against noise / sigma^2, the negative of the conditional log-density score.

The regression test starts a closed-form quadratic energy at zero scale. Standard normal data should push that scale positive, so the loss gradient must be negative. The test applies the same check to exact, denoising, and sliced score matching, pinning their shared convention. On the original code only the DSM case fails (grad = +1.9391); after this change all three pass.

Validation

  • pytest tests/losses/test_denoising_score_matching.py -v — 9 passed, 1 CUDA skip
  • pytest tests/ -v — 1764 passed, 108 skipped, 21 deselected
  • git diff --check

Closes #318

@soran-ghaderi soran-ghaderi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. it's clean and woring correctly. will be included in the next release.

@soran-ghaderi
soran-ghaderi changed the base branch from master to nightly September 15, 2026 01:48
@soran-ghaderi
soran-ghaderi merged commit da5a85d into soran-ghaderi:nightly Sep 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DenoisingScoreMatching learns an inverted energy

2 participants