[PR #1030] [CLOSED] serve: --elastic, an automatic elastic expert cache with a fixed core (opt-in, CUDA VMM) #2977

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

📋 Pull Request Information

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

Base: main ← Head: contrib/elastic-core-0139


📝 Commits (10+)

  • fa16567 setup: an earlier config that does not parse is skipped, not a crash; configs are written atomically (#459)
  • 749d957 setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446)
  • 5a30024 calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)
  • 9f60d13 serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448)
  • 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

📊 Changes

8 files changed (+730 additions, -21 deletions)

View changed files

📝 CMakeLists.txt (+10 -0)
➕ docs/ELASTIC_CACHE.md (+66 -0)
📝 include/strata/core/expert_cache.hpp (+30 -0)
📝 include/strata/prefill/prefill.hpp (+4 -1)
📝 src/core/expert_cache.cpp (+181 -1)
📝 src/prefill/prefill.cpp (+10 -7)
📝 src/program/generate.cpp (+358 -12)
➕ tests/core/expert_cache_elastic_test.cpp (+71 -0)

📄 Description

What

--elastic (opt-in, --serve, one CUDA GPU): the expert cache follows the free VRAM automatically while the
server runs. It complements #533's --vram-elastic (resized on request through POST /v1/vram): the two never open
together, and nothing changes when --elastic is not given.

  • Stable addresses. The arena is a reserved virtual range backed by physical chunks (CUDA VMM). Growing and
    shrinking never move the arena or the slot-offset table, so the verify plan, the prompt path and the device
    residency table keep the pointers they got at startup.
  • Two zones. The startup profile fills the cache; its last part is the tail (by default half the startup
    cache, at most 6 GiB; --elastic-tail-mib), which rotates, is lent, grows and shrinks. The slots before it are a
    fixed core: never lent to the prompt path, never chosen as a swap victim and never shrunk.
  • Policy. Keeps --elastic-reserve-mib (500) free. Grows with the most-used missing experts (then the profile's
    order) once the room has lasted --elastic-stable-ms (5000; doubles after a shrink that follows a growth, back to
    the base after 5 minutes without one).
    Shrinks at once when the room is gone, at most --elastic-shrink-step-mib (1024) per check, moving the tail's
    hottest experts into colder slots first, never a flush. Checked every --elastic-period-ms (1000) at the decode's
    safe point and at each request's start; the prompt path replans its loan after a resize.
  • Scope. Native pack with a startup profile and sized slots, one local CUDA GPU, serve mode. CLI generation, layer
    split, peer/remote tiers, the resident CPU complement and HIP keep the fixed cache; no VMM -> the plain arena.
  • Naming. ExpertCache::elastic_grow / elastic_shrink / elastic_mapped_bytes, apart from #533's byte-sized
    grow / shrink on the segmented arena.

Files: src/core/expert_cache.cpp + header (VMM arena), src/program/generate.cpp (options, core/tail, policy,
loan), src/prefill/prefill.{hpp,cpp} (host buffers sized for the largest chunk a later relayout can ask for),
tests/core/expert_cache_elastic_test.cpp, docs/ELASTIC_CACHE.md, CMakeLists.txt (driver library link, test).

Tests (RTX 2080 Ti 22 GB, Windows 11, CUDA 12.6, Release sm_75)

  • CTest expert_cache_elastic_test (real VMM: grow, shrink, regrow, stable addresses/offsets, preserved bytes,
    zeroed new slots, unchanged state after rejected requests, fixed reopen), expert_cache_per_layer_test,
    expert_profile_save_test, expert_cache_segmented_test: 4/4.
  • Without --elastic the output is bit-identical to upstream 0.1.39: teacher forcing with a fixed expert
    placement on a code and an explain task, per-position log-probabilities byte for byte equal.
  • 131k context, one run each on an idle machine: with --elastic the cache started at 6781 slots (core 3357 /
    tail 3424) and grew +300 experts while VRAM was free; L01 49.4 tok/s, L02 45.8 tok/s, prefill 153.9 s - against
    upstream's fixed cache 47.3 / 46.3 tok/s, 153.1 s (run-to-run noise). The gain is not on an idle machine but when
    other programs take and return VRAM: the fixed cache must be sized for the worst moment.

Full logs, scripts and the first port on 0.1.38 (numeric gate, 131k/250k dialogues):
https://github.com/imanu86/Strata-2080Ti/tree/evidence/elastic-cache

Origin

