core: don't fuse AddUnicast into a native block-quant matmul#2477
Open
czoli1976 wants to merge 1 commit into
Open
core: don't fuse AddUnicast into a native block-quant matmul#2477czoli1976 wants to merge 1 commit into
czoli1976 wants to merge 1 commit into
Conversation
A native block-quant AddMatMul chained with a fused AddUnicast in one kernel call (AddMatMul -> AddUnicast -> Store) miscomputes and saturates to inf; the kernels are covered for AddMatMul alone and for AddUnicast after Clear, but not for the two chained. Skip the AddUnicast fast-path fusion when the matmul consumes a block-quant weight natively, leaving the add as its own node. 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.
OptMatMul::fusefolds a following same-shapeAddinto the matmul as a fusedAddUnicast. When the matmul consumes a block-quant weight natively (no panel extractor), that chain —AddMatMul → AddUnicast → Storein one kernel call — miscomputes and saturates the output toinf, even with finite, contiguous inputs. This gates the AddUnicast fast-path off for native block-quant matmuls, leaving the residual add as its own (correct) node.Found on
Qwen2.5-7B-Instruct-q40ef16:PushSliceUpproduces a slicedn=1GEMV over the last token at the tail, the residual add fuses into it (arm64simd_mmm_f32_32x1_gen, q40 packing), and the last block's logits go NaN. With the fusion disabled the whole model decodes correctly (token-identical to Metal); llama3.2-1b / Qwen3-1.7b / openelm are unaffected.The kernels are individually covered —
AddMatMulalone (packed_packed) andAddUnicastafterClear(add_unicast_non_contiguous) — but not the two chained, which is the real gap. The proper follow-up is to add theAddMatMul(native block-quant) → AddUnicastchain to the linalg fuse proptests and fix the kernel; this change is the safe correctness guard in the meantime.🍍
🤖 Generated with Claude Code