2a5961a01b
matmul_i4_grouped is the reference the CUDA fmt=4 port (#298) is expected to reproduce, and it had no test of its own. @woolcoxm is currently debugging a CUDA backend against an oracle nobody had verified, which is two moving targets at once -- and he can't cross-check on CPU, since a 5-prompt run takes 8 hours on the 744B model. This checks matmul_i4_grouped against a plain-C reference that dequantizes nibble -> (v-8)*scale[i/gs] and accumulates in double, over 11 shapes: I a clean multiple of gs, a partial last group (the glen clamp), odd I (the scalar nibble tail), gs > I, gs=16/64/128, S>1, and the nibble extremes 0x00/0xFF -- which decode to -8/+7 because the format is offset-encoded, not two's complement. Reading that backwards turns 15 into -1 and looks like data-dependent noise rather than a bug. All 11 shapes match to ~1e-8 relative, so the CPU kernel is exact and can be trusted as the reference. One note on the tolerance, because the first draft of this test got it wrong and "found" a bug that wasn't there: the error is compared against the sum of |terms|, not against |result|. A dot product of signed terms can land near zero through cancellation, and then a 1e-6 absolute error -- ordinary f32 accumulator precision -- reads as a 1e-3 relative one. A wrong scale index or a wrong group boundary shifts the result by a fraction of the terms, so it is still caught at 1e-6. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>