Repository navigation
Conversation
This was referenced Oct 19, 2026
Open
…e the student's samples
zhihengy
force-pushed
the
dmd2/04-critic
branch
from
October 19, 2026 23:26
b9b818c to
79e0d90
Compare
This branch has not been deployed
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.
Fourth of the DMD2 stacked series, on top of #331.
--loss-type dmd2adds acritictrainer group that trains before the actor on every rollout. The critic starts from the teacher by default, learns the student's samples, then scores them with the frozen teacher and itself. The actor's generator loss arrives in [DMD2 5/7]; until then--loss-type dmd2takes the actor's prepare and loss hooks from the user.What
--loss-type dmd2selectsdata_conversion_hub.dmd2.expand_samples_to_train_pairs. Each sample comes from a rollout thatstop_at_random_step([DMD2 3/7] feat(rollout): stop the rollout at a random step for DMD2 backward simulation #331) stopped at stepi, and becomes one pair:latent = x_i,x0 = x̂0_i,timestep,sigma = σ_i,step_index = i, the cond and the sample index. Rewards are ignored.compute_trainer_argsreturns{"critic": ..., "actor": ...}underdmd2; other loss types still get{"actor": args}. The critic's args are a copy with these overrides:--hf-checkpointis the new--critic-load, which defaults to--teacher-load;--lris the new--critic-lr, which defaults to--lr;--load/--savepoint to sibling<dir>_criticdirs, the upstream--critic-savedefault;num_steps_per_rolloutis--dmd2-critic-steps-per-rollout(K, default 5), over the same DP shard as the actor;loss_hub.dmd2andloss_hub.sft.The actor's copy drops
--teacher-load, so only the critic group holds the teacher.Critic steps (
prepare_critic_batch) use the SFT flow-matching loss on the student'sx̂0_iwith the rollout's positive cond. The hook builds SFT-shaped pairs and callsprepare_sft_batch, so the critic's inputs, targets and seeds are exactly SFT's.Scoring (
predict_teacher_and_critic_x0) is the train-output hook from [DMD2 2/7] feat(ray): hand earlier trainer groups' outputs to later groups as external_data #330 and runs after the K steps.x̂0_iis re-noised at one σ from the--fsdp-flow-shiftgrid, limited to 2–98% of the train timesteps (the reference range). σ and the noise arestable_hash-seeded per rollout, micro-batch and DP rank.--dmd2-teacher-guidance-scaleover the rollout's negative cond. The critic predicts unguided.ctx.external_data["critic"].EMAOptimizer.use_weightsdoes, so sleep moves shards.Train metrics of a non-actor group carry its role:
train/critic-loss,train/critic-grad_norm,train/critic-lr. Upstream miles'log_train_stepdoes the same. The actor's keys don't change.validate_dmd2_argsinarguments.py:--teacher-load,--dmd2-teacher-guidance-scale >= 1and a visual--fsdp-flow-shift;It only rejects; defaults stay in
set_default_diffusion_args.--critic-loadand--critic-lrwithout--loss-type dmd2are rejected because nothing would read them.Docs:
cli-reference.md,customization.md,fsdp_model_roles.md.Why
FSDPTrainRayActorwith SFT hooks and the teacher as its frozen model, so the only change to the class is the metric names. Upstream miles builds its PPO critic the same way._compute_critic_overridesoverrides load, save and lr; the critic trains first, and the actor receives its outputs asexternal_data.--guidance_lrnext to--generator_lr. FastVideo's DMD2 gives each of student, teacher and critic its owninit_from, and the critic its ownfake_score_learning_rate(8e-6 against the student's 2e-6 in its Wan recipe). Upstream miles' PPO critic has--critic-load/--critic-lr, defaulting to--load/--lr. Here the student, teacher and critic start from--hf-checkpoint,--teacher-loadand--critic-load.gagainst its own recomputed x0 in [DMD2 5/7], so g's normalizer uses the trainer's x0, as in the reference.Known gap
When guidance is 1 the engine doesn't encode the negative prompt, so
denoising_env.neg_cond_kwargsis empty. Teacher CFG above 1 then raises an explicit error. Returning the negative cond without running CFG needs a small sglang-miles change, which will be a follow-up. Until then the teacher can only run unguided.Tests
tests/fast/backends/fsdp_utils/test_loss_hub_dmd2.py:prepare_sft_batchon (x̂0_i, positive cond).x_sand σ are reproduced from the seed, and σ stays within 2–98% of the grid.tests/fast/rollout/test_dmd2_convert.py: one pair per stopped sample. Full trajectories and trajectories that run past their first returned step are rejected.tests/fast/rollout/test_placement_group.py:dmd2adds a trainer.--critic-loadat--critic-lr, with sibling checkpoint dirs and K steps.tests/fast/utils/test_dmd2_arguments.py: valid args pass unchanged, and each unsupported combination is rejected.--critic-load/--critic-lrdefault to--teacher-load/--lrunless set, and are rejected withoutdmd2.Checklist
pre-commithooks (black, isort, ruff at the pinned versions) pass on the changed filespytest tests/fastis green (549 passed, 6 skipped; 518 on [DMD2 3/7] feat(rollout): stop the rollout at a random step for DMD2 backward simulation #331)python3 train_diffusion.py --helpstill parses (dmd2and the four new flags are listed)--dmd2-critic-steps-per-rollout,--dmd2-teacher-guidance-scale,--critic-load,--critic-lr)Stack
DMD2: distill a flow-matching teacher into a few-step student with distribution matching. Merge in order:
external_data--loss-type dmd2on the actor