Commit Graph
6 Commits
Author SHA1 Message Date
Niko1221 a215f95d52 quant_parity: a gate leg against stored reference digests, the live ggml compare for information
ggml-cpu's own results move with the compiler that builds the oracle:
GCC 14.3 fuses the IQ4_NL odd-block tail into an FMA, GCC 15.2 that and
the generic Q2_0 dot, where GCC 13.3 does not (55 and 238 rows of the
oracle, 1-4 ulp). The layer's results are the same bytes under all
three. A live compare alone therefore fails on a newer GCC for a change
in ggml, not in the layer.

Leg 1, the gate: every group (flavour, section, type, n) of the layer's
results against tests/quant/golden_x86.txt, the digests of the
reference that GCC 13.3's ggml-cpu computes for the same inputs (input
digest checked too). A toolchain family can carry its own line for a
group (msvc: MSVC does not contract the intrinsics' add-of-mul).
Leg 2, information: the row-by-row compare with the ggml-cpu linked
here; its summary names the compiler and the groups where that ggml
differs from the golden reference. QUANT_PARITY_LIVE_STRICT=1 makes it
fail too. Without golden lines for a flavour (arm64, or --rows other
than 24) leg 2 stays the gate.

The digest is FNV-1a 64, written in the test, with its published test
vectors checked at start. --dump-group KEY prints every row of a group
(ours per kernel and ggml's) for a diff against a GCC 13 run;
--write-golden FILE writes a flavour's lines; --regen-check (ctest
quant_golden_regen, only when the golden file exists) regenerates the
stored lines byte for byte under GCC 13.x (family gcc) or MSVC 19.4x
(family msvc) and skips elsewhere. tests/quant/make_golden.sh and
golden_merge.py make the file.
2026-11-10 20:25:56 +01:00
Niko1221 2d2773239d quant_parity: the same test inputs under every compiler
Two random draws in one expression have no evaluation order in C++: the
activation test's tie rows got other inputs under MSVC 19.44 than under
GCC (20 rows per group). Every draw of the test is now its own statement
(Rng::gauss, the tie rows, the boundary scales).

The activation and boundary quantizer tests pre-fill both output
buffers: Q8_K leaves an all-zero block's 16 block sums unwritten (ggml
and the layer alike), so those bytes carried an earlier row's contents.

No kernel changes; the inputs change once, so the golden digests that
follow are made from this version.
2026-11-10 20:06:15 +01:00
Niko1221 a550fd71f1 quant layer: STRATA_OWN_CPU_QUANT defaults ON on arm64; quant_parity skips ggml-cpu flavours that are not the Neon contract; quant_bench (rows against ggml-cpu); run_oracle arm flavours 2026-11-09 05:07:04 +01:00
Niko1221 9740a09628 quant layer: Arm NEON tier (ggml's NEON dots and Q8_0/Q8_1 quantizers ported, Arith::Neon), arm64 contraction of the Q8_K/Q4_0/dequant references, boundary-value oracle test 2026-11-09 04:59:30 +01:00
Niko1221 e5af60da09 quant layer: AVX2 and AVX tiers (ggml's x86 dots and Q8_0/Q8_1/Q8_K quantizers ported), dequantizers; bit-exact against ggml-cpu in all three flavours
x86 tiers of the layer, one translation unit per flavour compiled with that flavour's instruction-set flags, so the #if __AVX2__ / __AVX__ branches of
ggml's own x86 code (arch/x86/quants.c at the pin, ported to C++ in x86_helpers.inc, x86_dots.inc, x86_act.inc) select what ggml-cpu selects:
- Arith::Avx2 (dot_avx2.cpp, act_avx2.cpp: -mavx2 -mfma -mf16c): the release flavour.  21 dot types + Q2_0 (generic code under this contract, as in ggml),
  Q8_0 / Q8_1 round-half-even quantizers, Q8_K quantizer in AVX2 (the engine's q8k_quant_avx2 moved into the layer, byte-identical to the scalar _ref).
- Arith::Avx (dot_avx.cpp, act_avx.cpp: -mavx, AVX2/FMA/F16C off, #error if they leak in): the STRATA_ISA_FLOOR=avx flavour.
- -ffp-contract=fast on the tier files (ggml-cpu is gnu11 C, which contracts; this is -std=c++20) and STRATA_NOFUSE on the one scalar tail ggml's GCC does
  not fuse (IQ4_NL), found by the oracle test; STRATA_QUANT_AVX2_EXTRA is a cache variable for such experiments.
- dequant.hpp / dequant.cpp: ggml's dequantize_row_* for the 22 types the host side reads back; quantize_q4_0_ref was already in.
- quant_parity covers dequant_row and quantize_q4_0_ref against ggml-base's to_float and ggml_quantize_chunk(Q4_0) too.

Oracle (tests/quant/run_oracle.sh avx2 avx none), 15065 / 15065 / 14489 comparisons, 0 differences, on boston (AVX2 host) and p2006 (AVX-512 host,
the AVX-512 hardware is not used yet).  The Windows (MSVC) run is still to do.
2026-11-09 04:26:42 +01:00
Niko1221 8a2b0f5f00 quant layer: type table, CPU probe, Q8_0/Q8_1/Q8_K/Q4_0 reference quantizers, Generic-contract dots for every pool type, self-checks, ggml oracle test
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).
2026-11-09 04:11:27 +01:00