perf: tune BF16 GEMV for common transformer shapes - #53
Closed
0z5a wants to merge 2 commits into
Closed
Conversation
0z5a
marked this pull request as draft
September 2, 2026 14:37
0z5a
force-pushed
the
codex/optimize-common-gemv-shapes-main-0z5a
branch
from
September 2, 2026 15:33
7a8355c to
8545006
Compare
Owner
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.
Summary
(M,N,K)selectorautoonly where every projection clears the 5% per-shape gate and the dependent chain clears 3%; all other M/family combinations fail closed to the existing kernel or PyTorchL20 benchmark
Environment: NVIDIA L20 (SM89), PyTorch 2.11.0+cu128, CUDA 12.8. GPU5 retained the co-resident AstrAI service allocation throughout; it was not stopped or modified. The large LLaMA 3 70B chain started only after verifying 0% instantaneous utilization and 2,477 MiB free. CUDA compilation completed before timed cases.
CTA selection
The production kernel now instantiates 128- and 256-thread cooperative CTAs for M=1..8. All specializations compile with zero spills (26–52 registers, one barrier); the existing M=4 warp-tiled kernel remains at 42 registers, zero barriers, zero spills.
An identical-input, separately named, interleaved module comparison against the original 256-thread kernel used 21 samples × 200 inner iterations over 22 common shapes. The final selector retains only cells above the 5% gate:
Long-K, saturated, and sub-threshold cells retain the 256-thread fallback. All 88 comparison rows preserve row argmax.
Final primitive vs
F.linearFor the bands considered for new automatic dispatch (21 paired/interleaved samples):
Guarded dependent chains
Final
ASTRAI_GEMV=autoversus0, using distinct weights and including Python dispatch plus dependent MLP work:M=8 remains disabled even where the aggregate chain is positive because at least one projection misses the per-shape gate (Qwen Q/O, LLaMA 3 70B K/V, and OPT up). Existing LLaMA/GPT-NeoX policy remains unchanged, including the deliberate LLaMA 2 7B M=4 fallback.
These are synthetic projection-chain measurements, not whole-model throughput claims. Raw environment, parameters, median/p90 timings, numerical error, and argmax diagnostics are under
docs/benchmarks/.Validation
bf16_gemvbuild: successful; all cooperative specializations zero-spillruff format --check .: passedruff check . --select I: passedThe InfraSWE numbers are explicitly diagnostic and non-official. Official ProjectFit remains unresolved because the Draft is unsealed and fresh-process/system-trace/hidden-probe/evidence-manifest gates are incomplete.