mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #1128] 0.1.40 --kv-grow: a short request trims the K/V to 8192 cells and drops the conversation cache, so the next 128K+ continuation is re-read in full (20.9% of continuations, RTX 5090, IQ3_S) #474
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#474
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?
Originally created by @Darkstarrd-dev on GitHub (Oct 6, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1128
Summary
With
--kv-grow, a short request trims the elastic K/V to 8192 cells and the conversation cache goes with it, so the next long continuation of a 128K+ conversation is re-read in full (prompt 128859 tokens = 0 reused + 128859 read in 28947 ms).On the same server and workload, the share of continuations that lose the cache entirely:
--kv-grow(continuation = a prompt ≥5000 tokens that equals the previous long prompt plus what it generated, within 1%; the numbers below give the 5% variant too)
So
--kv-growraises the full-re-read rate by roughly 15–20x here.Environment
engine/BUILD.jsonversion0.1.40,strata.exe146,444,800 B, sha256e41abc2efd0eb43d…--max-context 262144,--kvint8, no--kv-resident(the whole K/V in VRAM), images on,--expert-cache auto,--prefill auto,--spec 4,--spec-min-p 0.7,--pcie-frac 0.20,--vram-reserve-mib 981,--kv-growserve/Reproduction (plain engine log)
Every loss in that run has this shape: a
K/V trimmed to 8192 cellstriggered by a 53/107/124/172/204/251-token request, then a grow, then the long prompt with0 reused.The nine losses (band 1%), with what the continuation carried:
In the same run the cached continuations take 0.4–2.5 s of prefill, so each loss costs about 25–35 s.
Why
kvg_trim(src/program/generate.cpp:5362) andkvg_ensure(:5258) take only a target cell count. They never look at the conversation checkpoints, and the elastic K/V shares one VMM range with the expert cache, so each shrink/grow remaps chunks and moves slots.The trim is called at
:8405withn + 256, wherenis the current (short) prompt's length:For a 204-token request that means "keep 8192 cells", even though the conversation cache holds a 127,557-token checkpoint whose K/V lives in those cells. Right after it, the checkpoint erase at
:8398andlive_ok = falseat:8400drop every checkpoint past the new (tiny) prompt:The next long prompt then finds
resume == 0and reads all 128K tokens again. The comment's "the outgoing session is parked" does hold for a short request that directly follows a long one —:8376(resume = parked.tokens) restores its token count — but after the trim to 8192 cells there is no cell left to restore a 128K prefix from, so the parked/checkpointed prefix is gone too.Suggested fix
Make the trim conversation-aware, e.g.:
max(cells this request needs, deepest live/checkpointed prefix + its turn)cells, orchecks/livehold a prefix longer than the new prompt, or--kv-growgrow without ever shrinking (aSTRATA_KV_GROW_TRIM=0-style opt-out). There is no such flag today;:8405is the onlykvg_trimcall site.Cost/benefit on this machine
--kv-growgain, same day, same desktop, slot-matched A/B (10,333–10,397 → 11,990–12,101 slots): decode 123.7 → 135.2 tok/s (+9.3%)--kv-growcost in the run above: 281 s of wasted prefill in 193 requests, against about 83 s saved by the faster decode in the same runFor long conversations it is a net loss here, so I have turned
--kv-growoff (decode falls to ~123.7 tok/s, slots to ~10,333). At the 5% band the same run is 16 losses / 504 s (30% of its total wall time) — the conclusion does not depend on which band is used.I can attach the full server log or a trimmed excerpt — tell me which you prefer.
@Niko1221 commented on GitHub (Oct 7, 2026):
Not fixed yet, and I need your help. In 0.1.40.2 I could not make the cache lose a conversation on an RTX 3060 (a 29K-token conversation, short requests in between): it was restored every time. What I did see is that each short request trims the K/V and the next turn grows it again and moves the experts again. 0.1.40.2 has an opt-in switch for that: STRATA_KV_GROW_HOLD=1 keeps the K/V as long as the longest parked conversation while it is parked (so --kv-grow gives back less VRAM then). Default behaviour is unchanged. Could you try STRATA_KV_GROW_HOLD=1 on your 5090 D and tell us whether the full re-reads stop? If you still see '0 reused', please send the engine log lines around it ('conversation cache: parked' / 'skip parking' / 'K/V trimmed' / 'K/V grown').
@Darkstarrd-dev commented on GitHub (Oct 7, 2026):
Verified on 0.1.40.2 (engine sha256
04a4df5678708051, RTX 5090 D, IQ3_S,--max-context 262144, int8 KV)Thanks for
STRATA_KV_GROW_HOLD— I ran the exact sequence from the report on the new engine to see whether it closes the issue on this machine. It does not here, and the reason is worth knowing: the hold's protection comes fromconversations.longest_tokens(), which is always 0 when the conversation cache cannot park.The hold only counts parked conversations
--conversation-cache-mibdefaults to 0 (off), and even with a budget set, every park must passconversation_memory_admitagainst--conversation-cache-min-free-mib(default 2560) plus the snapshot itself. With ~55 GB of experts pinned, this 64 GB PC has 1.2 GB of available physical RAM, so parking is refused every time:longest_tokens()stays 0, theholdargument is 0, and the trim proceeds exactly as before.A/B with the hold off and on, same engine, same binary, same desktop
100,939-token conversation → one 53-token standalone request → continue the 100K conversation:
STRATA_KV_GROW_HOLDoffK/V trimmed to 8192 cellsprompt 100948 tokens = 0 reused + 100948 read in 23678 ms(24.4 s wall)STRATA_KV_GROW_HOLDonK/V trimmed to 8192 cellsprompt 100948 tokens = 0 reused + 100948 read in 23678 ms(24.5 s wall)The engine log of the hold-on run, in order:
So the fix is a no-op in this configuration — not a wrong fix, just gated on a mechanism that is itself disabled.
Parking does fix the sequence when it can engage
Lowering the floor to
--conversation-cache-min-free-mib 256lets a 27,756-token conversation park, and then the same interference request no longer costs anything (and this works with--kv-growoff as well):But a 100K conversation needs ~2.2 GB of snapshot RAM, and this PC has 1.2 GB free with the experts pinned, so it still cannot park even at a 16 GiB budget and a 256 MiB floor. The 23.7 s re-read above is therefore not avoidable through parking on a 64 GB PC with a 50 GB expert set.
Suggestion
holdcurrently reads as "keep the K/V for the conversation that is coming back". When nothing is parked it would be more useful to fall back to the live conversation's length — at the trim call site that is the session the request just replaced, and at 0.1.40's:8400(live_ok = false) the engine still knowslive.size(). Something likemax(n + 256, conversations.longest_tokens(), live_tokens) + 256would protect the prefix that the checkpoints still hold even when parking is off.Two smaller notes from the same session, in case they are useful:
:8398(c.ids.size() > resume) already drops every checkpoint of the other conversation on a standalone request, socached=0there does not need the trim at all — I measuredcached=0with--kv-growoff and parking off at both 7.5K and 100K. That may be the same underlying "the outgoing session's checkpoints are not the new request's" assumption the hold was aimed at.--kv-growwas never slower at any point of a full tuning sweep (13 points, same binary, slot-matched): best 123.1 → 124.5 tok/s with the hold on, and the hold's own cost was inside the noise. So keeping it on is free; the issue is only the re-reads.Config used: IQ3_S,
--max-context 262144,--kv int8, no--kv-resident, images on,--expert-cache auto,--prefill auto,--spec 4,--pcie-frac 0.20,--spec-min-p 0.50,--adapt-every 1 --adapt-swaps 160 --adapt-decay 0.97,--vram-reserve-mib 981,--kv-grow,STRATA_KV_GROW_HOLD=1.@Niko1221 commented on GitHub (Oct 13, 2026):
Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.
If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.