Skip to content

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

Merged
davide221 merged 3 commits into
Luce-Org:mainfrom
dusterbloom:kvflash/scorer-followup
Nov 12, 2026
Merged

davide221 merged 3 commits into
Luce-Org:mainfrom
dusterbloom:kvflash/scorer-followup

Conversation

@dusterbloom

@dusterbloom dusterbloom commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

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.

View guided diff

…mass fails

The header claimed the same outputs as the AVX2 scorer. ggml_mul_mat quantises
queries to 8 bits for Q4_0/Q8_0 keys, so the select score deviates by up to
4e-2 at 400 sealed chunks and top-k sets can differ. Document that, add a
400-chunk bound test and an F32 exactness test, and make a NaN or Inf plane
sum fail the call instead of reaching nth_element.
…PU scorer rejects NaN

A failed thread creation destroyed joinable threads and called std::terminate.
The CPU scorer returned true with NaN scores for every chunk when one key
value was NaN or Inf. Also drop the unused tol parameter and a stale section
header in the exact-mass test.

@davide221 davide221 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

No issues found. Checked for bugs and logic errors in the changed code.

Reviewed 4d75667e · 0 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again

@dusterbloom dusterbloom reopened this Nov 11, 2026
score_chunks guarded S against the legacy 8-token kLookahead while passing
n_lookahead=128 to the drafter; a named constant now feeds both.

Review: Luce-Org#963 thread T8
@dusterbloom
dusterbloom force-pushed the kvflash/scorer-followup branch from 2dd92f8 to e9e0037 Compare November 12, 2026 07:49
@davide221
davide221 merged commit 6fe27a5 into Luce-Org:main Nov 12, 2026
12 checks passed
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.

2 participants