docs: FORK.md F15, AVX2 NVFP4 x Q8_0 dot product (not deployed)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PZz44SLQvTXMyWGio6t9DZ
This commit is contained in:
LumpiastyandClaude Opus 5.5 committed 2026-11-23 00:12:00 +01:00
1 parent af815458ca
commit ec3bf13f6e
1 file changed
+89 -1
+89 -1
View File
@@ -62,6 +62,7 @@ Status at the time of writing (2026-11-22):
- F12 Temporary upstream carries (open upstream PRs, drop when merged)
- F13 Per-pass views of host weights in looped layers (inkling2_loop)
- F14 User-message batch-break merge (one ubatch per short turn)
- F15 AVX2 NVFP4 x Q8_0 dot product (Inkling-2-Mini CPU experts)
4. Dead ends
5. Configuration that matters
6. Measurement methodology and traps
@@ -151,9 +152,10 @@ Oldest first. "Feature" points at the section below.
| 5f88124b3 | llama: env knob LLAMA_LOOP_FULL_COPY=0 to skip upstream's inkling2_loop full-copy guard (#32807) (branch `-20261122` only) | F13 |
| 6c895a491 | upstream-carry #32777: fit : prioritize looped MoE layers in device memory (branch `-20261122` only) | F12 |
| 70d39bdbc | scripts: fork-validate.sh - scratch arenas on /dev/shm, lock_id failed on overlayfs (branch `-20261122` only) | F9 |
| af815458c | ggml-cpu: faster AVX2 NVFP4 x Q8_0 dot product (two blocks per iteration, vector UE4M3 scales) (branch `-20261122`; `78a204bb2` on `fable5/nvfp4-avx2`) | F15 |
On `fable5/vram-ondemand-rebase-20261122` the #32735 carry (d2396e4e3) is gone (merged upstream) and
the other hashes in this table differ; the last four rows are hashes of that branch.
the other hashes in this table differ; the last five rows are hashes of that branch.
Later documentation-only commits (FORK.md, README, runbook) are not listed; they carry no code.
Everything down to `cce0ac1f0` is in production (`2fc9f9c35`, the documentation commit after it);
@@ -1689,6 +1691,92 @@ exact command line plus `-lv 4`, scratch port, arena and cache dir):
7. The 6-turn TTFT table of item 2 with the candidate, M only: turn 1 may be slower than 3.99 s
(the system-prompt split is back), turns 2-6 must match the M column within noise.
### F15. AVX2 NVFP4 x Q8_0 dot product (Inkling-2-Mini CPU experts)
Branch `fable5/nvfp4-avx2` (on the production branch tip `2caae7e11`). Not deployed. No knob: the
old kernel is gone from the AVX2 path (drop = revert the commit).
**What and why.** Inkling-2-Mini UD-Q4_K_XL stores the experts of 20 of its 24 layers as NVFP4
(ggml type 40: `block_nvfp4` = 4 UE4M3 scale bytes, one per 16 elements, then 32 bytes of E2M1
nibbles; within each 8-byte sub-block group the low nibbles are elements 0-7 and the high nibbles
8-15; values are the doubled E2M1 table `kvalues_fp4` and `ggml_ue4m3_to_fp32` returns the scale
times 0.5; the per-expert `ffn_*_exps.scale` tensor is a separate graph multiply). The host experts
(`-ot ...exps=CPU`) decode on the CPU through `ggml_vec_dot_nvfp4_q8_0`: the F13 profile had it at
21% of decode CPU time, plus 36% in the OpenMP barrier. CPU_REPACK has no NVFP4 path, so vec_dot is
what runs. Upstream's AVX2 loop did one block per iteration with 4 scalar UE4M3 table lookups, 2
scalar FP16 conversions, 4 scalar muls, broadcasts and 2 FMAs on one accumulator.
**Where.** `ggml/src/ggml-cpu/arch/x86/quants.c`: `ue4m3x8_to_fp32_half` and the `__AVX2__` branch
of `ggml_vec_dot_nvfp4_q8_0`. `tests/test-backend-ops.cpp`: perf cases at Inkling's expert shapes
(nvfp4, mxfp4, q4_0; `m=2304`, k 2304 and 1152, n 1/8/16/32, MUL_MAT and MUL_MAT_ID 128x8). Commit
`78a204bb2`.
**How it works.** Two blocks (128 weights) per iteration: one 32-byte load of `qs` per block, low and
high nibbles through a 256-bit `pshufb` of `kvalues_fp4`, `unpack{lo,hi}_epi64` + `permute2x128`
into the q8_0 element order, sign trick + `maddubs` against the two q8_0 blocks. The 8 sub-block sums
are reduced exactly in int16 (at most 16*12*127 = 24384) by two levels of `hadd_epi16` and one
`madd`, lanes `[b0s0 b0s2 b1s0 b1s2 | b0s1 b0s3 b1s1 b1s3]`. The 8 scale bytes are shuffled into the
same lane order and decoded in one vector: normal `(x & 0x7F) << 20` plus exponent bias 119 (bias 7
and the 0.5), subnormal `m * 2^-10` by blend, `0x7F` -> 0; bit-identical to `ggml_ue4m3_to_fp32` for
all 256 bytes (including the sign-bit quirk: 0xFF decodes to 240, as in the reference). The 4 q8_0
FP16 scales are packed in a GPR and converted with one `vcvtph2ps`. One mul + one FMA per
iteration. An odd last block takes the existing scalar tail. The AVX-only path and the generic
reference are untouched.
Tried and not kept (standalone harness `/root/arms/nvfp4-bench/nvfp4bench.c`, single core, min of
400 trials): 4 blocks per iteration with two accumulators (no change), `srlv`-based nibble split with
the q8_0 vector permuted instead (no change), `packs_epi32(madd)` instead of `hadd_epi16` (no
change), the scale decode via a denormal multiply (`as_float(x << 20) * 2^119`, -4% time but wrong
under DAZ, so not used). Ablation of the kept kernel: nibble decode + dot product about 60% of the
time, the reduction 17%, the scales 23%. Zen 2 runs it at about 2.7 IPC with FP pipe 2 the busiest
(`perf stat` `fpu_pipe_assignment`), not at the 4-pipe limit.
**Correctness.**
- Standalone: bit-exact scale decode for all 256 bytes and the lane order; random blocks (wild and
realistic scale bytes, n 64..2368, odd block counts) against the generic reference: worst error
3.7e-8 of the sum of |terms|.
- Linked against the built libraries (`vecdot_check.cpp`): 1400 rows of Gaussian weights at 4 scales
(1e-3 drives the UE4M3 scales into subnormals), quantized with the library, vs the exact dot of the
dequantized operands in double: new 5.5e-8, old 4.2e-8 (float rounding of the accumulation order).
- `test-quantize-fns`: nvfp4 dot product error 0.019774 in both builds (identical).
- `test-backend-ops -b CPU` cannot test a CPU kernel (it compares the CPU backend with itself).
**Measured (2026-11-22, pod, beside production, CPU-only scratch builds `-DGGML_VULKAN=OFF` in
`/root/arms/nvfp4-base` (`2caae7e11`) and `/root/arms/nvfp4`; logs in `/root/arms/nvfp4-bench/`).**
- Kernel, one pinned core, 64 rows L2-resident, min of 3000 trials, through the library's type
traits (`vecdot_perf.cpp`, `vp1.log`, 4 runs per arm, spread 0.2 ns): k=2304 129.0 -> 113.8 ns/row
(1.13x), k=1152 67.6 -> 59.5 (1.14x). Unchanged controls: q4_0 96.6 / 51.6, mxfp4 103.0 / 55.0 in
both builds. NVFP4 is still about 18% slower per row than q4_0.
- 6 threads streaming 512 MiB from DRAM (decode-like): every type, old or new, sits at the same
21-23 GB/s (best of 15; medians 11-21 GB/s under the co-tenants). At 6 threads the expert dot
product is DRAM-bound on this node, so the kernel speedup mostly turns into idle time, not decode
speed. A decode token streams about 1.3 GB of host NVFP4 experts at production's k=4 (8 experts x
36 layer passes x 35.8 MB).
- `test-backend-ops perf` at 6 threads is useless here: the unchanged q4_0 and mxfp4 cases varied
0.6x-1.7x between the two builds.
- llama-bench CPU-only decode, `-ngl 0 -t 6 -p 0`, arms B N N B, 6 rounds: rounds 1-2 tg32 x3 (`lb.log`): base 5.23 5.12 5.04 5.19, new 5.52 5.34 5.23 5.15 t/s,
medians 5.16 -> 5.29 (+2.5%); rounds 3-6 tg64 x5 (`lb2.log`): base 4.53 5.10 4.87 5.31 5.02 4.65 4.79
4.93, new 4.98 5.24 5.34 5.09 4.70 4.38 5.02 5.18, medians 4.90 -> 5.06 (+3.2%). The new build won 5
of the 6 rounds (mean of its two arms against the base pair). Below the 5% bar of section 6, so a
likely +2-3%, not proven. CPU-only is the upper bound of the effect: every layer's experts and
attention run on the CPU here; with production's k=4 the NVFP4 share of a token is smaller.
**What the GPU+CPU window should measure.** Production command line (`inkling_args`, k=4 `-ot`),
llama-bench `-lm none -ngl 99 -ot <k=4 pattern> -fa 1 -t 6 -b 1024 -ub 1024 -p 0 -n 256 -d 4096 -r 3`
(the F13 sweep's tg256 @ d4096 cell), base `2caae7e11` vs this branch, B N N B, medians (section 6).
Expected: decode +0-3% (DRAM-bound), prefill unchanged (prefill MUL_MAT_ID runs on the GPU for
ubatches >= 32). Optionally `perf record` the decode: `ggml_vec_dot_nvfp4_q8_0` should drop from 21%
by roughly a tenth and the barrier share rise. Then a greedy text request against the base build
(temperature 0): output may differ only by float rounding.
**How to drop it.** Revert `78a204bb2` (the kernel and the perf cases are independent hunks). Drop it
when upstream rewrites this AVX2 path.
**Rebase hazards.** Upstream changes to `block_nvfp4` (layout, scale semantics, the 0.5 convention in
`ggml_ue4m3_to_fp32`, the `0x7F`/sign handling TODO there) must be mirrored in
`ue4m3x8_to_fp32_half`; the standalone check (`nvfp4bench.c`) tests all 256 bytes against the
reference.
---
## 4. Dead ends