[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

Closed
opened 2026-11-04 01:43:19 +07:00 by bsakaguchi · 3 comments
Owner

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:

engine run --kv-grow continuations cache lost rate
0.1.28 off 20 0 0.0%
0.1.29 off 212 1 0.5%
0.1.36 off 412 3 0.7%
0.1.38 off 34 0 0.0%
0.1.39 off 567 8 1.4%
0.1.40 on 43 9 20.9%

(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-grow raises the full-re-read rate by roughly 15–20x here.

Environment

  • Strata 0.1.40, Windows 11 26200, engine from the release zip: engine/BUILD.json version 0.1.40, strata.exe 146,444,800 B, sha256 e41abc2efd0eb43d…
  • RTX 5090 D 32 GB (sm_120, driver 616.92), Intel Raptor Lake 8P+16E (no AVX-512, has AVX-VNNI), 64 GB RAM
  • IQ3_S, --max-context 262144, --kv int8, 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-grow
  • Expert cache 11,189 slots (10,305–10,919 holding experts); the elastic K/V moves between 8,192 and 180,224 cells (0.66 → 2.34 GiB)
  • Not about 0.1.40.1: the engine binary is the same one 0.1.40 shipped, and 0.1.40.1 only touches serve/

Reproduction (plain engine log)

strata serve: prompt 127557 tokens = 127437 reused + 120 read in 670 ms (179.1 tok/s)   <- long conversation, reused fine
strata: K/V trimmed to 8192 cells; 805 slots back to the expert cache, refilled from the profile
strata serve: prompt 204 tokens = 0 reused + 204 read in 882 ms                         <- a short request (new chat / title)
strata: K/V grown to 131072 cells (1.68 GiB); the expert cache gave 805 slots for it, 323 hotter experts moved ...
strata serve: prompt 128859 tokens = 0 reused + 128859 read in 28947 ms (4451.5 tok/s)   <- the SAME conversation: full re-read

Every loss in that run has this shape: a K/V trimmed to 8192 cells triggered by a 53/107/124/172/204/251-token request, then a grow, then the long prompt with 0 reused.

The nine losses (band 1%), with what the continuation carried:

P prefill the previous long prompt
108,610 23.6 s 108,040 + 5312
110,837 25.2 s 108,610 + 2177
113,456 25.3 s 110,837 + 154
128,859 28.9 s 127,557 + 561
129,742 29.4 s 128,985 + 542
128,229 28.9 s 124,858 + 3151
131,430 29.0 s 128,229 + 3151
133,023 31.1 s 131,430 + 102
157,034 34.9 s 155,651 + 1599

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) and kvg_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 :8405 with n + 256, where n is the current (short) prompt's length:

// the elastic K/V: the outgoing session is parked and this request rewrites every cell from `resume` on,
// so cells past this prompt's are no longer anyone's - far more than it needs go back to the cache
if (kvg.on) { kv_quiesce(); if (!kvg_trim(n + 256)) { ... } }

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 :8398 and live_ok = false at :8400 drop every checkpoint past the new (tiny) prompt:

checks.erase(std::remove_if(checks.begin(), checks.end(), [&](const ConvCheckpoint& c) {
                 return (int64_t) c.ids.size() > resume || !starts_with(c.ids, c.imgs);
             }), checks.end());

The next long prompt then finds resume == 0 and 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.:

  • keep at least max(cells this request needs, deepest live/checkpointed prefix + its turn) cells, or
  • skip the trim while checks/live hold a prefix longer than the new prompt, or
  • let --kv-grow grow without ever shrinking (a STRATA_KV_GROW_TRIM=0-style opt-out). There is no such flag today; :8405 is the only kvg_trim call site.

Cost/benefit on this machine

  • --kv-grow gain, 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-grow cost in the run above: 281 s of wasted prefill in 193 requests, against about 83 s saved by the faster decode in the same run

For long conversations it is a net loss here, so I have turned --kv-grow off (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.

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: | engine run | `--kv-grow` | continuations | cache lost | rate | | --- | --- | ---: | ---: | ---: | | 0.1.28 | off | 20 | 0 | 0.0% | | 0.1.29 | off | 212 | 1 | 0.5% | | 0.1.36 | off | 412 | 3 | 0.7% | | 0.1.38 | off | 34 | 0 | 0.0% | | 0.1.39 | off | 567 | 8 | 1.4% | | **0.1.40** | **on** | **43** | **9** | **20.9%** | (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-grow` raises the full-re-read rate by roughly **15–20x** here. ## Environment - Strata **0.1.40**, Windows 11 26200, engine from the release zip: `engine/BUILD.json` version `0.1.40`, `strata.exe` 146,444,800 B, sha256 `e41abc2efd0eb43d…` - RTX 5090 D 32 GB (sm_120, driver 616.92), Intel Raptor Lake 8P+16E (no AVX-512, has AVX-VNNI), 64 GB RAM - IQ3_S, `--max-context 262144`, `--kv` int8, **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-grow`** - Expert cache 11,189 slots (10,305–10,919 holding experts); the elastic K/V moves between 8,192 and 180,224 cells (0.66 → 2.34 GiB) - Not about 0.1.40.1: the engine binary is the same one 0.1.40 shipped, and 0.1.40.1 only touches `serve/` ## Reproduction (plain engine log) ``` strata serve: prompt 127557 tokens = 127437 reused + 120 read in 670 ms (179.1 tok/s) <- long conversation, reused fine strata: K/V trimmed to 8192 cells; 805 slots back to the expert cache, refilled from the profile strata serve: prompt 204 tokens = 0 reused + 204 read in 882 ms <- a short request (new chat / title) strata: K/V grown to 131072 cells (1.68 GiB); the expert cache gave 805 slots for it, 323 hotter experts moved ... strata serve: prompt 128859 tokens = 0 reused + 128859 read in 28947 ms (4451.5 tok/s) <- the SAME conversation: full re-read ``` Every loss in that run has this shape: a `K/V trimmed to 8192 cells` triggered by a 53/107/124/172/204/251-token request, then a grow, then the long prompt with `0 reused`. The nine losses (band 1%), with what the continuation carried: | P | prefill | the previous long prompt | | ---: | ---: | ---: | | 108,610 | 23.6 s | 108,040 + 5312 | | 110,837 | 25.2 s | 108,610 + 2177 | | 113,456 | 25.3 s | 110,837 + 154 | | 128,859 | 28.9 s | 127,557 + 561 | | 129,742 | 29.4 s | 128,985 + 542 | | 128,229 | 28.9 s | 124,858 + 3151 | | 131,430 | 29.0 s | 128,229 + 3151 | | 133,023 | 31.1 s | 131,430 + 102 | | 157,034 | 34.9 s | 155,651 + 1599 | 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`) and `kvg_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 `:8405` with `n + 256`, where `n` is the **current (short) prompt's** length: ```cpp // the elastic K/V: the outgoing session is parked and this request rewrites every cell from `resume` on, // so cells past this prompt's are no longer anyone's - far more than it needs go back to the cache if (kvg.on) { kv_quiesce(); if (!kvg_trim(n + 256)) { ... } } ``` 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 `:8398` and `live_ok = false` at `:8400` drop every checkpoint past the new (tiny) prompt: ```cpp checks.erase(std::remove_if(checks.begin(), checks.end(), [&](const ConvCheckpoint& c) { return (int64_t) c.ids.size() > resume || !starts_with(c.ids, c.imgs); }), checks.end()); ``` The next long prompt then finds `resume == 0` and 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.: - keep at least `max(cells this request needs, deepest live/checkpointed prefix + its turn)` cells, or - skip the trim while `checks`/`live` hold a prefix longer than the new prompt, or - let `--kv-grow` grow without ever shrinking (a `STRATA_KV_GROW_TRIM=0`-style opt-out). There is no such flag today; `:8405` is the only `kvg_trim` call site. ## Cost/benefit on this machine - `--kv-grow` gain, 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-grow` cost in the run above: **281 s of wasted prefill** in 193 requests, against about **83 s** saved by the faster decode in the same run For long conversations it is a net loss here, so I have turned `--kv-grow` off (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.
Author
Owner

@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').

<!-- gh-comment-id:6038012116 --> @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').
Author
Owner

@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 from conversations.longest_tokens(), which is always 0 when the conversation cache cannot park.

The hold only counts parked conversations

--conversation-cache-mib defaults to 0 (off), and even with a budget set, every park must pass conversation_memory_admit against --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:

strata serve: conversation cache: skip parking (physical RAM admission; need 2259 MiB plus 256 MiB floor, or telemetry unavailable)

longest_tokens() stays 0, the hold argument 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:

K/V after the 53-token request continuation
STRATA_KV_GROW_HOLD off K/V trimmed to 8192 cells prompt 100948 tokens = 0 reused + 100948 read in 23678 ms (24.4 s wall)
STRATA_KV_GROW_HOLD on K/V trimmed to 8192 cells prompt 100948 tokens = 0 reused + 100948 read in 23678 ms (24.5 s wall)

The engine log of the hold-on run, in order:

strata serve: prompt 53 tokens = 0 reused + 53 read in 572 ms ...
strata serve: conversation cache: skip parking (physical RAM admission; need 2259 MiB plus 256 MiB floor, ...)
strata serve: conversation cache: parked 60 tokens in 75.7 ms; parked=1 ...        <- only the 53-token request
strata: K/V trimmed to 8192 cells; 589 slots back to the expert cache, ...
strata serve: prompt 100948 tokens = 0 reused + 100948 read in 23678 ms (4263.4 tok/s), 16 generated ...

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 256 lets a 27,756-token conversation park, and then the same interference request no longer costs anything (and this works with --kv-grow off as well):

strata serve: conversation cache: parked 27756 tokens in 357.1 ms; parked=1 bytes=778155440 evictions=0
strata serve: prompt 27748 tokens = 27734 reused + 14 read in 342 ms    (0.7 s wall, cached=27734)

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

hold currently 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 knows live.size(). Something like max(n + 256, conversations.longest_tokens(), live_tokens) + 256 would 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:

  • With parking off, the checkpoint erase at :8398 (c.ids.size() > resume) already drops every checkpoint of the other conversation on a standalone request, so cached=0 there does not need the trim at all — I measured cached=0 with --kv-grow off 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.
  • On the plus side, --kv-grow was 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.

<!-- gh-comment-id:6040107819 --> @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 from `conversations.longest_tokens()`, which is always 0 when the conversation cache cannot park.** ### The hold only counts *parked* conversations `--conversation-cache-mib` defaults to **0 (off)**, and even with a budget set, every park must pass `conversation_memory_admit` against `--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: ``` strata serve: conversation cache: skip parking (physical RAM admission; need 2259 MiB plus 256 MiB floor, or telemetry unavailable) ``` `longest_tokens()` stays 0, the `hold` argument 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: | | K/V after the 53-token request | continuation | | --- | --- | --- | | `STRATA_KV_GROW_HOLD` **off** | `K/V trimmed to 8192 cells` | `prompt 100948 tokens = 0 reused + 100948 read in 23678 ms` (24.4 s wall) | | `STRATA_KV_GROW_HOLD` **on** | `K/V trimmed to 8192 cells` | `prompt 100948 tokens = 0 reused + 100948 read in 23678 ms` (24.5 s wall) | The engine log of the hold-on run, in order: ``` strata serve: prompt 53 tokens = 0 reused + 53 read in 572 ms ... strata serve: conversation cache: skip parking (physical RAM admission; need 2259 MiB plus 256 MiB floor, ...) strata serve: conversation cache: parked 60 tokens in 75.7 ms; parked=1 ... <- only the 53-token request strata: K/V trimmed to 8192 cells; 589 slots back to the expert cache, ... strata serve: prompt 100948 tokens = 0 reused + 100948 read in 23678 ms (4263.4 tok/s), 16 generated ... ``` 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 256` lets a 27,756-token conversation park, and then the same interference request no longer costs anything (and this works with `--kv-grow` off as well): ``` strata serve: conversation cache: parked 27756 tokens in 357.1 ms; parked=1 bytes=778155440 evictions=0 strata serve: prompt 27748 tokens = 27734 reused + 14 read in 342 ms (0.7 s wall, cached=27734) ``` **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 `hold` currently 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 knows `live.size()`. Something like `max(n + 256, conversations.longest_tokens(), live_tokens) + 256` would 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: - With parking **off**, the checkpoint erase at `:8398` (`c.ids.size() > resume`) already drops every checkpoint of the other conversation on a standalone request, so `cached=0` there does not need the trim at all — I measured `cached=0` with `--kv-grow` off 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. - On the plus side, `--kv-grow` was **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`.
Author
Owner

@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.

<!-- gh-comment-id:6156019903 --> @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](https://github.com/Niko1221/Strata/releases/tag/v0.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.
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#474
No description provided.