Skip to content

quant(gguf): Q4_K/Q6_K repack twins and the fused Q8_K quantizer contract in the shared seam - #3603

Open
lu-zero wants to merge 1 commit into
localai-org:mainfrom
lu-zero:row/QUANT-GGUF-CIQ-GEMM-q4k-q6k-repack
Open

lu-zero wants to merge 1 commit into
localai-org:mainfrom
lu-zero:row/QUANT-GGUF-CIQ-GEMM-q4k-q6k-repack

Conversation

@lu-zero

@lu-zero lu-zero commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

quant(gguf): Q4_K/Q6_K repack twins and the fused Q8_K quantizer contract in the shared seam

vt::cpu::QuantRepackMatmul was Q8_0-only while ggml (NEON+i8mm hosts)
dispatches every Q4_K/Q6_K weight with ne[1]%8==0 through its 8x8
repack kernels - proven byte-for-byte against the pinned oracle build
(5f4d22289): the oracle's numbers ARE the repacked numbers (8/8 live
ops, max=0), and the shared QuantizeRowQ8_K rounding differs from the
oracle binary's fused form on 396/7008 activation bytes of a live row.
This adds, additively behind VT_CPU_QUANT_REPACK_KQ=1 (default off =
byte-identical to today): Q4_K and Q6_K gemv twins (rows<=3), the
Q4_K/Q6_K i8mm GEMM arms (rows>3, NEON; this host has no SVE), and
QuantizeRowQ8KFused/QuantizeRowQ8K4x8Fused producing the oracle
binary's exact bytes. 393/393 assertions through the production
vt::MatmulBTQuant entry, 0 byte mismatches vs the tap build, five
mutation-verified discriminators (magic constant, gemm bias op, gemv
mask, bsums index, routing), inertness asserted on the default config,
and one knob documented in docs/ENVIRONMENT.md. The default-on flip is
deliberately deferred until the consumer re-proof wave lands (the
kolibri1 rewire is the first and is in flight).

Closes ISSUE-LOCAL-01M8M4B648PC33WK7K3ANACVVP

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [maki]

…emv/gemm twins and the fused Q8_K quantizer arms, opt-in

vt::cpu::QuantRepackMatmul gains the Q4_K and Q6_K repack twins so a model
no longer has to transcribe the serving oracle's kernels model-locally (the
kolibri11-u3 precedent, 5838c608b). Transcribed verbatim from the pinned tap
llama.cpp 5f4d22289 arch/arm/repack.cpp: ggml_gemv_q4_K_8x8_q8_K (:781),
ggml_gemv_q6_K_8x8_q8_K (:1570), ggml_gemm_q4_K_8x8_q8_K (:4015, NEON i8mm
arm), ggml_gemm_q6_K_8x8_q8_K (:4984, NEON i8mm arm); the SVE arms are not
transcribed because this host (and every host the i8mm predicate serves
here) exposes no SVE. The upstream kernels' fused vfmaq_f32 scale folds are
kept verbatim — the bit-identity target on this seam IS the oracle kernel, a
recorded deviation from the Q8_0 arm's non-fused vmla policy (the Q8_0 tier
stays byte-identical to the portable path). Dispatch mirrors the oracle's
forward_mul_mat shape: rows <= 3 the dotprod gemv over plain q8_K rows,
rows > 3 the 4-row i8mm gemm over BlockQ8Kx4 groups with leftover rows back
on the gemv.

The oracle binary compiles quantize_row_q8_K_ref under
-ffp-contract=fast, so nearest_int's magic add fuses into one vfma and our
contract=off build differs at 1-ULP ties (measured 396/7008 activation
bytes on a live kolibri row, 0/7008 random). Landed as ADDITIVE arms —
QuantizeRowQ8KFused and QuantizeRowQ8K4x8Fused (verbatim
ggml_quantize_mat_q8_K_4x8 plus the fused nearest_int); the default
BlockFromFloat table is untouched.

QuantRepackEligible/QuantRepackWeight extend to Q4_K/Q6_K (N%8==0,
K%256==0) behind the new VT_CPU_QUANT_REPACK_KQ opt-in (default off =
byte-identical to today): the repacked class is a different fp order, so a
default-on flip would silently move every k-quant model's outputs before
its consumers are re-proofed (kolibri11-u3, inkling2-w1, the qwen3_5 /
muse_glimmer keep-quant goldens, the deepseek_v4 stacked-expert
non-repacked contract). The coordinator flips the default when those
re-proofs land.

BIT-PROOF: tests/vt/test_quant_repack_kq_repack pins the seam BYTE-FOR-BYTE
to the tap build's exported kernels — 393/393 (fixture
tests/fixtures/quant-q4k-q6k-repack-oracle-f32.bin, generated by the scratch
generator in docs/bench-evidence/quant-q4k-seam-20261129/ against
/tmp/llamacpp-kolibri11-32891-build): the tap's quantize_row_q8_K bytes on
the 5 kolibri11 live rows, its ggml_quantize_mat_q8_K_4x8 bytes, its
repacked block bytes, and 40 kernel cases (live-row gemv m=1, gemm m=4, and
random Q4_K/Q6_K at m in {1,2,3,4,5,8} including the mixed case) through
the production vt::MatmulBTQuant entry with b.repacked set. In-test
discriminators: the default contract=off quantizer must differ from the
oracle on at least one live row, and the plain vec_dot class must differ
from the repacked outputs somewhere.

MUTATIONS (each followed by a byte-for-byte restore): magic constant +1.0f
in the fused quantizer (a first +0.5f attempt was a no-op below the f32 ULP
at 2^23 and stayed green — recorded); GemmQ4K8x8 bias vmlsq->vmlaq (14
failures); GemvQ6K8x8 high-bits mask 0x30->0x20 (8 failures; a first
mask-swap variant failed to COMPILE and left a stale binary reporting a
false green — the stale-binary hazard is recorded); the 4x8 quantizer's
bsums index shift (15 failures); disabling the Q4_K/Q6_K routing condition
in QuantRepackMatmul (the seam entry throws).

INERTNESS: ctest -R 'quant|repack' 28/28 on the default config;
test_kolibri1_gguf, test_deepseek_v4_gguf_load and test_flint_paged_engine
fail IDENTICALLY on the clean baseline ee9c3de (baseline run recorded in
.evidence/PROCESS.md) — pre-existing on this host, not caused by this
change. Preflight --staged exits 0 with six host-unavailable gates skipped
(x86/CUDA ISA builds, triton multiarch args, PR size needs the forge).

Fixes ISSUE-LOCAL-01M8M4B648PC33WK7K3ANACVVP in substance; the issue closes
when the row's coordinator records the landing. Spec note: this unit ran
under the row's committed spec umbrella (gguf-compute-in-quant-gemm.md /
the G7/G6 repack tiers); a row-level spec addendum for the q4k/q6k arms is
owed with the row's next lifecycle change.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant