block_quant: role-aware weight quantization policy#2433
Draft
czoli1976 wants to merge 2 commits into
Draft
Conversation
The block_quant rewrite assumed the constant weight was always einsum input 0, so on imported ONNX `activation @ weight` matmuls (weight at input 1) it wired the block-quant tensor and the injected group axis to the wrong operands and tripped the EinSum rank check. Derive the weight and activation slots from the matched input and wire them accordingly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Quantizing every constant matmul weight uniformly degrades quality on the few quant-sensitive tensors (embeddings, normalizations, output heads) while saving little on small matmuls. Gate the block_quant rewrite on a policy that protects those tensors by name and skips matmuls below a size threshold, quantizing the rest. 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.
What this does
Gates the
block_quanttransform on a role-aware policy instead of quantizing every constant matmul weight uniformly: quant-sensitive tensors (embeddings, normalizations, output heads) and matmuls too small to benefit are left in f32, and the rest are quantized to Q4_0.Why
Quantizing every weight uniformly degrades quality on the few sensitive tensors (embeddings/norms/heads are small and numerically sensitive — quantizing them costs accuracy and saves almost nothing) while small matmuls aren't worth the overhead. Protecting them by name + a size floor is the convention
llama.cpp/ GPTQ / bitsandbytes all converge on. The weight names survive ONNX import, so the policy can key on them.Tests: protected/tiny weights are skipped, the rest are quantized (L1), and the quantized result matches
X @ Q4_0(W)across both ONNX orientations (L2).Notes
attn_v/ffn_downto 8-bit) is a natural follow-up once a Q8_1-weight matmul path exists.Question for you
This bakes a name-based protected-list into core. Is that the shape you'd want, or would you rather it be configurable (transform params / a caller-supplied predicate or regex list), or kept out of core entirely? Happy to refactor toward whatever you prefer — opening as a draft to get your call before polishing.
🍍