Skip to content

[Perf] diffusion: Turn on breakable CUDA graphs by default for LTX-2/LTX-2.3 two-stage serving - #45977

Merged
mickqian merged 2 commits into
mainfrom
mick/diffusion-ltx2-bcg-default
Oct 24, 2026
Merged

mickqian merged 2 commits into
mainfrom
mick/diffusion-ltx2-bcg-default

Conversation

@mickqian

@mickqian mickqian commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

LTX-2 two-stage stage 1 runs at half resolution (~1.5k video tokens), so its step is launch-bound: on 4xB300, TRT-LLM's CUDA-graph configuration runs a stage-1 step in 0.044 s against 0.192 s for sglang eager. Breakable CUDA graphs (BCG) close most of that gap, and the graphs replay the same kernels, so the output is bitwise equal to eager. Today BCG is opt-in, so every flagless LTX deployment leaves this on the table.

BCG stays opt-in everywhere else. The validated-model list records correctness, not speed: FLUX.3 won 1 of 10 cells, Qwen-Image-2.1 on 1 GPU is 0.5% slower, and MiniMax-H3 Ref2VA showed no speedup.

HW (2 GPUs, CFG parallel) Model Eager (s) BCG (s) Δ
B300 LTX-2 T2V 768x512x121, 40 steps 6.693 / 6.882 3.797 / 3.785 −44%
B300 LTX-2.3 T2V 768x512x121, 30 steps 6.294 / 6.202 4.735 / 4.726 −24%
H200 LTX-2 T2V 768x512x121, 40 steps 7.398 / 7.593 5.969 / 5.970 −20%

B300 rows: two interleaved rounds, fresh server per arm. H200 rows: see Speed Tests.

Modifications

  • ModelDeploymentConfig.bcg_default_pipeline_class_names: the pipeline classes measured faster with BCG. LTX2PipelineConfig lists LTX2TwoStagePipeline; LTX-2.3 inherits it. The field names the pipeline class because one config serves the one-stage, two-stage and HQ pipelines, and only two-stage was measured.
  • --enable-breakable-cuda-graph defaults to unset. _adjust_breakable_cuda_graph_support resolves an unset flag to on only when all of these hold, and to off otherwise:
    • the pipeline class is opted in and the checkpoint is on the validated BCG list;
    • --performance-mode is auto or speed;
    • the platform is CUDA (current_platform.is_cuda(), so ROCm, NPU and MPS stay off) with separate host and device memory (GB10 stays off);
    • the server warms up at startup (sglang serve); sglang generate and request warmup would pay a full extra generation;
    • monolithic role, ComfyUI mode off;
    • no torch.compile, Cache-DiT, dynamic batching or --lora-path;
    • both stage DiTs stay resident: no DiT component, snapshot or layerwise offload, no FSDP, a GPU with at least 130 GiB (the threshold LTX already uses to pick resident mode), and LTX-2.3 in resident mode.
      An explicit --enable-breakable-cuda-graph true|false always wins. When the default turns BCG on, the server logs [Diffusion BCG] enabled by default for LTX2TwoStagePipeline; pass --enable-breakable-cuda-graph false to run eager.
  • Video BCG warmup now captures the model's full default resolution. It used the server-warmup resolution, which caps video at 832x480: LTX's 768x512 fits under the cap, but Wan (1280x720), MiniMax-H3 (1344x768) or LTX-2.5 (1920x1088) would capture a shape no request uses. Frame counts already used the full default under BCG.
  • Graphs replay the weights and LoRA branches they were captured with, and serving never re-captures. So an external LoRA change (/v1/set_lora, merge, unmerge) or resume_memory_occupation now drops the captured graphs, and later requests run eager with a warning. The two-stage pipeline's own per-request distilled-LoRA switch is part of the capture and is unaffected.
  • Docs: CLI reference and the LTX cookbook describe the default, its gates and the captured shape.

