fix(cpu-ops): complete lazy transpose for all packed matmul dtypes (Q4_0)#737
Merged
Conversation
…ypes Follow-up to #736 (Q8_0). The transpose lazy-rewrap `when` was still missing Q4_0 — a packed type chooseQuantizedMatmulHeap dispatches — so a packed Q4_0 matmul weight through linearProject (matmul(x, transpose(W))) hit the generic FP32 path and threw `Byte cannot be cast to Float`. Add the Q4_0 case so the `when` now covers EVERY packed type that can be a matmul weight (Q4_K/Q5_K/Q6_K/Q5_0/Q5_1/Q8_0/Q4_0). Adds `transpose_preserves_every_packed_quant_type` to PackedMatmulDispatchTest: transposes a 2-D tensor of each of the 7 packed types and asserts the shape flips and the packed encoding is preserved (no FP32 fallback / no crash). Content-agnostic, runs on every platform (jvm + linuxX64). See SKaiNET-transformers#178. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Follow-up to #736. Makes
ops.transpose's lazy-rewrap path cover every packed quant type that can be a matmul weight, not just Q8_0.Gap
#736 added Q8_0, but the
whenwas still missing Q4_0 — whichchooseQuantizedMatmulHeapdoes dispatch. So a packed Q4_0 matmul weight throughlinearProject(matmul(x, transpose(W))) still fell into the generic FP32 path and threwByte cannot be cast to Float.Now covered (== the full matmul-dispatch set): Q4_K, Q5_K, Q6_K, Q5_0, Q5_1, Q8_0, Q4_0.
(Bf16
get()→Float and Ternaryget()→Byte match their logicalV, so neither crashes in the generic path and neither is matmul-dispatched — out of scope.)Test
Adds
transpose_preserves_every_packed_quant_typetoPackedMatmulDispatchTest: transposes a 2-D tensor of each of the 7 packed types and asserts the shape flips and the packed encoding is preserved (no FP32 fallback, no crash). Content-agnostic; runs on jvm + linuxX64. Green locally (4/4).Ref: SKaiNET-transformers#178.
🤖 Generated with Claude Code