linalg/block_quant: W4A8 int8-dot decode GEMV for Q4_0#2348
Open
czoli1976 wants to merge 1 commit into
Open
Conversation
Quantizes the activation row to int8 per block and dots it with the unpacked 4-bit weights, scaling each block by the weight and activation scales. The contiguous inner loop autovectorizes to a NEON int8 dot. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Adds a W4A8 (4-bit weight, int8 activation) decode GEMV on the
Q4_0block-quant format —the CPU primitive for an int4-compute matmul path, as an alternative to today's
dequantize-to-f32-then-f32-kernel route.
Q4_0::w4a8_gemvquantizes the activation row to int8per block, dots it with the unpacked 4-bit weights, and scales each block by the weight and
activation scales.
Why
The GPU backends already do exactly this — CUDA routes
Q4_0to aQ4_0 × Q8_1kernel(
cuda/src/kernels/cu/mm_mv_q.cu), Metal tomul_mv_q4_0. On CPU the block-quant path onlydequantizes to f32, so the int4 win is just reduced weight bandwidth, not int8 compute. This is
the missing CPU piece.
Notes / numbers
Q4_0weight — the int8activation adds ≈0.3% (W4A8 ≈ W4A16); test included.
unsafe: the contiguousi8→i32inner loop autovectorizes to a NEONsdoton its own (integer reductions are associative; strict-IEEE f32 ones aren't).mmv_f32in a local prototype — that includesop-wrapper overhead, so a kernel-selection integration would be ≥ that.
Scope / integration
This PR is the kernel primitive only — it is intentionally not yet wired into kernel
selection. The integration question (the W4A8-vs-W4A16 numerical contract, and whether it lands as
a dedicated op like the Metal/CUDA
Q4_0×Q8ops or viastrategizeineinsum_matmul) is theopen discussion in #2341. Filing the validated primitive + numbers to ground that — happy to wire
it whichever way you prefer.
🤖 Generated with Claude Code