Skip to content

Backbone GEMMs and RMSNorm: microbenchmarks, a skinny GEMM and an opt-in engine patch series - #91

Merged
SamMausberg merged 20 commits into
mainfrom
backbone/gemm-bench
Oct 1, 2026
Merged

SamMausberg merged 20 commits into
mainfrom
backbone/gemm-bench

Conversation

@SamMausberg

@SamMausberg SamMausberg commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

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 from
one exclusive hold. Repo 1e56c79, engine tree a1c6b5f6d3 (patches 0001-0003), clean trees,
foreign CPU load 0.3-0.7 cores.

Results (measured, isolated)

  • What cuBLAS runs. The 2560-wide outputs (GDN out_proj, attention o_proj, MLP down)
    use split-K nvjet kernels plus splitKreduce_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_reduction changes neither time nor bits.
  • M = 1: SGLang's own Hopper GEMV is the fastest kernel on every shape. out_proj takes 8.57 us
    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 gemv loads it, but UnquantizedLinearMethod.apply dispatches only for
    cutedsl. Patch 0001 fixes that on its own.
  • M = 2-16: the Triton kernel beats cuBLAS only with PDL: 0.88-0.92x on out/o_proj and
    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.
  • Packed GDN input projection: bitwise equal to the separate qkvz and ba GEMMs at every M from
    1 to 1024. It is neutral to M = 16, 3% slower at 32, and 5-13% faster from 64.
  • Norm and SiLU folded into the GEMM: the prologue arithmetic reproduces FlashInfer's norm and
    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.
  • Derived, not a served result: at their best isolated times, the projections of a plain step
    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 (subcommands gemm, norm, merge, chain),
    lt_algos.cpp (cuBLASLt heuristic enumeration), make_table.py (routing table),
    summarize.py, README with commands.
  • engine/sglang/patches/backbone/0001-0008 and a backbone section in engine/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

  • GPU tests in hold 1: 21 passed, 2 failed. Both failures were test bugs, fixed in 8af79d9: one
    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.
  • Every Triton configuration in the sweep was compiled and checked against a float64 product in
    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.
  • The patch series applies to the pin with git am. The tree after 0003 equals the one the
    benchmarks ran (a1c6b5f6d3), and the tree after 0008 is 4623a8ed30, which equals
    engine/backbone at 59deb68e29.
  • pre-commit passes on the changed files.

Not yet measured

  • Exactness of each switch: greedy outputs against stock plain decode at c = 1 with
    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 combined
    lever.
  • Paired B-A-A-B serving runs against plain-tuned and mtp-tuned at c = 1, 8, 32, 128. Queued.

These will come in a follow-up PR together with the final routing table.

