Repository navigation
[Metal] Add int8 NAX path for affine quantized_matmul - #4802
Conversation
Almost, I think it's better to be implemented in qqmm 4722 converts the affine weights to symmetric int8 with one scale per row, so they are rounded a second time. Here the MMA uses the original codes, and the per-group scales and biases are applied in the kernel. |
239bfa7 to
21f5e03
Compare
21f5e03 to
1321d43
Compare
zcbenz
left a comment
There was a problem hiding this comment.
Sorry for the late response, after discussion we decided not to add affine qqmm: there is no common standard and we think it is against the direction of industry. But we do think that using int8 NAX to accelerate quantized_matmul is still a reasonable optimization, so can you please refactor this PR to only accelerate quantized_matmul without changing the interface of qqmm, and benchmark against #4722?
1321d43 to
cc830b1
Compare
Thanks, I have refactored the PR
Comparison with 4722. The numbers are from PR descriptions. M6 is the only chip in both. 4-bit, group size 64, bf16, speedup over
Precision: 4722 rounds The test machines I used are not mine, so I cannot run both PRs on the same shapes and machines for now. |
cc830b1 to
8d496df
Compare
8d496df to
718b9e5
Compare
mx.quantized_matmulgets a keyword argumentquantize_input(defaultFalse). Withquantize_input=True,xis quantized to signed 8 bits with one scale pergroup_sizeelements before the multiplication.Accuracy
M = 1024, K = N = 4096,
xandwfrom normal distribution, bf16. RMS error relative to the RMS ofx @ win float32:Performance
Measured on M5 Pro (16 cores), M5 Max (40 cores) and M6 (12 cores), bf16, group size 64. The numbers are from the previous QQMM version of this PR, the kernels and the routes for M >= 64 are the same.
Shapes (K x N): 4096x4096, 4096x14336, 14336x4096, 8192x2048.
Speedup of
quantize_input=Trueoverquantize_input=False, geomean over the 4 shapes (>1 is faster):M5 Pro
M5 Max
M6
For M < 32 the int8 MMAs are not used, and
quantize_input=Trueonly adds the cost of quantizingx.Per shape at M = 1024, microseconds (
quantize_input=False/quantize_input=True):4-bit:
8-bit: