From 7a375041d154d3cfd148a4a578c22777dd42b747 Mon Sep 17 00:00:00 2001 From: pipeob0 <36382709+pipeob0@users.noreply.github.com> Date: Mon, 28 Sep 2026 18:34:37 +0200 Subject: [PATCH] parity tool: count a new-kernel mismatch as a failure, not just print it The gate/up row and IQ4_NL down comparisons printed their distance from ggml's vec_dot without affecting the exit code, so a kernel that silently diverged still reported 0 failures. Gate both at 1e-5 (measured 3e-8 and 1e-7, so 100x headroom). Verified: 0 failures at 1e-5, and with the threshold dropped to 1e-9 the gate fires on every layer. Also corrects the comment above the gate/up dispatch: STRATA_NO_IQ512 drops an AVX-512 CPU to the AVX-2 kernel, not to ggml; ggml's vec_dot needs both switches set. --- src/kernels/cpu/native_expert.cpp | 5 +++-- src/kernels/native_expert_parity.cpp | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/kernels/cpu/native_expert.cpp b/src/kernels/cpu/native_expert.cpp index 6da199de..b5254456 100644 --- a/src/kernels/cpu/native_expert.cpp +++ b/src/kernels/cpu/native_expert.cpp @@ -79,8 +79,9 @@ void native_gu_rows(const NativeFmt& f, const uint8_t* blob, const void* const* int r0, int r1) { // the multi-token kernels decode the weights once for all tokens: 2.0-2.4x ggml-cpu at three tokens, no faster // at one (all are bound by the codebook lookups, ~5 GB/s per core), measured by native_expert_parity. AVX-512 - // first, then the AVX-2 one (Zen 2/3, Intel 12th-14th gen); STRATA_NO_IQ512 / STRATA_NO_IQ256 fall back to - // ggml-cpu's single-token vec_dot. + // first, then the AVX-2 one (Zen 2/3, Intel 12th-14th gen). STRATA_NO_IQ512 drops an AVX-512 CPU to the + // AVX-2 kernel, STRATA_NO_IQ256 drops the AVX-2 kernel; ggml-cpu's single-token vec_dot is reached only with + // both set (and on a CPU without AVX-512, STRATA_NO_IQ512 changes nothing). static const bool avx512 = cpu_avx512_ok() && std::getenv("STRATA_NO_IQ512") == nullptr; static const bool avx2 = std::getenv("STRATA_NO_IQ256") == nullptr; if (nt >= 2 && iq512_supported(f.gu_type)) { // one token: ggml-cpu is as fast or faster diff --git a/src/kernels/native_expert_parity.cpp b/src/kernels/native_expert_parity.cpp index defc649d..496cf5ea 100644 --- a/src/kernels/native_expert_parity.cpp +++ b/src/kernels/native_expert_parity.cpp @@ -132,8 +132,14 @@ int main(int argc, char** argv) { float* gp[NT]; for (int k = 0; k < NT; ++k) gp[k] = g.data() + k * FF; (is512 ? cpu::iq512_rows : cpu::iq256_rows)(f.gu_type, blob.data(), f.gu_row, (int) H, a, NT, gp, 0, (int) FF); + const double rg = rel(g, gref); std::printf(" %s %s gate rows vs ggml vec_dot: rel %.2e\n", - ggml_type_name((ggml_type) f.gu_type), tag, rel(g, gref)); + ggml_type_name((ggml_type) f.gu_type), tag, rg); + if (rg > 1e-5) { // ggml's own vec_dot is the reference: above 1e-5 it is a real mismatch, + std::printf(" %s %s gate rows MISMATCH (rel %.2e > 1e-5)\n", + ggml_type_name((ggml_type) f.gu_type), tag, rg); // not rounding (measured 3e-8) + ++failures; + } float* f1[1] = {ffp[0]}; const int it = 50; const auto gu = is512 ? cpu::iq512_gu_rows : cpu::iq256_gu_rows; @@ -177,16 +183,21 @@ int main(int argc, char** argv) { if (f.d_type == 20) { // (b3) the IQ4_NL multi-token AVX-2 kernel the pool now uses for IQ4_NL down projections, // against ggml-cpu's single-token vec_dot on the SAME Q8_0 activations (h), plus timing. - std::vector alt((size_t) NT * H), ref((size_t) NT * H); + std::vector alt((size_t) NT * H), refd((size_t) NT * H); float* altp[NT]; for (int k = 0; k < NT; ++k) altp[k] = alt.data() + k * H; cpu::iq4nl256_down_rows(blob.data() + f.down_off, f.d_row, (int) FF, hp, NT, altp, 0, (int) H); const auto* tdc = ggml_get_type_traits_cpu((ggml_type) f.d_type); for (int k = 0; k < NT; ++k) for (int64_t r = 0; r < H; ++r) - tdc->vec_dot((int) FF, ref.data() + k * H + r, 0, + tdc->vec_dot((int) FF, refd.data() + k * H + r, 0, blob.data() + f.down_off + (size_t) r * f.d_row, 0, hp[k], 0, 1); - std::printf(" iq4_nl AVX-2 multi-token down vs ggml down: rel %.2e\n", rel(alt, ref)); + const double rdn = rel(alt, refd); + std::printf(" iq4_nl AVX-2 multi-token down vs ggml down: rel %.2e\n", rdn); + if (rdn > 1e-5) { // measured 1e-7; same reasoning as the gate/up rows above + std::printf(" iq4_nl down MISMATCH (rel %.2e > 1e-5)\n", rdn); + ++failures; + } const int it = 50; const auto t0 = std::chrono::steady_clock::now(); for (int i = 0; i < it; ++i) @@ -195,7 +206,7 @@ int main(int argc, char** argv) { for (int i = 0; i < it; ++i) for (int k = 0; k < NT; ++k) for (int64_t r = 0; r < H; ++r) - tdc->vec_dot((int) FF, ref.data() + k * H + r, 0, + tdc->vec_dot((int) FF, refd.data() + k * H + r, 0, blob.data() + f.down_off + (size_t) r * f.d_row, 0, hp[k], 0, 1); const auto t2 = std::chrono::steady_clock::now(); const double usn = std::chrono::duration(t1 - t0).count() / it;