Skip to content

[diffusion] hold VAE decoder weights in their decode dtype from load - #35967

Merged
mickqian merged 1 commit into
sgl-project:mainfrom
mickqian:feat/vae-decoder-decode-dtype-residency
Aug 22, 2026
Merged

mickqian merged 1 commit into
sgl-project:mainfrom
mickqian:feat/vae-decoder-decode-dtype-residency

Conversation

@mickqian

@mickqian mickqian commented Aug 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The decode stage already rounds VAE decoder weights to the autocast compute dtype on first use (prepare_autocast_linear_weights, whose docstring notes the persisted rounding is numerically equivalent). This PR performs that rounding at load instead, so residency plans, host pins, and every host-to-device copy carry the compute size rather than the checkpoint size. A kill switch (SGLANG_DIFFUSION_DISABLE_EARLY_VAE_DECODER_CAST) restores the old placement; --disable-autocast and fp32 decode precisions are untouched.

Measured (MiniMax-H3, RTX 4090, 12 GiB cap + 32 GiB host convention, 5s/480p/20 steps)

decoder bytes video_vae residency decode output
before 9.7 GiB (fp32 store) 24 of 36 blocks, rest restreamed per tile 60 s baseline
after 4.9 GiB (fp16 from load) all 36 blocks held for the decode 9.4 s bit-identical (same sha256)

Denoise is unchanged (11.17 s/it, inside the 10.5–11.3 baseline band). No OOM; the run stays inside the 12 GiB cap.

Bit-identity holds because the decode already computed in fp16: casting fp32→fp16 at load lands on the same round-to-nearest-even values the stage produced per call. The embedding and output projections stay fp32 (their calls explicitly disable autocast), as does the encoder.

This also aligns the storage dtype with ComfyUI's H3 pipeline, which stages this VAE as fp16 (4965 MB); its decode-side advantage on 12 GB cards came entirely from that.

Notes

  • Applies to any VAE exposing prepare_decoder_autocast_weights (duck-typed); others are untouched.
  • A cast parameter is no longer a checkpoint-mapping view, so the mapped-weights gate naturally excludes it; the fp16 copy is anonymous host memory accounted by the existing budget.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #32563976293
Latest PR Test (Extra): ❌ Run #32564000895
Latest PR Test (AMD ROCm 7.2): ⏳ Run #32563976139

The decode stage already persists these frozen weights in the autocast
compute dtype on first use (prepare_autocast_linear_weights), so the
rounding is part of every output today; it just happens after residency
plans, host pins, and per-tile host-to-device copies were all sized for
the checkpoint dtype. Rounding at load makes them carry the compute
size: MiniMax-H3's video decoder drops from 9.7 to ~4.9 GiB, the
difference between restreaming a third of it per tile and holding all
36 blocks on a 12 GiB card for the decode.

SGLANG_DIFFUSION_DISABLE_EARLY_VAE_DECODER_CAST restores the old
placement; disable_autocast and fp32 decode precisions are untouched.

Co-Authored-By: Claude Fable 5 <[email protected]>
@github-actions github-actions Bot added the diffusion SGLang Diffusion label Aug 22, 2026
@mickqian mickqian added the run-ci CI: run the baseline test suite on this PR label Aug 22, 2026
mickqian added a commit to mickqian/sglang that referenced this pull request Aug 22, 2026
… cap

Rewrites the ComfyUI comparison for the fp16-held decoder (sgl-project#35967):
video_vae=36 fits 12 GB, the decode drops to ~10 s, and Recipe A wins
the whole request at 32/48/64 GB hosts (235/218/180 s vs 276-302 /
246-267 / 194-195 s). Both engines are hard-capped at 12 GiB with
set_per_process_memory_fraction -- ComfyUI's --reserve-vram alone is
soft and peaked at 13.5 GiB, which a real 12 GB card cannot give it.
Output equivalence is bit-level. Builder flags and hints carry the
measured tiers.

Depends on sgl-project#35967; do not merge before it.

Co-Authored-By: Claude Fable 5 <[email protected]>
@mickqian
mickqian merged commit 61981e1 into sgl-project:main Aug 22, 2026
261 of 288 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant