Skip to content

Add DMD2 and f-distill training losses - #2097

Closed
CharlelieLrt wants to merge 1 commit into
codex/diffusion-distillationfrom
codex/diffusion-distribution-matching
Closed

CharlelieLrt wants to merge 1 commit into
codex/diffusion-distillationfrom
codex/diffusion-distribution-matching

Conversation

@CharlelieLrt

@CharlelieLrt CharlelieLrt commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR extends DistillationLoss to DMD2 and f-distill. Users supply their
student, teacher, and auxiliary models, then choose the training phase explicitly
in their optimizer loop:

loss_fn = DistillationLoss(
    student, scheduler, method="DMD2", teacher=teacher,
    auxiliary_models={"fake_score": fake_score},
)
losses = loss_fn(x0, phase="auxiliary", step=step)
losses["total_loss"].backward()

The loss manages method-specific state, including f-distill ratio statistics,
while the caller controls phase order and optimizer updates. For adversarial
training, configure the teacher's feature_names and a
feature_fn(prediction, extras) callback that selects named features from its
output. The teacher always returns its prediction, even when the discriminator
uses only its features.

Weighted losses exclude masked values from residuals and applicable statistics.
For masked adversarial training, users provide an adversarial_fn callback
that excludes corrupted inputs during feature
extraction and weights the resulting discriminator scores. A pixel mask alone
cannot determine which discriminator scores are valid.

Checklist

  • This PR follows the contribution guidelines.
  • The documentation describes the API and its role in the stack.
  • This PR remains a draft.

Dependencies

If FastGen maintainers decline FastGen #44, we would close PhysicsNeMo #2100.
The preceding PhysicsNeMo stack would remain available.

Review process

Reviewers can compare this PR with its immediate parent. After a parent merges,
we update the remaining branches and their PR bases to keep each diff focused.

@CharlelieLrt CharlelieLrt added 2 - In Progress Currently a work in progress 5 - DO NOT MERGE Hold off on merging; see PR for details 5 - Merge After Dependencies Depends on another PR: do not merge out of order labels Oct 14, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown
Contributor

CODEOWNERS review map

Current for commit 6d301d6f2512. An approval covers every file listed for that owner; one owner is sufficient for shared files.

⏳ @CharlelieLrt — 8 file(s)
  • docs/api/diffusion/distillation.rst
  • physicsnemo/diffusion/distillation/losses.py
  • physicsnemo/diffusion/distillation/methods/dmd2/init.py
  • physicsnemo/diffusion/distillation/methods/dmd2/_fastgen.py
  • physicsnemo/diffusion/distillation/methods/f_distill/init.py
  • physicsnemo/diffusion/distillation/methods/f_distill/_fastgen.py
  • test/diffusion/helpers.py
  • test/diffusion/test_distribution_distillation.py
⏳ @megnvidia — 1 file(s)
  • docs/api/diffusion/distillation.rst

No CODEOWNER

  • CHANGELOG.md

Comment /codeowners-info to refresh.

@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch from e03650a to 5788d8a Compare October 14, 2026 05:35
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distribution-matching branch from 6d301d6 to 1f727bd Compare October 14, 2026 05:35
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distribution-matching branch from 1f727bd to a3caccc Compare October 14, 2026 17:03
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch 2 times, most recently from d1b90c9 to ac6b31b Compare October 16, 2026 01:19
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distribution-matching branch from a3caccc to 1e9b326 Compare October 16, 2026 01:19
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch from ac6b31b to e0d31b0 Compare October 16, 2026 02:52
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distribution-matching branch from 1e9b326 to 0263bdd Compare October 16, 2026 02:52
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch from e0d31b0 to 7d40640 Compare October 16, 2026 20:15
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distribution-matching branch 2 times, most recently from 6eb2025 to 28bfa6a Compare October 17, 2026 01:44
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch from 7d40640 to 036fccc Compare October 17, 2026 01:44
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch from 036fccc to d87a58a Compare October 28, 2026 03:42
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distribution-matching branch from 28bfa6a to ac444c0 Compare October 28, 2026 03:42
Signed-off-by: Charlelie Laurent <claurent@nvidia.com>
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch from d87a58a to 0a3860d Compare October 29, 2026 02:23
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distribution-matching branch from ac444c0 to 20a4d7a Compare October 29, 2026 02:23
@CharlelieLrt

Copy link
Copy Markdown
Collaborator Author

Continued in PhysicsNeMo #2202, from branch diffusion-distribution-matching in CharlelieLrt/modulus. The replacement preserves this implementation and includes the requested documentation clarifications. Please continue the review there. This PR retains the earlier discussion.

@CharlelieLrt
CharlelieLrt deleted the codex/diffusion-distribution-matching branch October 29, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2 - In Progress Currently a work in progress 5 - DO NOT MERGE Hold off on merging; see PR for details 5 - Merge After Dependencies Depends on another PR: do not merge out of order

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant