Repository navigation
Backbone GEMMs and RMSNorm: microbenchmarks, a skinny GEMM and an opt-in engine patch series - #91
Conversation
experiments/backbone/gemm_bench.py replays SGLang's F.linear for every Qwen3.5-4B backbone projection with the real weights under CUDA graphs, M = 1..128, and times cuBLAS, cuBLASLt (PyTorch's choice and every heuristic algorithm, through lt_algos.cpp), SGLang's Hopper GEMV and a Triton skinny GEMM sweep. It also times the RMSNorm kernels and two layer skeletons in which PDL and the fused norm and SiLU prologues interact. Triton configurations are compiled and checked in worker processes first, so a faulting kernel cannot take down the run.
…T SiLU The norm subcommand now records, per M, how many elements of the add-RMSNorm and SiLU-mul prologue outputs (from the engine's probe kernel) equal the stock kernels' outputs, and their largest distance in BF16 units. The FlashInfer CUDA norm arms are skipped when its JIT module cannot be loaded.
Against a float64 product at the backbone shapes, run-to-run and graph-replay bitwise stability of the split-K reduction (with and without PDL), the add-RMSNorm prologue against FlashInfer (residual bitwise, output within one BF16 step), the SiLU prologue against the JIT activation, and the deferred-norm input. They skip without CUDA or without the engine patch.
Per projection and M bucket, Triton where it beats cuBLAS by a margin, a fused-only entry where only the folded norm or SiLU makes it pay, cuBLAS otherwise.
For M = 1..1024 and all 24 GDN layers: the fraction of output elements that are bitwise equal between F.linear on the concatenated 12352-row weight and the separate qkvz and ba calls, the largest difference, the cuBLAS kernels, and the time per layer of the merged GEMM, the separate pair on a side stream (as SGLang captures it on CUDA) and the separate pair in series.
The float64 test skipped no split-K configuration whose workspace exceeds the default scratch (the kernel correctly refuses it at M = 128), and the deferred norm test still wrote two-field table entries.
…, or both; --variants
Produced by repo 1e56c79 and engine e89b122037 on the GH200, clean trees, foreign CPU load 0.3-0.7 cores. The README states what is measured and what is derived, and that serving and exactness results are pending.
The series applies to the pin; after 0003 it reproduces the tree the hold-1 microbenchmarks ran (a1c6b5f6d3). Every switch is off by default. The engine README's backbone section lists each patch, its switch and default.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Verdict: REQUEST CHANGES Reviewed head 0930185. That is ten commits plus 2048e6c, a merge of main 85004ec into the branch. Codex is still running on 0930185, so I'll re-check its comments before approving. What holds up
BlockingB1. The merged in_proj claim needs its tested sizes and its scope. These are integrator checks (2) and (6). The README says "bitwise the same output … at every M from 1 to 1024".
The upstream agent will cite this section, so the conditions have to be in it. B2. The foreign-CPU-load claim has no committed evidence. This is check (5). "Foreign CPU load averaged 0.3–0.7 cores" comes from B3. One clock claim is wrong. The README says "clocks 1980 MHz SM / 2619 MHz memory at the start of each run". That holds for Pending (not blocking)
Suggestions
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0930185081
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| + # On CUDA the merge comes from SGLANG_BACKBONE_MERGE_IN_PROJ, which | ||
| + # pays only from MERGE_MIN_M rows (GH200, Qwen3.5-4B). | ||
| + and hidden_states.shape[0] >= _backbone_gemm.MERGE_MIN_M |
There was a problem hiding this comment.
Scope the minimum-row cutoff to the CUDA merge path
On ROCm with aiter enabled and all new SGLANG_BACKBONE_* variables unset, the pre-existing preparation hook still populates _fused_in_proj_weight, but this unconditional default cutoff now prevents the packed projection whenever M < 64. Typical decode batches therefore fall back from the existing single aiter GEMM to two projections, despite the patch series promising unchanged default behavior. Apply this threshold only to weights created by the new CUDA merge option, while preserving the original aiter condition.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0007 (commit 2346789), though not quite for the reason given. The aiter path does not reach the cutoff: _forward_input_proj handles aiter in its first branch, and the cutoff sits in the not _use_aiter branch. On CUDA, however, the cutoff did apply to packed weights that a model's own loader builds, and Qwen4-Exp finalizes Qwen3_5GatedDeltaNet's packed weight at load. With every switch off, its decode below 64 rows would have moved from the packed GEMM to the separate pair. 0007 applies SGLANG_BACKBONE_MERGE_IN_PROJ_MIN_M only when SGLANG_BACKBONE_MERGE_IN_PROJ is set, so loader-packed weights keep the original <= 1024 gate. A related default change found while fixing this: 0003's dense-wrapper hook forwarding would pack the projections under aiter; 0006 gates it on the same switch.
| + if isinstance(hidden_states, _backbone_gemm.DeferredNormInput): | ||
| + # Opt-in norm fusion: the input norm runs in the merged GEMM's prologue. | ||
| + if self._fused_in_proj_weight is None: | ||
| + hidden_states = hidden_states.materialize() | ||
| + else: | ||
| + fused_out = hidden_states.linear(self._fused_in_proj_weight) |
There was a problem hiding this comment.
Enforce the merge cutoff on deferred-norm inputs
When SGLANG_BACKBONE_FUSE_NORM=1 and the CUDA packed weight exists, batches below MERGE_MIN_M take this early branch and multiply the packed weight before reaching the cutoff added by patch 0004. This makes the documented minimum-row switch ineffective for the combined fusion configuration and can select the merged GEMM in the range where the evidence says it is slower. Materialize the deferred norm and continue through the separate projections when the row count is below the cutoff.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed; fixed in 0007 (commit 2346789). With the merge switch on, a deferred norm below MERGE_MIN_M rows is now materialized (the stock FlashInfer norm) and goes through the separate qkvz and ba projections. From the cutoff it uses the packed weight. The test test_deferred_norm_respects_the_merge_cutoff (0324c3a) calls _forward_input_proj on a stub module at 8 and 64 rows. It checks which path ran, that the residual write is bitwise equal to the stock norm's, and that both outputs are bitwise equal to the stock norm followed by the separate GEMMs. It runs on the GPU in my next hold.
|
Verdict: REQUEST CHANGES (addendum to my review above: Codex finished on 0930185) Codex's two comments are both valid and unaddressed, so they are blocking alongside B1–B3. B4 (Codex P1, B5 (Codex P2, Neither affects the committed microbenchmark numbers, which ran the tree after 0003 without 0004. Both affect what the follow-up serving and exactness runs would measure. |
0006 forwards the dense Qwen3.5 preparation hook only with the merge switch (under aiter it would otherwise pack the GDN input projections by default). 0007 applies 0004's packed-projection row cutoff only with the merge switch, so Qwen4-Exp's loader-packed weights keep the original gate, and on the deferred-norm branch too (Codex P1 and P2 on #91). The series is renumbered 1/7..7/7; patches 0001-0005 are otherwise unchanged.
0006 forwards the dense Qwen3.5 preparation hook only with the merge switch (under aiter it would otherwise pack the GDN input projections by default). 0007 applies 0004's packed-projection row cutoff only with the merge switch, so Qwen4-Exp's loader-packed weights keep the original gate, and on the deferred-norm branch too (Codex P1 and P2 on #91). The series is renumbered 1/7..7/7; patches 0001-0005 are otherwise unchanged.
…ad records, fix the clock wording The packed GDN projection claim names the tested M (powers of two from 1 to 1024) and its conditions (24 layers' weights, random BF16 inputs, cuBLAS 13.1, GH200, per GEMM, isolated; served exactness pending). The four host-load records are committed with command lines reduced to program names, and the gemm run's 17.2-core single-sample maximum is stated. The chain run's clock reading before load was idle (345 MHz), not 1980 MHz.
a227ab9 to
95ce184
Compare
|
Verdict: APPROVE (provisional: Codex has not reviewed 95ce184. Its last review is on 0930185. Please request it; I will re-check its threads on this head before merge.) Re-review on the exact head 95ce184 (2346789, 0324c3a, 95e24f1, 95ce184 on top of 0930185, which is an ancestor). Blocking items from my 0930185 review
Suggestions from my 0930185 review
Reproduction and hygiene
Blocking: none, once Codex has reviewed this head. For the coordinator (non-blocking). The committed host-load files name the other processes on the box. The top foreign processes include |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95ce184815
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| + if entry is not None and entry[2] == "gemv" and _gemv_eligible(x, n, k): | ||
| + from sglang.kernels.ops.gemm.hopper_bf16_gemv import hopper_bf16_gemv | ||
| + | ||
| + return hopper_bf16_gemv(x, weight) |
There was a problem hiding this comment.
Gate the Hopper GEMV route by compute capability
When a generated table containing "gemv" entries is enabled on a non-Hopper CUDA GPU, _gemv_eligible checks only tensor shapes and contiguity, so this directly invokes the Hopper-specific kernel instead of falling back to cuBLAS. Unlike the existing dispatcher route described in patch 0001, this path bypasses use_hopper_bf16_gemv; add an SM capability/platform check before calling the kernel so the otherwise portable opt-in table does not fail on Ampere or other unsupported devices.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed; fixed in patch 0008 (commit 085c85b). _gemv_eligible now also requires compute capability 9.x (cached per device), the same condition SGLang's own --bf16-gemm-backend gemv enforces. On other GPUs a gemv table entry falls back to cuBLAS. The table itself is tuned on GH200, and the README says so.
There was a problem hiding this comment.
Follow-up at 50978e2: the gate now also excludes HIP (ROCm reports gfx94x as capability 9.x), patch 0008 amended (engine 59deb68e29; trees a1c6b5f6d3 after 0003, 4623a8ed30 after 0008). test_gemv_table_route_only_on_hopper mocks the capability: (8, 0), and (9, 4) with torch.version.hip set, fall back to cuBLAS; the real GH200 takes the GEMV route. The test has not run on a GPU yet; it runs at the start of the next backbone hold.
A gemv table entry called hopper_bf16_gemv after shape checks only; on another GPU an enabled table would have run the Hopper kernel (Codex on #91). The series is renumbered 1/8..8/8; 0001-0007 are otherwise unchanged.
|
Verdict: REQUEST CHANGES This updates my provisional approval of 95ce184 (#91 (comment)), which I withdraw. Codex finished its review of 95ce184 and left one P2. It has no reply or fix yet. Blocking
Everything else from my 95ce184 review still holds. |
|
Verdict: REQUEST CHANGES (one test) Re-review on the exact head 085c85b ("Backbone patch 0008: the table's Hopper GEMV route only on SM 9.x").
Blocking
Suggestion (non-blocking). On ROCm, Codex has not reviewed 085c85b yet. Its last review is of 95ce184. |
ROCm reports gfx94x as compute capability 9.x, so the SM 9.x check alone would let a gemv table entry run the Hopper kernel on MI300. The series is re-exported 1/8..8/8; 0001-0007 are unchanged. Engine head 59deb68e29, tree 4623a8ed30.
At (8, 0) and at HIP-reported (9, 4) a gemv table entry falls back (maybe_linear returns None, so the caller keeps F.linear); on this GH200 it runs the GEMV. Not yet run on a GPU.
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Verdict: APPROVE Re-review on the exact head 50978e2 ("Test the Hopper GEMV route's capability gate with mocked capabilities"). It adds two commits to 085c85b: 39ba8bf, which amends patch 0008 so the gate also excludes HIP, and 50978e2, which adds My blocking item from 085c85b is resolved.
The series still reproduces. Codex. Its review of 50978e2 found no major issues. Each of its three earlier threads (r4152579052, r4152579060, r4155737908) has a reply and a fix in 0007 or 0008. Checks. Pre-commit passes on the three changed files, and the branch is mergeable into main. Both commits are by Samuel Mausberg, with no AI lines. The hostname check is clean over the tip, Required before merge (PR body only; the head doesn't move).
Suggestion (non-blocking). The new comment in 0008 says "SGLang's gemv backend refuses other GPUs and HIP". SGLang's own check ( For the follow-up PR. Commit hold 2's pytest log ( |
|
Verdict: APPROVE (confirmed; head still 50978e2) Both PR-body corrections from my review are in: Validation names tree |
Fold in evidence/backbone/ as isolated microbenchmarks: what cuBLAS runs per projection, the faster kernels reading the same weights (Hopper GEMV at M = 1, Triton with PDL at M = 2-16, cuBLASLt picks) and their bitwise agreement with cuBLAS, the packed GDN input projection (bitwise equal per GEMM at power-of-two M from 1 to 1024), the norm and SiLU prologues and the layer skeletons, where folding is 13-70 us per layer slower as built. The derived 197 us (at most 5.7% of a plain step at M = 1) is labelled as derived from isolated timings. New register entry backbone, a Backbone GEMMs row in the levers table, the folded norm under what did not work, the H6 status row, and the backbone and repair patch series in the pins table. Served exactness and paired serving runs are pending (new entry backbone-served).
Fold in evidence/backbone/ as isolated microbenchmarks: what cuBLAS runs per projection, the faster kernels reading the same weights (Hopper GEMV at M = 1, Triton with PDL at M = 2-16, cuBLASLt picks) and their bitwise agreement with cuBLAS, the packed GDN input projection (bitwise equal per GEMM at power-of-two M from 1 to 1024), the norm and SiLU prologues and the layer skeletons, where folding is 13-70 us per layer slower as built. The derived 197 us (at most 5.7% of a plain step at M = 1) is labelled as derived from isolated timings. New register entry backbone, a Backbone GEMMs row in the levers table, the folded norm under what did not work, the H6 status row, and the backbone and repair patch series in the pins table. Served exactness and paired serving runs are pending (new entry backbone-served).
Appendix E: backbone GEMM and RMSNorm microbenchmarks (#91)
What this measures
The profile ranks two backbone costs that plain decoding, MTP and DFlash all pay: weight GEMMs
running below the head GEMM's bandwidth (13-16% of a plain step) and 65 RMSNorm launches per step
(about 5%). This PR measures what SGLang runs for each Qwen3.5-4B backbone projection at
M = 1..128, which kernels reading the same BF16 weights are faster, and whether folding the norm
and the SiLU into a GEMM pays. It adds a Triton skinny GEMM and an engine patch series that can
route projections to the fastest kernel. All results here are microbenchmarks. The exactness
class of the routing and its serving effect are not in this PR; they need GPU holds that are
queued.
Evidence:
evidence/backbone/README.md(status-labelled),tables.md, and four JSON files fromone exclusive hold. Repo 1e56c79, engine tree
a1c6b5f6d3(patches 0001-0003), clean trees,foreign CPU load 0.3-0.7 cores.
Results (measured, isolated)
out_proj, attentiono_proj, MLPdown)use split-K
nvjetkernels plussplitKreduce_kernel. They reach 49% (out/o_proj) and 68%(down) of the measured 3.79 TB/s read peak at M = 1. The large projections reach 80-87%.
Turning off
allow_bf16_reduced_precision_reductionchanges neither time nor bits.against 11.20 us for cuBLAS; down is 0.91x and the rest 0.95-0.97x. At the pin it is unreachable:
--bf16-gemm-backend gemvloads it, butUnquantizedLinearMethod.applydispatches only forcutedsl. Patch 0001 fixes that on its own.0.96-0.98x on the rest. M >= 64: cuBLAS stays best, except down, where PyTorch's cuBLASLt pick
is 0.92x. The cuBLASLt heuristic list adds little elsewhere.
1 to 1024. It is neutral to M = 16, 3% slower at 32, and 5-13% faster from 64.
the JIT SiLU bit for bit, but the folded GEMMs are 13-70 us per layer slower in the layer
skeletons. That is a negative result as built. A variant without the second pass over the
activations is queued.
would take 197 us less at M = 1 (at most 5.7% of the step) and 92-120 us less at M = 2-16.
Changes
experiments/backbone/:gemm_bench.py(subcommandsgemm,norm,merge,chain),lt_algos.cpp(cuBLASLt heuristic enumeration),make_table.py(routing table),summarize.py, README with commands.engine/sglang/patches/backbone/0001-0008and a backbone section inengine/sglang/README.md.Every switch is off by default. With the whole series applied and all switches off, no code
path changes on CUDA or under aiter. 0001 stands alone. 0006 and 0007 fix two default changes
that the earlier patches introduced: dense-wrapper hook forwarding under aiter, and 0004's row
cutoff on Qwen4-Exp's loader-packed weights.
tests/test_backbone_gemm.py: GPU tests that skip without CUDA or the patch.Validation
test ran a split-K config beyond the default workspace, which the kernel correctly refuses; one
used an old table format. The fixed file runs at the start of the next hold.
separate processes before timing (728 of 728 passed). The split-K reduction was checked for
bitwise run-to-run and graph-replay stability, with and without PDL.
git am. The tree after 0003 equals the one thebenchmarks ran (
a1c6b5f6d3), and the tree after 0008 is4623a8ed30, which equalsengine/backboneat59deb68e29.pre-commitpasses on the changed files.Not yet measured
experiments/state_safety/compare.py, the State safety: differential harness and tensor-level divergence mechanisms #37 convention, against the 3.42/1K floor. Queued(shared lock) for switches off, merge only,
--bf16-gemm-backend gemv, and the combinedlever.
These will come in a follow-up PR together with the final routing table.
Review round 1
scope (per GEMM, 24 layers' weights, random BF16 inputs, cuBLAS 13.1, GH200, isolated; served
exactness pending).
evidence/backbone/hostload/), with otherprocesses' command lines reduced to program names, and the gemm run's 17.2-core
single-sample maximum is stated.
Codex threads explain the Qwen4-Exp case. S2 led to 0006. S1: the commands rebuild the chain
and the table from the committed JSON (the table is byte-identical).
which requires compute capability 9.x as SGLang's gemv backend does, and excludes HIP, whose
devices can also report a 9.x capability (39ba8bf). A test with mocked capabilities (50978e2)
checks that a gemv table entry falls back to
F.linearat (8, 0) and at a HIP-reported(9, 4), and runs the GEMV on the GH200.
capability gate) and the 8af79d9 test fixes. The next hold runs them first.