Skip to content

[diffusion] feat: introduce ltx-2-two-stage device manager#22869

Merged
mickqian merged 25 commits intomainfrom
ltx-2.3-two-stage-ti2v
Apr 18, 2026
Merged

[diffusion] feat: introduce ltx-2-two-stage device manager#22869
mickqian merged 25 commits intomainfrom
ltx-2.3-two-stage-ti2v

Conversation

@mickqian
Copy link
Copy Markdown
Collaborator

@mickqian mickqian commented Apr 15, 2026

Modifications

One-stage

  • Disable DiT CPU offload by default on high-memory Hopper GPUs
  • Disable VAE CPU offload by default on high-memory Hopper GPUs

Two-stage

  • Prebuild and premerge the stage-2 distilled transformer (transformer_2, for snapshot and resident mode)
  • Pin the stage-1 transformer on GPU at startup when beneficial
  • Replace request-time module.to(cpu/cuda) switching with CPU snapshot based release
  • Fix an initialization regression where CPU snapshots redundantly cloned tensors that were already on CPU

Pre-merged LoRA (only applicable for two-stage)

when running two-stage pipeline, LoRA will be applied between two denoising stages, this would include:

  1. cuda.synchronize to wait for ongoing tasks
  2. layerwise_offload.disable_offload(): move the dit to GPU, h2d(required when dit-layerwise-offload is enabled), ~67.1s
  3. apply lora (~18.5s)
  4. layerwise_offload.offload(): optional, to resume the offload behavior

while with new approach snapshot mode:

  1. h2d (for dit_2), but for dit_1, points param.data directly to cpu_snapshot instead of d2h

for even more aggressive mode resident, all two dits are always kept resident.

Mode Pre-merged LoRA (two-stage) behavior Peak VRAM (observed) Mechanism summary
legacy No cuda.synchronize to wait for ongoing tasks + layerwise_offload.disable_offload + apply lora ~58.01 GB (H200) Old path is “sync first, then heavy transfers + merge”, so LoRA switch latency is large
snapshot (low_vram) Yes (snapshot_release path) more conservative overlap/prefetch to control memory ~57.22 GB (H100) Key idea is replacing d2h with pointer remap for stage-1 weights, while keeping only necessary H2D
snapshot (aggressive) Yes (same snapshot_release core) more aggressive overlap/early prefetch for dit_2 H2D ~95.12 GB (H200); OOM on H100 in this run Optimized for throughput via overlap, but with higher VRAM peak risk
resident Yes (resident switch path) Ideally no stage-switch DiT H2D/D2H (weights stay resident on GPU), only switch logic ~95.78 GB (H200) Best performance from minimal transfer/sync, at the cost of highest memory residency

Motivation

Statistics

Stage Breakdown

Stage legacy snapshot (low_vram) snapshot resident
InputValidationStage 0.05 0.06 0.05 0.04
TextEncodingStage 1629.37 1687.90 1597.86 1690.40
LTX2TextConnectorStage 26.26 27.36 27.96 26.49
LTX2HalveResolutionStage 0.06 0.06 0.06 0.06
LTX2LoRASwitchStage 126.90 0.02 0.01 0.01
LTX2SigmaPreparationStage 0.56 0.24 0.24 0.28
TimestepPreparationStage 32.19 24.99 29.40 38.28
LTX2AVLatentPreparationStage 0.19 0.11 0.12 0.14
LTX2ImageEncodingStage 0.02 0.03 0.01 0.01
LTX2AVDenoisingStage 13387.52 14256.86 10340.81 8572.26
LTX2UpsampleStage 752.47 1124.06 403.42 313.57
LTX2RefinementStage 804.25 2849.95 1333.42 884.42
LTX2AVDecodingStage 935.46 1191.01 826.38 851.44
expected_e2e_ms 28429.46 21344.75 14739.99 12532.90

Peak VRAM

Peak VRAM legacy snapshot resident
Peak GPU memory (GB) 58.01 95.12 95.78
Peak memory usage (MB) 59400 97402 98082

NOTES

  1. LTX2LoRASwitchStage no longer exists in non-legacy mode
  2. low_vram snapshot mode is default enabled on h100, while may be sub-optimal with sp > 1

Modifications

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

@github-actions github-actions Bot added lora diffusion SGLang Diffusion labels Apr 15, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request optimizes LTX-2.3 pipelines by implementing pre-merged stage 2 transformers and a CPU snapshot mechanism for efficient weight management. It also introduces performance profiling and adjusts default offloading settings for high-memory GPUs. Review feedback highlights safety concerns regarding the use of next(module.parameters()), which can raise StopIteration if parameters are missing. Additionally, a potential AttributeError in the denoising stage and a logic flaw in CPU tensor pinning were identified.

Comment thread python/sglang/multimodal_gen/runtime/pipelines/ltx_2_pipeline.py Outdated
Comment thread python/sglang/multimodal_gen/runtime/pipelines/ltx_2_pipeline.py Outdated
Comment thread python/sglang/multimodal_gen/runtime/pipelines/ltx_2_pipeline.py Outdated
Comment thread python/sglang/multimodal_gen/runtime/pipelines/ltx_2_pipeline.py Outdated
Comment thread python/sglang/multimodal_gen/runtime/pipelines_core/stages/denoising_av.py Outdated
Comment thread python/sglang/multimodal_gen/runtime/pipelines/ltx_2_pipeline.py
@mickqian
Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added documentation Improvements or additions to documentation run-ci labels Apr 15, 2026
@mickqian mickqian force-pushed the ltx-2.3-two-stage-ti2v branch from e89d478 to b94e8d0 Compare April 16, 2026 11:19
mickqian and others added 10 commits April 16, 2026 19:57
Revert _adjust_offload LTX-2.3 special branch and
_temporarily_disable_offload behavior change to match
origin/main, keeping only offload infrastructure changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts:
#	python/sglang/multimodal_gen/runtime/pipelines_core/stages/ltx_2_denoising.py
Off-topic for the offload PR; redundant with the outer
StageProfiler that already wraps each PipelineStage. Restores
parity with origin/main.
@mickqian mickqian changed the title [diffusion] optimize ltx-2.3 offload hot paths [diffusion] feat: introduce ltx-2-two-stage device manager Apr 17, 2026
@mickqian mickqian merged commit 0d94c33 into main Apr 18, 2026
49 of 53 checks passed
@mickqian mickqian deleted the ltx-2.3-two-stage-ti2v branch April 18, 2026 03:04
zhangying098 pushed a commit to zhangying098/sglang that referenced this pull request Apr 23, 2026
kyx1999 pushed a commit to KMSorSMS/sglang that referenced this pull request Apr 27, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants