[PR #1011] [CLOSED] kv: one pinned KV pool shared by the sessions (--kv-pool-tokens; 4 lanes x 256K pin 6.24 GiB instead of 15.5) #2963

Closed
opened 2026-11-04 02:04:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1011
Author: @xdbxdbx
Created: 10/6/2026
Status: ❌ Closed

Base: main ← Head: kv-shared-pool


📝 Commits (10+)

  • eb8da1d /metrics: each request's speculative draft counts, and their sums in the totals (#457)
  • 6a09387 setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)
  • d6a91e2 docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)
  • d8d4ad3 Merge branch 'f-135-eng' into rel-0.1.35
  • 7b600d5 Merge branch 'f-135-small' into rel-0.1.35
  • d9ab843 Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it
  • 57bd713 sycl: pipeline the expert cache's profile fill (model load 3-4x faster)
  • e3bdd74 A prompt cancelled mid-read is logged and recorded with the tokens it read (#471)
  • f2aaba1 "The draft head does not fit" says what to change (#474)
  • 64987c8 UPDATE.bat / update.sh: update Strata without starting the model (#475)

📊 Changes

6 files changed (+46 additions, -17 deletions)

View changed files

📝 include/strata/core/layer.hpp (+1 -0)
📝 serve/server.py (+10 -3)
📝 src/core/kv_pool.cpp (+5 -1)
📝 src/core/layer.cpp (+1 -0)
📝 src/core/mtp.cpp (+5 -0)
📝 src/program/generate.cpp (+24 -13)

📄 Description

Problem

With KV streaming (--kv-resident) every session pins the whole context's K/V in RAM: the main session and each --batch slot. At --max-context 262144 that is 3.09 GiB per session, so 4 lanes pin 5 x 3.09 = 15.5 GiB, although the conversations together rarely fill one context, let alone five.

Change

--kv-pool-tokens N (with --kv-resident): the sessions share one pinned pool of N cells for the streamed QSA layers. A session holds only the chunks (4096 cells) its conversation has reached.

  • Chunk tables: each session has a chunk table (device copy at a fixed address, so captured graphs keep working, plus a host mirror). Every host-addressing site translates block -> pool block: the decode kernels (qsa.cu, kv_q8.cu, kv_q4.cu), the stream movers (kv_stream.cu), prefill, and conversation snapshots, which split copies at chunk boundaries. Unreserved entries point at a trash chunk, so a stray write never lands in another session's cells.
  • Moves, not copies: a conversation moves between the main session and a slot (admission, and a slot handing its conversation back) by swapping chunk tables. A prompt read that gives way (BYIELD) still copies.
  • When the pool is full:
    • an idle slot's cached conversation gives way, oldest first;
    • a new request is refused: ERR KV pool full, answered as 503 with Retry-After (code: kv_pool_full; in a stream, the error event carries the code, and Anthropic streams use overloaded_error);
    • a decoding lane that can't grow ends with finish pool, reported as "truncated": true (llama.cpp's field).
  • RoPE: the slot sessions borrow the main session's RoPE table (64 MiB per slot at 262K).
  • Metrics: /metrics reports the pool's use (kv_pool: cells, free, held per session).
  • Server fix: an ERR for a request now ends it at once. The server used to wait 300 s for a DONE/BADM that never comes after a refusal.

Without --kv-pool-tokens there are no tables, and every site uses the identity layout as before.

Validation

RTX 4090, 64 GB RAM, Qwen3.8-Flash-Next IQ2_XS, --resident-experts --kv int8 --kv-resident 32768; single runs.

  • Pinned K/V: the 524288-cell pool pins 6.24 GiB, against 15.5 GiB for 4 lanes + main without it.
  • 4 lanes x 256K, 512K pool, more than the pool holds: 4 prompts of 140K-151K tokens (586K in all) all answered 200. When the pool ran short, a finished lane's cached conversation gave way.
  • Admission by move: 52-79 ms for 140K-151K tokens, against 1.0-1.1 s copied (133K: 1128 ms, 143K: 1020 ms).
  • Pressure (64K context, 128K pool, 4 lanes x ~40K prompt, up to 1500 tokens each): two lanes ran to 1500 tokens; one ended at 45049 cells with truncated: true; the fourth request, arriving while three lanes decoded, got 503 kv_pool_full with Retry-After: 10 as soon as its turn came.
  • Throughput with the pool, 4 lanes x 256K: 83.0 tok/s total on code, 81.5 on prose.
  • RAM: available RAM stayed at 15.0 GB or more, with no page-file writes.

Note

At 4 x 256K with resident experts, a 64 GB Windows PC runs close to its commit limit (RAM + page file). With an automatically sized page file (10 GB here, a 73.9 GB limit), the 25 GB resident expert copy was sometimes refused at start. A fixed 32 GB page file removes that; nothing is written to it.


🔄 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/1011 **Author:** [@xdbxdbx](https://github.com/xdbxdbx) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `kv-shared-pool` --- ### 📝 Commits (10+) - [`eb8da1d`](https://github.com/Niko1221/Strata/commit/eb8da1d8c26ec41e6ffb084fdf579dba7cad10bd) /metrics: each request's speculative draft counts, and their sums in the totals (#457) - [`6a09387`](https://github.com/Niko1221/Strata/commit/6a093874fe037020f49bd5cf053879ff6a133c21) setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444) - [`d6a91e2`](https://github.com/Niko1221/Strata/commit/d6a91e2d1770d0f469d6ec15890acc7ee93e764c) docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438) - [`d8d4ad3`](https://github.com/Niko1221/Strata/commit/d8d4ad337d3c98ba21d3bd0af1a16e9177e112b6) Merge branch 'f-135-eng' into rel-0.1.35 - [`7b600d5`](https://github.com/Niko1221/Strata/commit/7b600d55ff801caaaa11542af1523050992e049b) Merge branch 'f-135-small' into rel-0.1.35 - [`d9ab843`](https://github.com/Niko1221/Strata/commit/d9ab8435f654c368c586340d490915f6addf56a3) Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it - [`57bd713`](https://github.com/Niko1221/Strata/commit/57bd713454ddb4b965f994e95d95cacd68c93fb1) sycl: pipeline the expert cache's profile fill (model load 3-4x faster) - [`e3bdd74`](https://github.com/Niko1221/Strata/commit/e3bdd7449223c4305ef53e331538346765855a2c) A prompt cancelled mid-read is logged and recorded with the tokens it read (#471) - [`f2aaba1`](https://github.com/Niko1221/Strata/commit/f2aaba1e3d219a6ff165fca367d92b6a1dad7080) "The draft head does not fit" says what to change (#474) - [`64987c8`](https://github.com/Niko1221/Strata/commit/64987c891dc7cf3edb954f5b5f6b8cde233594db) UPDATE.bat / update.sh: update Strata without starting the model (#475) ### 📊 Changes **6 files changed** (+46 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/layer.hpp` (+1 -0) 📝 `serve/server.py` (+10 -3) 📝 `src/core/kv_pool.cpp` (+5 -1) 📝 `src/core/layer.cpp` (+1 -0) 📝 `src/core/mtp.cpp` (+5 -0) 📝 `src/program/generate.cpp` (+24 -13) </details> ### 📄 Description ## Problem With KV streaming (`--kv-resident`) every session pins the whole context's K/V in RAM: the main session and each `--batch` slot. At `--max-context 262144` that is 3.09 GiB per session, so 4 lanes pin 5 x 3.09 = 15.5 GiB, although the conversations together rarely fill one context, let alone five. ## Change `--kv-pool-tokens N` (with `--kv-resident`): the sessions share one pinned pool of N cells for the streamed QSA layers. A session holds only the chunks (4096 cells) its conversation has reached. - **Chunk tables:** each session has a chunk table (device copy at a fixed address, so captured graphs keep working, plus a host mirror). Every host-addressing site translates block -> pool block: the decode kernels (`qsa.cu`, `kv_q8.cu`, `kv_q4.cu`), the stream movers (`kv_stream.cu`), prefill, and conversation snapshots, which split copies at chunk boundaries. Unreserved entries point at a trash chunk, so a stray write never lands in another session's cells. - **Moves, not copies:** a conversation moves between the main session and a slot (admission, and a slot handing its conversation back) by swapping chunk tables. A prompt read that gives way (BYIELD) still copies. - **When the pool is full:** - an idle slot's cached conversation gives way, oldest first; - a new request is refused: `ERR KV pool full`, answered as **503 with Retry-After** (`code: kv_pool_full`; in a stream, the error event carries the code, and Anthropic streams use `overloaded_error`); - a decoding lane that can't grow ends with finish `pool`, reported as `"truncated": true` (llama.cpp's field). - **RoPE:** the slot sessions borrow the main session's RoPE table (64 MiB per slot at 262K). - **Metrics:** `/metrics` reports the pool's use (`kv_pool`: cells, free, held per session). - **Server fix:** an `ERR` for a request now ends it at once. The server used to wait 300 s for a `DONE`/`BADM` that never comes after a refusal. Without `--kv-pool-tokens` there are no tables, and every site uses the identity layout as before. ## Validation RTX 4090, 64 GB RAM, Qwen3.8-Flash-Next IQ2_XS, `--resident-experts --kv int8 --kv-resident 32768`; single runs. - **Pinned K/V:** the 524288-cell pool pins 6.24 GiB, against 15.5 GiB for 4 lanes + main without it. - **4 lanes x 256K, 512K pool, more than the pool holds:** 4 prompts of 140K-151K tokens (586K in all) all answered 200. When the pool ran short, a finished lane's cached conversation gave way. - **Admission by move:** 52-79 ms for 140K-151K tokens, against 1.0-1.1 s copied (133K: 1128 ms, 143K: 1020 ms). - **Pressure** (64K context, 128K pool, 4 lanes x ~40K prompt, up to 1500 tokens each): two lanes ran to 1500 tokens; one ended at 45049 cells with `truncated: true`; the fourth request, arriving while three lanes decoded, got 503 `kv_pool_full` with `Retry-After: 10` as soon as its turn came. - **Throughput with the pool**, 4 lanes x 256K: 83.0 tok/s total on code, 81.5 on prose. - **RAM:** available RAM stayed at 15.0 GB or more, with no page-file writes. ## Note At 4 x 256K with resident experts, a 64 GB Windows PC runs close to its commit limit (RAM + page file). With an automatically sized page file (10 GB here, a 73.9 GB limit), the 25 GB resident expert copy was sometimes refused at start. A fixed 32 GB page file removes that; nothing is written to it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:04:31 +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#2963
No description provided.