Review round 1

  • B1: the packed in_proj claim now names the tested M (powers of two from 1 to 1024) and its
    scope (per GEMM, 24 layers' weights, random BF16 inputs, cuBLAS 13.1, GH200, isolated; served
    exactness pending).
  • B2: the four host-load records are committed (evidence/backbone/hostload/), with other
    processes' command lines reduced to program names, and the gemm run's 17.2-core
    single-sample maximum is stated.
  • B3: the clock wording now says the chain run's pre-load reading was idle (345 MHz).
  • B4 and B5 (Codex P1 and P2) are fixed in 0007, with a test of the deferred-norm cutoff; the
    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).
  • Codex on 95ce184 (the table's GEMV route ran the Hopper kernel on any GPU): fixed in 0008,
    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.linear at (8, 0) and at a HIP-reported
    (9, 4), and runs the GEMV on the GH200.
  • Not yet run on a GPU: the tests added since hold 1 (the deferred-norm cutoff, the gemv
    capability gate) and the 8af79d9 test fixes. The next hold runs them first.

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.
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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T14:14:03.290682Z 50978e2 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@SamMausberg

Copy link
Copy Markdown
Owner Author

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

  • The patch series reproduces. git am of 0001–0003 onto the pin bd66ce343e gives tree a1c6b5f6d3. That is the tree of the hold's engine commit e89b122037 recorded in every JSON. Adding 0004–0005 gives 9bbca48e2e, the tree of engine/backbone (58bb7769e2).
  • Integrator check (4) holds. The engine README has a ## backbone section with one row per patch, giving each one's switch and its unchanged default. Patch 0001 dispatches only when --bf16-gemm-backend gemv is set, and 0003 only behind SGLANG_BACKBONE_*.
  • tables.md regenerates byte-identical from the four committed JSONs with summarize.py.
  • The headline numbers match the tables:
    • out_proj at M = 1: 8.57 against 11.20 µs;
    • in_proj_ba: 2.75 against 5.43 µs;
    • read-peak shares of 49%, 68% and 80–87%;
    • the derived 2481 − 2284 = 197 µs, and 197 / 3460 = 5.7%, with the 3.46 ms step taken from evidence/profiles/README.md;
    • the skeleton table.
  • Labels, checks (1) and (3). The README separates measured from derived. The 197 µs is labelled derived and "at most". The norm and SiLU fold is reported as a loss of 13–70 µs per layer with the skeleton numbers.
  • The merge is pure. Re-doing 85004ec into b0912d6 gives no conflict and no difference from 2048e6c.
  • Hygiene. pre-commit passes. The commits and all five patches are Sam's, with no AI attribution and no citation of the workstream notes.

Blocking

B1. 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". merge_microbench.json tests M = 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024. Please:

  • name those sizes;
  • scope the claim to per-GEMM outputs of the 24 GDN layers' input projections (12,352 × 2,560 packed against 12,288 + 64), BF16, on this GH200, in an isolated microbenchmark;
  • say that served-token exactness is pending.

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 hostload_{gemm,norm,merge,chain}.json, which exist only in ~/vp-data/backbone/runs/h1. Their means are 0.675, 0.538, 0.385 and 0.291, so the range is right. Commit the four files and cite them. Also give the gemm run's peak: its maximum was 17.2 cores, though the run was not flagged contended.

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 chain_microbench.json's memory clock only: its clocks_at_start reads 345 MHz SM, an idle clock sampled before the load. Either say three of the four runs started at 1980 MHz and the chain sample read idle, or log clocks under load.

Pending (not blocking)

  • The GPU tests: hold 1 ran 21 passed and 2 failed (test bugs, fixed in 8af79d9), and the fixed file has not run on a GPU yet. Commit its log from the next hold, before the serving follow-up relies on the kernel.
  • Exactness classes and paired serving runs, as the README and PR body say.

Suggestions

  • S1. chain and make_table.py read $R/gemm_full.json, which is not committed (--evidence writes the reduced form). Note that in the commands, or let make_table.py read the committed form, so the routing table can be rebuilt from the repository.
  • S2. Patch 0003's new Qwen3_5ForConditionalGeneration.prepare_before_cuda_graph_capture forwards to the inner model. That is a no-op on CUDA with every switch off. On ROCm with aiter, though, it newly enables the packed path for this class. "With all off no code path changes" therefore holds on CUDA. Worth a word if this goes upstream.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +104 to +106
+ # 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +217 to +222
+ 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SamMausberg

Copy link
Copy Markdown
Owner Author

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, 0004-table-gemv-mode-merge-min-rows.patch:106). The SGLANG_BACKBONE_MERGE_IN_PROJ_MIN_M cutoff (default 64) applies to every packed in_proj weight, including the one the pre-existing ROCm/aiter hook builds when all SGLANG_BACKBONE_* variables are unset. On ROCm, decode batches below 64 rows would therefore drop from aiter's single packed GEMM to two projections. That breaks the engine README's "with all of them off no code path changes". Apply the cutoff only to the weight the CUDA merge option creates. Together with my S2, this means the series should state, and test, unchanged default behaviour on both CUDA and ROCm paths, or scope the claim to CUDA.

B5 (Codex P2, 0003-route-backbone-projections.patch:222). With SGLANG_BACKBONE_FUSE_NORM=1 and the packed weight present, the deferred-norm branch multiplies the packed weight before the 0004 cutoff is reached. Below MERGE_MIN_M it therefore selects the merged GEMM in exactly the range the evidence says is slower (3% at M = 32). Materialize the norm and take the separate projections below the cutoff, and add a test for the combined configuration.

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.

SamMausberg added a commit that referenced this pull request Oct 1, 2026
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.
@SamMausberg

