Make get_qmv_batch_limit consider which vector kernel it guards - #3987
Open
katlun-lgtm wants to merge 2 commits into
Open
Make get_qmv_batch_limit consider which vector kernel it guards#3987katlun-lgtm wants to merge 2 commits into
katlun-lgtm wants to merge 2 commits into
Conversation
The qmv batch limit picked the matmul crossover from (D, O) and the architecture alone, while the vector kernel it protects differs by quantization mode (use_qmv_wide: fp modes everywhere, affine on gen 15+, plain qmv otherwise) and the two scale very differently in M. Give the limit the quantization mode and retune the one cell measured so far — affine with qmv_wide active on gen-15 non-desktop parts — where the measured crossover tracks D * O rather than the dims separately: identical D * O shapes (4096x4096 and 2048x8192) cross at the same M. fp modes, the gen <= 14 tables, and the desktop tiers are unchanged pending measurements on those paths.
2048x2048 crosses at 17, 2048x4096 at 16, and everything from ~12M elements up (3072x4096 through 5120x17408, six shapes) crosses at 13.
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.
Proposed changes
Follow-up from #3863 (@zcbenz: "get_qmv_batch_limit does not consider use_qmv_wide").
The limit picks the vector→matmul crossover from (D, O) and the architecture alone, while the vector kernel it guards differs by quantization mode (
use_qmv_wide: fp modes everywhere, affine on gen 15+, plainqmvotherwise). This passes the mode in and retunes the one cell I can measure — affine withqmv_wideactive, gen-15 non-d— leaving fp modes, the gen ≤ 14 tables, and thedtiers unchanged for measurements on other hardware.Measured crossovers (M3 Max
g15s, both routings forced at the same M via a local env-override build, cold weights round-robin so nothing stays cache-resident, min of 8 trials × 30 reps, M ∈ 3–20, 4-bit gs 128, bf16 activations):The crossover tracks D·O for affine — 4096×8192 and 2048×16384 (same D·O) cross at the same M — and settles on a floor of 13 that holds across a 5× range of sizes. Below it qmv_wide's margin is large (1.2–3.5× at M ≤ 10 on these shapes); above it qmm pulls ahead steadily (1.5–1.7× by M=20).
End-to-end effect (default routing, this branch vs 0.32.0, same harness):
No cell regresses beyond ±2% noise (full sweep M ∈ 3–20 × 7 shapes).
I ran mxfp4 through the same harness: its crossover is K-dependent rather than D·O-dependent (4096×8192 crosses at 11 where 2048×16384 crosses at 13), so fp wants its own cell rather than inheriting this one — data below if useful.
mxfp4 crossovers (same harness)
2048×2048: 17 · 4096×4096: 13 · 3072×8192: 13 · 4096×8192: 11 · 2048×16384: 13 · 4096×14336: 11 · 5120×17408: 11
One correction to the sweep I posted on #3863: it put the large-shape crossover near 7. This finer forced-routing sweep on current main puts the floor at 13; the earlier number was inconsistent with its own native-qmv_wide measurement at M=10 (0.49 ms measured, vs the ~0.72 ms at M=9 the crossover claim implied). The table above supersedes it.
test_quantized.pypasses in full (32 tests, 2896 subtests). Routing-only change — both kernels are already covered by those tests.Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes (clang-format v21.1.8 as pinned)test_quantized.pycovers both kernels)