Skip to content

[DMD2 10/10] feat(dmd2): train_dmd2.py and --dmd2-critic-scoring original, the reference's separate scoring - #351

Open
zhihengy wants to merge 5 commits into
mainfrom
dmd2/07-original-scoring
Open

zhihengy wants to merge 5 commits into
mainfrom
dmd2/07-original-scoring

Conversation

@zhihengy

@zhihengy zhihengy commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Tenth and last of the DMD2 stacked series, on main now that #343, #367, #368 and #372 are in. Adds --dmd2-critic-scoring original: tianweiy/DMD2's scoring, a separate noise draw and a critic forward on the last step's samples before the critic trains on them. The default, reuse-critic-step, keeps the current behavior, where that step's training forward doubles as the critic's score. The two differ only in whether the scoring shares the critic's last SFT draw and forward, so a run of each isolates what that reuse costs or buys.

DMD2 gets its own driver for this, train_dmd2.py, as async NFT has train_diffusion_async.py: the critic / actor order of a rollout is written out there, instead of a generic phase schedule in train_diffusion.py.

What

  • --dmd2-critic-scoring {reuse-critic-step, original}, default reuse-critic-step (no behavior change).
  • train_dmd2.py: the entrypoint for --loss-type dmd2 (train_diffusion.py now rejects it). Per rollout, with K = --dmd2-critic-steps-per-rollout:
    • reuse-critic-step: critic trains its K steps → actor trains on its scores.
    • original: critic trains steps 0..K−2 → critic scores the last step's pairs, forward only → actor trains on the scores → critic trains step K−1. With K = 1 the first train is dropped.
    • A group saves after its last train of the rollout and, under --offload-train, sleeps before another group wakes. The rest of the loop (eval, dataset save, weight update) is train_diffusion.py's.
  • FSDPTrainRayActor.train(..., optim_steps=(lo, hi)) trains that range of the rollout's optimizer steps with the micro-batch ids of the full run; a range outside the schedule, or one under --diffusion-recompute-old-log-prob, is rejected. The EMA steps once per rollout, by the call whose range ends at the last step.
  • FSDPTrainRayActor.compute(rollout_id, rollout_data_ref, external_data, hooks_key) runs the loss hub's (loss_type, hooks_key) hooks forward-only: their train-input selection, one no-grad forward per micro-batch through the trunk (_forward_train_pair_batch takes the hooks to run), numbered past the rollout's training micro-batches so no training forward shares a draw, then their train-output hook, boxed as train's output. The models are resharded after; the optimizer, scheduler, EMA and step count stay. RayTrainGroup.async_compute dispatches it per rank.
  • loss_hub.dmd2: the critic's scoring batch and the kept x0 are factored into prepare_scoring_batch and keep_scores, which both modes use. Under original the critic's last training step is plain SFT (full grid, no teacher, keeps nothing) and the new ("dmd2", "critic-scoring") hooks (prepare_scoring_batch, scoring_formula with no loss, last_step_pairs, score_last_step_samples) score the last 1/K of the shard at the scoring draw with the critic before its last update.
  • wake_up is a no-op while the group is awake: a group that trains and then scores in one wake would otherwise wake twice, and waking a frozen model twice replaces its pinned host copies with its GPU parameters.
  • The H3 recipe passes train_script="train_dmd2.py" (its --reference evals keep train_diffusion.py). Docs: cli-reference.md, customization.md, launch-script.md.

Why

  • Both settings score the last step's batch with the critic after K−1 updates and before it trains on that batch, the reference's order ([DMD2 6/10]). reuse-critic-step lets the K-th SFT step and the scoring share one draw, restricted to the scoring range, and one forward. original is the control for that reuse: independent draws, one more critic forward per scored sample, and the critic's last step on the full grid. The scored sample set, dmd2_loss_formula and select_scored_pairs are the same.
  • Scoring after the critic's K steps, from the train-output hook, would need no new driver, but it is not the reference's order: the critic would have trained on the samples it scores, which pulls x0_fake toward them. So the critic's K steps are split around the actor.
  • A dedicated driver rather than a schedule: the order is one algorithm's, read top to bottom in one file, and the trainer offers only train over a step range and compute. The hooks of the forward-only pass sit in the loss hub's table like any other, and they call the shared prepare and keep functions directly, so the training-mode check (_is_scoring_step) cannot switch them off.
  • Cost of original per rollout: a critic forward per scored sample and, under --offload-train, one more sleep/wake of the critic and of the actor, since the critic returns after the actor. reuse-critic-step stays the default.