Copy link
Copy Markdown
Owner Author

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

  • B1 (scope of the packed in_proj claim): fixed. The README now:
    • names M = 1, 2, 4, ..., 1024;
    • states the scope: per GEMM, 12,352 x 2,560 packed against 12,288 + 64, the 24 GDN layers' real weights, random BF16 inputs (torch.randn, as in gemm_bench.py), cuBLAS 13.1 on this GH200, in an isolated microbenchmark;
    • says that served-token exactness is pending.
  • B2 (host load): fixed. evidence/backbone/hostload/h1_{gemm,norm,merge,chain}.json are committed and cited. Their means are 0.675, 0.538, 0.385 and 0.291 cores. The gemm run's single-sample maximum of 17.24 is stated (217 samples, not flagged as contended), and the others peak at 2.44 at most. Each file says its command lines are reduced to program names, and the hostname appears in none of them (runtime search).
  • B3 (clocks): fixed. The README says three runs read 1980/2619 MHz before starting, the chain run read an idle 345 MHz, and clocks under load were not logged.
  • B4 (Codex P1, cutoff): fixed by 0007, and the reply is right that aiter never reached the cutoff.
    • I applied 0001-0007 to the pin. In the patched _forward_input_proj, the packed-GEMM block with the row cutoff is guarded by not _use_aiter.
    • The real change of default was on CUDA, for loaders that pack the weights themselves. With SGLANG_BACKBONE_MERGE_IN_PROJ off, the condition reduces to the pin's original gate (at most 1,024 rows).
  • B5 (Codex P2, deferred norm): fixed by 0007.
    • With the merge on and fewer than MERGE_MIN_M rows, a deferred norm is materialized and the separate projections run.
    • test_deferred_norm_respects_the_merge_cutoff (0324c3a) checks both sides of the cutoff bit for bit against the stock norm. It runs in the next hold, with the GPU tests from 8af79d9. Both logs are pending, and neither is blocking for this PR's microbenchmark claims.

Suggestions from my 0930185 review

  • S1: done. The commands rebuild the chain and the routing table from the committed gemm_microbench.json.
  • S2: done, as patch 0006. The dense model's preparation hook is forwarded only with the merge switch. The engine README's "unchanged" column now covers CUDA and aiter, with 0006 and 0007 explained.

Reproduction and hygiene

  • git am of 0001-0003 onto the pin bd66ce343e gives tree a1c6b5f6d3, the hold-1 tree. Adding 0004-0007 gives ac1d852350, the tree of engine/backbone 5758637531.
  • Pre-commit passes over 0930185..95ce184.
  • The commits are by Samuel Mausberg, with no AI lines in the commits or the PR body. The branch is MERGEABLE.

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 claude, the agent CLI. No evidence on main has named it so far. Whether that belongs in public evidence under Sam's name is Sam's call. If not, a generic label such as "other user processes" would keep the measurement.

@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

1 similar comment
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +87 to +90
+ 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@SamMausberg

Copy link
Copy Markdown
Owner Author

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

  1. Gate the Hopper GEMV route by compute capability (Backbone GEMMs and RMSNorm: microbenchmarks, a skinny GEMM and an opt-in engine patch series #91 (comment)).
    • Patch 0004's table mode gemv calls SGLang's Hopper GEMV once _gemv_eligible holds, and that function checks only shapes and contiguity. 0001's dispatcher goes through use_hopper_bf16_gemv; this route bypasses it.
    • An opt-in table containing gemv entries would therefore call a Hopper-only kernel on Ampere or any other non-SM90 device, instead of falling back to cuBLAS.
    • The path is opt-in, so no default changes. But the README presents the table as portable, so the route needs the same capability check: SM 9.x, and not HIP. Below that, fall back to the cuBLAS path.
    • Please add the check and a CPU-side test that mocks the capability and checks the route falls back. Then rebuild the patch series and confirm the trees again: after 0003 it must still be a1c6b5f6d3, the hold-1 tree; after the new patch, the new head of engine/backbone.

Everything else from my 95ce184 review still holds.

@SamMausberg

Copy link
Copy Markdown
Owner Author

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").

  • Codex P2 r4155737908 is fixed in patch 0008 and has a reply. _gemv_eligible now also requires x.is_cuda and compute-capability major 9 (cached per device). That is the same condition SGLang's own --bf16-gemm-backend gemv enforces (unquant.py: get_device_capability()[0] != 9 raises). Elsewhere the call falls back to cuBLAS.
  • The series still reproduces. git am of 0001-0008 onto the pin gives tree a1c6b5f6d3 after 0003 (the hold-1 tree) and 8dbbc8fa8f after 0008, which is the tree of engine/backbone fbdc3165b0. 0001-0007 change only in their "n/8" numbering.
  • Docs and checks. The engine README has a row for 0008. Pre-commit passes over 95ce184..085c85b. The commit is by Samuel Mausberg, with no AI lines.

Blocking

  1. The new gate has no test. My last review asked for a CPU-side test with the capability mocked, and none was added.
    • Please add one to tests/test_backbone_gemm.py: torch.cuda.get_device_capability mocked to (8, 0), a gemv table entry, and an assertion that the route falls back to the cuBLAS path. Also a (9, 0) case that takes the GEMV route.
    • The lru_cache on _is_sm90 needs a cache_clear() in the test.

Suggestion (non-blocking). On ROCm, torch.cuda.get_device_capability() reports major 9 for gfx94x (MI300), and x.is_cuda is true there. So this gate, like SGLang's own gemv check, would still choose the Hopper JIT kernel on MI300 if a table with gemv entries were enabled. Adding torch.version.hip is None (or SGLang's is_cuda()) would close that. It is opt-in and matches upstream's own condition, so it is not blocking.

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.
@SamMausberg

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 50978e2226

