[GH-ISSUE #3726] [Other] Setup, low-RAM mode: KV streaming is never chosen (withdrawn: slower for agent workloads) #1558

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

Originally created by @altiber on GitHub (Oct 22, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3726

Environment: Windows 11, Strata v0.2.2 (011c9e60), engine 0.1.47 built from source (CUDA 13.0, archs 86;120), Q2_0 native pack, layer split over RTX 5070 Ti 16 GB + RTX 3070 8 GB (gpu: [0,1], card order 1,0), Ryzen 7 9700X, 31 GB RAM, --resident-experts, --max-context 131072 --kv int8, MTP + --spec 4.

kv_streaming_wanted / step 7 turn KV streaming on only when ram >= MODELS[model]["ram_gb"] + kv_ram + 1, i.e. when the RAM holds all the experts. On a low-RAM PC (31 GB with Q2_0) that is never true, so the KV cache stays in VRAM - although there the RAM copy is partial anyway and the GPU cache is what matters most.

Turned on by hand (--kv-resident 32768) on the PC above, with the WDDM fix from the companion issue:

KV in VRAM KV streaming
expert cache, RTX 3070 (stage 0) 1941 slots 2086 slots
room for experts, RTX 5070 Ti 7.57 GiB 8.65 GiB
pinned RAM for the K/V - 0.26 GiB
fresh ~20K-token prompt 23.5 s (~920 tok/s) 14.3-17.6 s (1140-1440 tok/s)
decode, 300 tokens 106-112 tok/s 81-108 tok/s (same spread)

(The prompt figures are from different engine builds a day apart, same model and config otherwise; take them as indicative.)

Proposal: in the low-RAM mode stream as well, when the RAM has the KV cache plus 16 GB for the OS:

diff --git a/setup.py b/setup.py
index 8358380b..31e7109a 100644
--- a/setup.py
+++ b/setup.py
@@ -5546,6 +5546,14 @@ def kv_streaming_ram_gb(ctx, kv) -> float:
     return ctx * (13 * KV_CELL_BYTES.get(kv, 1056)) / 1e9
 
 
+def kv_streaming_low_ram(model, ctx, kv, ram) -> bool:
+    """The low-RAM mode (the RAM cannot hold all the experts, so the most-used ones are kept and the rest read from
+    the SSD): the streamed KV cache takes its RAM from that copy, but frees the VRAM the KV cache held for more
+    experts on the GPUs, which is worth far more (a GPU hit is no PCIe and no SSD read).  So stream there too when
+    the RAM has the cache and 16 GB for the OS beside it."""
+    return ram < MODELS[model]["ram_gb"] and ram >= kv_streaming_ram_gb(ctx, kv) + 16
+
+
 def kv_streaming_wanted(model, ctx, kv, ram, choice="auto") -> bool:
     """Will setup stream this model's KV cache on this PC: from 64K up, when the RAM holds the cache beside the
     model's experts (+1 GB); `--kv-streaming on|off` overrides the RAM test (the owner's rule), and WSL never
@@ -5553,7 +5561,8 @@ def kv_streaming_wanted(model, ctx, kv, ram, choice="auto") -> bool:
     asks it too: a config's `--kv-resident` and a preset's "auto" are the same setting when this says yes."""
     if is_wsl() or choice == "off":
         return False
-    return ctx >= 65536 and (ram >= MODELS[model]["ram_gb"] + kv_streaming_ram_gb(ctx, kv) + 1 or choice == "on")
+    return ctx >= 65536 and (ram >= MODELS[model]["ram_gb"] + kv_streaming_ram_gb(ctx, kv) + 1 or choice == "on" or
+                             kv_streaming_low_ram(model, ctx, kv, ram))
 
 
 def low_ram_one_gpu_why(model, ram, choice, sel=None) -> list[str]:
@@ -8831,7 +8840,7 @@ def main() -> int:
     # when it fits.
     kv_ram_gb = kv_streaming_ram_gb(ctx, kv)      # the branches below are kv_streaming_wanted, with its messages
     # --kv-streaming on|off overrides the RAM test (the owner's rule); WSL stays off - it cannot stream.
-    stream_fits = ram >= MODELS[model]["ram_gb"] + kv_ram_gb + 1
+    stream_fits = ram >= MODELS[model]["ram_gb"] + kv_ram_gb + 1 or kv_streaming_low_ram(model, ctx, kv, ram)
     if is_wsl() and ctx >= 65536:
         ok("WSL: KV streaming off (the driver pins only about 1 GB of RAM); the KV cache stays in VRAM")
         if a.kv_streaming == "on":
Originally created by @altiber on GitHub (Oct 22, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/3726 **Environment:** Windows 11, Strata v0.2.2 (011c9e60), engine 0.1.47 built from source (CUDA 13.0, archs 86;120), Q2_0 native pack, layer split over RTX 5070 Ti 16 GB + RTX 3070 8 GB (`gpu: [0,1]`, card order 1,0), Ryzen 7 9700X, 31 GB RAM, `--resident-experts`, `--max-context 131072 --kv int8`, MTP + `--spec 4`. `kv_streaming_wanted` / step 7 turn KV streaming on only when `ram >= MODELS[model]["ram_gb"] + kv_ram + 1`, i.e. when the RAM holds **all** the experts. On a low-RAM PC (31 GB with Q2_0) that is never true, so the KV cache stays in VRAM - although there the RAM copy is partial anyway and the GPU cache is what matters most. Turned on by hand (`--kv-resident 32768`) on the PC above, with the WDDM fix from the companion issue: | | KV in VRAM | KV streaming | |---|---|---| | expert cache, RTX 3070 (stage 0) | 1941 slots | 2086 slots | | room for experts, RTX 5070 Ti | 7.57 GiB | 8.65 GiB | | pinned RAM for the K/V | - | 0.26 GiB | | fresh ~20K-token prompt | 23.5 s (~920 tok/s) | 14.3-17.6 s (1140-1440 tok/s) | | decode, 300 tokens | 106-112 tok/s | 81-108 tok/s (same spread) | (The prompt figures are from different engine builds a day apart, same model and config otherwise; take them as indicative.) Proposal: in the low-RAM mode stream as well, when the RAM has the KV cache plus 16 GB for the OS: ```diff diff --git a/setup.py b/setup.py index 8358380b..31e7109a 100644 --- a/setup.py +++ b/setup.py @@ -5546,6 +5546,14 @@ def kv_streaming_ram_gb(ctx, kv) -> float: return ctx * (13 * KV_CELL_BYTES.get(kv, 1056)) / 1e9 +def kv_streaming_low_ram(model, ctx, kv, ram) -> bool: + """The low-RAM mode (the RAM cannot hold all the experts, so the most-used ones are kept and the rest read from + the SSD): the streamed KV cache takes its RAM from that copy, but frees the VRAM the KV cache held for more + experts on the GPUs, which is worth far more (a GPU hit is no PCIe and no SSD read). So stream there too when + the RAM has the cache and 16 GB for the OS beside it.""" + return ram < MODELS[model]["ram_gb"] and ram >= kv_streaming_ram_gb(ctx, kv) + 16 + + def kv_streaming_wanted(model, ctx, kv, ram, choice="auto") -> bool: """Will setup stream this model's KV cache on this PC: from 64K up, when the RAM holds the cache beside the model's experts (+1 GB); `--kv-streaming on|off` overrides the RAM test (the owner's rule), and WSL never @@ -5553,7 +5561,8 @@ def kv_streaming_wanted(model, ctx, kv, ram, choice="auto") -> bool: asks it too: a config's `--kv-resident` and a preset's "auto" are the same setting when this says yes.""" if is_wsl() or choice == "off": return False - return ctx >= 65536 and (ram >= MODELS[model]["ram_gb"] + kv_streaming_ram_gb(ctx, kv) + 1 or choice == "on") + return ctx >= 65536 and (ram >= MODELS[model]["ram_gb"] + kv_streaming_ram_gb(ctx, kv) + 1 or choice == "on" or + kv_streaming_low_ram(model, ctx, kv, ram)) def low_ram_one_gpu_why(model, ram, choice, sel=None) -> list[str]: @@ -8831,7 +8840,7 @@ def main() -> int: # when it fits. kv_ram_gb = kv_streaming_ram_gb(ctx, kv) # the branches below are kv_streaming_wanted, with its messages # --kv-streaming on|off overrides the RAM test (the owner's rule); WSL stays off - it cannot stream. - stream_fits = ram >= MODELS[model]["ram_gb"] + kv_ram_gb + 1 + stream_fits = ram >= MODELS[model]["ram_gb"] + kv_ram_gb + 1 or kv_streaming_low_ram(model, ctx, kv, ram) if is_wsl() and ctx >= 65536: ok("WSL: KV streaming off (the driver pins only about 1 GB of RAM); the KV cache stays in VRAM") if a.kv_streaming == "on": ```
Author
Owner

@github-actions[bot] commented on GitHub (Oct 22, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6342005586 --> @github-actions[bot] commented on GitHub (Oct 22, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@altiber commented on GitHub (Oct 23, 2026):

Measured on a real coding-agent workload, I withdraw this proposal.

With --kv-resident 32768 (and the WDDM fix of #3725) the expert caches did grow as described (3070 stage: 1941 -> 2086 slots, 5070 Ti room 7.57 -> 8.65 GiB) and a cold ~20K prompt read faster in a synthetic bench. But on ~2 h of a Kilo agent run (525 requests vs 1323 before, same model and machine, medians by input length) the whole request was slower, worst for short prompts:

input KV in VRAM KV streaming
< 40K 43.5 tok/s 33.7 tok/s
40-60K 50.8 tok/s 48.0 tok/s
60-80K 50.6 tok/s 44.9 tok/s
> 80K 46.8 tok/s 46.8 tok/s

The agent mostly appends a tail to a cached prompt, and that tail reads the RAM-held KV blocks. So for a low-RAM PC running an agent, keeping the KV cache in VRAM (the current rule) looks right.

<!-- gh-comment-id:6360880246 --> @altiber commented on GitHub (Oct 23, 2026): Measured on a real coding-agent workload, I withdraw this proposal. With `--kv-resident 32768` (and the WDDM fix of #3725) the expert caches did grow as described (3070 stage: 1941 -> 2086 slots, 5070 Ti room 7.57 -> 8.65 GiB) and a cold ~20K prompt read faster in a synthetic bench. But on ~2 h of a Kilo agent run (525 requests vs 1323 before, same model and machine, medians by input length) the whole request was slower, worst for short prompts: | input | KV in VRAM | KV streaming | |---|---|---| | < 40K | 43.5 tok/s | 33.7 tok/s | | 40-60K | 50.8 tok/s | 48.0 tok/s | | 60-80K | 50.6 tok/s | 44.9 tok/s | | > 80K | 46.8 tok/s | 46.8 tok/s | The agent mostly appends a tail to a cached prompt, and that tail reads the RAM-held KV blocks. So for a low-RAM PC running an agent, keeping the KV cache in VRAM (the current rule) looks right.
Author
Owner

@github-actions[bot] commented on GitHub (Oct 23, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6360901454 --> @github-actions[bot] commented on GitHub (Oct 23, 2026): Thanks, this follows the format now.
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#1558
No description provided.