Skip to content

[DMD2 10/10] feat(dmd2): --dmd2-critic-scoring original, scored by a forward-only pass before the critic's last step - #375

Closed
zhihengy wants to merge 8 commits into
dmd2/06b-h3-dmd2-e2efrom
dmd2/07b-view-on-372
Closed

zhihengy wants to merge 8 commits into
dmd2/06b-h3-dmd2-e2efrom
dmd2/07b-view-on-372

Conversation

@zhihengy

@zhihengy zhihengy commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

--dmd2-critic-scoring original: tianweiy/DMD2's scoring, a separate noise draw and 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.

This branch now follows the review suggestion below: the scoring runs inside the critic's own train call, as a forward-only pass before its last step, so the PR no longer adds train_dmd2.py, compute / async_compute, the optim_steps range or the wake_up guard. #416 implements the same suggestion with the scoring batch inside the last step's PreparedBatch and has the side-by-side table; one of the two gets closed. #351 is the earlier version with the separate driver.

What

  • --dmd2-critic-scoring {reuse-critic-step, original}, default reuse-critic-step (no behavior change).
  • LossHooks.forward_only, a ForwardOnlyHooks(runs_before_step, prepare, formula): before each optimizer step the predicate names, _train_core calls the trunk with that prepare and formula on the step's micro-batches, without grad, numbered past the rollout's training micro-batches. What the formula keeps goes into the same train_output_inputs list. _forward_train_pair_batch takes the hooks to run.
  • loss_hub.dmd2: the scoring batch and the kept x0 are factored into prepare_scoring_batch and keep_scores, which both modes use. The critic declares ForwardOnlyHooks(is_scored_before_training, prepare_scoring_batch, scoring_formula): under original its last step is plain SFT (full grid, no teacher, keeps nothing) and the pass before it scores that step's pairs at a separate draw in the scoring range.
  • Both modes run critic → actor through train_diffusion.py.

Why

  • The critic's last step does not read the actor, and the actor reads only the scores, so "score → actor → critic's last step" and "score → critic's last step → actor" are the same computation. The scoring only has to precede that step's update.
  • The loop owns the micro-batch schedule, so it numbers the forward-only draws and the hooks need no schedule knowledge. The pass is the trunk called a second time with other hooks: PreparedBatch, the formula signature and the trunk's forward path are unchanged.
  • Cost of original per rollout: a critic and a teacher forward per scored sample. No extra sleep/wake under --offload-train, unlike the separate driver.
  • The earlier note that compute skipped materialize_stored_tensors no longer applies: the scoring runs inside train, which materializes.

Tests

  • test_train_input_hook.py: the pass runs before its steps train, without grad, through the forward-only hooks, numbered past the training micro-batches and counting on across steps; the train-output hook receives what both kinds of forward kept.
  • 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; scoring_formula returns no loss and keeps x_s − σ v of both forwards; each mode scores the last step exactly once. test_loss_hub_selection.py: the critic's forward_only entry.

Validation

Checklist

  • pre-commit hooks pass on the changed files
  • Added/updated tests for new behaviour
  • python3 train_diffusion.py --help parses; --dmd2-critic-scoring is listed
  • The public flag appears in the CLI reference docs
  • No example added

@zhihengy
zhihengy force-pushed the dmd2/07b-view-on-372 branch from a6e8635 to 36222f1 Compare November 11, 2026 11:54
@Rockdu
Rockdu force-pushed the dmd2/08-teacher-in-trunk branch from 9ea9eb3 to b9e206a Compare November 11, 2026 13:03
@Rockdu
Rockdu force-pushed the dmd2/07b-view-on-372 branch 2 times, most recently from 8732fa8 to 676119c Compare November 11, 2026 13:16
@Rockdu
Rockdu changed the base branch from dmd2/08-teacher-in-trunk to dmd2/06b-h3-dmd2-e2e November 11, 2026 13:16
@Rockdu
Rockdu added this pull request to stack #374 November 11, 2026 13:41
@Rockdu
Rockdu removed this pull request from stack #374 November 11, 2026 15:54
@Rockdu
Rockdu added this pull request to stack #379 November 11, 2026 15:55
@Rockdu
Rockdu force-pushed the dmd2/07b-view-on-372 branch from 676119c to 0992d73 Compare November 11, 2026 17:00
zhihengy and others added 5 commits November 11, 2026 09:01
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>
@Rockdu
Rockdu force-pushed the dmd2/07b-view-on-372 branch from 0992d73 to a48de7f Compare November 11, 2026 17:01
@Rockdu Rockdu added the run-ci-e2e Run e2e metric-regression tests on this PR label Nov 17, 2026
@Rockdu

