Skip to content

Add sCM and MeanFlow distillation losses - #2096

Closed
CharlelieLrt wants to merge 1 commit into
codex/diffusion-trigflowfrom
codex/diffusion-distillation
Closed

CharlelieLrt wants to merge 1 commit into
codex/diffusion-trigflowfrom
codex/diffusion-distillation

Conversation

@CharlelieLrt

@CharlelieLrt CharlelieLrt commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR introduces the alpha DistillationLoss API for training existing
PhysicsNeMo models with sCM or MeanFlow. Users install the optional
diffusion-fastgen extra, create a loss object, and call it from their own
optimizer loop:

loss_fn = DistillationLoss(student, scheduler, method="MeanFlow", teacher=teacher)
losses = loss_fn(x0, condition=condition, step=step)
losses["total_loss"].backward()

WeightedDistillationLoss supports pixel masks and soft weights, while the
BaseDistillationLoss contract lets users define native methods without FastGen.
The adapters remain private, so users continue to work with PhysicsNeMo models
and noise schedulers. The loss does not load teacher weights or manage
optimizers, and inference continues to use PhysicsNeMo samplers.

MeanFlow students receive (t, DiffusionExtraTimes(r=r, batch_size=[B])).
For sCM, models return their prediction paired with
DiffusionExtraOutputs(logvar=logvar, batch_size=[B]). Every forward call
returns a prediction tensor.

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 e03650a8fba5. An approval covers every file listed for that owner; one owner is sufficient for shared files.

⏳ @CharlelieLrt — 19 file(s)
  • docs/api/diffusion/distillation.rst
  • physicsnemo/diffusion/_fastgen.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/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/noise_schedulers/_fastgen.py
  • test/diffusion/data/distillation_meanflow_weighted.pth
  • test/diffusion/data/distillation_scm_weighted.pth
  • test/diffusion/helpers.py
  • test/diffusion/test_distillation_api.py
  • test/diffusion/test_distillation_losses.py
  • test/diffusion/test_fastgen_network.py
  • test/diffusion/test_fastgen_noise_scheduler.py
⏳ @coreyjadams — 1 file(s)
  • pyproject.toml
⏳ @ktangsali — 2 file(s)
  • docs/api_diffusion.rst
  • pyproject.toml
⏳ @megnvidia — 2 file(s)
  • docs/api/diffusion/distillation.rst
  • docs/api_diffusion.rst

No CODEOWNER

  • .importlinter
  • CHANGELOG.md
  • uv.lock

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-distillation branch from 5788d8a to d1b90c9 Compare October 14, 2026 17:03
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-trigflow branch from bda6a91 to ab1841d Compare October 16, 2026 01:19
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch from d1b90c9 to ac6b31b Compare October 16, 2026 01:19
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-trigflow branch from ab1841d to fbfcd1b Compare October 16, 2026 02:52
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch 2 times, most recently from e0d31b0 to 7d40640 Compare October 16, 2026 20:15
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-trigflow branch 2 times, most recently from 901fe94 to a9b6d79 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-trigflow branch from a9b6d79 to ff99456 Compare October 28, 2026 03:42
@CharlelieLrt
CharlelieLrt force-pushed the codex/diffusion-distillation branch from 036fccc to d87a58a Compare October 28, 2026 03:42
Signed-off-by: Charlelie Laurent <claurent@nvidia.com>
@CharlelieLrt

Copy link
Copy Markdown
Collaborator Author

Continued in PhysicsNeMo #2201, from branch diffusion-distillation 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-distillation 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