Repository navigation
[diffusion] ERNIE-Image bit-exact residual-gate fast path (H200 1024^2 e2e 16.17 -> 15.75 s) - #33734
Merged
Merged
Conversation
…2 e2e 16.17 -> 15.75 s, denoise 15.43 -> 15.12 s) Wire the existing residual_gate_add_cuda kernel into both residual-gate sites of the ERNIE-Image shared-AdaLN block. The fused kernel is bit-exact vs the eager residual + gate * update pair for half dtypes (torch.equal; full 1024x1024 generated image is md5-identical to main), so it runs on the lossless default path with no quality gate. The AdaLN modulation params are made contiguous once per forward (bit-exact copy) so the kernel guard accepts the broadcast gate layout. Revives the lossless-safe half of closed PR sgl-project#30170. The non-bit-exact CuTe-DSL norm+scale/shift fusions from that PR were re-validated behind a quality=high mount and rejected again: same-seed full-image PSNR 18.83 dB / SSIM 0.797 vs lossless misses the quality=high bar (PSNR > 25), so they are not included. H200, baidu/ERNIE-Image-Turbo, 1024x1024, 50 steps, fixed prompt+seed, median of 9 (first of 10 dropped): e2e wall 16.17 -> 15.75 s (-2.6%), DenoisingStage 15.43 -> 15.12 s (-2.0%). Kernel microbench per site (1,4216,4096) bf16: 71.0 -> 28.0 us. Co-Authored-By: Claude Fable 5 <[email protected]>
BBuf
requested review from
AgainstEntropy,
HaiShaw,
mickqian,
ping1jing2 and
yichiche
as code owners
August 5, 2026 17:00
This was referenced Aug 6, 2026
Merged
saturn-acc
pushed a commit
to saturn-acc/sglang
that referenced
this pull request
Aug 16, 2026
…2 e2e 16.17 -> 15.75 s) (sgl-project#33734) Co-authored-by: Claude Fable 5 <[email protected]>
Atituiset
pushed a commit
to Atituiset/sglang
that referenced
this pull request
Sep 10, 2026
…2 e2e 16.17 -> 15.75 s) (sgl-project#33734) Co-authored-by: Claude Fable 5 <[email protected]>
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
The ERNIE-Image shared-AdaLN block updates its residual stream twice per layer with an eager two-kernel pair:
The in-tree
residual_gate_add_cudakernel (already used by LTX-2 on its default path) collapses each pair into one launch and, for half dtypes, reproduces the eager pair's rounding bit-for-bit. ERNIE-Image runs bf16 and, with CFG enabled by default, executes 2 forwards/step x 36 blocks x 2 sites x 50 steps = 7,200 such pairs per 1024x1024 image, so the launch/round-trip saving is visible end to end while the output stays byte-identical.This revives the lossless-safe half of closed PR #30170 (see "Relation to #30170" below).
Modifications
ernie_image.py: add_ernie_residual_gate_add(same shape/style as the LTX-2 helper) and use it at both residual-gate sites ofErnieImageSharedAdaLNBlock.forward. Guarded fast path with one-time fallback to the eager expression; restricted to fp16/bf16 where the kernel is bit-exact (for fp32 it would contract to an fma and stop being bit-exact, so fp32 stays on the eager pair).(B, 1, D)contiguous once per transformer forward (a bit-exact copy of tiny tensors) so the kernel guard accepts the broadcast gate layout.Speed Tests (H200)
baidu/ERNIE-Image-Turbo, 1024x1024, 50 steps, bf16, eager (torch.compile is not enabled by default for this pipeline), fixed prompt andseed=42,use_pedisabled to remove prompt-enhancement nondeterminism. Client wall-clock, 10 consecutive generations in one process, first dropped, median of 9. Baseline was run twice to bound run-to-run noise.The DenoisingStage delta is fully explained by the kernel microbenchmark: 2 CFG forwards/step x 36 blocks x 2 sites x 43 us saved x 50 steps ~ 310 ms ~ the measured 313 ms.
Kernel microbenchmark at the real shape
(1, 4216, 4096)bf16 (4096 image tokens + text tokens, hidden 4096), 200 iters after warmup:residual + gate * updateresidual_gate_add_cudaAccuracy Tests
Bit-exactness is proven at three levels (H200, bf16):
torch.equal, real shapes, bf16/fp16True,max_abs_diff = 0324a06b56c4616aeaebd0d8d5017de9eon both)Unit test:
test/registered/kernels/ops/diffusion/test_ernie_residual_gate_add.py(bit-exactness across dtypes at real ERNIE shapes, broadcast and full-shape gate layouts; registered forbase-b-kernel-unit).pre-commit run --files ...: all hooks pass.Relation to closed PR #30170
#30170 wired three fused kernels into this block and was closed for quality regressions (SSIM 0.72-0.80). This PR re-validated all three with a per-kernel bit-exactness protocol:
residual_gate_add_cudatorch.equal)fused_norm_scale_shift(CuTe-DSL)fused_scale_residual_norm_scale_shift(CuTe-DSL)The two non-bit-exact norm+modulation fusions were additionally re-tested behind a
quality="high"mount (per the #33536 DenoisingStage mount/unmount pattern) with a clean fixed-prompt protocol: they add a further -3.8 pp of denoise time but produce same-seed full-image PSNR 18.83 dB / SSIM 0.797 vs lossless, missing thequality="high"bar (PSNR > 25). The 50-step trajectory is genuinely perturbed by the fp32 single-pass modulation, confirming (with a clean baseline) why #30170 was rejected, so they are excluded rather than gated.🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #31064821373
Latest PR Test (Extra): ⏳ Run #31064821237