Tests

  • tests/fast/test_train_dmd2.py: the production driver loop on both modes with K = 1 and 3, with and without --offload-train: the event order, the actor's external_data ({"critic": scores}), saves after a group's last train, sleeps before another group; the critic trains exactly K steps per rollout and the actor once, with the scoring before the critic's last update; other loss types are rejected. test_train_diffusion.py: dmd2 is rejected.
  • test_train_optim_steps.py: a step range trains those steps only, with the full run's micro-batch ids; ranges outside the schedule and under the old-log-prob recompute are rejected; the EMA steps once per rollout, by the call that trains the last step.
  • test_compute_hooks.py: the kept pairs forward once each, numbered after the full schedule's micro-batches, through the hooks handed in; the models are resharded; the step count stays. test_train_output_handoff.py: compute unboxes external_data and boxes its output like train. test_reference_models.py: the trunk runs the hooks it is handed instead of the group's.
  • test_loss_hub_dmd2.py: under original the last step is plain SFT and keeps nothing; the scoring batch equals the reuse mode's last-step batch at the same micro-batch id (draw, sigmas, teacher scale, conds); scoring_formula returns no loss and the kept x0 equal x_s − σ v of the critic's and the teacher's forwards; last_step_pairs is the set select_scored_pairs keeps. test_loss_hub_selection.py: the new table entry.
  • test_placement_group.py: rank pairing of async_train with a step range and of async_compute. test_sleep_wake.py: sleep → wake → wake → sleep moves the models and optimizer once each way.