ℹ️ 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".

@SamMausberg

Copy link
Copy Markdown
Owner Author

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 test_gemv_table_route_only_on_hopper.

My blocking item from 085c85b is resolved.

  • The test mocks torch.cuda.get_device_capability to (8, 0), and to (9, 4) with torch.version.hip set. It asserts that _gemv_eligible is false and maybe_linear returns None, so the caller keeps F.linear. On real Hopper it asserts that the GEMV route runs and agrees with F.linear. _is_hopper.cache_clear() runs before each case and in finally, so a mocked result cannot leak into other tests.

  • The test has not run on a GPU yet; hold 2 runs it first. I checked its logic on the CPU instead, with CUDA hidden, against the patched backbone_gemm.py, a CUDA-looking stub input and a stub hopper_bf16_gemv:

    • Patched gate: (8, 0) and HIP (9, 4) fall back, and (9, 0) takes the GEMV.
    • Gate removed: the (8, 0) case takes the GEMV, so the test fails.
    • The 085c85b gate (capability only): the HIP (9, 4) case takes the GEMV, so the test fails.

    So the test catches both the missing gate and the missing HIP check.

  • The non-blocking ROCm suggestion is taken: _is_hopper returns False when torch.version.hip is set.

The series still reproduces. git am of 0001-0008 onto the pin bd66ce343e gives tree a1c6b5f6d3 after 0003, which is the hold-1 tree, and 4623a8ed30 after 0008. That is the tree of engine/backbone 59deb68e29. Only 0008 changed. The engine README's header and its 0008 row are updated, and no file still references the old patch name, _is_sm90 or fbdc3165.

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, git log -p origin/main..HEAD and the PR text.

Required before merge (PR body only; the head doesn't move).

  1. Validation says the tree after 0008 equals engine/backbone (8dbbc8fa8f). It is now 4623a8ed30 (engine/backbone 59deb68e29).
  2. The last line of "Review round 1" should mention HIP and the test. For example: "fixed in 0008, which requires compute capability 9.x on CUDA and excludes HIP, with a mocked-capability test (50978e2)". Validation should also say that the tests added since hold 1 (test_deferred_norm_respects_the_merge_cutoff, test_gemv_table_route_only_on_hopper) and the fixes in 8af79d9 have not run on a GPU yet, and that hold 2 runs them first.

Suggestion (non-blocking). The new comment in 0008 says "SGLang's gemv backend refuses other GPUs and HIP". SGLang's own check (unquant.py: get_device_capability()[0] != 9 raises) does not test for HIP, so on MI300 it would pass. "SGLang's gemv backend requires SM90" would be accurate. That can wait for the follow-up series, because amending 0008 again would change the tree hashes.

For the follow-up PR. Commit hold 2's pytest log (~/vp-data/backbone/runs/h2/pytest.log) with the exactness and serving evidence.

@SamMausberg

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE (confirmed; head still 50978e2)

Both PR-body corrections from my review are in: Validation names tree 4623a8ed30 (engine/backbone 59deb68e29), and the review section records the HIP exclusion (39ba8bf), the mocked-capability test (50978e2), and that the tests added since hold 1 and the 8af79d9 fixes have not run on a GPU yet.

@SamMausberg
SamMausberg merged commit dbebf40 into main Oct 1, 2026
SamMausberg added a commit that referenced this pull request Oct 1, 2026
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).
SamMausberg added a commit that referenced this pull request Oct 1, 2026
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).
SamMausberg added a commit that referenced this pull request Oct 1, 2026
Appendix E: backbone GEMM and RMSNorm microbenchmarks (#91)
SamMausberg added a commit that referenced this pull request Oct 2, 2026
Sync TASKS.md with #45, #52, #91 and #120-#168; measured, derived and open per hypothesis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant