Repository navigation
[Performance] Optimize Qwen3.5 GDN prefill projection layouts - #36267
Merged
YAMY1234 merged 6 commits intoSep 4, 2026
Merged
Conversation
YAMY1234
marked this pull request as ready for review
August 25, 2026 19:35
YAMY1234
requested review from
BBuf,
DarkSharpness,
Fridge003,
HaiShaw,
HydraQYH,
Qiaolin-Yu,
celve,
hebiao064,
ispobock,
merrymercy,
yizhang2077 and
yuan-luo
as code owners
August 25, 2026 19:35
Collaborator
Author
|
/tag-and-rerun-ci |
Collaborator
Author
|
/rerun-failed-ci bypass-fastfail b08e11e |
This was referenced Sep 4, 2026
7 tasks done
StevenChenSE
pushed a commit
to StevenChenSE/sglang
that referenced
this pull request
Sep 6, 2026
4 of 5 tasks
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Sep 24, 2026
…j output via strided views Upstream 07199fa (v0.5.20), adapted to the fork paths and dispatch. The 27B's GDN (16 k / 48 v heads, ratio 3) is outside the fork's fused split list [1, 2, 4], so every GDN layer of every prefill chunk ran split + b/a .contiguous() + torch.cat(q, k, v) + a z reshape copy before the gated norm. The in_proj output is already block-contiguous per token ([q|k|v|z], [b|a], MergedColumnParallelLinear with tp_units), so prefill needs no copy at all. Ported: - jit_kernel/triton/gdn_fused_proj.py: qwen3_5_gdn_prefill_projection_views (mixed_qkv / z [T,Hv,Dv] / b / a as views; rank-LOCAL head counts, so the uneven GDN split per rank is untouched). - layers/attention/fla/layernorm_gated.py: rms_norm_gated takes a strided 3-D gate [T, H, D] against x [T*H, D] (Z_IS_3D / Z_HEADS in the 1-pass kernel); the 2-D path and its callers (mixer2) are unchanged. - models/qwen3_5.py: CUDA extend-without-speculative takes the views and hands the 3-D gate to the norm; decode / target-verify / draft-extend keep the existing dispatch (fused split for [1,2,4], unfused split otherwise). Consumers checked for strides: Triton causal_conv1d (x.stride used, output via empty_like keeps the permutation -> dense, verified), track_conv_indices gather, fused_qkv_split_gdn_prefill (strided input), fused_gdn_gating (row strides), the TC-piecewise/BCG custom op (passes tensors through). Not ported (not applicable): gdn_prefill_qkv_prepare_fwd + the gdn_flashinfer.py hunk -- FlashInfer GDN prefill is only auto-selected on SM90/SM100 (is_sm100_supported = major 10); sm86/sm120 run Triton. Metal note: causal_conv1d's stride_x_token is a tl.constexpr, so the first prefill after this change JIT-builds one new Triton variant per rank (row stride = local qkvz width instead of qkv width); likewise the changed gated-norm kernel. Triton cache, seconds, not a tvm-ffi/ninja build. Tests (CPU, incg cgroup): test/registered/unit/layers/attention/test_gdn_prefill_layout_36267.py - views == the fork's unfused split, bit-exact, for uneven 27B ranks (5/15, 6/18) and the full 16/48 stage, on dense and fused-GEMM-strided projections; - Qwen3_5GatedDeltaNet.forward: EXTEND (views, strided mixed_qkv + 3-D gate reach attn/norm) == DECODE split path, bit-exact; TARGET_VERIFY stays on the split path; - rms_norm_gated strided 3-D gate == dense 2-D gate on the production Triton kernel under TRITON_INTERPRET, norm before/after gate, vs torch reference. 4 passed (10 subtests). On the base sources: 4 failed + 1 error.
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Sep 24, 2026
…rides: fused split for head ratio 3 Upstream 8a1e6e4 (v0.5.20), the GDN part only, plus the row-stride hunk of upstream 52fecfd (sgl-project#37500) that the fork's port of sgl-project#37500 (e46a4db) left out. The 27B's GDN (16 k / 48 v heads, ratio 3) was outside the fused split list [1, 2, 4]: every decode / DFLASH verify step ran split + 2x .contiguous() + torch.cat + a z reshape copy on every GDN layer. The contiguous fused split kernel now walks a non-power-of-two head group one HEAD_V head at a time (V_POW2 constexpr prunes the dead branch; power-of-two groups keep the wide vector access), and qwen3_5 enables ratio 3 on CUDA (_GDN_FUSED_QKVZBA_RATIOS = (1, 2, 3, 4) on CUDA, (1, 2, 4) elsewhere). Prefill keeps the sgl-project#36267 strided views; verify then hands views on (sgl-project#33778). Row strides (sgl-project#37500): the kernel read rows at the dense widths. With finalize_fused_in_proj (called for the NF model, qwen4_exp; its GDN ratio is also 3) the split gets two column views of ONE GEMM output (row pitch = qkvz + ba width), so routing ratio 3 here without the strides would have read the wrong rows for every token after the first on NF. The 27B does not call finalize_fused_in_proj (dense rows); the wrapper now also asserts unit column strides. Not ported from sgl-project#34859 (not applicable to INT8 on sm86/sm120): sm120 FP8 GEMV, Hopper bf16 GEMV (SM90 only), SM90 FlashInfer GDN prefill default, NVFP4 SiLU+quant fusion, DSpark / qwen2_moe / deepseek / modelopt hunks. Tests (CPU, incg cgroup): test/registered/unit/layers/attention/test_gdn_fused_split_head_ratios_34859.py - production kernel under TRITON_INTERPRET vs plain slicing, ratios 1/2/3/4, uneven 27B rank-local heads 5/15 and 6/18, full 16/48, dense and fused-GEMM-strided rows: 14/14 bit-exact (worker run under incg; the shared 3 GiB cgroup OOM-killed the pytest wrapper of this class twice while other agents' suites ran). Base kernel: strided rows wrong for ratios 1/2/4, ratio 3 does not compile (arange not a power of two). - qwen3_5 dispatch: decode and target verify take the fused split for ratio 3, extend takes the views: 3 passed.
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Sep 26, 2026
…cks, chronologisch) Grundlage: Präsenz-Scan aller 230 27B-Commits seit 76f8deb gegen diesen Baum (Stichprobe der hinzugefügten Zeilen je Commit); die 94 fehlenden minus die bewusst anders gewählten Formen (76e87ac/4ae11ababd -> S3 form.calibration_identity; 479f6ec/d7f588e017/d0fba8955f/34892e3017 -> S2 NF-Formen; 7f81f09/3c14481318 -> S4/S7a; 3dbb790 line_gate_27b (Werkzeug, Schritt 9); 8604d13 W100-by-name (Nutzer: bleibt aus); 6545e2c flashinfer-Pin in pyproject (Image-Frage, nicht Baum)). Liste: 92bbccb eb5d044 829ebd0 431fcbc ef4d11f 6816062 a233e50 2cc593c f0c8451 87cc4fb c529777 31f2dbe c50085a 3301a96 036b368 e1d1fe9 03c68af 6dddc2e 06932b5 87389c4 58a7490 f85ac55 fc64aa5 5aa24dd 97c0e9a 159333c d9f1532 f3c685b 8550655 e50fb59 db2c2ef f09dc0d c255e10 51b810e 28a55a2 34965fc ff3d9cc 340a018 bee5e10 67b6352 fdade85 ed6630d f1c9a43 b434831 517f26d 0b6b60b a40837f 644de86 aff2b7c 197b701 856024b 238512a 9738626 b857a22 1f8c24d d294b3e 810239d b429dfd e714c95 9efd974 3d63e0a d3cfcf3 fee6134 7985b56 49a14e9 fc45706 19c720e 5306bee 6f1235a c98eaa3 93bc802 328349e f9fb3a2 572af73 94fa8b4 d342caa 2fd7d7e 3ebbb96 871d55f 78c2f16 3babf51 196f6a8 e70af54 22eccfc Inhalt: Upstream-Ports (sgl-project#33758 sgl-project#37818 sgl-project#36738 sgl-project#33459/sgl-project#30096 sgl-project#34446 sgl-project#36267 sgl-project#33778 sgl-project#34859 sgl-project#36415 sgl-project#35255/sgl-project#36638 sgl-project#39858/sgl-project#40259 sgl-project#31417 sgl-project#34892 sgl-project#32225 sgl-project#30832/sgl-project#36626 sgl-project#39574 sgl-project#29579 sgl-project#31468 sgl-project#32575 sgl-project#31648); xsn409/410-Wake-Verdikte; Vision-Linie V1-V3b + xsn438 (SGLANG_WEG2_VISION_FLIP_URGENT); D-Planer L6 (159333c); DFLASH-Window-Pool sync-frei, PLAN_SYNC_FREE, D-Kollektive (vocab-argmax, a2a-Merge, deferred rebuild), #DGAP/D_DEFER_SEQ_LENS_CPU; Mamba-Anker Raster 4096 + Per-Path-Cap + Inner-Release; P-TRIM (--p-trim-end-anchor); FP8 uniform Marlin; ModelOpt/NVFP4 RadixArk; GGUF G1-G6 + F1/F2; native-mixed sgl-project#38 (sm_8x W4A8, sm_12x CUTLASS/W4A16); RC1-Capture-Set; sgl-project#49 Agent-Turns; dynchunk (--p-chunk-policy, --p-chunk-dynamic-min-tokens). Auflösungen (Gabel -> Form, Grund): - L6 d_operating_point_rows: 27B (d) "Token-Vektor auf jeder Position aus der Kapazität" nur bei TP-symmetrischem D (Profil d_layout paged_dcp); sonst NF-sgl-project#1293-Pin + NF-Anker- Klausel. mamba_ssm_dtype aus EARLY_READ_FACTS nur bei Profil early_read_flags. Overhead-Kalibrierung liest mit form.CalibrationIdentity statt LineIdentity. - RC1 Capture-Set: neuer RecordKey-Term d_capture_set (qwen27b), Leser CalibrationIdentity.d_max_running_requests; nextflash unverändert. - URC Carrier-Hold: 27B _weg2_carrier_hold entfällt (S2 NF-Rotation), Inner-Release und Per-Path-Cap bleiben (Env, Default aus; 27b.env setzt sie). - scheduler_pp_mixin/overlap_utils/batch_result_processor: NF H49/H58 und 27B #PGAP/#DGAP komponiert (beide Instrumente getrennt schaltbar). - schedule_policy: P-TRIM-Kurzschluss vor NF H63-Fold/QSA-Korn; sgl-project#36415 Hoist + NF computed_input_len. - gdn_backend sgl-project#33778: 27B-strided-Verify; NF-Ring flacht beide Layouts ab. - flashinfer_backend: RC9-Datei + NF-Form-A-Waiver (27B-intern mehrfach gegabelt). - checkpoint_census: GGUF-Leser + NF exclude_segments (PLE) in einer Aggregation. - xchg_manifest: FLAT_SEGMENTS in beiden (dst/src) NF-Breitenbedingungen ausgenommen. - vram_peak_window: NF-Kumulativ-Peak liest über den 27B-Fast-Read. - FP8: 8c86eb8-Rest nachgezogen (private Workspace-Registry entfernt, wie RC9). - argv_d: vision= an allen drei Aufrufstellen (inkl. NF --d-only). - census_checkpoint_decision (W161) jetzt für beide Profile aktiv. Gates: py_compile aller geänderten Dateien; ruff F821/F811 ohne neue Funde gegenüber dem Vorgänger (PendingSeqLensCpu ist String-Annotation wie in RC9); dup_defs_gate 0 neu. Tests: 73 portierte Testdateien, Lauf nach dem Ruhefenster (Boot aktiv).
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
Qwen3.5 GDN prefill materializes QKV/Z/B/A projection slices early, then performs separate Q/K/V layout copies before FlashInfer prefill. These data-movement kernels are material at long cached-prefix prefill sizes.
Modifications
Accuracy Tests
31547880.9904.5270111.00 / 031789550.9854.49661.00 / 0Both runs used non-simulated five-shot GSM8K normal generation.
Speed Tests and Profiling
AgentX cache-on workload
AgentX cache-on A/B from jobs
3177414 -> 3177457: identical manifest, request stream, actual cached/new work, rank load, and 36/36 exactly-once cohorts.24,122.42325,369.772+5.171%27,587.79029,105.925+5.503%29,825.88730,974.960+3.853%30,627.01832,138.435+4.935%30,803.71932,204.009+4.546%30,831.46232,093.066+4.092%Matched
prefix=57,344,new=8,192profiling:15.185688 ms2.760650 ms-81.821%250.885729 ms240.355773 ms-4.197%241.837455 ms(TRT)240.355773 ms(SGLang candidate)-0.613%The comparison isolates the GDN layout change while keeping the workload and execution contract fixed.
Kernel microbenchmark and profiling
Contiguous-input reuse was validated on GB300 with the production
fused_qkv_split_gdn_prefill -> gdn_prefill_qkv_prepare_fwdchain. Job3291878used BF16 Qwen3.5 local dimensionsT=8192,H_QK=4,H_V=16,D=128, with 50 warmup iterations and medians over nine repeats of 100 iterations.0.105018 ms0.067229 ms1.562x(-35.98%)0.135026 ms0.098273 ms1.374x(-27.22%)Nsight Systems job
3291970confirms the structural result over 100 full-chain iterations:gdn_prefill_qkv_prepare_kerneldrops from 100 calls to 0, while fused split remains at 100 calls and Q/K L2Norm remains at 200 calls. The redundant V copy is removed by reusing fused-split storage.Static workload E2E
A clean same-node E2E A/B from job
3293694compares base67853c580482dbc9b69aad5022a0cdd3a1606570with candidate09173bc2619ccc678533e54ff7c9b1a91c11a08a. Both arms use Qwen3.5-397B-A17B-NVFP4-V2 on one GB300 node with TP4, exactISL=8192/OSL=1, seed 42, radix cache disabled, and 32,768 aggregate prefill tokens. C32/C128 use 64/256 warmup requests followed by 96/384 formal requests.100,392102,139+1.74%-1.73%96/96100,595102,126+1.52%-1.50%384/384All formal requests completed without errors, and server logs confirm that the 32,768-token prefill batches used the breakable CUDA graph. Reported prefill graph capture memory also decreased from
6.20 GBto5.88 GBper TP rank (-5.16%).Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ✅ Run #33360571667
Latest PR Test (Extra): ❌ Run #33360571497
Latest PR Test (AMD ROCm 7.2): ❌ Run #33360571676