Repository navigation
[Perf] diffusion: Cache the fused linear-GELU verdict per linear - #44643
Merged
Merged
Conversation
can_use_linear_gelu re-ran the input-independent guards (architecture, quantization, bias, weight layout) on every call, ~2.7 us per call. The verdict is now kept per linear and cleared when sites are mounted or unmounted; the input checks still run every call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mickqian
requested review from
BBuf,
niehen6174 and
yingluosanqian
as code owners
October 16, 2026 03:12
Collaborator
Author
|
/tag-and-rerun-ci |
detain
pushed a commit
to detain/sglang
that referenced
this pull request
Oct 19, 2026
…-project#44643) Co-authored-by: Mick Qian <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit 949e1a2) Fork note (SM120 / skynet2): the arch carve-out inside the cached verdict returns False for arch.major*10+arch.minor >= 120, so on our 4x RTX PRO 6000 Blackwell Workstation cards the fused cublasLt GELU epilogue stays off. What still applies for us is exactly the caching win: the per-call can_use_linear_gelu() short-circuits after the cheap x.dtype/weight checks instead of re-running can_use_linear_gelu_static() over the linear's module tree on every DiT block call. No behavior change vs today's eager path; verdict is False either way. (cherry picked from commit 5866482a023a7ca70479f1394ede3c39bda9329f)
4 of 5 tasks
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
can_use_linear_geluruns at every quality-gated GELU up-projection: FLUX, Qwen-Image, LongCat, LTX-2, HunyuanVideo, GLM-Image and Wan. On every call it re-ran the input-independent guards:skip_bias_addandgather_outputchecks;That is 2.67 µs per call on an x86 host, mostly
getattrmisses onnn.Module. In a py-spy profile of FLUX.1 TP2 it was 1.3% of the denoise host time.Modifications
In
fused_linear_gelu_site.py:WeakKeyDictionary.mount_fused_linear_geluandunmount_fused_linear_geluclear it, so a re-mount re-reads the linear.x.dtype == weight.dtype.No model call site changes. No memory is involved.
Accuracy Tests
On H200:
test_sites.py: 25 passed, including the newtest_linear_gelu_verdict_is_reused_until_remount. It checks that three calls read the linear once and that a re-mount reads it again.test_wan_gelu_mlp.py: passed.test_model_fast_paths.py: 114 passed.Speed Tests and Profiling
Base
c15edf314d, torch 2.14.1, H200 (Xeon 8558P).can_use_linear_gelubeforecan_use_linear_geluafterEnd to end, FLUX.1-dev TP2 eager on 2xH200, client wall-clock median. Both paths were built into one server and chosen per request, rotating in the same process, with #44251 applied to both. An extra base arm measures in-process noise.
Output images are unchanged: the same path is chosen.
Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ✅ Run #39018724667
Latest PR Test (Extra): ❌ Run #39018724597
Latest PR Test (AMD ROCm 10): ❌ Run #39018724683