Skip to content

Add DMD2 and f-distill training losses - #2202

Draft
CharlelieLrt wants to merge 4 commits into
NVIDIA:mainfrom
CharlelieLrt:diffusion-distribution-matching
Draft

CharlelieLrt wants to merge 4 commits into
NVIDIA:mainfrom
CharlelieLrt:diffusion-distribution-matching

Conversation

@CharlelieLrt

@CharlelieLrt CharlelieLrt commented Oct 29, 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 #2205.
The preceding PhysicsNeMo stack would remain available.

Review process

This draft replaces PhysicsNeMo #2097 and comes from the personal fork. This migration preserves the implementation. The first commit also includes the requested documentation clarifications.

Review the isolated commit diff for this layer. Each branch adds one commit to its prerequisite branch. All replacement PRs target upstream main, so later PRs include prerequisite commits awaiting merge in their Files changed tab. After prerequisites merge, update the remaining branches to remove them from those diffs.

Signed-off-by: Charlelie Laurent <claurent@nvidia.com>
Signed-off-by: Charlelie Laurent <claurent@nvidia.com>
Signed-off-by: Charlelie Laurent <claurent@nvidia.com>
Signed-off-by: Charlelie Laurent <claurent@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 29, 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 d9228f8bfe2b. An approval covers every file listed for that owner; one owner is sufficient for shared files.

⏳ @CharlelieLrt — 54 file(s)
  • docs/api/diffusion/distillation.rst
  • docs/api/diffusion/introduction.rst
  • docs/api/diffusion/models.rst
  • docs/api/diffusion/noise_schedulers.rst
  • docs/api/diffusion/preconditioners.rst
  • physicsnemo/diffusion/init.py
  • physicsnemo/diffusion/_fastgen.py
  • physicsnemo/diffusion/base.py
  • physicsnemo/diffusion/distillation/init.py
  • physicsnemo/diffusion/distillation/_fastgen.py
  • physicsnemo/diffusion/distillation/base.py
  • physicsnemo/diffusion/distillation/losses.py
  • physicsnemo/diffusion/distillation/methods/init.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
  • physicsnemo/diffusion/distillation/methods/meanflow/init.py
  • physicsnemo/diffusion/distillation/methods/meanflow/_fastgen.py
  • physicsnemo/diffusion/distillation/methods/scm/init.py
  • physicsnemo/diffusion/distillation/methods/scm/_fastgen.py
  • physicsnemo/diffusion/metrics/losses.py
  • physicsnemo/diffusion/noise_schedulers/init.py
  • physicsnemo/diffusion/noise_schedulers/_fastgen.py
  • physicsnemo/diffusion/noise_schedulers/edm.py
  • physicsnemo/diffusion/noise_schedulers/iddpm.py
  • physicsnemo/diffusion/noise_schedulers/linear_gaussian.py
  • physicsnemo/diffusion/noise_schedulers/rectified_flow.py
  • physicsnemo/diffusion/noise_schedulers/trigflow.py
  • physicsnemo/diffusion/noise_schedulers/ve.py
  • physicsnemo/diffusion/noise_schedulers/vp.py
  • physicsnemo/diffusion/preconditioners/init.py
  • physicsnemo/diffusion/preconditioners/preconditioners.py
  • physicsnemo/diffusion/utils/model_wrappers.py
  • test/diffusion/data/distillation_meanflow_weighted.pth
  • test/diffusion/data/distillation_scm_weighted.pth
  • test/diffusion/data/trigflow_precond_conv.mdlus
  • test/diffusion/data/trigflow_precond_conv_coefficients.pth
  • test/diffusion/data/trigflow_precond_conv_forward.pth
  • test/diffusion/data/trigflow_precond_conv_sigma.pth
  • test/diffusion/data/trigflow_precond_linear.mdlus
  • test/diffusion/data/trigflow_precond_linear_coefficients.pth
  • test/diffusion/data/trigflow_precond_linear_forward.pth
  • test/diffusion/data/trigflow_precond_linear_sigma.pth
  • test/diffusion/helpers.py
  • test/diffusion/test_distillation_api.py
  • test/diffusion/test_distillation_losses.py
  • test/diffusion/test_distribution_distillation.py
  • test/diffusion/test_fastgen_network.py
  • test/diffusion/test_fastgen_noise_scheduler.py
  • test/diffusion/test_model_io.py
  • test/diffusion/test_noise_schedulers.py
  • test/diffusion/test_preconditioners.py
  • test/diffusion/test_trigflow.py
⏳ @coreyjadams — 1 file(s)
  • pyproject.toml
⏳ @ktangsali — 2 file(s)
  • docs/api_diffusion.rst
  • pyproject.toml
⏳ @megnvidia — 6 file(s)
  • docs/api/diffusion/distillation.rst
  • docs/api/diffusion/introduction.rst
  • docs/api/diffusion/models.rst
  • docs/api/diffusion/noise_schedulers.rst
  • docs/api/diffusion/preconditioners.rst
  • docs/api_diffusion.rst

No CODEOWNER

  • .importlinter
  • CHANGELOG.md
  • uv.lock

Comment /codeowners-info to refresh.

This branch has not been deployed

No deployments
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