Repository navigation
Conversation
`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>
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>
…re micro-batching
…tprocess 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>
…e the student's samples
… 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>
…metrics to judge it
… reward reads the media
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>
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).
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).
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.
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.
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).
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.
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.
…by the critic's prepare hook
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.
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>
…roxy 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>
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>
Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
…d before the training forward A prepare hook can now return a second batch on the same pairs, `PreparedBatch.forward_only_batch`. The trunk runs the teacher it asks for and its model on it without grad, before the training batch's forwards, and hands the two predictions to the formula as `forward_only_teacher_pred` and `forward_only_pred`; a formula whose prepare sets no such batch receives neither. The trunk's forwards of one batch move into a local function it calls once per batch. For the second batch's draw, the hooks' ctx carries the rank's micro-batches per optimizer step once the schedule exists: a hook that adds it to its micro-batch id gets an id no training forward of its own or a later step has when its step is the last.
…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.
f2f18e9 to
3c339bf
Compare
…he trunk runs them off PreparedBatches Each stage of a micro-batch is a model and the batch it is sent: the training forward (the EMA and reference forwards take its batch too), the frozen teacher on its own batch (its own CFG fields and conds), and the actor's extra no-grad forward on a second batch. The prepare hook returns them as PreparedBatches(actor, teacher, actor_forward); PreparedBatch is one stage's input and holds no batch of its own type. The trunk runs the stages in order through one _compute_noise_pred(model, batch) and derives nothing; the formula receives each stage's prediction next to its batch (teacher_pred / teacher_batch, actor_forward_pred / actor_forward_batch), its positional `prepared` staying the training batch. Each loss module keeps a builder that returns a PreparedBatch (sft_batch, nft_batch, flow_grpo_batch, generator_batch, scoring_batch) and registers the prepare_*_batch hook that wraps it; DMD2 composes its stages from sft_batch and scoring_batch, so the DMD2-only knobs (grid_index_range, draw) stay off the public hook. The family's input_dtype_policy is resolved once per run (InputDtypes, in the actor's __init__) and each stage's inputs are cast with it as they are sent: PreparedBatch.model_inputs(input_dtypes) returns compute_noise_pred's kwargs in the boundary dtypes, and the batch's own fields keep the rollout dtypes for the formulas. No stage prepares again inside the trunk and no batch carries a cast copy. DMD2's scoring draw under --dmd2-critic-scoring original is a named draw on the same micro-batch (sft_batch's draw="scoring" enters the seed) instead of a micro-batch id offset, so the hook needs no count of micro-batches per step and DiffusionLossContext.num_microbatches_per_optim_step goes away.
3c339bf to
07a6f9d
Compare
…ed them to main
|
Added two commits on top of yours (untouched): 07a6f9d reworks the trunk, 3debb87 takes the DMD2 proxy recipe / test / standard as #366 merged them, so the branch merges cleanly. #418 is folded in; an earlier force-push of this branch is undone. The idea behind the rework: batches are not grouped by whether a forward has grad, but by which model is fed. The teacher gets its own batch (its own CFG and conds), the actor gets its training batch, and when the critic needs a second forward of its own model it gets a second batch; the EMA and reference forwards take the actor's batch, since their inputs must be exactly the actor's. So:
Default mode is numerically unchanged; |
…the rework must follow live there
…s the other hook tests do
Alternative to #375 for the same flag,
--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. Both follow the review suggestion on #375 to score inside the critic's own train call, so neither addstrain_dmd2.py,compute/async_compute, theoptim_stepsrange or thewake_upguard. This PR takes the suggestion literally: on its last step the critic's prepare hook also returns the scoring batch, and the trunk forwards it without grad before the training forward. #375 runs a forward-only pass before the step instead. One of the two gets closed; draft until then.What
--dmd2-critic-scoring {reuse-critic-step, original}, defaultreuse-critic-step(no behavior change).PreparedBatch.forward_only_batch: a second prepared batch on the same pairs._forward_train_pair_batchruns the teacher it asks for and its model on it without grad, before the training batch's forwards, and passes the formulaforward_only_teacher_predandforward_only_pred. A formula whose prepare sets no such batch receives neither, so the other formulas and the custom-formula contract are unchanged. The trunk's forwards of one batch (input dtype policy, the teacher, the model) become a local function called once per batch.DiffusionLossContext.num_microbatches_per_optim_step: set by_train_coreonce the schedule exists, so the train-input hook still sees 0.loss_hub.dmd2: the scoring batch and the kept x0 are factored intoprepare_scoring_batchandkeep_scores, which both modes use. Underoriginalthe last step is plain SFT (full grid, no teacher) and carriesprepare_scoring_batch(..., microbatch_id=microbatch_id + m)as its forward-only batch;critic_loss_formulakeeps the x0 of that batch's forwards and returns the SFT loss of the training forward.Why
microbatch_id + mon the last step is the id range past the rollout's training micro-batches, the draws the separatecomputecall of [DMD2 10/10] feat(dmd2): train_dmd2.py and --dmd2-critic-scoring original, the reference's separate scoring #351 used, so the scores are the same.Compared with #375
LossHooks.forward_only, with a predicate over the stepPreparedBatch.forward_only_batch_train_core: a no-grad loop over the step's micro-batches, calling the trunk with the scoring hooks_forward_train_pair_batch: two batches per callhooksargumentctxhas to carry the micro-batch count and is rebuilt after the schedule existsscoring_formulawith no loss;critic_loss_formulaunchangedcritic_loss_formulatakes two more predictionsmiles/diff against the baseTests
test_reference_models.py: a forward-only batch runs through its teacher and the model without grad before the training forward, and the formula receives both predictions.test_train_input_hook.py: the ctx of the forwards and the train-output hook carries the micro-batch count of the preprocessed pairs; the train-input hook's does not.test_loss_hub_dmd2.py: underoriginalonly the last step carries a scoring batch and it stays plain SFT; that batch equals the reuse mode's last-step batch at the id one step of micro-batches later (draw, sigmas, teacher scale, conds); the formula keepsx_s − σ vof the forward-only forwards and returns the SFT loss; each mode scores the last step exactly once.Validation
pytest tests/fastin the CI CPU environment at f2f18e9: 725 passed._train_coreand_forward_train_pair_batchwith the DMD2 critic hooks, a 3-parameter critic and teacher, K = 3, 2 micro-batches per step, AdamW. Against a48de7f (the old [DMD2 10/10] feat(dmd2): --dmd2-critic-scoring original, scored by a forward-only pass before the critic's last step #375 head) driven as itstrain_dmd2.pydid (train(0, K−1)→compute→train(K−1, K)), the scores, the critic's final parameters and every step's loss and grad norm are bitwise equal; [DMD2 10/10] feat(dmd2): --dmd2-critic-scoring original, scored by a forward-only pass before the critic's last step #375's new head gives the same. With the scoring ids shifted onto the training ids the scores differ, so the check sees the draw.run-ci-basic): the CPU stages, stage-b and the three e2e tests that label runs pass (SD3 NFT, SD3 OCR GRPO and LTX-2.3 GRPO match their standards). The LTX-2.3 job first died of the node's host-RAM limit while it overlapped [DMD2 10/10] feat(dmd2): --dmd2-critic-scoring original, scored by a forward-only pass before the critic's last step #375's suites and passed when rerun alone.e2e-labelled tests, the H3 DMD2 proxy among them, and--dmd2-critic-scoring originalon GPU. The trunk refactor touches every loss type's forward path, so this PR needs the full e2e set (run-ci-e2e) more than [DMD2 10/10] feat(dmd2): --dmd2-critic-scoring original, scored by a forward-only pass before the critic's last step #375 does.Checklist
pre-commithooks pass on the changed filespython3 train_diffusion.py --helpparses;--dmd2-critic-scoringis listed