Skip to content

[sglang-miles] [Diffusion] Let a rollout request skip the VAE decode - #46545

Open
zhihengy wants to merge 1 commit into
sgl-project:sglang-milesfrom
zhihengy:dmd2/rollout-skip-decode
Open

zhihengy wants to merge 1 commit into
sgl-project:sglang-milesfrom
zhihengy:dmd2/rollout-skip-decode

Conversation

@zhihengy

@zhihengy zhihengy commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Data-free DMD2 in miles-diffusion (radixark/miles_diffusion#343) trains only on the rollout trajectory: the student's input and x0 prediction from dit_trajectory, and the cond from denoising_env. With no reward model, nothing reads the decoded media of a training rollout. Every rollout request still runs the VAE decode (video and, for MiniMax H3, audio) and ships the decoded video. For H3 at 768p 16:9 5 s that is 124×768×1344×3 B = 384 MB per sample even as uint8, about 123 GB per 320-sample rollout through HTTP and msgpack.

Modifications

  • RolloutRequest / SamplingParams: rollout_return_generated_output, default True (no behavior change). It is a SamplingParams field without batch_sig_exclude, so requests that decode and requests that don't are never batched together.
  • rollout_output_without_decode (stages/decoding.py): the OutputBatch with the rollout trajectory, trajectory timesteps / latents, metrics and usage, and no media.
  • DecodingStage.forward and MiniMaxH3DecodingStage.forward return it first thing when the field is False, before loading or running a VAE. H3's verify_output accepts that output (no media, a rollout trajectory) and still rejects any other empty output.
  • rollout_generate rejects a request with the field False whose output came back decoded anyway (400). Decoding stages that override forward without the check (LTX-2, Cosmos3, MOVA, ...) would otherwise decode silently; they can opt in the same way. _build_response takes the response count from num_outputs_per_prompt when there is no output.

Accuracy Tests

MiniMax-H3 (t2va, 2×B200 TP2, 768p 16:9 4 s = 1344×768 / 107 frames, 4 steps, ode, seed 1234, rollout_video_dtype=uint8, rollout_return_dit_trajectory and rollout_return_denoising_env on), on a tree with this commit and #46544 (audio in the response) on top of sglang-miles 2a2fb73; the two touch separate response fields:

  • With rollout_return_generated_output=False, dit_trajectory (latents [5, 32256, 96], timesteps, sigmas, step indices), denoising_env (9 tensors) and rollout_log_probs are bitwise equal to the decoded request's; generated_output is None.
  • With the default, the decoded request is unchanged: against sglang-miles 2a2fb73 on the same request, the decoded video, dit_trajectory, denoising_env and rollout_log_probs are bitwise equal.

Speed Tests and Profiling

Same setup, after one warm-up request:

decode on (6 runs) rollout_return_generated_output=False (4 runs)
MiniMaxH3DecodingStage 1.27 s 0.0000 s
inference_time_s 5.92-5.94 s 4.66-4.67 s
response body 396.2 MB 63.7 MB
client wall time 8.2-11.6 s 5.6-7.0 s

The remaining 63.7 MB is the full 5-latent trajectory; a DMD2 request that stops at a step and returns two latents ships about 25 MB.

Tests

  • test_rollout_api.py:
    • the field reaches the pipeline request (Req), and defaults to True;
    • DecodingStage and MiniMaxH3DecodingStage return the request's trajectory without touching the VAE;
    • H3's output verification accepts the trajectory-only output and still rejects an empty output without a rollout trajectory;
    • a response without output has one entry per requested output, with the trajectory sliced per sample.
  • 44 passed in test_rollout_api.py; 443 passed across the 29 unit files that touch decoding, H3, rollout and sampling params. pre-commit run on the changed files is clean.

CI States

Latest PR Test (Base): ❌ Run #42312084991
Latest PR Test (Extra): ❌ Run #42312084872
Latest PR Test (AMD ROCm 10): ❌ Run #42312084897

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

@Rockdu
Rockdu force-pushed the dmd2/rollout-skip-decode branch from 80711a2 to 6613ac2 Compare November 6, 2026 23:27
@Rockdu

Rockdu commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Short term: problems this PR should fix before merge

P0-1. Ming and Nomas crash inside the decoding stage when the flag is set.
MingImageDecodingStage.forward and NomasDecodingStage.forward call super().forward() and then index output.output (ming_image.py:222-226, nomas/stages.py:446-447). With the check at the top of DecodingStage.forward, the base returns output=None and the subclass raises TypeError on it. Any rollout_return_generated_output=False request on those pipelines fails with a traceback instead of a trajectory.

P0-2. LTX-2 AV, JoyEcho AV and Helios (chunked path) ignore the flag, run the full DiT + VAE, and only then get a 400.
Their forward overrides never reach the base check (ltx_2/decoding_av.py:150, joy_echo/memory.py:940 inherits it, helios_decoding.py:37 on the chunked branch). The PR's post-hoc 400 in rollout_api.py:371 catches this by noticing output is not None, but by then the whole generation has been paid for. The same happens on every pipeline whose terminal stage is not a DecodingStage at all (flux3_image, ideogram, mova, cosmos3, pi05, and the denoiser side of a disaggregated deployment). Which of P0-1 / P0-2 / "works" a model lands in depends only on how its override happens to be written.

P0-3. H3 fails verification for rollout=False + skip.
MiniMaxH3DecodingStage.verify_output (PR head :313-320) decides "skipped" from "no output, no file paths, no audio, and a trajectory present". A request with rollout=False carries no trajectory, so the rule misses, add_check("output", None, [is_tensor, ...]) fails, and the request dies with a verification error. #343's eval path does not set the flag, so the e2e did not see it, but the rule is an inference and this is where it leaks.

P1. Every skipped training rollout now runs empty_cache().
gpu_worker._finalize_output_batch:921-934 reads output is None and not return_raw_frames as "the decoded tensor went to disk, release the pool". A skipped decode matches it on every rollout: a cudaFree sweep per request (or the idle-release timer with defer_cache_release), and the pool regrows on the next denoise. Before the PR a rollout always had output set and never entered this branch. Silent, perf only, on the exact path #343 runs.

P2. In three modes the request fails with the wrong error. No wrong data, but the message blames something else:

  • dynamic batching (--batching-max-size > 1): _split_batched_output finds neither output nor output_file_paths and every request in the batch gets "could not split merged output" (batched rollouts were already broken: the split never copies rollout_trajectory_data);
  • disaggregation: the orchestrator reports "Decoder returned no output";
  • /generate routes: the field lives on SamplingParams, so extra_sampling_params can set it, and the user gets "Model generation returned no output".

Fixes, smallest set that closes P0 and P1

  1. Say it instead of implying it. OutputBatch.generated_output_skipped: bool = False, set only by rollout_output_without_decode. P0-3's rule becomes if batch.generated_output_skipped: return result; P1 becomes and not output_batch.generated_output_skipped. (Not re-keying P1 on output_file_paths here: on TP > 1 the non-output ranks clear output without setting it, so that would change those ranks.)

  2. Short-circuit at the outermost layer of every decode forward, not inside the base. One decorator in decoding.py, applied to the base and to all 12 overrides (all return OutputBatch, so returning early is safe in each):

    def skip_decode_if_requested(forward):
        @functools.wraps(forward)
        def wrapper(self, batch, server_args):
            if not batch.rollout_return_generated_output:
                return rollout_output_without_decode(batch)
            return forward(self, batch, server_args)
        return wrapper

    Closes P0-1 (ming/nomas never reach their indexing) and the first half of P0-2 (no override can miss the check). A unit test over DecodingStage.__subclasses__() keeps the list complete.

  3. Reject before the forward. The HTTP process has no pipeline, so at the top of gpu_worker.execute_forward: a skip request on a pipeline whose stages[-1] is not a DecodingStage returns a fixed error without running anything; rollout_api maps that error to 400 and drops the post-hoc check. Closes the second half of P0-2 and makes P2's three modes fail up front with the right message where the terminal stage is not a decoder (disagg denoiser side); the batching and /generate readers stay as TODOs.

Kept from the PR, checked: the field stays in the batch signature (no batch_sig_exclude), and _build_response counting from num_outputs_per_prompt matches H3 (no request expansion).

Long term

Keep the stage-local design and make the decorator the contract: every DecodingStage.forward is wrapped, generated_output_skipped is the one signal consumers read, admission is "terminal stage is a DecodingStage". The decoding stage is the only place that knows what "no decoded output" looks like for its model, and it sits below component_uses, so skipping never changes residency; a per-request stage list in the pipeline base would add a scheduling axis for one boolean, a VAE-less server mode would fork every recipe, and a /decode service is its own project. On top of the contract, in order: split skipped batches by per_req_counts and slice rollout_trajectory_data per request (fixes batched rollouts in general); forward the signal through disaggregation; reject the flag on the /generate routes at admission; re-key cache release on the transport that happened.

@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 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Required checks failed on 6613ac2; this PR cannot be merged until they pass.

PR title (run)

PR title must use "[Type] scope: title" or "[Type] [Hardware] scope: title". Type must be one of: Feat, Fix, Refactor, Perf, Doc, Test, CI, Chore. Scope is required and may be any module or model name, with unrestricted letter case (letters, numbers, dots, underscores, slashes, or hyphens). Hardware is optional; use a single tag without spaces. Use uppercase hardware tags (AMD, NVIDIA, NPU, MI300X), except for exactly these four spellings: Intel, Apple, Huawei, Ascend. Reverts must use GitHub's default format: Revert "original title". Use one space between fields and after the colon, with a non-empty title and no leading or trailing whitespace. Examples: "[Fix] attention: Fix KV cache indexing", "[Feat] qwen3: Add model support", "[Perf] [AMD] flash-attn: Optimize decode performance".
Edit the title; the check reruns on its own.

Lint (run)
Run pre-commit run --all-files locally and push the result. The run log shows any other failing step.

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