Validation on CI (2 x H200, the #366 proxy)

Both modes ran the #366 proxy (2 rollouts of 4 prompts, 2 critic steps, 1 student step, --deterministic-mode, --fsdp-cpu-offload) through train_dmd2.py on the 3gpu runner with record-e2e-standards.yml, from a temporary branch (deleted since) that carried this PR's commits on the current main (the output-store PRs, which this chain still predates) plus #366's e2e: commit df68b9f. This PR's head is that code rebased onto main after the chain merged, with the output-store follow-ups folded into their commits (compute materializes the stored tensors like train; train_dmd2.py releases the rollout after the last group's train, as train_diffusion.py does); neither changes a forward.

  • reuse-critic-step, https://github.com/radixark/miles_diffusion/actions/runs/43006736048: the recorded artifact equals the committed test_h3_t2va_dmd2_16xGPU_single_node_2xGPU_proxy.json bit for bit on all 22 metric points (the file differs only in its meta.commit). The default mode through the new driver, the step-range train and the hook table is the old loop.
  • original, https://github.com/radixark/miles_diffusion/actions/runs/43006739665 (a copy of the proxy with --dmd2-critic-scoring original, on the temporary branch only): completes; per rollout the log shows critic step → wake_up (no-op, 0.0 s) → compute (14.6 s: a critic and a teacher forward on the 2 kept samples) → critic sleeps → actor wakes, trains, sleeps → critic wakes, trains its last step → update_weights; critic steps 1–4 and student steps 1–2 all emit their metrics. Step 1 of the critic (the first SFT draw) and the rollout x0 statistics match the reuse run bit for bit; the scoring-dependent metrics differ, as the scoring draw is independent and the critic's last step runs on the full grid.
reuse-critic-step original
Job wall time (engine up → job succeeded) 48.8 min 47.6 min
Rollout 0: critic train / scoring / actor train / critic last step 569 s (both steps) / in the train / 355 s / – 294 s / 15 s / 298 s / 243 s
Rollout 1: same 479 s / in the train / 245 s / – 240 s / 15 s / 229 s / 220 s
Peak allocated per rank (critic, actor) 32.8 GB, 32.8 GB 32.8 GB, 32.8 GB
Device memory used after the scoring (critic) 50.9 / 51.2 GB 49.9 / 50.1 GB
Device memory used after the actor's step 46.7 / 47.3 GB 47.0 / 47.3 GB

The two CPU-offloaded 31B optimizers dominate the step times, so the per-step spread (569 s vs 479 s for the same two reuse steps) is the runner, not the mode; original's extra cost at this size is the 15 s compute and one more sleep/wake pair per rollout.

Checklist

  • pre-commit hooks (black, isort, ruff at the pinned versions) pass on the changed files
  • Added/updated tests for new behaviour
  • pytest tests/fast: 727 passed, 3 skipped; the 5 failures in test_loss_hub_flow_grpo.py fail on plain main as well (rockdu/fix-flow-grpo-loss-test), the other 3 and the 4 collection errors are the local env's missing radix_transfer_plugins on this head (on main at f853234; the output-store files that need radix_transfer_plugins are the usual local collection errors)
  • python3 train_diffusion.py --help and python3 train_dmd2.py --help parse; --dmd2-critic-scoring is listed
  • The public flag appears in the CLI reference docs
  • No example added

Stack

DMD2: distill a flow-matching teacher into a few-step student with distribution matching. Merge in order:

  1. [DMD2 1/10] [DMD2 1/10] refactor(ray): build each trainer's args from a trainer config list #335: per-trainer args from a trainer config list
  2. [DMD2 2/10] [DMD2 2/10] feat(ray): train several colocated trainer groups in the sync driver #329: several colocated trainer groups in the sync driver
  3. [DMD2 3/10] [DMD2 3/10] feat(ray): hand earlier trainer groups' outputs to later groups as external_data #330: hand earlier trainer groups' outputs to later groups as external_data
  4. [DMD2 4/10] [DMD2 4/10] feat(fsdp): add a train-input hook that preprocesses train pairs before micro-batching #338: a train-input hook that preprocesses a trainer group's train pairs before micro-batching
  5. [DMD2 5/10] [DMD2 5/10] feat(rollout): stop the rollout at a random step for DMD2 backward simulation #331: few-step rollout and the DMD2 step strategy (needs [Feat] diffusion-rl: stop a rollout at a requested step sgl-project/sglang#45230)
  6. [DMD2 6/10] [DMD2 6/10] feat(dmd2): train a fake-score critic group from the teacher and score the student's samples #333: DMD2 critic group: critic training and teacher/critic scoring of its last step
  7. [DMD2 7/10] [DMD2 7/10] feat(dmd2): train the student with the distribution matching gradient from the critic group's scores #334: --loss-type dmd2 on the actor
  8. [DMD2 8/10] [DMD2 8/10] perf(ray): sleep each trainer group right after its train #342: sleep each trainer group right after its train
  9. [DMD2 9/10] [DMD2 9/10] feat(dmd2): add the MiniMax H3 4-step DMD2 recipe with eval media and DMD2 metrics #343: MiniMax H3 4-step DMD2 recipe, eval media and DMD2 metrics
  10. refactor(fsdp): select loss hooks by a (loss_type, role) table #367, refactor(fsdp): DiffusionLossContext stops carrying loop state #368 (loss hooks by (loss_type, role), loop state as hook arguments) and refactor(fsdp): run the DMD2 teacher forward in the actor, requested by the critic's prepare hook #372 (the teacher forward in the trunk), merged
  11. [DMD2 10/10] this PR: train_dmd2.py and --dmd2-critic-scoring original

A GAN head and other follow-ups come after this series.

@zhihengy
zhihengy added this pull request to stack #339 November 2, 2026 10:06
@zhihengy
zhihengy force-pushed the dmd2/07-original-scoring branch from ba4bb14 to f50339e Compare November 9, 2026 22:16
@zhihengy
zhihengy force-pushed the dmd2/07-original-scoring branch from f50339e to 0c5ceec Compare November 10, 2026 12:53
Rockdu added a commit that referenced this pull request Nov 11, 2026
prepare_critic_batch did three things in one body: build the SFT batch,
pick the scoring step's grid range, and collate the teacher's CFG inputs.
The teacher part is its own function now, _request_teacher_forward, and
the two helpers it shared with #351 are back, so the critic's prepare
reads as SFT plus the last step's teacher request. No behaviour change.
@zhihengy
zhihengy force-pushed the dmd2/07-original-scoring branch from 0c5ceec to a6e8635 Compare November 11, 2026 11:00
@zhihengy zhihengy changed the title [DMD2 10/10] feat(dmd2): add --dmd2-critic-scoring original, the reference's separate scoring before the critic's last step [DMD2 10/10] feat(dmd2): train_dmd2.py and --dmd2-critic-scoring original, the reference's separate scoring Nov 11, 2026
@zhihengy
zhihengy force-pushed the dmd2/07-original-scoring branch from a6e8635 to 36222f1 Compare November 11, 2026 11:54
Rockdu added a commit that referenced this pull request Nov 11, 2026
prepare_critic_batch did three things in one body: build the SFT batch,
pick the scoring step's grid range, and collate the teacher's CFG inputs.
The teacher part is its own function now, _request_teacher_forward, and
the two helpers it shared with #351 are back, so the critic's prepare
reads as SFT plus the last step's teacher request. No behaviour change.
@Rockdu
Rockdu marked this pull request as draft November 11, 2026 13:04
Base automatically changed from dmd2/06-h3-recipe to main November 11, 2026 15:45
Rockdu added a commit that referenced this pull request Nov 11, 2026
…by the critic's prepare hook (#372)

* feat(ray): hand earlier trainer groups' outputs to later groups as external_data

* fix(fsdp): box the train output so the driver's ray.get only waits

`train` returned its train output directly, so the driver's ray.get on the
train refs pulled every rank's output into the controller before the next
group read it again from the object store. Return `Box(ray.put(output))`
like the rollout shards: the driver gets a small box, the payload stays in
the store until the paired rank of a later group unboxes it.

Also note the train-output hook as a `--teacher-load` consumer in
docs/fsdp_model_roles.md, which cli-reference.md already did.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* fix(ray): hand later trainer groups the output boxes, not the raw refs

train returns Box(ray.put(output)); the driver discarded its ray.get and
passed the task refs on, so the consumer's box.inner hit an ObjectRef.
Keep the boxes the way the rollout shards are kept.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* feat(fsdp): add a train-input hook that preprocesses train pairs before micro-batching

* refactor(fsdp): rename the train-input hook to custom_train_input_postprocess

Review on #338: `custom_train_input_postprocess_func` says what the hook
does, a post-processing step on the converted train pairs. The flag
follows the prepare hook's pattern: `--custom-train-input-postprocess-path`
sets `args.custom_train_input_postprocess_path`, loaded into
`self.custom_train_input_postprocess_func`. Docs and the hook test follow.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* feat(rollout): stop the rollout at a random step for DMD2 backward simulation

* feat(dmd2): train a fake-score critic group from the teacher and score the student's samples

* feat(dmd2): train the student with the distribution matching gradient from the critic group's scores

* fix(dmd2): follow the train-input hook rename in the DMD2 defaults

#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>

* perf(ray): sleep each trainer group right after its train

* feat(dmd2): add the MiniMax H3 4-step DMD2 recipe with the media and metrics to judge it

* feat(dmd2): skip the engine's VAE decode of training rollouts when no reward reads the media

* build: declare imageio-ffmpeg, which the eval media muxing imports

miles/ray/rollout.py imports imageio_ffmpeg to mux the eval audio; the
GPU image had it only as a transitive dependency and the hosted CPU
suite not at all, so tests/fast/rollout/test_eval_media.py failed to
import there.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* docs(h3): say the DMD2 recipe downloads the VidProM prompt list from the Hub

* docs(dmd2): count the VidProM prompts after dedup

* fix(dmd2): load the FastH3 reference by its Hub id on every node

* refactor(args): drop the teacher consumer check

Whether a hook forwards the teacher is the hook's business; the argument
layer cannot tell from --loss-type and the hook paths who will read it,
so the check only ever guessed. --teacher-load is now accepted under every
loss type (dmd2 still requires it).

* refactor(fsdp): select loss hooks from a (loss_type, role) table

Stop filling the --custom-*-path arguments on behalf of nft / dmd2 and
stop overriding them per trainer role: a group's prepare, formula,
train-input and train-output hooks come from loss_hub.LOSS_HOOKS keyed by
(loss_type, role), the way miles core's get_loss_function does. Only
custom_loss reads the path flags. The critic overrides shrink to the six
values that really differ (checkpoint, lr, load/save dirs, steps, batch).

* fix(args): reject --custom-*-path outside --loss-type custom_loss

A path given under any other loss type would be silently ignored now that
the table selects the hooks, so fail at parse time instead.

* fix(args): reject --diffusion-recompute-old-log-prob under dmd2

DMD2 has no log-prob ratio to recompute, and once the recompute loop
passes its real step index the critic's last window would run its
scoring prepare and formula a second time. sft_loss and nft already
reject the flag.

* refactor(fsdp): pass the loop counters to the hooks as arguments

microbatch_id and optim_step_idx were written onto DiffusionLossContext
before every forward and read back by the hooks; the planned micro-batch
prefetch would race on them. They are now required keyword arguments of
every prepare and formula hook, passed by the two trunk loops; the
numbering is unchanged (training from 0, the old-log-prob recompute of
windows 1.. reuses their training forwards' numbers).

* refactor(fsdp): hand the train-output list to the hooks as an argument

The DMD2 critic formula appended its scoring inputs to a list on the
context and the train-output hook read them back: a hook-to-hook channel
invisible in the call graph. The trunk now owns one list per train call
and passes it to the formulas and to the train-output hook.

* refactor(fsdp): freeze DiffusionLossContext

Nothing writes the context after construction any more: it is the
rollout-level, read-only view the hooks share. eq=False keeps identity
comparison; a synthesized hash would fail on the dict fields.

* refactor(fsdp): run the DMD2 teacher forward in the actor, requested by the critic's prepare hook

* fix(fsdp): run the teacher forward without the student's true_cfg_scale

* refactor(dmd2): pull the teacher request out of prepare_critic_batch

prepare_critic_batch did three things in one body: build the SFT batch,
pick the scoring step's grid range, and collate the teacher's CFG inputs.
The teacher part is its own function now, _request_teacher_forward, and
the two helpers it shared with #351 are back, so the critic's prepare
reads as SFT plus the last step's teacher request. No behaviour change.

---------

Co-authored-by: Claude Mythos 5.1 <noreply@anthropic.com>
Co-authored-by: rockdu <kangrdu@gmail.com>
zhihengy and others added 5 commits November 11, 2026 21:58
A group that trains and then scores in the same wake would wake twice, and waking a frozen model twice replaces its
pinned host copies with its GPU parameters, so the next sleep would leave the teacher on the GPU.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
`train(..., optim_steps=(lo, hi))` runs windows lo..hi-1 of the rollout's micro-batch schedule with the micro-batch
ids of the full run, so a range draws the same noise as the whole rollout would; a range outside the schedule, or
one under --diffusion-recompute-old-log-prob, is rejected. The EMA steps once per rollout, by the call whose range
ends at the last step. `RayTrainGroup.async_train` passes the range through.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
`FSDPTrainRayActor.compute(rollout_id, rollout_data_ref, external_data, hooks_key)` runs the loss hub's
`(--loss-type, hooks_key)` hooks without grad: their train-input selection, one forward per micro-batch through the
trunk (`_forward_train_pair_batch` takes the hooks to run instead of the group's), numbered past the rollout's
training micro-batches so no training forward shares a draw, then their train-output hook, boxed as train's output
is. The models are resharded after; the optimizer, scheduler, EMA and step count stay. `RayTrainGroup.async_compute`
dispatches it per rank like `async_train`.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
…ate scoring forward

`reuse-critic-step` (default, no behavior change): the critic's last training step draws in the scoring range, asks
for the teacher and keeps both x0 as the score. `original`: that step is plain SFT and keeps nothing; the new
`("dmd2", "critic-scoring")` hooks, run forward-only by `FSDPTrainRayActor.compute`, score the last step's pairs
(`last_step_pairs`) at the scoring draw with the critic before its last update, as tianweiy/DMD2 does. Both modes share
`prepare_scoring_batch` and `keep_scores`, so they score the same function of the same draw.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
…actor within a rollout

`--loss-type dmd2` runs through its own entrypoint, as async NFT does: under `reuse-critic-step` the critic trains
and the actor trains on its scores; under `original` the critic trains steps 0..K-2, scores forward-only, the actor
trains on the scores and the critic trains step K-1. A group saves after its last train of the rollout and, under
--offload-train, sleeps before another group wakes. `train_diffusion.py` sends dmd2 here; the H3 recipe passes
`train_script="train_dmd2.py"` (its reference evals keep train_diffusion.py).

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
@zhihengy
zhihengy force-pushed the dmd2/07-original-scoring branch from 36222f1 to d0c8631 Compare November 11, 2026 22:02
@zhihengy
zhihengy marked this pull request as ready for review November 16, 2026 22:51
Rockdu added a commit that referenced this pull request Nov 25, 2026
…#366)

* feat(ray): hand earlier trainer groups' outputs to later groups as external_data

* fix(fsdp): box the train output so the driver's ray.get only waits

`train` returned its train output directly, so the driver's ray.get on the
train refs pulled every rank's output into the controller before the next
group read it again from the object store. Return `Box(ray.put(output))`
like the rollout shards: the driver gets a small box, the payload stays in
the store until the paired rank of a later group unboxes it.

Also note the train-output hook as a `--teacher-load` consumer in
docs/fsdp_model_roles.md, which cli-reference.md already did.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* fix(ray): hand later trainer groups the output boxes, not the raw refs

train returns Box(ray.put(output)); the driver discarded its ray.get and
passed the task refs on, so the consumer's box.inner hit an ObjectRef.
Keep the boxes the way the rollout shards are kept.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* feat(fsdp): add a train-input hook that preprocesses train pairs before micro-batching

* refactor(fsdp): rename the train-input hook to custom_train_input_postprocess

Review on #338: `custom_train_input_postprocess_func` says what the hook
does, a post-processing step on the converted train pairs. The flag
follows the prepare hook's pattern: `--custom-train-input-postprocess-path`
sets `args.custom_train_input_postprocess_path`, loaded into
`self.custom_train_input_postprocess_func`. Docs and the hook test follow.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* feat(rollout): stop the rollout at a random step for DMD2 backward simulation

* feat(dmd2): train a fake-score critic group from the teacher and score the student's samples

* feat(dmd2): train the student with the distribution matching gradient from the critic group's scores

* fix(dmd2): follow the train-input hook rename in the DMD2 defaults

#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>

* perf(ray): sleep each trainer group right after its train

* feat(dmd2): add the MiniMax H3 4-step DMD2 recipe with the media and metrics to judge it

* feat(dmd2): skip the engine's VAE decode of training rollouts when no reward reads the media

* build: declare imageio-ffmpeg, which the eval media muxing imports

miles/ray/rollout.py imports imageio_ffmpeg to mux the eval audio; the
GPU image had it only as a transitive dependency and the hosted CPU
suite not at all, so tests/fast/rollout/test_eval_media.py failed to
import there.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* docs(h3): say the DMD2 recipe downloads the VidProM prompt list from the Hub

* docs(dmd2): count the VidProM prompts after dedup

* fix(dmd2): load the FastH3 reference by its Hub id on every node

* refactor(args): drop the teacher consumer check

Whether a hook forwards the teacher is the hook's business; the argument
layer cannot tell from --loss-type and the hook paths who will read it,
so the check only ever guessed. --teacher-load is now accepted under every
loss type (dmd2 still requires it).

* refactor(fsdp): select loss hooks from a (loss_type, role) table

Stop filling the --custom-*-path arguments on behalf of nft / dmd2 and
stop overriding them per trainer role: a group's prepare, formula,
train-input and train-output hooks come from loss_hub.LOSS_HOOKS keyed by
(loss_type, role), the way miles core's get_loss_function does. Only
custom_loss reads the path flags. The critic overrides shrink to the six
values that really differ (checkpoint, lr, load/save dirs, steps, batch).

* fix(args): reject --custom-*-path outside --loss-type custom_loss

A path given under any other loss type would be silently ignored now that
the table selects the hooks, so fail at parse time instead.

* fix(args): reject --diffusion-recompute-old-log-prob under dmd2

DMD2 has no log-prob ratio to recompute, and once the recompute loop
passes its real step index the critic's last window would run its
scoring prepare and formula a second time. sft_loss and nft already
reject the flag.

* refactor(fsdp): pass the loop counters to the hooks as arguments

microbatch_id and optim_step_idx were written onto DiffusionLossContext
before every forward and read back by the hooks; the planned micro-batch
prefetch would race on them. They are now required keyword arguments of
every prepare and formula hook, passed by the two trunk loops; the
numbering is unchanged (training from 0, the old-log-prob recompute of
windows 1.. reuses their training forwards' numbers).

* refactor(fsdp): hand the train-output list to the hooks as an argument

The DMD2 critic formula appended its scoring inputs to a list on the
context and the train-output hook read them back: a hook-to-hook channel
invisible in the call graph. The trunk now owns one list per train call
and passes it to the formulas and to the train-output hook.

* refactor(fsdp): freeze DiffusionLossContext

Nothing writes the context after construction any more: it is the
rollout-level, read-only view the hooks share. eq=False keeps identity
comparison; a synthesized hash would fail on the dict fields.

* refactor(fsdp): run the DMD2 teacher forward in the actor, requested by the critic's prepare hook

* fix(fsdp): run the teacher forward without the student's true_cfg_scale

* refactor(dmd2): pull the teacher request out of prepare_critic_batch

prepare_critic_batch did three things in one body: build the SFT batch,
pick the scoring step's grid range, and collate the teacher's CFG inputs.
The teacher part is its own function now, _request_teacher_forward, and
the two helpers it shared with #351 are back, so the critic's prepare
reads as SFT plus the last step's teacher request. No behaviour change.

* test(e2e): run the H3 DMD2 recipe as a 2-GPU proxy in CI

The DMD2 recipe only knew its 2 x 8 topology. Give it the knobs an e2e
needs: --num-nodes / --num-gpus-per-node (one node starts its own ray
cluster), --critic-steps-per-rollout, --eval-interval 0 / --save-interval 0
to drop eval and checkpoints (0 used to reach should_run_periodic_action's
modulo), --fsdp-cpu-offload and --master-dtype. The three 31B models do not
fit two GPUs with their optimizers, so the proxy keeps parameters, gradients
and optimizer states in host memory with a bf16 master and steps on the CPU.

tests/e2e/short/test_h3_t2va_dmd2_2xGPU.py runs 2 rollouts of 4 prompts
(2 critic steps of 2, 1 student step on the last 2) under --deterministic-mode
and checks the critic loss and grad norm, the student grad norm and the DMD2
metrics against the recorded standard. The 16-GPU defaults are unchanged.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* test(e2e): record the H3 DMD2 standard on CI and name the test as a proxy

The standard comes from record-e2e-standards.yml on the 3gpu runner
(run 42809959116, sglang zhihengy/sglang:dmd2/h3-dmd2-e2e), not from a
local run. The test is renamed to the 16xGPU_single_node_2xGPU_proxy
form the wan22 and krea2 proxies use, since it runs the 16-GPU recipe
shrunk to two GPUs.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* test(e2e): re-record the H3 DMD2 standard on sglang-miles

record-e2e-standards.yml run 43032161294 on the 3gpu runner, this branch
at daff1b5 on sglang-miles 47930723 (the tip with sgl-project/sglang#49440
and #49143, so no ci-sglang-pr override). All 22 metric points match the
two records on the previous combo branch bit for bit; only meta.commit moves.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

* test(e2e): run the H3 DMD2 proxy with LoRA adapters instead of CPU offload

The full-parameter 2-GPU proxy keeps about 1.6 TB in host memory and Ray's memory monitor
kills it whenever another e2e shares the CI node. The recipe script gets --lora: the student
and the critic train LoRA adapters over frozen bf16 bases (about 112 GB per GPU, about 530 GB
of host memory), and the e2e test uses it. The 16-GPU recipe stays full-parameter, and
--fsdp-cpu-offload still runs it on fewer GPUs. --loss-type dmd2 now accepts --use-lora.

* test(e2e): re-record the H3 DMD2 standard for the LoRA proxy

Recorded on the 3gpu CI runner by run 45285320503 at 439990e.

* docs(dmd2): state the LoRA proxy's GPU memory as the trainer reports it

* docs(h3): drop the single-node smoke section from the model page

The model page carries recipes meant to be run; the single-node --lora / --fsdp-cpu-offload modes are
smoke configurations for CI and development, documented where they live: the recipe script's docstring
and the e2e test. The section also copied the docstring word for word.

---------

Co-authored-by: Claude Mythos 5.1 <noreply@anthropic.com>
Co-authored-by: rockdu <kangrdu@gmail.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant