Repository navigation
[DMD2 7/10] feat(dmd2): train the student with the distribution matching gradient from the critic group's scores - #334
Merged
Merged
Conversation
This was referenced Oct 19, 2026
Merged
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
from
October 19, 2026 23:26
d9f0737 to
208e5b3
Compare
6 tasks done
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
from
October 21, 2026 06:08
208e5b3 to
3c9ec4a
Compare
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
from
October 23, 2026 21:20
3c9ec4a to
a53e480
Compare
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
from
October 23, 2026 23:47
a53e480 to
8f6f2f6
Compare
6 tasks done
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
from
October 24, 2026 00:09
8f6f2f6 to
7be2676
Compare
zhihengy
marked this pull request as ready for review
October 24, 2026 00:14
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
from
October 24, 2026 00:17
7be2676 to
701ad88
Compare
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
from
October 26, 2026 06:19
701ad88 to
40a9e8c
Compare
5 of 6 tasks
Merged
5 of 6 tasks
6 tasks done
Rockdu
force-pushed
the
dmd2/05-dmd2-loss
branch
from
November 4, 2026 19:41
40a9e8c to
1526969
Compare
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
2 times, most recently
from
November 10, 2026 03:59
ec28a5c to
8b569c1
Compare
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
from
November 10, 2026 11:44
8b569c1 to
439ad5c
Compare
4 tasks done
zhihengy
force-pushed
the
dmd2/05-dmd2-loss
branch
from
November 11, 2026 08:18
439ad5c to
0c30c25
Compare
Rockdu
force-pushed
the
dmd2/05-dmd2-loss
branch
3 times, most recently
from
November 11, 2026 15:44
b458443 to
573d59a
Compare
… from the critic group's scores
#338 renamed the hook to --custom-train-input-postprocess-path; the DMD2 defaults and the critic override still set custom_train_input_function_path, so --loss-type dmd2 failed in parse_args. Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
Rockdu
force-pushed
the
dmd2/05-dmd2-loss
branch
from
November 11, 2026 15:44
573d59a to
1401a22
Compare
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.
Seventh of the DMD2 stacked series, on top of #333.
--loss-type dmd2now trains the actor. It trains on the samples the critic group scored, the critic's last step, and for each the student recomputes its x0 at the rollout's stepi, then follows the teacher-minus-critic scores that the critic group handed over.What
select_scored_pairsis the actor's train-input hook ([DMD2 4/10] feat(fsdp): add a train-input hook that preprocesses train pairs before micro-batching #338): it keeps only the train pairs the critic scored, i.e. the last 1/K of its DP shard, before the actor builds its micro-batches. The trainer itself doesn't know about DMD2. Scores for samples outside the shard are rejected, so a broken rank pairing fails instead of shrinking the batch.prepare_generator_batch: the student's unguided forward at(x_i, t_i)with the pair's positive cond.dmd2_loss_formula:x0 = x_i - σ_i·v;g = nan_to_num((x̂0_fake - x̂0_real) / mean|x0 - x̂0_real|);loss = 0.5·mean((x0 - sg(x0 - g))²), so∂loss/∂x0 = g / numel.This is the reference gradient: tianweiy/DMD2
compute_distribution_matching_loss, with the same batch-mean MSE once the actor divides by the pair count.--loss-type dmd2fills these two hooks the waynftfills its own, andselect_scored_pairsas the train-input hook. The critic group runs without a train-input hook. [DMD2 6/10]'s requirement for user hooks is dropped.Metrics:
dmd2_grad_abs_mean;x0_mean_abs_diff,x0_max_abs_diffandx0_rel_max, which compare the trainer's x0 with the rollout'sx̂0_i(same step, same weights) through the existingrecord_rollout_train_abs_diff.Single DiT component only, as with NFT.
Why
x̂0_i. The normalizer and the gradient path use the trainer's x0. The two x0s differ only by rollout/train numerics, because the actor takes one step per rollout on synced weights. Thex0_*metrics measure that gap on every step.x_iitself.Tests
tests/fast/backends/fsdp_utils/test_loss_hub_dmd2.py:tests/fast/utils/test_dmd2_arguments.py:dmd2fills the converter, prepare, loss and train-input paths, but never over a user's own.tests/fast/utils/test_trainer_config.py: the critic group runs without the train-input hook.Checklist
pre-commithooks (black, isort, ruff at the pinned versions) pass on the changed filespytest tests/fast: 559 passed, 7 skipped; the same 4 environment failures as [DMD2 6/10] feat(dmd2): train a fake-score critic group from the teacher and score the student's samples #333python3 train_diffusion.py --helpstill parses (no flags added)customization.mdtable lists thedmd2hooks)Stack
DMD2: distill a flow-matching teacher into a few-step student with distribution matching. Merge in order:
external_data--loss-type dmd2on the actorA GAN head and other follow-ups come after this series.