Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .agents/evidence/quant-q4k-seam-20261129/PROCESS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# QUANT-GGUF-CIQ-GEMM — q4k/q6k repack shared-seam unit (2026-11-29)

Helper session `q4k-seam`, row QUANT-GGUF-CIQ-GEMM, worktree
/tmp/quant-q4k-seam from main ee9c3de77, branch
row/QUANT-GGUF-CIQ-GEMM-q4k-q6k-repack. Canonical issue
ISSUE-LOCAL-01M8M4B648PC33WK7K3ANACVVP (.agents/issues/QUANT-GGUF-CIQ-GEMM/).

## Unit

1. `vt::cpu::QuantRepackMatmul` gains the Q4_K and Q6_K repack twins: the
dotprod gemv (rows <= 3) and the i8mm 4-row GEMM (rows > 3, leftover rows
back on the gemv), transcribed verbatim from the pinned tap
/tmp/llamacpp-kolibri11-tap at 5f4d22289 (arch/arm/repack.cpp:781/:1570/
:4015/:4984 NEON arms; the SVE arms are NOT transcribed — this host
exposes no SVE, /proc/cpuinfo, so the oracle binary dispatches the NEON
arms). The upstream kernels' fused `vfmaq_f32` scale folds are kept
verbatim (the bit-identity target here is the oracle kernel — a different
fp order from the vec_dot path), a recorded deviation from the Q8_0 arm's
non-fused vmla policy (file header, cpu_quant_repack_arm.cpp).
2. QuantizeRowQ8KFused (explicit std::fma == the oracle binary's
-ffp-contract=fast nearest_int) and QuantizeRowQ8K4x8Fused (verbatim
ggml_quantize_mat_q8_K_4x8 + fused nearest_int) — ADDITIVE arms; the
default BlockFromFloat table is untouched.
3. QuantRepackEligible/QuantRepackWeight extended to Q4_K/Q6_K (N%8==0,
K%256==0 — the pinned selection, repack.cpp:5011-5017/:5052-5059); the
portable make_block_{q4_K,q6_K}x8 interleave lives in cpu_quant_repack.cpp.

## Bit-proof (tap build /tmp/llamacpp-kolibri11-32891-build at 5f4d22289)

Fixture tests/fixtures/quant-q4k-q6k-repack-oracle-f32.bin (5,385,315 bytes,
sha256 2975aa85fd1be8192f7f8e4a90fac2d0f01dfd32727dbfdee44a11d9eb30132f)
generated by the scratch generator in this directory (compiled against the
tap libs), containing:
- the tap's quantize_row_q8_K bytes on the 5 kolibri11 live rows,
- the tap's ggml_quantize_mat_q8_K_4x8 bytes + input,
- the tap's REPACKED block bytes for Q4_K/Q6_K 512x2560 (weights synthesized
from a shared xorshift32 LCG — leg 3 doubles as the generator-drift
tripwire),
- 40 kernel cases: the 5 live-row Q4_K tensors at m=1 (gemv, live row) and
m=4 (gemm), plus Q4_K/Q6_K random shapes at m in {1,2,3,4,5,8} (m=5 =
4-row gemm + gemv leftover, the oracle forward_mul_mat shape).

RED/GREEN (test_quant_repack_kq_repack):
- GREEN: 393/393 assertions byte-for-byte (green-full-run.txt). Notably the
gemm legs pin OUR QuantizeRowQ8K4x8Fused + GemmQ{4,6}K8x8 against the
TAP's own quantize_mat + gemm pairing — the interleaved-q8_K bsums layout
question raised during transcription is settled empirically by these legs.
- The in-test discriminating controls: the default contract=off quantizer
must differ from the oracle on at least one live row (passes; some live
rows and all-random rows coincide, per the kolibri actcheck evidence), and
the plain vec_dot class must differ from the repacked outputs somewhere.

## Mutations (each: bend, rebuild, run, restore byte-for-byte — backups kept)

- M2 QuantizeRowQ8KFused magic constant +1.0f: 5 leg-1 memcmp reds + gemv
reds. First attempt +0.5f was a NO-OP (below the f32 ULP at 2^23) and
stayed green — recorded as a bad mutation (kolibri precedent).
- M3 GemmQ4K8x8 bias vmlsq->vmlaq: 14 failures, red.
- M4 GemvQ6K8x8 high-bits mask 0x30->0x20: 8 failures, red. First attempt
(mask_hi -> mask_lo) failed to COMPILE (-Werror unused variable) and left
a stale binary reporting a false green — recorded; the redo notes the
stale-binary hazard.
- M5 QuantizeRowQ8K4x8Fused bsums index <<2->>1: 15 failures, red.
- M6 reachability: Q4_K/Q6_K routing condition disabled in
QuantRepackMatmul: the seam entry throws ("weight must be a repacked q8_0
tensor"), red. VT_CPU_QUANT_REPACK=portable skips the test coherently
(exit 77), which is inertness, not red.

## Inertness (default config, this host)

- ctest -R 'quant|repack': 28/28 pass (4 CUDA/ROCm skip coherently).
- ctest GGUF-model subset (kolibri/flint/gguf_load/inkling2): running at
the time of writing; result recorded below.

## Consumers owed re-proofs (coordinator dispatches)

- kolibri11-u3 (model-local twin 5838c608b) — may now switch to the shared
seam in its own follow-up; NOT rewired here.
- inkling2-w1 per-op table.
- qwen3_5_gguf_weights.cpp and muse_glimmer_gguf_weights.cpp: the only two
loaders calling QuantRepackEligible/QuantRepackWeight; their eligible
Q4_K/Q6_K weights now REPACK on i8mm hosts and take the oracle repacked
class (intended change; their keep-quant goldens and any byte-exact gates
need re-proof).
- MatmulBTQuantGrouped (cpu_quant_gemm.cpp) repacked slices for Q4_K/Q6_K
expert towers.
- Every other MatmulBTQuant / QuantTraits.from_float consumer (deepseek_v4,
flint, laguna, minimax_h3, glm5_next, qwen4_exp, CUDA/ROCm/Vulkan/TT
providers) is byte-unchanged by construction (additive arms; default
from_float table untouched) but is listed for the fresh reviewer's
mutation check.

## Scope discipline

Seam + tests only; no model rewiring; no push; no tolerance concepts
anywhere (byte-for-byte or nothing). 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.

## APPENDIX 2026-11-29 (later same day) — opt-in default + attribution

First staged preflight surfaced three GGUF-model gate failures
(test_kolibri1_gguf logit band + hard flips, test_deepseek_v4_gguf_load
stacked-expert non-repacked contract, test_flint_paged_engine goldens).
Attribution: test_flint_paged_engine needs the untracked per-host
tests/vllm/models/flint_goldens_q4_k_m.json (absent from a fresh worktree);
test_kolibri1_gguf and test_deepseek_v4_gguf_load fail IDENTICALLY on the
clean baseline ee9c3de77 (baseline run in /tmp/quant-q4k-base-bld, same
signatures: 5x logit-band CHECKs + hard_flips; the deepseek_v4.cpp:631
non-repacked contract throw) — pre-existing on this host, not caused by this
unit.

Nevertheless the eligibility extension DID flip eligible k-quant weights to
the repacked class by default, which silently moves every Q4_K/Q6_K model's
outputs on an i8mm host before its consumers are re-proofed. Resolution: the
Q4_K/Q6_K arm of QuantRepackEligible is OPT-IN behind
VT_CPU_QUANT_REPACK_KQ=1 (default off = byte-identical to today); the seam
dispatch, kernels, fused quantizers and bit-proof legs are unchanged (the
bit-proof test sets the flag in-process). The coordinator flips the default
when the consumer re-proofs land (kolibri11-u3, inkling2-w1,
qwen3_5/muse_glimmer keep-quant goldens, deepseek_v4 stacked-expert
contract).

## APPENDIX 2026-11-29 (preflight repair, coordinator-visible)

- check-env-doc: the new knob is now documented as a behavior-changing
selection row in docs/ENVIRONMENT.md (VT_CPU_QUANT_REPACK_KQ, default off,
inertness guarantee stated in the row).
- test_check_test_registration -> test_every_fetch_content_site_is_pinned_off
(6 != 3): PRE-EXISTING/environmental, NOT the staged content. Root cause:
the gate counts `FetchContent_Declare` under the WORKTREE root (rglob
CMakeLists.txt/*.cmake, skipping only .git), so an in-tree build directory
(build/_deps/*-src) inflates the count. Verified: the identical unittest
passes on the clean shared checkout at ee9c3de77 (no build dir), fails in
this worktree only while build/ existed, and passes after the build moved
out-of-tree (/tmp/quant-q4k-seam-bld) with the same staged content. Routed
to the coordinator as a checker-environment hazard: a gate that rglobs the
worktree counts developer build artifacts as tree content. Not fixed here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== Inertness rerun with the OPT-IN default (VT_CPU_QUANT_REPACK_KQ unset): model-gate subset ===

Total Test time (real) = 268.41 sec

The following tests FAILED:
40 - test_kolibri1_gguf (Failed)
214 - test_flint_paged_engine (Failed)
235 - test_deepseek_v4_gguf_load (Failed)
Errors while running CTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== MUTATION M2 (contract arm): magic constant 12582912.0f -> 12582913.0f in QuantizeRowQ8KFused ===
NOTE: a first attempt with +0.5f was a NO-OP mutation (below the f32 ULP at 2^23) and stayed green; recorded as a bad mutation, then repeated with +1.0f per the kolibri precedent.
./tests/vt/test_quant_repack_kq_repack.cpp:245: ERROR: CHECK( std::memcmp(fused.data(), tap.data(), tap.size()) == 0 ) is NOT correct!
./tests/vt/test_quant_repack_kq_repack.cpp:245: ERROR: CHECK( std::memcmp(fused.data(), tap.data(), tap.size()) == 0 ) is NOT correct!
./tests/vt/test_quant_repack_kq_repack.cpp:245: ERROR: CHECK( std::memcmp(fused.data(), tap.data(), tap.size()) == 0 ) is NOT correct!
./tests/vt/test_quant_repack_kq_repack.cpp:245: ERROR: CHECK( std::memcmp(fused.data(), tap.data(), tap.size()) == 0 ) is NOT correct!
./tests/vt/test_quant_repack_kq_repack.cpp:245: ERROR: CHECK( std::memcmp(fused.data(), tap.data(), tap.size()) == 0 ) is NOT correct!
./tests/vt/test_quant_repack_kq_repack.cpp:356: ERROR: CHECK( mismatches == 0 ) is NOT correct!
./tests/vt/test_quant_repack_kq_repack.cpp:356: ERROR: CHECK( mismatches == 0 ) is NOT correct!
./tests/vt/test_quant_repack_kq_repack.cpp:356: ERROR: CHECK( mismatches == 0 ) is NOT correct!
./tests/vt/test_quant_repack_kq_repack.cpp:356: ERROR: CHECK( mismatches == 0 ) is NOT correct!
./tests/vt/test_quant_repack_kq_repack.cpp:356: ERROR: CHECK( mismatches == 0 ) is NOT correct!
[doctest] Status: SUCCESS!
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== MUTATION M3 (Q4_K i8mm gemm): dmins scale applied with + instead of the vmlsq bias-subtract (bias term bent) ===
[doctest] assertions: 393 | 379 passed | 14 failed |
[doctest] Status: FAILURE!
[doctest] Status: SUCCESS!
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== MUTATION M4 (Q6_K gemv): high-2-bits extraction mask 0x30 -> 0x20 (bent) ===
NOTE: a first attempt replacing mask_hi with mask_lo failed to COMPILE (unused variable, -Werror) and left a stale binary that reported a false green; recorded, then repeated with a compiling value bend.
[doctest] assertions: 393 | 385 passed | 8 failed |
[doctest] Status: FAILURE!
[doctest] Status: SUCCESS!
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== MUTATION M5 (4x8 mat quantizer): bsums index formula bent ===
[doctest] assertions: 393 | 378 passed | 15 failed |
[doctest] Status: FAILURE!
[doctest] Status: SUCCESS!
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== MUTATION M6 (reachability): Q4_K/Q6_K routing condition disabled — arms unreachable from the seam entry ===
[3/3] Linking CXX executable tests/test_quant_repack_kq_repack
./tests/vt/test_quant_repack_kq_repack.cpp:167: ERROR: test case THREW exception: vt: quant_repack_matmul: weight must be a repacked q8_0 tensor at ./src/vt/cpu/cpu_quant_repack_arm.cpp:1093
[doctest] assertions: 111 | 111 passed | 0 failed |
[doctest] Status: FAILURE!
[doctest] Status: SUCCESS!
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ID: ISSUE-LOCAL-01M8M4B648PC33WK7K3ANACVVP
Title: Q4_K/Q6_K repack matmul arms absent from QuantRepackMatmul; QuantizeRowQ8_K contract=off bytes diverge from oracle
Row: QUANT-GGUF-CIQ-GEMM
State: OPEN
Kind: bug
GitHub: -
Mirror: PENDING
Availability: FULL
Created: 2026-11-29
Updated: 2026-11-29
Closed: -

## Problem

The serving oracle (llama.cpp 5f4d22289, NEON+i8mm host) computes every Q4_K and Q6_K matmul with ne[1]%8==0 through REPACKED kernels: rows<=3 -> ggml_gemv_q4_K_8x8_q8_K / ggml_gemv_q6_K_8x8_q8_K, rows>3 -> the i8mm ggml_gemm arm (repack.cpp:5011-5017/:5052-5059). The shared seam vt::cpu::QuantRepackMatmul is Q8_0-only, so every consumer (e.g. kolibri11-u3) must transcribe kernels model-locally; the kolibri lane's comparator (docs/bench-evidence/kolibri11-u3-oracle-20261125/repack-gemv-comparator-20261129.txt) proves repack-vs-oracle max=0 bit-exact while our vec_dot path differs up to 3.5e-3 relRMS on blk.4.attn_output. Separately, the oracle binary compiles quantize_row_q8_K_ref under -ffp-contract=fast so nearest_int's magic add fuses into one vfma; our contract=off build differs at 1-ULP ties (measured 396/7008 activation bytes on a live row, 0/7008 random). Evidence: /tmp/kolibri11-u3/PROCESS.md (2026-11-29 entries), tap tree /tmp/llamacpp-kolibri11-tap at 5f4d22289.

## Resolution

-
1 change: 1 addition & 0 deletions docs/ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ portable/reference path. In normal operation leave them unset.
| `VT_CPU_PAGED_ATTN_SCALAR_FMA` | off | Set `1` to run the draft FMA-contracted scalar body of the CPU paged attention (4-lane pairwise K dot, fused V accumulate) instead of the default pre-batch sequential order (`src/vt/cpu/cpu_paged_attn.cpp`). NOT bit-identical to the default — the summation order changes — so it is a measurement arm only: the local bisect for row FIX-PAGED-REGRESSION (docs/bench-evidence/fix-paged-regression-20261028/) named the 2cd6b8a14 contraction as the first bad commit behind the dtype bit-identity and glm4 goldens regressions, and the default was restored to the pre-batch order. The PERF-CPU-ATTN-NEON sweep and the kolibri1 W3 gate pin `=1` for the cases that measure this arm |
| `VT_CPU_QUANT_MMLA` | `auto` | Select the Arm i8mm quant-dot tier. `portable` (also `0`/`off`/`false`) disables it; `i8mm` (also `1`/`on`/`true`) forces it and fails closed unless Linux `HWCAP2_I8MM` or Darwin `hw.optional.arm.FEAT_I8MM` is present |
| `VT_CPU_QUANT_REPACK` | `auto` | Select the Arm i8mm+DotProd Q8_0 repack tier. `portable` (also `0`/`off`/`false`) disables it; `i8mm` (also `1`/`on`/`true`) forces it and fails closed unless the exact Linux HWCAP/HWCAP2 or Darwin sysctl capabilities are present |
| `VT_CPU_QUANT_REPACK_KQ` | off | Set `1` to extend the repack-at-load eligibility to Q4_K and Q6_K weights (N%8==0, K%256==0 — the pinned oracle's selection, llama.cpp 5f4d22289 repack.cpp:5011-5017/:5052-5059): the loader then repacks them into the block_q4_Kx8/block_q6_Kx8 interleave and `kMatmulBTQuant` computes them through the oracle's repacked gemv (rows<=3) / i8mm gemm (rows>3) kernels — a DIFFERENT fp order from the vec_dot path, so outputs move to the oracle's bytes. Default OFF is byte-identical to the plain path for every model; flip it only after the consumers of those weights are re-proofed (kolibri11-u3, inkling2-w1, the qwen3_5/muse_glimmer keep-quant goldens, the deepseek_v4 stacked-expert non-repacked contract). Bit-proof: `test_quant_repack_kq_repack` (393/393 byte-exact vs the tap build; evidence `.agents/evidence/quant-q4k-seam-20261129/`) |
| `VT_DFLASH_DRAFT` | off | The DFlash2-classified draft proposes through the bundle's DIRECT-ARGMAX arm (`dflash2.py` `has_selector == false`): full-vocab argmax per block row over the block forward, the candidate selector and its codebooks never resident (~254 MB freed), and the `RefuseDflash1ArgmaxOnDflash2Block` guard bypassed as the operator's explicit choice. The verify stays lossless (greedy accept = the target's argmax), so the emitted tokens are unchanged and only acceptance/TPOT can move. Default OFF keeps the selector lane byte-identical (QWEN38-DFLASH2-STAGE-C W3) |
| `VT_DFLASH_CTX_MAX_TOKENS` | unset (the resolved cap is `max_model_len + 1 + k`, itself capped at an 8 GiB budget shared across `--max-num-seqs`, so `8 GiB / max_num_seqs` per request) | Caps the DFlash/DFlash2/DSpark draft's CONTEXT STORE in tokens, PER REQUEST. The store is a per-request, per-draft-layer bf16 pool holding K and V, so its size is `tokens x num_draft_layers x num_kv_heads x head_dim x 2 x 2` bytes per concurrent request, and the runner builds ONE PER BATCH ROW — so what the device holds is that number times `--max-num-seqs`, and `gpu_memory_utilization` accounts NONE of it. The default budget is therefore the AGGREGATE rather than a per-request allowance: a 262144-token `--max-model-len` would ask for about a gigabyte per request, and unbounded device residency has OOM-rebooted a box here ([#1647](https://github.com/mudler/vllm.cpp/issues/1647)). Set this BELOW the advertised context to bound that memory, or ABOVE the default share to speculate further into a long context — the aggregate arithmetic (`tokens x bytes_per_token x max_num_seqs`) is then yours. The effective limit AND the aggregate it costs are announced at startup either way. A request whose context passes the limit keeps running WITHOUT speculation, on the target alone — never refused, and never fatal: before [#1919](https://github.com/mudler/vllm.cpp/issues/1919) the store was a fixed 4096 slots unrelated to `--max-model-len`, and the first prompt above it threw from inside an EngineCore step and left the server answering `[request submitted to a stopped AsyncLLM]` for every later request. Mirrors upstream, whose draft context lives in the engine's own paged KV cache sized `cdiv(max_model_len, block_size)` and whose speculators emit an EMPTY draft where they cannot serve a request |
| `VT_DFLASH_PAGED` | on (CUDA, DFlash spec-decode) | The materialized `[context;block]` draft forward instead of the fixed-capacity paged draft-KV store read through `vt::DFlashPagedBlockAttention` (bit-identical; only the DFlash single-request propose path) |
Expand Down
1 change: 1 addition & 0 deletions docs/bench-evidence/quant-q4k-seam-20261129/fixture.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2975aa85fd1be8192f7f8e4a90fac2d0f01dfd32727dbfdee44a11d9eb30132f tests/fixtures/quant-q4k-q6k-repack-oracle-f32.bin
Loading
Loading