tests: a rotated int8 group decodes back through the Hadamard

libquant's rtn at codes=i8 group=128 scale=bf16 transform=fwht128, decoded through the core:
the weight gemm_nt_q reads at i8a8h comes back as its source, with less error than the plain
grid on a source with outliers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
eddie168168andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-19 10:42:13 +02:00
1 parent 83856506e1
commit 037427e67e
1 file changed
+24
+24
View File
@@ -81,6 +81,30 @@ TEST(a_rotated_int4_group_decodes_back_through_the_hadamard) {
CHECK(eb < ea);
}
TEST(a_rotated_int8_group_decodes_back_through_the_hadamard) {
NEED_LIBQUANT();
/* What gemm_nt_q reads at dtype i8a8h: i8 codes with a bf16 scale a (row, 128), each group
* rotated by the unnormalised Hadamard and the 1/128 in the stored scale. A scale that kept
* the factor, or lost it twice, decodes 128 times off, and a skipped rotation to noise. */
const int64_t R = 32, C = 512;
const std::vector<float> w = draw(R * C, 2, 30.0f);
Opts plain, rot;
plain.s("codes", "i8").i("group", 128).s("scale", "bf16");
rot.s("codes", "i8").i("group", 128).s("scale", "bf16").s("transform", "fwht128");
Quantised a = quantise(quantizer("rtn"), plain, "x", R, C, w);
Quantised b = quantise(quantizer("rtn"), rot, "x", R, C, w);
REQUIRE_EQ(a.status, RAD_OK);
REQUIRE_EQ(b.status, RAD_OK);
CHECK_EQ(enc_name(b.enc), std::string("i8*bf16[1x128]/fwht128"));
const double ea = rel_err(w, decode(a, R, C)), eb = rel_err(w, decode(b, R, C));
std::fprintf(stderr, " int8 g128: plain %.5f, rotated %.5f\n", ea, eb);
/* An int8 grid's error is a few parts in a thousand; with outliers the rotation is again the
* better grid. */
CHECK(ea < 0.03);
CHECK(eb < 0.01);
CHECK(eb < ea);
}
TEST(the_w4nl_table_is_exact_in_e4m3_and_beats_minus_8_to_7_after_the_rotation) {
NEED_LIBQUANT();
/* The sixteen levels libr4d's w4nla8h kernel decodes, in its code order, as a container