Skip to content

[Feat] diffusion: [sglang-miles] Serve MiniMax-H3-Image training rollouts (cherry-pick #49552, #49574) - #51113

Open
zhihengy wants to merge 12 commits into
sgl-project:sglang-milesfrom
zhihengy:h3-image/image-rollout
Open

zhihengy wants to merge 12 commits into
sgl-project:sglang-milesfrom
zhihengy:h3-image/image-rollout

Conversation

@zhihengy

@zhihengy zhihengy commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

miles-diffusion is adding MiniMax-H3-Image (t2i, 6-step PDD) as a Flow-GRPO train family (radixark/miles_diffusion#395). Its rollouts come from sglang-miles, which has neither the image pipeline nor a rollout path through it:

This PR brings the pipeline over and gives the image loop the rollout transition.

Modifications

The first three commits are the port. At the next rebase of sglang-miles onto a release that has #49552 and #49574 they are already upstream, and what is left to carry is the rest of this PR: the sglang-miles-specific change, 9 files, +686 -29, about half of it tests (git diff fc627fa6a..HEAD on this branch). If the PR lands as one squashed commit, that 9-file diff is what the commit resolves down to.

1. Cherry-pick of #49552 (170804b). main had three PRs under it that this branch does not have; each conflict keeps this branch's side:

2. Cherry-pick of #49574 (6be0d75), without conflicts.

3. Unit test adaptation. Four tests that came with #49552 assume main-only interfaces, and one sglang-miles test predates the image decode path:

  • image_api uploads through its _upload_and_cleanup_images helper here, not CloudStorage.upload_all_and_cleanup.
  • eager_on_graph has no output_factory here, so the layerwise graph test's boundary returns a fresh tensor.
  • The timestep dedup fingerprint reads rollout_stop_step_index, which the schedule test's stand-in batch did not carry.
  • The skip-decode rollout test builds its H3 decoding stage without __init__, so it now sets the audio_vae that verify_output reads.

The rest: rollouts in the image denoise loop.

  • minimax_h3_image_denoise_loop(rollout=...): asks the request's MiniMaxH3ImageRollout whether a step is noisy. A noisy step goes through the rollout transition; every other step is the loop's own Euler update x + (σ_k − σ_{k+1})·v, the line a serving request runs, so a rollout without noise is a serving request bit for bit. Every step is recorded.
  • _noisy_transition (minimax_h3_rollout.py): the cps / flow-sde math of the H3 video update, moved out of it unchanged. It takes its settings as arguments and returns the mean, the noise std and the noise it drew with the next rows. The video update calls it with the values it read before and returns what it returned. _step_is_noisy is the one test both loops use for "this step draws noise".
  • MiniMaxH3ImageRollout: the image request's rollout state, built once per request from its rollout fields. Flow-sde's sigma_max is the grid's second sigma, as FlowRolloutController takes it, passed to the transition as an argument; nothing is written on the request.
  • Step noise: the generator that draws it is seeded with the request generator's next draw (image_noise.py, draw 4), not with the request seed. That seed's first draw on the same device is the draw the initial latent came from, so a generator seeded with it would hand the first noisy step the initial noise again.
  • rollout_debug_mode: the response carries the four debug tensors FlowRolloutController returns (unit noise, transition mean, noise std, model output as noise − clean), [1, T, ...]. miles-diffusion compares its own forward and transition mean against them.
  • MiniMaxH3DenoisingStage builds the rollout for a rollout request; the returned conditioning is what the trainer replays: encoder_hidden_states, h3_packed_layout and h3_token_tags. _decode_image carries rollout_trajectory_data to the OutputBatch.
  • MiniMaxH3ImageSamplingParams._validate rejects, with the request: a cps rollout that keeps the Gaussian constants and has a noisy last step (the grid ends at sigma 0, where cps has no noise, so that step's log-prob is 0/0; a request with rollout_sde_type="cps" and every other field at its default answered 200 with a NaN), a rollout with reference images (they are not returned for the trainer to replay), rollout_stop_step_index (the image loop does not apply the stop), a noisy step off the release's grid (it would run as a deterministic rollout), and returned latents the loop never produces (they would fail only after the denoise).

Without rollout=true the image loop is unchanged.

Not changed here, both in the transition the video loop already had:

  • The video loop passes max(sigmas) as sigma_max. Its grid starts at 1.0, so a flow-sde video rollout with a noisy step 0 divides by zero; the image loop passes the second sigma.
  • cps with the Gaussian constants (rollout_log_prob_no_const=false) has no finite log-prob on a noisy last step, where its std is 0. The image request is rejected for it; the video path still answers with a NaN. miles-diffusion sends cps without the constants.

Also unchanged, as on the H3 video path: rollout_return_dit_trajectory and rollout_return_denoising_env are accepted and not read. The image rollout always returns the latents the request asks for and the conditioning.

Accuracy Tests

MiniMaxAI/MiniMax-H3-Image at 8ced6006 on H200, torch 2.13 / sglang-kernel 0.4.7 (older than this branch's pins, torch 2.14.1 / sglang-kernel 0.4.10).

The port (at commit 3's tree)

Check Result
t2i, 2048², 1 GPU 1.93 s (cookbook: 1.934 s), ~92 GB peak
edit (replace one object of the reference) correct; exercises the reference encode merged by hand in commit 1
TP2 (--num-gpus 2 --tp-size 2 --warmup-mode off --lora-merge-mode merge, the flags miles-diffusion passes) starts and generates
min_generation_area at 1024² / 512² ~0.7 s / ~0.24 s
/rollout/generate with rollout=false 200 with the image
H3 video, one t2va rollout request (TP2, 10 steps, sde) against sglang-miles trajectory, log-probs and decoded video byte-identical

Not bit-identical to main: at the same settings and seed, t2i differs by at most 6/255 (PSNR 55-58 dB) and edit by more (PSNR 44.6 dB). The cause was not localized; the prerequisites this branch lacks are the candidates. Each setting reproduces bit for bit on this branch.

Rollouts

Measured at 416435f. Six commits follow it:

  • b5e82c7 and a35b2d2 restructure the rollout state and the transition's return value. They change no value either computes (bitwise, see Tests).
  • a8af0bb rejects a cps request that keeps the Gaussian constants and has a noisy last step. None of the requests measured here was one.
  • bb1443a, 4c6feff and 1350135 are tests.

The training run reported in radixark/miles_diffusion#400 ran its rollouts at b5e82c7.

TP2 as above, 512², 6 steps, guidance 1, quality="exact"; 0.27 s per rollout, 66 GB per GPU as nvidia-smi reports it.

  • rollout=true with noise level 0 returns the image of rollout=false with the same seed, bit for bit.
  • A cps rollout with noise on steps 1 and 2 returns 7 latents of [256, 96] fp32 and log-probs that are non-zero on steps 1 and 2 only. Its first two latents, the ones before the first noisy step, equal the noise-free run's. miles-diffusion's rollout response parser reads the trajectory and the conditioning.
  • Trainer against engine, on a deterministic rollout: the trainer's forward (Diffusers MiniMaxH3ImageTransformer2DModel in bf16, through the family of [H3-Image 3/4] feat(h3-image): add the MiniMax H3 Image train family for t2i Flow-GRPO with LoRA radixark/miles_diffusion#395) on the returned latents and conditioning predicts the engine's velocity to 1.8-3.8% relative error per step (cosine ≥ 0.9993). As a control, step 3 through step 0's PDD head is off by 5.5%, against 2.1% through its own.
  • Training with miles-diffusion on 8 H200 (FSDP DP=8 colocated with four TP2 engines, cps 0.8 on 2 of the 6 steps, debug mode on), 8 optimizer steps: the trainer's forward against the engine's debug model output differs by 0.020 to 0.027 in mean absolute value (the output's mean magnitude is about 1), its transition mean by 0.014 to 0.019 noise stds, and the log-prob by 0.7e-4 to 1.1e-4.

cps against flow-sde, 32 prompts × 4 seeds, PickScore of each image minus the noise-free rollout of the same prompt and seed (0.8067 on average, with a seed-to-seed std of 0.017):

Transition Noise level Noisy steps PickScore diff (± s.e.) Pairs worse
cps 0.8 0, 1 −0.0030 ± 0.0028 52%
cps 0.8 1, 2 +0.0002 ± 0.0021 53%
cps 0.8 2, 3 +0.0041 ± 0.0016 43%
cps 0.8 3, 4 +0.0043 ± 0.0012 40%
cps 0.8 0-4 +0.0052 ± 0.0029 42%
cps 0.4 1, 2 −0.0022 ± 0.0019 57%
cps 0.6 1, 2 −0.0011 ± 0.0019 49%
cps 1.0 1, 2 +0.0006 ± 0.0024 48%
sde 0.3 1, 2 −0.0041 ± 0.0017 63%
sde 0.5 1, 2 −0.0181 ± 0.0022 77%
sde 0.7 0, 1 −0.0412 ± 0.0033 91%
sde 0.7 1, 2 −0.0388 ± 0.0029 91%
sde 0.7 2, 3 −0.0331 ± 0.0026 92%
sde 0.7 3, 4 −0.0511 ± 0.0031 98%

Every row's latents and log-probs are finite. cps keeps the 6-step model's quality at every window and level tried, and flow-sde costs quality in proportion to its noise level (visible grain at 0.7), so the miles-diffusion recipe uses cps.

LoRA sync, which the recipe relies on and this PR does not change: update_weights_from_tensor with weight_update_mode="lora_merge" (rank 64, all attention and feed-forward projections, 624 tensors in one bucket or three) answers Updated 312 LoRA layers in transformer from IPC tensors (skipped 0 unknown layers). With a strong adapter on every module type, the trainer holding the same adapter predicts the engine's velocity to 1.7-3.0% per step and the trainer without it is off by 9-27%. A zero adapter restores the pre-LoRA image and trajectory bit for bit.

Tests

  • test_minimax_h3_image_denoise_loop.py:

    • A rollout step outside the noise window is the serving step bit for bit, and its debug mean is the step itself with a zero std.
    • A noisy cps / sde step returns the transition and the log-prob miles scores (cps without the Gaussian constants, sde with them), with sigma_max from the grid's second sigma, and debug tensors that reproduce the step. Each case fails on a flipped velocity sign or an ignored step window, and the sde case with max(sigmas).
  • test_minimax_h3_image_pipeline.py, through the timestep, latent, denoising and decoding stages, with fakes that follow the stage's device so they run on the GPU unit lane:

    • a rollout request returns its trajectory and conditioning;
    • a request for a subset of latents returns that subset, with the log-probs and debug tensors still one per step, which is how miles indexes them. It fails if the debug tensors follow the latent filter;
    • the first noisy step's noise is not the initial latent's draw. It fails with the step generator seeded with the request seed.
  • test_minimax_h3_image_sampling.py: a rollout with references, a stop step, a noisy step off the grid, no or unreachable returned latents, or cps with the constants on a noisy last step (by the default window, or by a window that names the step) is rejected. A noisy step off the grid is also rejected when the request omits num_inference_steps and the server fills it.

  • test_minimax_h3_image_pipeline.py: a rollout at noise level 0, or of type ode, takes no noisy step. It fails if the noisy steps come from the window alone. A cps rollout with every step in the window and rollout_log_prob_no_const, the request miles sends without a step strategy, runs: steps 0-4 carry a log-prob and the last step's is exactly 0.

  • The video update on sglang-miles and at the head, on random rows for cps / sde / ode, with and without constants, three step windows, fp32 and bf16 rows, CPU and CUDA: rows, log-prob sums, counts and the noise buffer are bitwise equal on 72 configurations. Across the later refactor that names the transition's fields (b5e82c7 against 4c6feff), the same on 432 configurations, with three sigma pairs and noise levels 0 and 0.8 added.

  • python/sglang/multimodal_gen/test/unit, one GPU visible:

    Tree Passed Skipped Failed Errors
    sglang-miles 3f7c4f0 6296 165 107 37
    commit 3 (the port) 6637 173 107 37
    416435f 6647 173 107 37

    The failed and erroring tests are the same set by name in all three runs, and none is an H3 test: they fail on the base in this environment too. The commits after 416435f touch the H3 rollout files, the image sampling params and their tests only. At the head 1350135 the unit files with minimax_h3, rollout or weight in their name (45 files) give 825 passed, 8 skipped; the whole directory was not rerun.

  • pre-commit run on the changed files is clean. Validation was run locally.

yz-wqf and others added 4 commits November 17, 2026 23:59
…ct#49552)

Co-authored-by: Reynor <reynor@minimaxi.com>
Co-authored-by: Mick Qian <mickqian@users.noreply.github.com>
Co-authored-by: niehen6174 <1639206518@qq.com>
(cherry picked from commit 170804b)

Picked onto sglang-miles, which forked from main before this commit's
prerequisites. Adapted while resolving:
- no PikaH3FlexPipeline, stochastic_sampling or lora_adapter (sgl-project#47378 is not here)
- keyframe rows are not cached (sgl-project#48122 is not here), so the encode keeps one function
- _pdd_project uses the bare eager_on_graph of this branch (sgl-project#46709 is not here)
- the rollout schedule truncation and skip-decode hooks of sglang-miles are kept
…shot, keep H3 video conditioning, fix profiler test pollution (sgl-project#49574)

(cherry picked from commit 6be0d75)
The tests picked with sgl-project#49552 assume main-only interfaces, and one
sglang-miles test predates the image decode path:
- image_api uploads through its _upload_and_cleanup_images helper here, not
  CloudStorage.upload_all_and_cleanup
- eager_on_graph has no output_factory here, so the layerwise graph test's
  boundary returns a fresh tensor
- the timestep dedup fingerprint reads rollout_stop_step_index, which the
  schedule test's stand-in batch did not carry
- the skip-decode rollout test builds its H3 decoding stage without __init__,
  so it now sets the audio_vae that verify_output reads
…ts in the image denoise loop

A rollout request to the image pipeline ran a serving generation and returned no trajectory, so /rollout/generate answered 500. The image loop now steps its target rows through the H3 rollout transition on the steps the request names, records every step's latents and log-prob, and returns them with the conditioning the trainer replays (encoder_hidden_states, h3_packed_layout, h3_token_tags), as the video loop does. A step outside the noise window keeps the image loop's own Euler update, so a rollout without noise is a serving generation bit for bit. The image decode carries the trajectory to the output. A rollout with reference images or a stop step is refused: neither is returned or honored.

@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 pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added documentation Improvements or additions to documentation diffusion SGLang Diffusion labels Nov 18, 2026
…hrough an explicit transition and return debug tensors

The image loop wrote sigma_max on the request for the shared transition to read back, and a wrapper repeated both the video update's noisy-step test and the loop's own Euler update. The cps / flow-sde math is now minimax_h3_rollout_noisy_transition, which takes its settings as arguments and returns the mean and noise std with the next rows; the video update calls it with the values it read before and returns what it returned (bit for bit on 72 configurations). The image loop asks MiniMaxH3ImageRollout whether a step is noisy and runs its own update on every other step, so a rollout without noise executes the serving line itself.

rollout_debug_mode now returns the four debug tensors FlowRolloutController returns (unit noise, transition mean, noise std, model output), which miles compares its own forward against. A noisy step or a returned latent off the release's grid is rejected with the request instead of running as a deterministic rollout or failing after the denoise. The stage-level rollout test follows the stage's device, so it also runs on the GPU unit lane, and the cps case scores the constant-free log-prob miles sends for cps.
…p noise after the request's initial noise

The rollout generator was seeded like the request's generator, on the same device, so its first draw repeated the draw the initial latent came from: the first noisy step's exploration noise was the initial noise again, not independent of the state. The trajectory and its log-probs stayed self-consistent, so nothing downstream flagged it. The step generator is now seeded with the request generator's next draw, which keeps every rank on the same stream and works for a CPU request generator on a GPU host.
…returns when the request asks for a subset of latents

miles asks back the latents of the noisy steps only, then indexes the log-probs and the debug tensors by step number. Nothing covered a subset request: debug tensors that followed the latent filter passed every test.
…t its settings at construction

MiniMaxH3ImageRollout kept the request and read its rollout fields again on every step. It now takes them as arguments (for_request reads them once), and its noisy steps are a set computed at construction. The transition returns the noise it drew instead of threading a buffer through its arguments; the video update keeps its buffer and stays bitwise what it was. The debug tensors use the names FlowRolloutController and the response use for them, and the two helpers no caller outside the module needs are private. image_noise.py's ordering note says why draw 4 may follow draw 1.
… whose last step has no finite log-prob

The image grid ends at sigma 0, where cps has no noise. With the Gaussian constants kept, that step's
log-prob is 0/0, and a request with `rollout_sde_type="cps"` and every other field at its default
(all steps noisy, constants kept) answered 200 with a NaN in `rollout_log_probs`. The request is
rejected with the two ways out: `rollout_log_prob_no_const`, or a window without the last step.
…ields and decide a noisy step from its type and level

`_noisy_transition` returned six tensors by position, three of one shape, and both callers unpacked
them with placeholders. It returns a NamedTuple read by field.

`_step_is_noisy` took the batch and re-derived the effective sde type its video caller had just
computed, reading the noise level without the default that caller uses. It is a predicate of the
type and the level; the video update passes the two values it read. The video update is bitwise
what it was on 432 configurations (cps / sde / ode, with and without constants, three windows,
fp32 and bf16, three sigma pairs, noise level 0 and 0.8, CPU and CUDA).
…llout and the grid check after the server fills the step count

Every stage-level rollout test ran cps at 0.8 with an explicit window, so the two other ways a step
is deterministic, noise level 0 and `ode`, never reached the request-to-noisy-steps mapping: a
mapping from the window alone would run cps with a zero std or raise on `ode` mid-denoise.

The off-grid cases all passed `num_inference_steps`, which the constructor checks. A request without
it is checked only after `_adjust` fills the release's count.
…of the Gaussian-constants switch

- A window that names the last step is rejected like the default window: the constructor
  case covered only `rollout_sde_step_indices=None`.
- With `rollout_log_prob_no_const` the same request runs: steps 0-4 carry a log-prob and the
  last step's is exactly 0.

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 documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants