fix(kvflash): #934 follow-ups: graph scorer tolerance stated, non-finite keys fail, spawn failure joins

Merged
DU
23d ago
+103-12

This follow-up to #934 corrects what the graph scorer header claims and closes three small robustness gaps in the same code. It changes no kernels and makes no performance claim.

What changes

  1. kvflash_gpu_mass.h said the graph scorer gives "the same outputs" as kvflash_exact_mass_scores_fast_multi. It does not. For Q4_0 and Q8_0 keys, ggml_mul_mat quantises the queries to 8 bits, while the AVX2 scorer keeps them in F32. The header now states the measured deviation and that the two scorers are not interchangeable inside one session. The unit test gets a 400-chunk case asserting the real bound (5e-2) and an F32-keys case asserting float-rounding agreement (1e-4), which shows the graph itself is right and the deviation comes from the query quantisation only.
  2. run_workers called std::terminate when a thread could not be created after earlier ones had started (pids limit, no stack memory). It now joins the started threads and rethrows.
  3. Both scorers returned success with NaN scores for every chunk when one key value was NaN or Inf. They now fail the call, and the graph scorer reports "non-finite mass".
  4. Removed an unused tol parameter and a stale section header from the exact-mass test.

Measurement methodology

The only numbers here are the scorer deviation figures in the header comment. They compare the graph scorer against the AVX2 scorer on the same synthetic keys and the same queries, so nothing but the scorer differs.

  • Backend: the ggml CPU backend (what the unit test runs). CUDA/HIP deviation is not measured, and the header says so.
  • Geometry: the unit-test fixture, 2 layers, 2 KV heads, 3 query heads per KV head, head dim 64, 16-token chunks, 8 queries, fixed RNG seed.
  • Metric: largest relative difference of the selector-v2 score (max over queries of the mean top-plane mass) over all chunks.
  • Result: about 2e-3 at 60 sealed chunks, 1.7e-2 at 200, 4e-2 at 400 for Q4_0; F16 keys under 1e-3; F32 keys about 1e-6.
  • Each figure is a single deterministic run (fixed seed, no timing involved), so no warmup, power limit or repeat count applies.

No before/after speed benchmark is included because no hot path changed. The 1.7 s figure for the CPU scorer (64 queries, 514 sealed chunks) in the header comes from #934 and was not re-measured here.

Tests: the four KVFlash unit sources (exact mass, graph mass, user-question helpers, PFlash mapper) build without warnings in a CPU-only build and pass 66 of 66. The new cases failed before the fixes.

Known limits, not addressed here

  • Scorer memory grows linearly with history length on both paths (about 0.8 GiB for a CPU reselect at 2062 chunks and 128 queries).
  • A caller should pick one scorer per process, or skip a reselect on a guard refusal, instead of falling back to the other scorer mid-session; that belongs with the engine wiring.