Written for the community Strata-2080Ti fork (https://github.com/imanu86/Strata-2080Ti), where it has been the
daily build's default since late September 2026 on a modified RTX 2080 Ti shared with desktop programs. This PR
isolates it from the fork's other changes on top of 0.1.39.

🤖 Generated with Claude Code


🔄 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/1030 **Author:** [@imanu86](https://github.com/imanu86) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `contrib/elastic-core-0139` --- ### 📝 Commits (10+) - [`fa16567`](https://github.com/Niko1221/Strata/commit/fa165679f9860552ac97ebd07118bb8db286be4a) setup: an earlier config that does not parse is skipped, not a crash; configs are written atomically (#459) - [`749d957`](https://github.com/Niko1221/Strata/commit/749d957a1790b1a171dd4a01ab3e31b3882c9892) setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446) - [`5a30024`](https://github.com/Niko1221/Strata/commit/5a3002446dbb9dfcabb7d0bd9f113da90cc2f3c0) calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447) - [`9f60d13`](https://github.com/Niko1221/Strata/commit/9f60d13246e46b02b1dd0841980b4d18b0faaea7) serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448) - [`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 ### 📊 Changes **8 files changed** (+730 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+10 -0) ➕ `docs/ELASTIC_CACHE.md` (+66 -0) 📝 `include/strata/core/expert_cache.hpp` (+30 -0) 📝 `include/strata/prefill/prefill.hpp` (+4 -1) 📝 `src/core/expert_cache.cpp` (+181 -1) 📝 `src/prefill/prefill.cpp` (+10 -7) 📝 `src/program/generate.cpp` (+358 -12) ➕ `tests/core/expert_cache_elastic_test.cpp` (+71 -0) </details> ### 📄 Description ## What `--elastic` (opt-in, `--serve`, one CUDA GPU): the expert cache follows the free VRAM **automatically** while the server runs. It complements #533's `--vram-elastic` (resized on request through `POST /v1/vram`): the two never open together, and nothing changes when `--elastic` is not given. - **Stable addresses.** The arena is a reserved virtual range backed by physical chunks (CUDA VMM). Growing and shrinking never move the arena or the slot-offset table, so the verify plan, the prompt path and the device residency table keep the pointers they got at startup. - **Two zones.** The startup profile fills the cache; its last part is the **tail** (by default half the startup cache, at most 6 GiB; `--elastic-tail-mib`), which rotates, is lent, grows and shrinks. The slots before it are a fixed **core**: never lent to the prompt path, never chosen as a swap victim and never shrunk. - **Policy.** Keeps `--elastic-reserve-mib` (500) free. Grows with the most-used missing experts (then the profile's order) once the room has lasted `--elastic-stable-ms` (5000; doubles after a shrink that follows a growth, back to the base after 5 minutes without one). Shrinks at once when the room is gone, at most `--elastic-shrink-step-mib` (1024) per check, moving the tail's hottest experts into colder slots first, never a flush. Checked every `--elastic-period-ms` (1000) at the decode's safe point and at each request's start; the prompt path replans its loan after a resize. - **Scope.** Native pack with a startup profile and sized slots, one local CUDA GPU, serve mode. CLI generation, layer split, peer/remote tiers, the resident CPU complement and HIP keep the fixed cache; no VMM -> the plain arena. - **Naming.** `ExpertCache::elastic_grow` / `elastic_shrink` / `elastic_mapped_bytes`, apart from #533's byte-sized `grow` / `shrink` on the segmented arena. Files: `src/core/expert_cache.cpp` + header (VMM arena), `src/program/generate.cpp` (options, core/tail, policy, loan), `src/prefill/prefill.{hpp,cpp}` (host buffers sized for the largest chunk a later relayout can ask for), `tests/core/expert_cache_elastic_test.cpp`, `docs/ELASTIC_CACHE.md`, `CMakeLists.txt` (driver library link, test). ## Tests (RTX 2080 Ti 22 GB, Windows 11, CUDA 12.6, Release sm_75) - CTest `expert_cache_elastic_test` (real VMM: grow, shrink, regrow, stable addresses/offsets, preserved bytes, zeroed new slots, unchanged state after rejected requests, fixed reopen), `expert_cache_per_layer_test`, `expert_profile_save_test`, `expert_cache_segmented_test`: 4/4. - **Without `--elastic` the output is bit-identical to upstream 0.1.39**: teacher forcing with a fixed expert placement on a code and an explain task, per-position log-probabilities byte for byte equal. - 131k context, one run each on an idle machine: with `--elastic` the cache started at 6781 slots (core 3357 / tail 3424) and grew +300 experts while VRAM was free; L01 49.4 tok/s, L02 45.8 tok/s, prefill 153.9 s - against upstream's fixed cache 47.3 / 46.3 tok/s, 153.1 s (run-to-run noise). The gain is not on an idle machine but when other programs take and return VRAM: the fixed cache must be sized for the worst moment. Full logs, scripts and the first port on 0.1.38 (numeric gate, 131k/250k dialogues): https://github.com/imanu86/Strata-2080Ti/tree/evidence/elastic-cache ## Origin Written for the community Strata-2080Ti fork (https://github.com/imanu86/Strata-2080Ti), where it has been the daily build's default since late September 2026 on a modified RTX 2080 Ti shared with desktop programs. This PR isolates it from the fork's other changes on top of 0.1.39. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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:38 +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#2977
No description provided.