Skip to content

[Feat] diffusion: [sglang-miles] Stop a rollout at a requested step inside the rollout controller - #49440

Merged
Rockdu merged 6 commits into
sglang-milesfrom
rockdu/rollout-stop-step
Nov 11, 2026
Merged

Rockdu merged 6 commits into
sglang-milesfrom
rockdu/rollout-stop-step

Conversation

@Rockdu

@Rockdu Rockdu commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

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 steps 0..i, send step i straight to the terminal sigma, and return x_i's x0 prediction after i + 1 DiT 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 in prepare_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

  • FlowRolloutController owns 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), fixes sigma_max from the full grid (a stop at step 0 draws the same first-step noise as the full rollout), and stop_at(i) keeps sigmas[:i+1] + [terminal] and timesteps[:i+1]. It steps on its own grid: transition() takes next_sigma from self.sigmas[step_index + 1], so the scheduler's grid stays whole. truncate_rollout_sigmas moves into the controller module.
  • rollout_hooks: the default builder passes sigmas=scheduler.sigmas and timesteps=batch.timesteps (the loop's published timesteps; Krea-2 feeds its DiT raw sigmas between 0 and 1, not scheduler.timesteps). New set_rollout_early_stop_if_enabled(batch) runs directly after prepare_rollout_if_enabled and before the loop reads batch.timesteps: a no-op for serving and for a rollout without a stop, otherwise controller.stop_at(i) and batch.timesteps = controller.timesteps, so the loop keeps iterating batch.timesteps. finalize_rollout_if_enabled raises when the loop's step count differs from the controller schedule, replacing the prepare-time guard; a loop that steps past the schedule fails in transition(). Both hooks' docstrings state where in a loop they go.
  • The generic DenoisingStage._prepare_denoising_loop calls the two hooks before reading batch.timesteps, so warmup, boundary-expert and cache-dit step counts follow the stop; Cosmos3 reads batch.timesteps after 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).
  • The base TimestepPreparationStage and rollout_scheduler.py return to their sglang-miles state: no stop truncation, no stop field in the dedup fingerprint, truncate_rollout_schedule removed. Grouped requests keep sharing one scheduler; the controller is per request.
  • MiniMax H3 keeps the stage-level truncation from [Feat] diffusion-rl: stop a rollout at a requested step #45230 (through the shared helper) because its loop runs its own rollout state instead of a controller; moving it onto a multi-stream controller is a follow-up, marked 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, pass transition into 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 on x_i - sigma_i * v_i; the sde type's last step is still stochastic.

Testing

CPU unit tests (torch 2.15 cpu), run from python/:

python -m pytest -q sglang/multimodal_gen/test/unit/test_scheduler_rollout_unit.py sglang/multimodal_gen/test/unit/test_cosmos3_rollout.py sglang/multimodal_gen/test/unit/test_rollout_api.py
# 63 passed, 2 skipped   (#45230 head: 60 passed, 2 skipped)

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 in transition() 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 passes batch.timesteps; set_rollout_early_stop_if_enabled; finalize step-count check; guard removed.
  • runtime/post_training/rollout_scheduler.py: back to the sglang-miles state.
  • runtime/pipelines_core/stages/denoising.py, model_specific_stages/cosmos3.py: hooks before reading batch.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 the sglang-miles state.
  • 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

  • LTX-2 denoise paths that update latents without 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 on sglang-miles (empty log-prob list). The res2s grid (N+2 sigmas) now fails fast at controller construction instead.
  • MiniMax H3 onto a multi-stream generic controller (then its stage truncation goes).
  • Whether the stop step should force an ODE update for sde-type rollouts.

Checklist

  • pre-commit run --all-files passes (run on head 38430699be)
  • Added/updated tests for new behaviour
  • Unit tests green (63 passed, 2 skipped, command above)
  • GPU rollout gate: not run (no devbox in this session)
  • Docs: no docs mention the rollout request fields; none updated

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-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

zhihengy and others added 6 commits November 9, 2026 15:59
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>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added the diffusion SGLang Diffusion label Nov 10, 2026
@Rockdu
Rockdu merged commit 5fb7b3c into sglang-miles Nov 11, 2026
53 of 61 checks passed
@Rockdu
Rockdu deleted the rockdu/rollout-stop-step branch November 11, 2026 13:39
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants