mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #378] [CLOSED] Elastic K/V (--kv-grow, opt-in): the K/V takes VRAM as the context grows, the expert cache holds the rest (+68% cache on a 16 GB card at 262K) #2607
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#2607
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/378
Author: @sergqwer
Created: 10/1/2026
Status: ❌ Closed
Base:
main← Head:pr/kv-grow📝 Commits (3)
3c97b4aElastic K/V (--kv-grow): the K/V takes VRAM as the context grows, the expert cache holds the restb959ac4Elastic K/V: VMM access failures roll back, failed growth stops the engine, the trim maps one rund5ee0ccElastic K/V: a run that cannot lend cache slots maps the whole window up front; its table uploads wait for the copy📊 Changes
9 files changed (+811 additions, -5 deletions)
View changed files
📝
CMakeLists.txt(+6 -1)📝
include/strata/core/expert_cache.hpp(+12 -0)📝
include/strata/core/layer.hpp(+24 -0)➕
include/strata/core/vmm.hpp(+76 -0)📝
src/core/expert_cache.cpp(+21 -0)📝
src/core/layer.cpp(+154 -4)➕
src/core/vmm.cpp(+164 -0)📝
src/program/generate.cpp(+292 -0)➕
tests/core/vmm_test.cpp(+62 -0)📄 Description
At
--max-context 262144the K/V of the whole context is allocated at start: 3.35 GiB at int8 with the drafter's. The expert cache is sized around it. On a 16 GB card that is a quarter of the VRAM, and most requests never reach those cells.With
--kv-grow(orSTRATA_KV_GROW=1), the K/V holds physical memory only for the cells the requests reach. The expert cache holds the rest. It is off by default: more slots move experts between the GPU and the CPU, which changes tokens, so it does not pass a byte-identical gate against main by design.How it works:
core/vmm.hpp). The K/V pools and the cache arena are CUDA VMM ranges: addresses reserved once, physical memory mapped in 2 MiB chunks. The driver calls go throughcudaGetDriverEntryPointByVersion, so nothing linkscuda.lib.--max-contextcells always fit: the window is never smaller.--max-new.--kv-resident), every expert in RAM (not the low-RAM tier). Otherwise the flag is ignored.STRATA_KV_GROW_INIT/_STEP/_FLOOR.tests/core/vmm_testmaps, moves a chunk between ranges keeping its bytes, and releases.One pitfall worth knowing: a device-to-device
cudaMemcpydoes not wait for the copy. The moves sync before their source chunks are unmapped. Without that, the copy faulted, and the error surfaced at the nextcudaMemsetas "no VRAM".Same output when nothing moves
Setup: IQ2_XS (ISTA), RTX 5090, a 32K prompt and 64 tokens, fixed
--expert-cache 14900. First-token logits were dumped with #276'sSTRATA_DUMP_FIRST_LOGITSin a test build.These are bit-identical to 0.1.31, logits and tokens:
--kv-growmapped whole (STRATA_KV_GROW_INIT=262144);--kv-growgrown from 4096 cells into new VRAM (_FLOORabove the cache).Grown by giving up 266 slots (171 experts moved): the same first token and the same 64 tokens here. In general a given-up expert is computed on the CPU, which rounds differently.
Speed
Setup: IQ2_XS (ISTA), RTX 5090, 9950X3D, 128 GB, Windows 11,
--max-context 262144 --kv int8 --prefill auto --spec 4, cache auto, 256 tokens. The runs alternated with and without the flag.--kv-grow--vram-reserve-mib 17884): expert cacheOn our NVFP4 fork (2.76 MB experts, 5090) the cache grows from ~7,060 to ~8,290 slots and a short chat from 111-115 to 126-133 tok/s.
Serve
A served run with
--conversation-cache-mib 8192behaved as expected:🤖 Generated with Claude Code
https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.