Behavior to know about (one-shot MISSED warning, then eager; no regression against today's eager path):

  • Only the captured shape replays: 768x512, 121 frames, the warmup's quality level, text-to-video. The OpenAI video API defaults to 4 seconds, which LTX rounds to 89 frames, so those requests run eager unless the server passes --warmup-num-frames 89. Image-conditioned requests run eager.
  • A request at another quality level (for example quality="exact") runs eager; the runners are already keyed per level.
  • Per-request attention-backend overrides are rejected under BCG, as before.

Tests:

  • test_server_args.py::TestBreakableCudaGraphDefault: flagless LTX-2 two-stage serving on a mocked 141 GiB CUDA GPU resolves BCG on and captures 768x512; LTX-2.3 needs resident; explicit off, offline runs, request warmup, memory/manual modes, compile, batching, --lora-path, ComfyUI, one-stage and HQ pipelines, unvalidated checkpoints, every DiT offload form, low free memory and an 80 GB card resolve it off; ROCm (is_cuda() false) and shared-memory devices stay off; explicit on elsewhere is unchanged.
  • test_cfg_parallel_warmup.py::test_bcg_capture_keeps_the_full_default_video_resolution.
  • test_diffusion_bcg_padding.py::TestBCGWeightChangeAfterCapture: set_lora, merge, unmerge and resume_memory_occupation drop the graphs, and the runner then runs eager.

On main the default-on, platform-gate, capture-shape and graph-drop tests fail; the gate-off cases pass there by construction and guard the gates from here on.

Accuracy Tests

LTX-2 two-stage on 2xH200, CFG parallel, the benchmark-default command (--performance-mode speed), seed 42, 768x512x121. Same MP4 bytes and same decoded-frame md5 for every arm:

Server Request Path Output
this PR, no BCG flag default quality BCG replay 742a1862…
this PR, --enable-breakable-cuda-graph false default quality eager 742a1862…
main default quality eager 742a1862…
this PR, no BCG flag quality="exact" eager (no graph at that level) same as eager server
this PR, no BCG flag API default, 89 frames eager (MISSED) same as eager server
this PR, no BCG flag after /v1/set_lora eager (graphs dropped) same as eager server after the same call

With the CI-shaped request (1 second = 25 frames, quality="exact", --warmup-num-frames 25 --warmup-sampling-params '{"quality": "exact"}'), BCG, eager and main also produce identical outputs.

Speed Tests and Profiling

LTX-2 two-stage, 2xH200, CFG parallel, the benchmark-default command (--performance-mode speed --dit-layerwise-offload false --enable-torch-compile false, no BCG flag), 768x512x121, 40 steps. diffusion-bench-framework single_e2e (median of 2 measured requests after warmup), fresh server per run, rounds interleaved main / PR / main / PR:

round 1 round 2
main (eager) 7.398 s 7.593 s
this PR (BCG by default) 5.969 s 5.970 s

Stage breakdown (round 2): LTX2AVDenoisingStage 5.368 → 3.702 s, LTX2RefinementStage 1.187 → 1.096 s, decode unchanged (0.67 s). On Hopper the FA attention calls stay eager, so each forward captures 289 segments; on B300 LTX attention is captured as well (1 segment per forward), which is why the gain there is about twice as large.

Cost on 2xH200, this PR with and without --enable-breakable-cuda-graph false, two alternating rounds:

BCG default --enable-breakable-cuda-graph false
Startup to healthy (round 1 / round 2) 104.1 / 84.1 s 86.1 / 78.0 s
Server warmup 121 frames, 40 steps: 52.1 / 32.2 s 25 frames, 2 steps: 31.6 / 26.5 s
Peak memory per request (rank 0) 82,654 MB 75,690–75,704 MB

Startup grows by about 6 s once caches are warm (about 20 s on a cold first start), and peak memory by 6.9 GB. On B300 the same comparison was +2 s and +0.95 GB (LTX-2) / +1.1 GB (LTX-2.3).

CI and baselines

No perf or memory baseline should move:

  • The H100 suite's LTX cases run on 80 GB cards, below the 130 GiB gate, so they stay eager. The B200, 5090 and XPU suites have no LTX two-stage case, and AMD is not CUDA.
  • The explicit-BCG CI tests (test_diffusion_bcg_*zimage_turbo.py) are image models; the warmup-resolution change only affects video.
  • If an H200/B200-class LTX two-stage case is added later, its runtime peak will include the capture (+~7 GB on Hopper), and its warmup runs one full generation; seed its baseline with the usual two-step flow.

Risks

  • Startup grows by one full-shape generation plus capture: +6 s on 2xH200 with warm caches, about +20 s on a cold first start, +2 s on B300.
  • Peak memory grows by ~7 GB on Hopper, where attention stays eager (289 segments per signature), against ~1 GB on Blackwell, where LTX attention is captured too (1 segment). The 130 GiB gate keeps 80 GB cards, whose speed-mode headroom is smaller than that, on eager.
  • LTX-2.3 is validated on B300 only (above). The H200 runs here cover LTX-2.
  • [Fix] diffusion: Keep dynamic LoRA deltas on fused linear-GELU sites #45943 changes the dynamic-LoRA linear path that stage 2 runs; BCG captures whatever eager runs, so outputs stay equal to eager, but its speed should be re-checked once both land.

Checklist

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ✅ Run #39950830926
Latest PR Test (Extra): ❌ Run #39950830821
Latest PR Test (AMD ROCm 10): ❌ Run #39950830987

…-stage serving

LTX2TwoStagePipeline stage 1 is ~1.5k tokens and launch-bound; breakable
CUDA graphs replay the same kernels, so the output is bitwise equal to
eager. The flag stays off everywhere else because the validated-model list
records correctness, not speed.

- ModelDeploymentConfig.bcg_default_pipeline_class_names: pipelines
  measured faster with BCG; LTX2PipelineConfig lists LTX2TwoStagePipeline.
- enable_breakable_cuda_graph defaults to None. Unset, it turns on in
  auto/speed mode for an opted-in pipeline on a validated checkpoint when
  the platform is CUDA with separate host memory, the server warms up at
  startup (sglang serve), the role is monolithic, ComfyUI mode is off, no
  torch.compile, Cache-DiT, batching or --lora-path, and both stage DiTs
  stay resident: no DiT offload or FSDP, a >=130 GiB GPU (the LTX resident
  rule; capture holds ~7 GB more on Hopper) and LTX-2.3 in resident mode.
- BCG warmup captures the full default resolution instead of the
  832x480-capped video warmup shape.
- External LoRA changes and resume_memory_occupation drop captured graphs:
  graphs replay capture-time weights and LoRA branches and serving never
  re-captures, so later requests run eager.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mintlify

mintlify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
sglang-doc 🟢 Ready [View Preview](https://lmsysorg-mick-diffusion-ltx2-bcg-default.mintlify.site/cookbook/diffusion/LTX/LTX2 & LTX2.3) Oct 23, 2026, 5:22 AM

💡 Tip: Enable Automations to automatically generate PRs for you.

@mickqian

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added documentation Improvements or additions to documentation diffusion SGLang Diffusion run-ci CI: run the baseline test suite on this PR labels Oct 23, 2026
@github-actions

This comment has been minimized.

@mickqian mickqian changed the title [diffusion] Breakable CUDA graphs on by default for LTX-2/LTX-2.3 two-stage serving [Perf] diffusion: Turn on breakable CUDA graphs by default for LTX-2/LTX-2.3 two-stage serving Oct 23, 2026
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 lora 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