Skip to content

[DMD2 5/10] feat(rollout): stop the rollout at a random step for DMD2 backward simulation - #331

Merged
Rockdu merged 1 commit into
mainfrom
dmd2/03-few-step-rollout
Nov 11, 2026
Merged

Rockdu merged 1 commit into
mainfrom
dmd2/03-few-step-rollout

Conversation

@zhihengy

@zhihengy zhihengy commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fifth of the DMD2 stacked series, on top of #338. A step strategy can now stop the engine at step i, so one rollout returns the student's input x_{σ_i} and its x0 prediction x̂0_i: the data that DMD2's backward simulation trains on.

What

  • Step strategies return (sde, ret, stop). stop is sent as rollout_stop_step_index. The three built-ins return stop=None, so their requests are unchanged. A custom strategy must now return the third element; None keeps the old behavior.
  • New built-in stop_at_random_step. It draws i ~ U{0..N-1} from the request seed and returns ret=[i, i+1], stop=i and no SDE filter. The engine runs steps 0..i and sends step i straight to σ=0. The trajectory then holds x_{σ_i} followed by x̂0_i as its final latent. With --diffusion-sde-type cps --diffusion-noise-level 1.0, every earlier step re-noises its x0 prediction with fresh noise, which is the DMD2 multi-step sampler.
  • Docs: the strategy signature in customization.md and cli-reference.md, and the new built-in.

Nothing consumes this yet. The critic and actor PRs (6/10, 7/10) read i = latent_step_indices[0] and σ_i = sigmas[i] from the trajectory.

