[PR #2458] [CLOSED] engine: --dump-kv-select, the decode windows' KV block selections as a policy-bench trace (#2415) #4052

Closed
opened 2026-11-07 15:32:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2458
Author: @MrKop-git
Created: 10/14/2026
Status: ❌ Closed

Base: main ← Head: pr/dump-kv-select


📝 Commits (1)

  • 5781936 engine: --dump-kv-select, the decode windows' KV block selections as a trace for the policy bench (#2415)

📊 Changes

5 files changed (+156 additions, -4 deletions)

View changed files

📝 docs/DETAILS.md (+7 -0)
📝 include/strata/core/layer.hpp (+15 -1)
📝 src/core/layer.cpp (+100 -1)
📝 src/core/verify.cpp (+17 -2)
📝 src/program/generate.cpp (+17 -0)

📄 Description

Summary

The engine-side half of #2415 (the bench is #2434): --dump-kv-select PATH records what the KV streaming page pool is actually asked for - one record per resolve call of the decode windows, int32 layer, int32 k, k int32 block ids, k float32 weights, the shape tools/replay_kv_stream_policy.py reads.

  • The resolve wrapper copies each selection into per-QSA-layer pinned staging at fixed addresses, so the captured graphs bake the copies in as memcpy nodes; a flush after the window's cudaStreamSynchronize appends the records. Weights are 1.0 (the indexer's scores are not copied).
  • The staging is allocated at kv_select_dump_open, before any window is captured - the first build died on exactly that (an allocation inside a capture poisons its stream).

What it changes and what it leaves alone

The resolve wrapper gains a dump_slot argument (the two verify call sites pass the QSA ordinal; the prompt path passes nothing), a small dump block in layer.cpp, a flush in verify.cpp after the window sync, and --dump-kv-select plumbing in generate.cpp. Without the flag nothing runs and every answer is unchanged - the copies are the only new work, and they exist only when the flag is given.

How it was checked

  • kv_stream_parity PASS (q4_0 and k8v4: 0 failures, ring restore identical) on a GTX 1080 Ti (sm_61, STRATA_EXPERIMENTAL_SM60=ON), CUDA build with g++-14.
  • Live captures from this box's IQ3_S pack (the deployment's own args + --dump-kv-select): a 127-token prompt → a 115 KB trace (348 calls), a 4095-token prompt → a 3.5 MB trace (684 calls, 441,848 block lookups, 12,586 distinct blocks). The engine ran unchanged otherwise (prefill 276 tok/s, decode 20.7 tok/s on this card).
  • Both traces replay through #2434's bench. On the 4K trace, at a per-layer pool between one call's width (646 blocks) and the working set (~1,050 blocks) the real selections rank the policies:
pool/layer compulsory clock (today) lrfu lru oracle
768 12,586 41,878 40,046 69,929 31,552
896 12,586 21,741 21,014 23,646 16,114

(misses; lower is better). So on real QSA selections LRFU beats the kernel's CLOCK by 3-4% of misses, LRU is worse than both, and Belady says more is on the table - the numbers #2415 asked for before anyone changes the default.

Not tested

HIP (no toolchain on this box; the .cu sources are shared with the HIP build) and SYCL (a separate engine tree with no dump). The --batch window path keeps each layer's last call per window (documented in DETAILS.md). No wall-time claim from the miss counts - that is the live A/B #2415's next step, using the engine's own KV streaming: line.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2458 **Author:** [@MrKop-git](https://github.com/MrKop-git) **Created:** 10/14/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/dump-kv-select` --- ### 📝 Commits (1) - [`5781936`](https://github.com/Niko1221/Strata/commit/5781936e975dbead996941e33c2d120878d4981c) engine: --dump-kv-select, the decode windows' KV block selections as a trace for the policy bench (#2415) ### 📊 Changes **5 files changed** (+156 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+7 -0) 📝 `include/strata/core/layer.hpp` (+15 -1) 📝 `src/core/layer.cpp` (+100 -1) 📝 `src/core/verify.cpp` (+17 -2) 📝 `src/program/generate.cpp` (+17 -0) </details> ### 📄 Description ## Summary The engine-side half of #2415 (the bench is #2434): `--dump-kv-select PATH` records what the KV streaming page pool is actually asked for - **one record per resolve call** of the decode windows, `int32 layer, int32 k, k int32 block ids, k float32 weights`, the shape `tools/replay_kv_stream_policy.py` reads. - The resolve wrapper copies each selection into per-QSA-layer **pinned staging at fixed addresses**, so the captured graphs bake the copies in as memcpy nodes; a flush after the window's `cudaStreamSynchronize` appends the records. Weights are 1.0 (the indexer's scores are not copied). - The staging is allocated at `kv_select_dump_open`, **before any window is captured** - the first build died on exactly that (an allocation inside a capture poisons its stream). ## What it changes and what it leaves alone The resolve wrapper gains a `dump_slot` argument (the two verify call sites pass the QSA ordinal; the prompt path passes nothing), a small dump block in layer.cpp, a flush in verify.cpp after the window sync, and `--dump-kv-select` plumbing in generate.cpp. **Without the flag nothing runs and every answer is unchanged** - the copies are the only new work, and they exist only when the flag is given. ## How it was checked - `kv_stream_parity` **PASS** (q4_0 and k8v4: 0 failures, ring restore identical) on a GTX 1080 Ti (sm_61, `STRATA_EXPERIMENTAL_SM60=ON`), CUDA build with g++-14. - **Live captures** from this box's IQ3_S pack (the deployment's own args + `--dump-kv-select`): a 127-token prompt → a 115 KB trace (348 calls), a 4095-token prompt → a 3.5 MB trace (684 calls, 441,848 block lookups, 12,586 distinct blocks). The engine ran unchanged otherwise (prefill 276 tok/s, decode 20.7 tok/s on this card). - Both traces replay through #2434's bench. On the 4K trace, at a per-layer pool between one call's width (646 blocks) and the working set (~1,050 blocks) the **real selections rank the policies**: | pool/layer | compulsory | clock (today) | lrfu | lru | oracle | |---:|---:|---:|---:|---:|---:| | 768 | 12,586 | 41,878 | **40,046** | 69,929 | 31,552 | | 896 | 12,586 | 21,741 | **21,014** | 23,646 | 16,114 | (misses; lower is better). So on real QSA selections LRFU beats the kernel's CLOCK by 3-4% of misses, LRU is worse than both, and Belady says more is on the table - the numbers #2415 asked for before anyone changes the default. ## Not tested HIP (no toolchain on this box; the .cu sources are shared with the HIP build) and SYCL (a separate engine tree with no dump). The `--batch` window path keeps each layer's last call per window (documented in DETAILS.md). No wall-time claim from the miss counts - that is the live A/B #2415's next step, using the engine's own `KV streaming:` line. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:32:49 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4052
No description provided.