mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3919] [Engine] kv: size the resident ring from the run's depth (opt-in, STRATA_KV_RING_ADAPT) #4833
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4833
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3919
Author: @xyzzing
Created: 10/24/2026
Status: 🔄 Open
Base:
main← Head:v4-kv-ring-adapt📝 Commits (5)
2e435afkv: size the resident ring from the run's depth (opt-in, STRATA_KV_RING_ADAPT)0ffb592kv: grow the resident ring only when it can cover the context (drafter-aware)3db7b83kv: the ring grows only past twice the cap - the 64K tier regressed under needed>=capaa782aakv: the adaptive ring sizes a serve session from --context, and =0 turns it off65fb418docs: STRATA_KV_RING_ADAPT in the KV cache table📊 Changes
4 files changed (+46 additions, -0 deletions)
View changed files
📝
docs/DETAILS.md(+1 -0)📝
include/strata/core/layer.hpp(+3 -0)📝
src/core/layer.cpp(+21 -0)📝
src/program/generate.cpp(+21 -0)📄 Description
Supersedes #3168 (closed in the 0.2.0-beta tracker reset). The /reopen check on #3168 passed but GitHub itself would not reopen it (the branch was force-pushed while closed; the bot's reply names this case and points at a linked new PR). The 0.2.0-beta measurements and the discussion stay in #3168; this PR's tables were measured on v0.2.3.1 (build 0.1.48.1) and fold in one real finding (the 64K regression, see Why commit 3).
The branch is now rebased onto main (
9f7d977d2, post-0.2.9). The tables below are from v0.2.3.1 (build 0.1.48.1); the new base carries its own verification, see Passed.Problem and result
The resident K/V ring is one global value (
--kv-resident), and the QSA KV pool is sized by it, so a ring chosen for depth is paid by every run. On this fork's card (RX 7900 XTX, gfx1100, IQ3_S pack) a flat raise is a measured loss at shallow depth: ring 32,768 -> 49,152 at 1K cost 40 % of the MTP path (acceptance 207/207 -> 149-156/215) while being worth +11.7 % @32K / +21.6 % @128K on 0.2.0.This PR sizes the ring from the run's depth:
STRATA_KV_RING_ADAPT=1makes the configured--kv-residentthe cap; a shallow run keeps the live 32,768, a deep one grows toward the cap. Unset (or =0) restores today's behavior exactly. On v0.2.3.1 the adaptive ring is worth +23.9 % decode at 128K and is a verified no-op at every tier it does not grow on:Against a static 49,152 (what a user who raised
--kv-residentby hand would run) the flag is worth +22.8 % at 1K (drafter acceptance back to 197/197, 207/207 from 167/173 and 147/204), -2.1 % at 32K (n=2, acceptance mix differs), and a no-op at 128K (the rule grows there, so both arms run the cap).Related discussion
#3168 (this PR's predecessor: the 0.2.0-beta tables, the discussion, and the /reopen attempt). #2450/#2630/#3166 (the resident-KV setup rule, the page-pool eviction policy, and the shallow-depth drafter interaction, carried over from #3168's body).
Approach
Five commits:
qsa_kv_ring_adapt(g, cells_needed, cap)(+ declaration inlayer.hpp): opt-in sizing,--kv-residentbecomes the cap. The hook ingenerate.cppruns before the session arena is sized and the graphs are captured, becauseqsa_state_bytes->kv_pool_bytessizes the pool by slots.needed >= capform regresses 64K by -16.5 % on that base (74.8 -> 62.5 tok/s, n=2 interleaved, acceptance 39/50 vs 27/41): at 64K the grown ring's draft windows cost more than they return. 128K in the same window still gained +23.3 %. The crossover sits between 64K and 128K, so the rule grows only whenneeded >= 2 * cap- every measured tier below the crossover keeps the live 32,768 (verified per-cell: identical acceptance both arms), and a context of twice the cap or deeper still receives the cap. The 0.2.0-era table in #3168 predates this amendment and stands as history, not as the current claim.a6458d82fixes two things found after the measurements above.STRATA_KV_RING_ADAPT=0used to turn the option on (the code only checked that the variable was set), while this body said unset or =0 restores today's behavior; it now reads the variable once and treats unset, empty or 0 as off, any other non-zero value as on. Second, serve mode sized the ring from the CLI prompt plus--max-new: under--servethe CLI prompt is empty and sessions live for the whole process, so a serve deployment with a cap above the 32,768 floor kept the floor at every depth instead of getting the measured deep-context behavior.--servenow sizes from--context; one-shotgeneratekeeps sizing from prompt plus requested tokens. The engine's stderr line still starts withstrata generate: KV ring adaptive:and now names where the depth came from,serve context <n>orprompt <n> + <m> new.d202fb5cadds a row forSTRATA_KV_RING_ADAPTto the KV cache table in docs/DETAILS.md: opt-in,--kv-residentbecomes the cap, the 32,768 floor, the 2x-cap rule, generate versus--servesizing, unset or 0 as off, and the RX 7900 XTX measurements.The branch is rebased onto current main (0.2.8, engine 0.1.54); the first three commits replayed with no conflicts. Files touched:
include/strata/core/layer.hpp(+3),src/core/layer.cpp(+21),src/program/generate.cpp(+21),docs/DETAILS.md(+1).Validation
Passed:
--spec 5 --kv int8 --lookup-chain 2etc.), greedy one-shot through the engine's own prefill/decode counters; the ring the engine actually ran is recorded per cell and engagement prints only when the ring changes, so a silent fallback cannot masquerade: tables above; raw logsr32-cell-*,r32b-cell-*,r32c-cell-*.iq_parity,iq_multi_parity,s2_expert_grouped_parityPASS.macos-14job this branch predated.Failed:
needed >= capthreshold at 64K on v0.2.3.1: -16.5 % (fixed by commit 3; kept here as the finding).Passed (on the new base, for the record):
9f7d977d2): 549 targets, rc=0, gfx1100 HIP, pinned-SDK toolchain.Not run:
907376df); it needs one >=65 GB free-memory window on the measurement box and lands in this body as a table when it runs.Current-base figures (2026-11-06, the refresh line this PR now rides)
Measured on the composed base this PR rebases onto (upstream v0.2.9, engine 0.1.55 + the replayed fork chain, RX 7900 XTX 24 GB, gfx1100, IQ3_S GSQ-RCO, production environment, Linux): the public same-protocol replay (exact-token synthetic-record prompts, three secret codes, retrieval-validated, 256 output tokens, temperature 0, seed 42, no prompt cache, median of 3; 21/21 requests passed;
TTFT= time to first output token, which at these lengths is the prompt read + ~1 s):Decode is flat with context (83-95 tok/s from 1K to 64K; the paired 32-cell gate window on the same base measured decode +7.1 % at 32K and +8.4 % at 128K against the 0.1.48.1 production build, ms-per-round -6.7/-10.3 %, prefill +1.3/+0.6 %, control noise +/-1.3 %).
Community context (IQ3_S rows from this repository's community table)
Not like-for-like: the community rows are 0.1.38/0.1.39-era engines (five-plus releases behind this base), mixed Windows/Linux, and different CPU/RAM tiers; they are cited for context only. On decode, the fresh 0.1.55 figures sit at or above the same-quant 4090 rows at every measured length; on prefill at depth this box remains behind the 5070 Ti/5090 rows (a discrete-VRAM streaming boundary this PR does not address - the ring sizing here is about the decode path's cost at shallow depth, not prefill throughput).
Limits
The cap a user picks must still be one their card can hold (here 49,152 int8 cells on 24 GB beside the other allocations). The 2x-cap threshold is calibrated by measurement between 64K and 128K on v0.2.3.1; a deeper re-measure on a future base may move it.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.