Rockdu commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR! One thought on original: could the scoring forward live inside the critic's last step instead of a separate compute phase? Same pattern as prepare asking for the teacher: on step K-1, also build the scoring batch (microbatch_id + m, m = micro-batches per step), and the trunk runs the teacher and the critic no-grad on it before the training forward. Weights, draw ids and the step K-1 training stay the same, so I'd expect it to match the current original bit for bit (a GPU test could confirm).

Since the critic's last step doesn't depend on the actor, the order could then be critic → actor like reuse, and compute/async_compute, optim_steps, the wake_up no-op and train_dmd2.py might not be needed anymore. Also a small thing: compute doesn't call materialize_stored_tensors, so original with --use-output-store would read unmaterialized refs.

…in call under --dmd2-critic-scoring original

The critic's last step does not depend on the actor's update, and the actor reads only the scores, so the scoring
only has to precede that step's update, not the actor's train. A group's hooks can now declare a forward-only pass,
`LossHooks.forward_only`: before the optimizer steps it names, the trunk runs its prepare and formula without grad
on that step's micro-batches, numbered past the rollout's training ones. The DMD2 critic declares its scoring
hooks there, so both modes run critic -> actor through train_diffusion.py, and train_dmd2.py goes.

The critic's forwards and their order are the ones of the split calls: steps 0..K-2, the scoring forwards at
micro-batch ids K*m.., step K-1.

Suggested by Rockdu on #375.
…guard, which nothing calls now

They existed to split the critic's steps around a forward-only scoring call from train_dmd2.py. The scoring now
runs inside the critic's one train call, so `FSDPTrainRayActor.compute` / `RayTrainGroup.async_compute`, the
`optim_steps` range of `train`, and the awake check that kept a second `wake_up` in one wake from repointing the
frozen models' host copies have no caller. The trunk keeps its `hooks` argument, which the forward-only pass uses.
@zhihengy zhihengy changed the title [DMD2 10/10, view on #372] feat(dmd2): train_dmd2.py and --dmd2-critic-scoring original [DMD2 10/10] feat(dmd2): --dmd2-critic-scoring original, scored by a forward-only pass before the critic's last step Nov 20, 2026
@Rockdu
Rockdu removed this pull request from stack #379 November 25, 2026 06:21
@Rockdu
Rockdu deleted the branch dmd2/06b-h3-dmd2-e2e November 25, 2026 06:22
@Rockdu Rockdu closed this Nov 25, 2026
Rockdu pushed a commit that referenced this pull request Nov 25, 2026
…ate scoring forward

`reuse-critic-step`, the default, keeps the current behavior: the critic's last training forward, drawn in the
scoring range, is its score. Under `original` the last step trains plain SFT on the full grid and its prepare hook
also returns the scoring batch, a separate draw in the scoring range with the teacher asked for, as the step's
forward-only batch; the formula keeps the x0 of that batch's teacher and critic forwards, which the trunk runs
before the step's training forward and so before its update, as tianweiy/DMD2 does. Both modes score the same
samples and hand the actor the same structure, through train_diffusion.py.

The scoring batch and the kept x0 are factored into `prepare_scoring_batch` and `keep_scores`, which both modes use.

Suggested by Rockdu on #375.

(cherry picked from commit f2f18e9)
(cherry picked from commit eee94ab26f6a6bd9cbb5804188ad768134ace0e4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci-e2e Run e2e metric-regression tests on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants