Repository navigation
Conversation
…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.
zhihengy
requested review from
AgainstEntropy,
BBuf,
HaiShaw,
JustinTong0323,
kevin-mii,
mickqian,
niehen6174,
ping1jing2,
sogalin,
wisclmy0611,
yichiche and
zijiexia
as code owners
November 18, 2026 00:20
…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.
This was referenced Nov 18, 2026
… 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
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.
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:mainin [Feat] diffusion/model: Support MiniMaxAI/MiniMax-H3-Image #49552 and its follow-up [Fix] diffusion: MiniMax-H3 follow-ups: load the public H3-Image snapshot, keep H3 video conditioning, fix profiler test pollution #49574, after this branch's fork point./rollout/generaterequest withrollout=trueruns a plain generation, ignores the rollout fields and fails with 500rollout_trajectory_data must be present when rollout=True.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-milesonto a release that has #49552 and #49574 they are already upstream, and what is left to carry is the rest of this PR: thesglang-miles-specific change, 9 files, +686 -29, about half of it tests (git diff fc627fa6a..HEADon 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).
mainhad three PRs under it that this branch does not have; each conflict keeps this branch's side:PikaH3FlexPipeline,stochastic_samplingorlora_adapter.minimax_h3_encode_keyframe_cond_rowsstays one function and takes the newcrop_to_even/generatorarguments itself._pdd_projectuses this branch's bareeager_on_graph, withoutoutput_factory.sglang-mileshas in the H3 stages are kept.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-milestest predates the image decode path:image_apiuploads through its_upload_and_cleanup_imageshelper here, notCloudStorage.upload_all_and_cleanup.eager_on_graphhas nooutput_factoryhere, so the layerwise graph test's boundary returns a fresh tensor.rollout_stop_step_index, which the schedule test's stand-in batch did not carry.__init__, so it now sets theaudio_vaethatverify_outputreads.The rest: rollouts in the image denoise loop.
minimax_h3_image_denoise_loop(rollout=...): asks the request'sMiniMaxH3ImageRolloutwhether a step is noisy. A noisy step goes through the rollout transition; every other step is the loop's own Euler updatex + (σ_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_noisyis 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'ssigma_maxis the grid's second sigma, asFlowRolloutControllertakes it, passed to the transition as an argument; nothing is written on the request.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 tensorsFlowRolloutControllerreturns (unit noise, transition mean, noise std, model output as noise − clean),[1, T, ...]. miles-diffusion compares its own forward and transition mean against them.MiniMaxH3DenoisingStagebuilds the rollout for a rollout request; the returned conditioning is what the trainer replays:encoder_hidden_states,h3_packed_layoutandh3_token_tags._decode_imagecarriesrollout_trajectory_datato theOutputBatch.MiniMaxH3ImageSamplingParams._validaterejects, with the request: acpsrollout that keeps the Gaussian constants and has a noisy last step (the grid ends at sigma 0, wherecpshas no noise, so that step's log-prob is 0/0; a request withrollout_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=truethe image loop is unchanged.Not changed here, both in the transition the video loop already had:
max(sigmas)assigma_max. Its grid starts at 1.0, so a flow-sdevideo rollout with a noisy step 0 divides by zero; the image loop passes the second sigma.cpswith 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 sendscpswithout the constants.Also unchanged, as on the H3 video path:
rollout_return_dit_trajectoryandrollout_return_denoising_envare accepted and not read. The image rollout always returns the latents the request asks for and the conditioning.Accuracy Tests
MiniMaxAI/MiniMax-H3-Imageat 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)
--num-gpus 2 --tp-size 2 --warmup-mode off --lora-merge-mode merge, the flags miles-diffusion passes)min_generation_areaat 1024² / 512²/rollout/generatewithrollout=falsesde) againstsglang-milesNot 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:
cpsrequest that keeps the Gaussian constants and has a noisy last step. None of the requests measured here was one.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 asnvidia-smireports it.rollout=truewith noise level 0 returns the image ofrollout=falsewith the same seed, bit for bit.cpsrollout 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.MiniMaxH3ImageTransformer2DModelin 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.cps0.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.cpsagainst 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):cpscpscpscpscpscpscpscpssdesdesdesdesdesdeEvery row's latents and log-probs are finite.
cpskeeps the 6-step model's quality at every window and level tried, and flow-sdecosts quality in proportion to its noise level (visible grain at 0.7), so the miles-diffusion recipe usescps.LoRA sync, which the recipe relies on and this PR does not change:
update_weights_from_tensorwithweight_update_mode="lora_merge"(rank 64, all attention and feed-forward projections, 624 tensors in one bucket or three) answersUpdated 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:cps/sdestep returns the transition and the log-prob miles scores (cpswithout the Gaussian constants,sdewith them), withsigma_maxfrom 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 thesdecase withmax(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:test_minimax_h3_image_sampling.py: a rollout with references, a stop step, a noisy step off the grid, no or unreachable returned latents, orcpswith 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 omitsnum_inference_stepsand the server fills it.test_minimax_h3_image_pipeline.py: a rollout at noise level 0, or of typeode, takes no noisy step. It fails if the noisy steps come from the window alone. Acpsrollout with every step in the window androllout_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-milesand at the head, on random rows forcps/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:sglang-miles3f7c4f0The 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,rolloutorweightin their name (45 files) give 825 passed, 8 skipped; the whole directory was not rerun.pre-commit runon the changed files is clean. Validation was run locally.