Skip to content

core: don't fuse AddUnicast into a native block-quant matmul#2477

Open
czoli1976 wants to merge 1 commit into
sonos:mainfrom
czoli1976:fix/blockquant-gemv-addunicast-fusion
Open

core: don't fuse AddUnicast into a native block-quant matmul#2477
czoli1976 wants to merge 1 commit into
sonos:mainfrom
czoli1976:fix/blockquant-gemv-addunicast-fusion

Conversation

@czoli1976

Copy link
Copy Markdown
Contributor

OptMatMul::fuse folds a following same-shape Add into the matmul as a fused AddUnicast. When the matmul consumes a block-quant weight natively (no panel extractor), that chain — AddMatMul → AddUnicast → Store in one kernel call — miscomputes and saturates the output to inf, 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: PushSliceUp produces a sliced n=1 GEMV 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 — AddMatMul alone (packed_packed) and AddUnicast after Clear (add_unicast_non_contiguous) — but not the two chained, which is the real gap. The proper follow-up is to add the AddMatMul(native block-quant) → AddUnicast chain to the linalg fuse proptests and fix the kernel; this change is the safe correctness guard in the meantime.

🍍

🤖 Generated with Claude Code

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>
@czoli1976 czoli1976 mentioned this pull request Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant