Repository navigation
[Feat] diffusion: [sglang-miles] Stop a rollout at a requested step inside the rollout controller - #49440
Merged
Conversation
…a stop the pipeline ignores
The controller takes the model's full sigma grid and timesteps from its builder, cuts both to steps 0..rollout_stop_step_index itself and steps on its own grid, so a stop needs nothing from a model's timestep stage. The scheduler's next_sigma and dt are no longer read, and sigma_max comes from the full grid so a stop at step 0 draws the full rollout's noise. A loop that steps past the schedule, or finalizes with another step count, fails loudly; this replaces the hook-side guard. Co-authored-by: Andy Ye <89891424+zhihengy@users.noreply.github.com>
The generic loop and Cosmos3 build the rollout controller first and iterate denoising_timesteps(batch): the controller's schedule for a rollout, batch.timesteps for serving. The generic loop derives its warmup, boundary-expert and cache-dit step counts from that schedule, so a requested stop shortens every count with the loop. Cosmos3 uses the default builder and so gets the stop with no change of its own. Co-authored-by: Andy Ye <89891424+zhihengy@users.noreply.github.com>
The base timestep stage no longer cuts the scheduler's grid for a stop, and its dedup fingerprint no longer carries the stop: the controller owns the truncated schedule per request, so grouped requests keep sharing one scheduler and the scheduler's grid stays whole. MiniMax H3 runs its own rollout state instead of a controller and keeps cutting its video and audio grids in its stage until it migrates. Co-authored-by: Andy Ye <89891424+zhihengy@users.noreply.github.com>
Rockdu
requested review from
AgainstEntropy,
BBuf,
HaiShaw,
kevin-mii,
mickqian,
niehen6174,
ping1jing2 and
yichiche
as code owners
November 10, 2026 03:02
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
Merged
4 tasks done
zhihengy
added a commit
to radixark/miles_diffusion
that referenced
this pull request
Nov 11, 2026
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>
This was referenced Nov 13, 2026
Rockdu
added a commit
to radixark/miles_diffusion
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 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.
Supersedes #45230: zhihengy's three commits are kept first with their authorship, the rework commits sit on top. #45230 itself is left untouched.
Motivation
radixark/miles_diffusion#331 (DMD2 few-step rollout) asks the engine to stop a rollout at denoising step
i: run steps0..i, send stepistraight to the terminal sigma, and returnx_i's x0 prediction afteri + 1DiT forwards. #45230 implemented the stop by truncating the sigma grid inside each model's timestep-preparation stage (the base stage and MiniMax H3) and guarding inprepare_rollout_if_enabled. That puts a second per-model rollout hookup next to the controller builder, which the rollout framework already treats as the single model-side hookup, and it rewrote the grid of the stage-local scheduler that serving requests share.Modifications
FlowRolloutControllerowns the rollout's denoising schedule. It takes the model's full sigma grid and the loop's timesteps from its builder (exactly one sigma past the timesteps), fixessigma_maxfrom the full grid (a stop at step 0 draws the same first-step noise as the full rollout), andstop_at(i)keepssigmas[:i+1] + [terminal]andtimesteps[:i+1]. It steps on its own grid:transition()takesnext_sigmafromself.sigmas[step_index + 1], so the scheduler's grid stays whole.truncate_rollout_sigmasmoves into the controller module.rollout_hooks: the default builder passessigmas=scheduler.sigmasandtimesteps=batch.timesteps(the loop's published timesteps; Krea-2 feeds its DiT raw sigmas between 0 and 1, notscheduler.timesteps). Newset_rollout_early_stop_if_enabled(batch)runs directly afterprepare_rollout_if_enabledand before the loop readsbatch.timesteps: a no-op for serving and for a rollout without a stop, otherwisecontroller.stop_at(i)andbatch.timesteps = controller.timesteps, so the loop keeps iteratingbatch.timesteps.finalize_rollout_if_enabledraises when the loop's step count differs from the controller schedule, replacing the prepare-time guard; a loop that steps past the schedule fails intransition(). Both hooks' docstrings state where in a loop they go.DenoisingStage._prepare_denoising_loopcalls the two hooks before readingbatch.timesteps, so warmup, boundary-expert and cache-dit step counts follow the stop; Cosmos3 readsbatch.timestepsafter the hooks too. Cosmos3 uses the default builder and gets the stop with no model-side change (under [Feat] diffusion-rl: stop a rollout at a requested step #45230 its own timestep stage never truncated, so the guard rejected the request). LTX-2 AV's audio stream steps a clone of the video scheduler without a controller; in rollout mode the clone takes the controller's schedule so both streams stop at the same step (under [Feat] diffusion-rl: stop a rollout at a requested step #45230 the stage truncation covered it implicitly).TimestepPreparationStageandrollout_scheduler.pyreturn to theirsglang-milesstate: no stop truncation, no stop field in the dedup fingerprint,truncate_rollout_scheduleremoved. Grouped requests keep sharing one scheduler; the controller is per request.TODO(rockdu).What a new model has to do now: nothing stop-specific. Build the controller from its own sigma grid and timesteps, call the two hooks before reading
batch.timesteps, passtransitioninto the update line, call finalize after the loop.Request field and semantics are unchanged from #45230:
rollout_stop_step_index(0-indexed); for ODE and CPS the terminal step lands onx_i - sigma_i * v_i; thesdetype's last step is still stochastic.Testing
CPU unit tests (torch 2.15 cpu), run from
python/:New cases: a stopped rollout keeps the full rollout's prefix bit for bit, lands on the x0 prediction and leaves the scheduler's grid untouched; stop at step 0 keeps the full grid's
sigma_max; out-of-range stop rejected; a loop that iterates its own grid fails intransition()and in finalize; the stop cuts the pipeline's published timesteps (Krea-2 scale) rather than the scheduler's; Cosmos3 runs a stopped rollout through its real denoise loop (2 DiT forwards, final latent == x0 prediction, scheduler grid whole). Each new case was checked red on the code without its change.Not covered by a unit test: the LTX-2 AV audio clone following the controller's schedule (building that stage's loop context needs a real transformer).
Not executed: the GPU rollout gate (rollout=False == serving, ODE rollout bitwise == serving, stopped prefix bitwise == full run, final latent ==
x_i - sigma_i * v_i) on a devbox; miles_diffusion#331 end to end.Files
runtime/post_training/flow_rollout_controller.py: schedule ownership (timesteps,stop_at,truncate_rollout_sigmas), transition on the controller's grid.runtime/post_training/rollout_hooks.py: builder passesbatch.timesteps;set_rollout_early_stop_if_enabled; finalize step-count check; guard removed.runtime/post_training/rollout_scheduler.py: back to thesglang-milesstate.runtime/pipelines_core/stages/denoising.py,model_specific_stages/cosmos3.py: hooks before readingbatch.timesteps.model_specific_stages/ltx_2/denoising.py: audio scheduler clone follows the controller's schedule.runtime/pipelines_core/stages/timestep_preparation.py: back to thesglang-milesstate.model_specific_stages/minimax_h3/stages/timestep_preparation.py: stage-level truncation kept, helper import moved,TODO(rockdu).configs/sample/sampling_params.py,entrypoints/post_training/{io_struct,rollout_api}.py: the request field (from [Feat] diffusion-rl: stop a rollout at a requested step #45230).test/unit/test_scheduler_rollout_unit.py,test_cosmos3_rollout.py,test_rollout_api.py: the cases above.Follow-ups not in scope
scheduler.step(the res2s sampler, the stage-1 guider) and JoyEcho's DMD step bypass the rollout controller; a rollout on them already failed at finalize onsglang-miles(empty log-prob list). The res2s grid (N+2 sigmas) now fails fast at controller construction instead.sde-type rollouts.Checklist
pre-commit run --all-filespasses (run on head38430699be)63 passed, 2 skipped, command above)CI States
Latest PR Test (Base): ❌ Run #42746750415
Latest PR Test (Extra): ❌ Run #42746750643
Latest PR Test (AMD ROCm 10): ❌ Run #42746750581
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: