Repository navigation
qmv_fast: take affine 1/4-bit at half-block K (partial last block) - #8
Merged
Merged
Conversation
The guarded partial-block tail of qmv_fast_impl handles half a block, so the host gate takes affine 1/4-bit K that are half-block multiples (Gemma 4 12B K = 3840, down_proj K = 11008). fp modes keep the full block: fp_qmv_fast_impl has no tail. A tail lane now loads only if all of its values are in the row.
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. |
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.
Part of numen-tech/gemma4-qat#192 (epic numen-tech/gemma4-qat#178).
What
qmv_fastnow takes affine/affine_sym 4-bit with K % 256 == 0 and 1-bit with K % 512 == 0, which is half its block. Before, those shapes needed a whole block (K % 512 for 4-bit, K % 1024 for 1-bit) and otherwise fell back to the genericqmv.The target is Gemma 4 12B (QAT q4_0, gs32). Its q/k/v, gate/up and tied-head matmuls have K = 3840 = 7.5 blocks, so at M = 1 they ran
qmv. Lizzy-7B'sdown_proj(K = 11008) is in the same position.qmv_fast_impl(kernels/quantized.h): the partial-last-block guard is now "this lane's whole slice is in the row", i.e.aligned_end + (simd_lid + 1) * values_per_thread <= in_vec_size. Lanes outside it read nothing: no weights, scales, biases or x. All lanes still join thesimd_sum. When K %values_per_thread== 0 this matches the old lane-start test, so it is hardening and not a behaviour change.qmv_fast_k_alignment(bits, mode)(quantized.cpp): returnsblock / 2for affine 1-bit and 4-bit, andblockotherwise. Used byqmvandgather_qmv.fp_qmv_fast_implhas no tail, so fp modes keep the whole block.K % values_per_thread, whichK % group_sizealready implies. block/2 is the cutoff measured for 1/4-bit; widening it is numen-tech/gemma4-qat#260.qmvand an fp32 reference.Numerics
qmv_fastare bit-identical: the loop body is unchanged and the tail never runs for them.qmv_fastsums 16 values per lane vs 8 inqmv, so outputs differ at rounding level.qmv's plus one output-dtype ulp. The gemma4-qatQmvFastTailKernelTestsassert exactly that.Evidence
See the gemma4-qat PR for the gate results: tok/s A/B, greedy diff, dispatch budget, and the full Swift suite.
Merge order
Source/Cmlx/mlxto the merged commit);Package.resolved).