mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
New static library strata_quant (include/strata/quant/, src/quant/), no ggml dependency: block layouts and codebooks come from the quant header. - types.hpp: ggml's type ids and block geometry (type_info, row_bytes), activation type per weight type; unknown ids answer nullptr. - isa.hpp: Isa (hardware) and Arith (arithmetic contract: Generic, Avx, Avx2, Neon), Caps probe with the STRATA_FORCE_ISA cap, default_arith(). - act.hpp / dot.hpp: kernel tables with best-kernel lookup per (type, contract, hardware); references: ggml's _ref quantizers and _generic dots ported to C++ (22 dot types: Q2_0, Q4_0/1, Q5_0/1, Q8_0, IQ4_NL, MXFP4, NVFP4, Q2_K..Q6_K, IQ1_S/M, IQ2_XXS/XS/S, IQ3_XXS/S, IQ4_XS). - selfcheck.hpp: every kernel against the reference on exact synthetic data (powers-of-two scales, small activations), once per process. - tests/quant/quant_parity.cpp (the only program that links ggml-cpu) compares the layer with ggml-cpu bit for bit; run_oracle.sh builds it in the three flavours (portable AVX2, STRATA_ISA_FLOOR=avx, none). Generic tier vs the none flavour: 13825 comparisons, 0 differences (Q4_0 excluded there: ggml's SSE4.2 flavour has an SSSE3 branch that is not the generic C code).
28 lines
1.6 KiB
C++
28 lines
1.6 KiB
C++
// include/strata/quant/selfcheck.hpp - start-up self-checks against our own reference (own-stack phase 2).
|
|
//
|
|
// ggml used to be the thing the engine compared its rows with at first use; now the reference is the layer's scalar code. A synthetic row
|
|
// pair is built from a fixed PRNG with every scale a power of two and small activation values, so every float operation of every
|
|
// contract is exact (all partial sums are integers below 2^24 or dyadic fractions) and every kernel must give the reference's bits
|
|
// whatever its summation order. That catches a wrong lane, shuffle, sign or table, which is what a miscompiled or mis-dispatched kernel does.
|
|
// The summation ORDER of each kernel is not checked here: the oracle tests (tests/quant/quant_parity.cpp) check it against ggml-cpu.
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include "strata/quant/act.hpp"
|
|
#include "strata/quant/dot.hpp"
|
|
|
|
namespace strata::quant {
|
|
|
|
/// True when the kernel gives the reference's result on the synthetic rows (several row counts, odd block counts). `why` gets one line on failure.
|
|
bool selfcheck(const DotKernel& k, std::string* why = nullptr);
|
|
/// Same for an activation quantizer: against the reference quantizer of the Generic contract on tie-free inputs (the tie behaviour is
|
|
/// the oracle test's job).
|
|
bool selfcheck(const ActKernel& k, std::string* why = nullptr);
|
|
|
|
/// dot_kernel() with the check built in: the best kernel that passes (each (type, contract, isa) is checked once per process); nullptr if none.
|
|
const DotKernel* checked_dot_kernel(Type w, Arith a) noexcept;
|
|
const ActKernel* checked_act_kernel(Type act, Arith a) noexcept;
|
|
|
|
} // namespace strata::quant
|