Skip to content

[Feat] diffusion-rl: stop a rollout at a requested step - #45230

Open
zhihengy wants to merge 4 commits into
sgl-project:sglang-milesfrom
zhihengy:dmd2/few-step-stop
Open

zhihengy wants to merge 4 commits into
sgl-project:sglang-milesfrom
zhihengy:dmd2/few-step-stop

Conversation

@zhihengy

@zhihengy zhihengy commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

DMD2 distillation in miles-diffusion (radixark/miles_diffusion#331) trains the few-step student at a random step i, on an input the student generated itself (backward simulation). One rollout has to return the student's input x_{σ_i} and its x0 prediction x̂0_i, and the steps after i are wasted work.

The rest of the sampler already exists here: with rollout_sde_type="cps" and rollout_noise_level=1.0, each step re-noises its x0 prediction with fresh noise, x_next = (1-σ') x̂0 + σ' ε, which is the DMD2 multi-step sampler. The only missing piece is stopping at step i.

Modifications

  • RolloutRequest / SamplingParams: new rollout_stop_step_index, default None (no behavior change).
  • truncate_rollout_sigmas (rollout_scheduler.py): keeps steps 0..i of a sigma grid and appends the terminal sigma, sigmas[:i+1] + sigmas[-1:]. Step i then goes straight to σ=0, where both cps and ode return x̂0 exactly, and the engine runs i+1 DiT forwards instead of N. An i outside the schedule is rejected. It takes a scheduler's tensor or a plain list.
  • prepare_rollout_if_enabled (rollout_hooks.py): for a rollout request with a stop, cuts batch.scheduler through the helper (truncate_rollout_schedule: the sigmas, and timesteps[:i+1]) and republishes batch.timesteps, before it builds the controller. The timestep stages stay rollout-agnostic, with their dedup fingerprints unchanged. The hook then rejects a controller whose sigma grid is not the i+2-point stopped grid: a loop that hands the hook its own controller must build it on the cut schedule, or it would return a full rollout as if it had stopped.
  • DenoisingStage._prepare_denoising_loop calls the hook right after it takes batch.scheduler, before it reads batch.timesteps, so the warmup, MoE boundary and cache-dit step counts follow the stopped schedule. Cosmos3DenoisingStage reads batch.timesteps after its hook call for the same reason. LTX-2 does not call the hook and does not get the stop.
  • MiniMax H3's loop runs on its own video/audio grids, not on batch.scheduler: minimax_h3_rollout_sigmas (minimax_h3_rollout.py, next to H3's other rollout helpers) cuts both grids alike, and _run_full_loop applies it right after it resolves the grids, so the cache-dit step count, the progress bar, the loop and the trajectory collector all see the cut grids. The PDD check in H3's timestep stage still validates the full grid.
  • Dynamic batching keeps requests with different stops apart: the field is a SamplingParams field without batch_sig_exclude, so it is in the batch signature.

The stop is a schedule cut before the loop, done by the rollout hook rather than inside the controller's transition: the controller only replaces the update inside scheduler.step, after that step's DiT forward, while the loops derive their step counts from the schedule up front. diffusers stops early the same way (denoising_end in the SDXL pipeline cuts the timesteps before the loop). num_inference_steps keeps the requested N; only the progress bar and the cache-dit step count read it.

With the existing rollout_return_step_indices=[i, i+1], the trajectory holds x_{σ_i} followed by x̂0_i, so no response field is added.

Accuracy Tests

FLUX.2-klein-base-4B, 1×B200, 512², 4 steps, cps / noise level 1.0, guidance 1, debug tensors on, at the head commit 996dec8. Each stopped rollout is compared with a full 4-step rollout that uses the same seed:

stop i returned σ latent_step_indices x_{σ_i} vs full run final latent vs x_i - σ_i·v_i (bf16) DiT forwards
0 1.0, 0 [0, 1] bitwise equal bitwise equal 1
1 1.0, 0.9581, 0 [1, 2] bitwise equal bitwise equal 2
2 1.0, 0.9581, 0.884, 0 [2, 3] bitwise equal bitwise equal 3
3 1.0, 0.9581, 0.884, 0.7175, 0 [3, 4] bitwise equal bitwise equal 4

Without the field, a full rollout at the head is bitwise equal to sglang-miles bff3f6a: latents, sigmas, model outputs and the decoded image.

MiniMax-H3 (t2va, 2×B200 TP2, 768p 16:9 4 s, 4 steps, flow shift 12 / audio shift 3, seed 1234; at 22f93b5): for ode and cps (noise level 1.0) and every stop i in 0..3, the returned σ is the full grid's [:i+1] + [0], x_{σ_i} is bitwise equal to the full run, and the server runs i+1 denoise steps. With ode, the full run's x_{i+1} replayed from the stopped x0 is bitwise equal. H3's cps floors the predicted-noise weight at sqrt(1e-12), so its x0 differs from ode's by up to 5.25e-6. Without the field, full ode / cps latents and sigmas are bitwise equal to 077b40c.

These GPU runs predate the last commit, which moves the cut from the timestep stages into the rollout hook (and, for H3, into its rollout helpers). The loops receive the same stopped schedule as before, which the unit tests pin; the GPU runs were not repeated.

Tests

  • test_scheduler_rollout_unit.py:
    • A stopped rollout replays the full run's prefix bit for bit and ends on the x0 prediction; it fails if the terminal sigma isn't re-appended. The same holds for H3, whose video and audio grids are cut alike.
    • A stop outside the schedule is rejected.
    • The rollout hook cuts the request's scheduler, batch.timesteps and the controller's grid to steps 0..i plus the terminal sigma, and a later request on the same scheduler runs in full. A controller built on an uncut grid is rejected (the case fails without the check).
  • test_rollout_api.py: the field is forwarded to the sampling params.
  • 54 passed, 2 skipped (CUDA) across both files on CPU; test_cosmos3_rollout.py, test_minimax_h3_denoise_loop.py, test_timestep_preparation_logging.py, test_cosmos3.py and test_minimax_h3_pdd_offline.py pass (167 tests). pre-commit run on the changed files is clean. Validation was run locally.

CI States

Latest PR Test (Base): ❌ Run #42755185399
Latest PR Test (Extra): ❌ Run #42755185255
Latest PR Test (AMD ROCm 10): ❌ Run #42755185256

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

@github-actions

This comment has been minimized.

@Rockdu
Rockdu force-pushed the dmd2/few-step-stop branch from 996dec8 to 0544736 Compare November 5, 2026 08:05
@github-actions

This comment has been minimized.

)
timesteps = scheduler.timesteps

if batch.rollout and batch.rollout_stop_step_index is not None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's integrate this part into our pluggable rollout controller if possible

…ut hook, not the timestep stages

Review on sgl-project#45230 asked for the stop to live in the pluggable rollout
layer. `prepare_rollout_if_enabled` now cuts `batch.scheduler` and
`batch.timesteps` to steps 0..i plus the terminal sigma before it builds
the controller, and still rejects a controller on an uncut grid. The base
denoising loop calls the hook before it reads the schedule, so the
warmup, boundary and cache-dit step counts follow the stop; Cosmos3 reads
its timesteps after the hook for the same reason. The two timestep stages
go back to their serving-only code and dedup fingerprints.

MiniMax H3's loop runs on its own video/audio grids: `minimax_h3_rollout_sigmas`
joins H3's other rollout helpers and cuts both grids where the full loop
resolves them.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
@zhihengy zhihengy changed the title [sglang-miles] [Diffusion] Stop a rollout at a requested step [Feat] diffusion-rl: stop a rollout at a requested step Nov 10, 2026

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

diffusion SGLang Diffusion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants