Repository navigation
[KDA-Pilot] Add diffusion residual-gate CUDA fast path for LTX2 - #29361
Merged
Merged
Conversation
BBuf
requested review from
DarkSharpness,
HydraQYH,
celve,
mickqian,
ping1jing2,
yhyang201,
yingluosanqian and
yuan-luo
as code owners
June 26, 2026 02:20
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
…batched-gate reject Address review feedback on sgl-project#29361: - Log a warning (with traceback) when residual_gate_add_cuda fails and the sticky process-global disable kicks in, so the silent perf regression is diagnosable. Mirrors the warning the Cosmos3 cat-pad fallback already emits. - Restore the two unrelated blank-line removals in LTX2 forward signatures to keep the diff focused on the kernel change. - Extend the rejection test to assert a batched [B>1, 1, D] gate is not treated as row-broadcast and falls back, pinning the broadcast contract. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… branch Address CUDA-side review feedback on sgl-project#29361: - bcast row-tile kernel now grid-strides over row tiles and the y grid dim is clamped to 65535, so very large row counts no longer exceed the gridDim.y hardware limit and fail the launch. Behavior is identical for production shapes (one tile per block when row_tiles <= 65535). - residual_gate_add_vec_kernel drops the GateMode template parameter and the never-launched row-broadcast branch (the vectorized broadcast path uses the dedicated tile kernel), keeping the vectorized full-gate path single-purpose. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
Collaborator
Author
This was referenced Jun 27, 2026
BBuf
added a commit
to BBuf/sglang
that referenced
this pull request
Aug 6, 2026
…024^2 50-step denoise 3.358 -> 3.318 s) Wire the existing residual_gate_add_cuda kernel (in-tree since sgl-project#29361, already on the LTX-2 default path; same helper pattern as ERNIE-Image Flux2TransformerBlock x 4 sites (img/txt attn+mlp) and Flux2SingleTransformerBlock x 1 site (joint stream). On FLUX.2-dev (8 dual + 48 single blocks, hidden 6144) that is 80 sites/step = 4,000 eager mul+add pairs per 50-step 1024x1024 image; on FLUX.2-klein-4B (validation model - dev is gated with no ungated mirror; 5 dual + 20 single, hidden 3072) it is 40 sites/step. The kernel is bit-exact vs the eager pair for half dtypes (torch.equal at real FLUX.2 shapes; full generated image md5-identical to main), so it runs on the lossless default path with no quality gate. fp32 stays on the eager pair; batched [B>1,1,D] gates fail the guard and fall back automatically. FLUX.2's modulation params are already dense [1,1,D] rows, and an instrumented klein run hit the fused path on all 160 helper calls of a 4-step generation (zero fallbacks). H200, FLUX.2-klein-4B, 1024x1024, 50 steps, bf16, fixed prompt+seed, median of 9 per run (first of 10 dropped), two clean runs combined (n=18/arm; a third run hit a host load spike on the shared box and is reported separately in the PR): DenoisingStage 3.358 -> 3.318 s (-1.2%); per-run minima -1.2% to -1.7% in all three runs; e2e wall within shared-host noise. Kernel microbench per site, bf16: (1,4096,3072) 53.2 -> 20.6 us, (1,4608,3072) 59.3 -> 23.1 us (2.6x), (1,512,3072) neutral; klein's 40-site sum (1.04 ms/step, 52 ms/image) brackets the measured 40-55 ms clean-window denoise delta. Generated images are md5-identical to main at both 50 steps and the default 4-step klein preset (all 10 iterations, every run). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Chronostasys
pushed a commit
to MindLab-Research/sglang
that referenced
this pull request
Aug 24, 2026
…project#29361) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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
Add a native CUDA JIT fast path for the LTX-2.3 residual-gate update pattern from KDA-Pilot task
b200_diffusion_residual_gate_add__multi_shape/ BBuf/KDA-Pilot#134.The hot pattern is equivalent to:
for contiguous
[B, L, D]tensors with either a full gate or a broadcast gate shaped[B, 1, D]. The LTX-2.3 HQ two-stage path hits large broadcast rows such as[1, 32640, 4096]and full-gate rows such as[1, 8160, 4096]across the DiT residual, attention, and MLP updates.Modifications
diffusion_residual_gate_addlightweight JIT CUDA kernel.torch.compiletracing sees an opaque op instead of tracing JIT/module loading.fuse_scale_shift_kernelimplementation if the JIT load/launch fails.torch.compile(fullgraph=True)custom-op test.Accuracy Tests
B200:
Result:
12 passed.H100:
Result:
12 passed.Speed Tests and Profiling
Kernel benchmark command:
B200 kernel benchmark:
H100 kernel benchmark:
B200 Nsight Compute check for the large broadcast workload:
The row-tiled CUDA path reuses each broadcast gate vector across 4 rows, removes the expensive flat-index modulo from the hot loop, and reduces repeated gate memory traffic.
B200 model E2E benchmark:
ion-b200, NVIDIA B200,CUDA_VISIBLE_DEVICES=7.Lightricks/LTX-2.3, nativeLTX2TwoStageHQPipeline; no diffusers fallback observed.1920x1088x121f, recommended HQnum_inference_steps=15,seed=42.sglang generate --warmup; metric isperf.jsontotal_duration_ms, with the warmup request excluded.B200 Visual Output Check
Visual equivalence check uses the same full LTX-2.3 HQ command as the model benchmark above.
ion-b200, NVIDIA B200,CUDA_VISIBLE_DEVICES=7.4d06d4c97f; PR commit:b4dfe508ca45.A beautiful sunset over the ocean,1920x1088x121f, recommended HQnum_inference_steps=15,seed=42.LTX2TwoStageHQPipelinewas used for both runs; no diffusers fallback was observed.0.984868, PSNR average41.339961 dB.Left is
main; right is this PR:MP4 artifacts: main.mp4, pr.mp4, side-by-side.mp4.
Checklist
torch.compilecompatibility.torch.compile(fullgraph=True)custom-op unit test included.Review and Merge Process
This is a focused KDA-Pilot kernel integration PR. The expected useful effect is the faster residual-gate update group in LTX-2.3 HQ DiT blocks; whole-model speedup is visible but modest because attention, MLP, and decode still dominate the full video generation runtime.
CI States
Latest PR Test (Base): ❌ Run #28272388900
Latest PR Test (Extra): ❌ Run #28272388830