Why

  • DMD2 trains the student at a random step i, on an input the student produced itself (backward simulation). The first i steps are a no-grad rollout, so they belong in the engine. This is the same split as Flow-GRPO, whose selected SDE steps are picked miles-side by --diffusion-step-strategy-path.
  • The critic trains on x̂0_i, and the generator recomputes it from x_{σ_i}, so the rollout has to return both. Truncating the schedule makes x̂0_i the final latent. That needs no new response field, and the engine runs i+1 DiT forwards instead of N.
  • Re-noising with fresh noise is the existing cps transition at noise_level=1: x_next = (1-σ') x̂0 + σ' ε. At σ'=0 it returns x̂0 exactly; so does ode.

sglang side

sgl-project/sglang#45230 is one commit on sglang-miles bff3f6ae7 (+94 lines, 34 of them non-test). Merge it and bump the image before this PR: an engine without it drops the unknown field and silently runs every step.

  • RolloutRequest / SamplingParams get a new rollout_stop_step_index field.
  • After set_timesteps, TimestepPreparationStage truncates the schedule to timesteps[:i+1] and sigmas[:i+1] + terminal. It rejects i outside the schedule.
  • The field is part of the stage's dedup fingerprint, so grouped requests with different stops don't share a schedule.

Validation

Engine A/B on FLUX.2-klein-base-4B (1×B200, 512², 4 steps, cps / noise 1.0, guidance 1, debug tensors on). SD3.5-M was not run because its weights are gated and unavailable on this devbox. FLUX.2 also tests a resolution-dependent mu shift. Requests come from stop_at_random_step and are parsed by apply_rollout_image_response. Each one 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, the sglang branch is bitwise equal to sglang-miles bff3f6ae7 on a full rollout: latents, sigmas, model outputs and the decoded image.
  • sglang unit tests: 53 passed in test_scheduler_rollout_unit.py and test_rollout_api.py. The new case checks that 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.

Tests

  • tests/fast/rollout/test_step_strategy_hub.py: the new strategy returns [i, i+1] and stop=i, and it draws every step over seeds. The built-ins return stop=None.

Checklist

  • pre-commit hooks pass on the changed files (both repos)
  • Added/updated tests for new behaviour
  • pytest tests/fast is green (523 passed, 6 skipped; 522 on [DMD2 4/10] feat(fsdp): add a train-input hook that preprocesses train pairs before micro-batching #338)
  • If launch flags changed, python3 train_diffusion.py --help still parses (no flag added; the --diffusion-step-strategy-path contract changed)
  • If a public flag was added, it appears in the CLI reference docs (signature updated in cli-reference.md and customization.md)
  • If an example was added, it has a real walkthrough (no examples added)

Stack

DMD2: distill a flow-matching teacher into a few-step student with distribution matching. Merge in order:

  1. [DMD2 1/10] [DMD2 1/10] refactor(ray): build each trainer's args from a trainer config list #335: per-trainer args from a trainer config list
  2. [DMD2 2/10] [DMD2 2/10] feat(ray): train several colocated trainer groups in the sync driver #329: several colocated trainer groups in the sync driver
  3. [DMD2 3/10] [DMD2 3/10] feat(ray): hand earlier trainer groups' outputs to later groups as external_data #330: hand earlier trainer groups' outputs to later groups as external_data
  4. [DMD2 4/10] [DMD2 4/10] feat(fsdp): add a train-input hook that preprocesses train pairs before micro-batching #338: a train-input hook that preprocesses a trainer group's train pairs before micro-batching
  5. [DMD2 5/10] this PR: few-step rollout and the DMD2 step strategy
  6. [DMD2 6/10] [DMD2 6/10] feat(dmd2): train a fake-score critic group from the teacher and score the student's samples #333: DMD2 critic group: critic training and teacher/critic scoring of its last step
  7. [DMD2 7/10] [DMD2 7/10] feat(dmd2): train the student with the distribution matching gradient from the critic group's scores #334: --loss-type dmd2 on the actor
  8. [DMD2 8/10] [DMD2 8/10] perf(ray): sleep each trainer group right after its train #342: sleep each trainer group right after its train
  9. [DMD2 9/10] [DMD2 9/10] feat(dmd2): add the MiniMax H3 4-step DMD2 recipe with eval media and DMD2 metrics #343: MiniMax H3 4-step DMD2 recipe, eval media and DMD2 metrics

A GAN head and other follow-ups come after this series.

@zhihengy
zhihengy added this pull request to stack #332 October 19, 2026 20:42
@zhihengy
zhihengy marked this pull request as ready for review October 19, 2026 23:01
@zhihengy zhihengy added the run-ci-basic Authorize and run only basic unlabeled CI tests label Oct 19, 2026
@zhihengy
zhihengy removed this pull request from stack #332 October 21, 2026 06:08
@zhihengy
zhihengy force-pushed the dmd2/03-few-step-rollout branch from acfa478 to 96c124b Compare October 21, 2026 06:08
@zhihengy
zhihengy added this pull request to stack #336 October 21, 2026 06:08
@zhihengy zhihengy changed the title [DMD2 3/7] feat(rollout): stop the rollout at a random step for DMD2 backward simulation [DMD2 4/8] feat(rollout): stop the rollout at a random step for DMD2 backward simulation Oct 21, 2026
@zhihengy
zhihengy removed this pull request from stack #336 October 24, 2026 00:08
@zhihengy
zhihengy changed the base branch from dmd2/02-external-data to dmd2/02b-train-input-hook October 24, 2026 00:08
@zhihengy
zhihengy force-pushed the dmd2/03-few-step-rollout branch from 96c124b to f10ffd3 Compare October 24, 2026 00:09
@zhihengy
zhihengy added this pull request to stack #339 October 24, 2026 00:09
@zhihengy zhihengy changed the title [DMD2 4/8] feat(rollout): stop the rollout at a random step for DMD2 backward simulation [DMD2 5/8] feat(rollout): stop the rollout at a random step for DMD2 backward simulation Oct 24, 2026
@zhihengy
zhihengy force-pushed the dmd2/03-few-step-rollout branch from f10ffd3 to b9639d9 Compare October 24, 2026 00:17
@zhihengy zhihengy changed the title [DMD2 5/8] feat(rollout): stop the rollout at a random step for DMD2 backward simulation [DMD2 5/9] feat(rollout): stop the rollout at a random step for DMD2 backward simulation Oct 26, 2026
@zhihengy zhihengy changed the title [DMD2 5/9] feat(rollout): stop the rollout at a random step for DMD2 backward simulation [DMD2 5/10] feat(rollout): stop the rollout at a random step for DMD2 backward simulation Nov 2, 2026
@Rockdu
Rockdu force-pushed the dmd2/03-few-step-rollout branch from b9639d9 to d945c99 Compare November 4, 2026 19:41

@Rockdu Rockdu left a comment

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.

LGTM, but need to merge after sglang-miles part is merged

@zhihengy
zhihengy force-pushed the dmd2/03-few-step-rollout branch from d945c99 to 598da69 Compare November 9, 2026 22:16
@zhihengy
zhihengy force-pushed the dmd2/03-few-step-rollout branch from 598da69 to 466982c Compare November 10, 2026 03:59
@zhihengy
zhihengy force-pushed the dmd2/03-few-step-rollout branch from 466982c to fecb253 Compare November 10, 2026 11:44
@zhihengy
zhihengy force-pushed the dmd2/03-few-step-rollout branch from fecb253 to 4868030 Compare November 11, 2026 08:18
@Rockdu
Rockdu force-pushed the dmd2/03-few-step-rollout branch from 4868030 to 2cec35d Compare November 11, 2026 15:43
Base automatically changed from dmd2/02b-train-input-hook to main November 11, 2026 15:43
@Rockdu
Rockdu force-pushed the dmd2/03-few-step-rollout branch from 2cec35d to e08e93e Compare November 11, 2026 15:43
@Rockdu
Rockdu merged commit b1e4e6e into main Nov 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci-basic Authorize and run only basic unlabeled CI tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants