[PR #4020] [Engine] generate: allow the elastic K/V with --peer-device #4880

Open
opened 2026-11-07 16:31:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4020
Author: @chimpera
Created: 10/24/2026
Status: 🔄 Open

Base: main ← Head: vmm-peer-series


📝 Commits (4)

  • bb22771 vmm: create each range's chunks on the device that is current at reserve(), not the one captured by the once-only api() init
  • 3230e5c expert cache: only the primary cache maps its arena through VMM; a peer tier's is one cudaMalloc again
  • e0b9230 peer: create the peer device's context before the arena's whole-range pin
  • fa20b7e generate: allow the elastic K/V with --peer-device

📊 Changes

5 files changed (+56 additions, -23 deletions)

View changed files

📝 include/strata/core/expert_cache.hpp (+4 -2)
📝 include/strata/core/vmm.hpp (+3 -2)
📝 src/core/expert_cache.cpp (+1 -7)
📝 src/core/vmm.cpp (+33 -8)
📝 src/program/generate.cpp (+15 -4)

📄 Description

Problem and result

--kv-grow turns itself off whenever a second GPU is present — the gate reads o.peer_device < 0 — so adding a peer tier costs the primary its elastic K/V. Nothing in the machinery requires the exclusion; what it protected against is fixed here directly, and the two now run together.

Why the gate was there. set_vmm was static: enabling it mapped every expert cache's arena through a vmm.cpp range — including the peer tier's. And a range's physical chunks were created with the device id captured at the once-only api() init (the primary's device), not the device that owns the range, so a second card's mapping failed while that card sat nearly empty. Reproduced on this PR's v0.1.45 base with only the gate line removed: with --kv-grow --peer-device 1, startup ended in

strata generate: peer experts: ExpertCache: mapping 18.05 GiB of VRAM failed: out of memory

on a card with ~20 GiB free — the peer's chunks were being allocated on the primary. (First seen on the strata-nvfp4 fork's 2× RTX 3090 pair; the same vmm.cpp ships here with the elastic K/V.)

Repost of #1223, closed in the 0.2.0-beta tracker reset of 2026-10-19 rather than declined ("a fix of a restriction, not a speed change, so it is outside this round"). Rebased onto current main (0.2.4.2); the restriction the series removes is still there (generate.cpp's elastic gate still reads o.peer_device < 0), the four commits apply clean, and everything below was re-measured on the submitted revision.

Approach

  1. vmm_chunk_new takes the device; a range creates its chunks on the device current at reserve(), not the one captured at init. Device 0 is granted access to a peer range only when cudaDeviceCanAccessPeer says a path exists, with an owner-only fallback (cuMemSetAccess rejects an unreachable remote location outright, failing the whole map).
  2. set_vmm is per-instance: only the cache the K/V borrows from maps through VMM; a peer tier's cache is one plain cudaMalloc. This is what makes the gate unnecessary.
  3. The peer device's context is created before the arena's whole-range pin (cuMemMap/cuMemSetAccess on a peer range need it to already exist).
  4. The gate loses its o.peer_device < 0 clause. Layer splits, --batch and --vram-elastic still turn the elastic K/V off, as before.

Single-GPU behavior is unchanged: a range on the current device creates its chunks exactly as before, and the single-card outputs below are identical between main and this branch.

Validation

Environment: 2× RTX 3090 (a PHB pair, no NVLink), ThreadRipper Pro 5965WX, Qwen3.8-Flash-Next 125B IQ3_S, CUDA 13.4 (archs 86;120). Revision: this branch's four commits on 0.2.4.2 (7dd5cf18); main side = 7dd5cf18. The same physical rig the original PR was measured on, with the same deck — re-run today on the submitted code.

Passed:

  • Build: cmake -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON — the engine builds clean on bare 7dd5cf18 + the four commits.
  • The restriction on stock 0.2.4.2, live: strata generate: --kv-grow is off (one GPU, a profile, the whole K/V in VRAM, every expert in RAM, no --batch, --vram-elastic or --peer-device) — with the peer tier otherwise healthy (peer GPU 1: 11789 experts, 22.50 GiB).
  • This branch, same flags (--kv-grow --peer-device 1): no refusal line; peer attaches (11776 experts, 22.50 GiB); the elastic K/V grows under load — strata: K/V grown to 65536 cells (0.86 GiB); the expert cache gave 318 slots for it, 94 hotter experts moved to colder ones' slots — with a 45K-token prompt through it.
  • Single-GPU identity: 4 greedy prompts (temperature 0) byte-identical between stock 0.2.4.2 and this branch on one card.
  • Decode (median of 3, same day, same shape): solo 93.7 tok/s; stock + peer (elastic refused) 116.8; this branch + peer + elastic 119.6. The elastic K/V is capacity, not a speed claim; peer residency is what moved the number.
  • Original v0.1.45 measurements (same rig) are in #1223: solo 56.4 / +peer 65.0 tok/s medians at 16K context, peer attach 9488 experts / 18.06 GiB.

Failed:

  • None observed. One honest note: with the peer + elastic on, one of the four short greedy prompts flipped (atars vs atarts, reversing "strata"). The single-GPU path is identical, and the flip tracks expert residency, which this branch changes on the primary (8737 vs 7105 resident — the peer/VMM changes free VRAM the primary cache takes): which experts are resident is documented to be able to move a reply (the 2026-09-27 cache-parity result, quoted at boot). Stated as observed; not investigated further here.

Not run:

  • AMD/HIP and Intel builds (NVIDIA-only code paths: vmm.cpp is CUDA virtual memory).
  • An NVLink peer pair (this rig is PCIe; cudaDeviceCanAccessPeer was true over the root complex).
  • More than two GPUs.

Limits

  • The elastic K/V still excludes layer splits, --batch and --vram-elastic, as before.
  • A peer tier's cache is one cudaMalloc (not VMM): its size is whatever --peer-reserve-mib/--peer-slots leave, as before.

🤖 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/4020 **Author:** [@chimpera](https://github.com/chimpera) **Created:** 10/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `vmm-peer-series` --- ### 📝 Commits (4) - [`bb22771`](https://github.com/Niko1221/Strata/commit/bb22771cadb6f5f2f50d5a8e850affcea4cf2ac8) vmm: create each range's chunks on the device that is current at reserve(), not the one captured by the once-only api() init - [`3230e5c`](https://github.com/Niko1221/Strata/commit/3230e5c565a4378748cd8377f792446d502fe4c5) expert cache: only the primary cache maps its arena through VMM; a peer tier's is one cudaMalloc again - [`e0b9230`](https://github.com/Niko1221/Strata/commit/e0b9230b242d70bf717cdce64b8376db2668f189) peer: create the peer device's context before the arena's whole-range pin - [`fa20b7e`](https://github.com/Niko1221/Strata/commit/fa20b7e8a2563d3301c0a32f6b854fd28915d6eb) generate: allow the elastic K/V with --peer-device ### 📊 Changes **5 files changed** (+56 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/expert_cache.hpp` (+4 -2) 📝 `include/strata/core/vmm.hpp` (+3 -2) 📝 `src/core/expert_cache.cpp` (+1 -7) 📝 `src/core/vmm.cpp` (+33 -8) 📝 `src/program/generate.cpp` (+15 -4) </details> ### 📄 Description ## Problem and result `--kv-grow` turns itself off whenever a second GPU is present — the gate reads `o.peer_device < 0` — so adding a peer tier costs the primary its elastic K/V. Nothing in the machinery requires the exclusion; what it protected against is fixed here directly, and the two now run together. **Why the gate was there.** `set_vmm` was static: enabling it mapped *every* expert cache's arena through a `vmm.cpp` range — including the peer tier's. And a range's physical chunks were created with the device id captured at the once-only `api()` init (the primary's device), not the device that owns the range, so a second card's mapping failed while that card sat nearly empty. Reproduced on this PR's v0.1.45 base with only the gate line removed: with `--kv-grow --peer-device 1`, startup ended in strata generate: peer experts: ExpertCache: mapping 18.05 GiB of VRAM failed: out of memory on a card with ~20 GiB free — the peer's chunks were being allocated on the primary. (First seen on the strata-nvfp4 fork's 2× RTX 3090 pair; the same `vmm.cpp` ships here with the elastic K/V.) ## Related discussion Repost of #1223, closed in the 0.2.0-beta tracker reset of 2026-10-19 rather than declined ("a fix of a restriction, not a speed change, so it is outside this round"). Rebased onto current main (0.2.4.2); the restriction the series removes is still there (`generate.cpp`'s elastic gate still reads `o.peer_device < 0`), the four commits apply clean, and everything below was re-measured on the submitted revision. ## Approach 1. `vmm_chunk_new` takes the device; a range creates its chunks on the device current at `reserve()`, not the one captured at init. Device 0 is granted access to a peer range only when `cudaDeviceCanAccessPeer` says a path exists, with an owner-only fallback (`cuMemSetAccess` rejects an unreachable remote location outright, failing the whole map). 2. `set_vmm` is per-instance: only the cache the K/V borrows from maps through VMM; a peer tier's cache is one plain `cudaMalloc`. This is what makes the gate unnecessary. 3. The peer device's context is created before the arena's whole-range pin (`cuMemMap`/`cuMemSetAccess` on a peer range need it to already exist). 4. The gate loses its `o.peer_device < 0` clause. Layer splits, `--batch` and `--vram-elastic` still turn the elastic K/V off, as before. Single-GPU behavior is unchanged: a range on the current device creates its chunks exactly as before, and the single-card outputs below are identical between main and this branch. ## Validation Environment: 2× RTX 3090 (a PHB pair, no NVLink), ThreadRipper Pro 5965WX, Qwen3.8-Flash-Next 125B IQ3_S, CUDA 13.4 (archs 86;120). Revision: this branch's four commits on 0.2.4.2 (7dd5cf18); `main` side = 7dd5cf18. The same physical rig the original PR was measured on, with the same deck — re-run today on the submitted code. **Passed:** - Build: `cmake -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON` — the engine builds clean on bare 7dd5cf18 + the four commits. - The restriction on stock 0.2.4.2, live: `strata generate: --kv-grow is off (one GPU, a profile, the whole K/V in VRAM, every expert in RAM, no --batch, --vram-elastic or --peer-device)` — with the peer tier otherwise healthy (`peer GPU 1: 11789 experts, 22.50 GiB`). - This branch, same flags (`--kv-grow --peer-device 1`): no refusal line; peer attaches (`11776 experts, 22.50 GiB`); the elastic K/V grows under load — `strata: K/V grown to 65536 cells (0.86 GiB); the expert cache gave 318 slots for it, 94 hotter experts moved to colder ones' slots` — with a 45K-token prompt through it. - Single-GPU identity: 4 greedy prompts (temperature 0) byte-identical between stock 0.2.4.2 and this branch on one card. - Decode (median of 3, same day, same shape): solo 93.7 tok/s; stock + peer (elastic refused) 116.8; this branch + peer + elastic 119.6. The elastic K/V is capacity, not a speed claim; peer residency is what moved the number. - Original v0.1.45 measurements (same rig) are in #1223: solo 56.4 / +peer 65.0 tok/s medians at 16K context, peer attach 9488 experts / 18.06 GiB. **Failed:** - None observed. One honest note: with the peer + elastic on, one of the four short greedy prompts flipped (`atars` vs `atarts`, reversing "strata"). The single-GPU path is identical, and the flip tracks expert residency, which this branch changes on the primary (8737 vs 7105 resident — the peer/VMM changes free VRAM the primary cache takes): which experts are resident is documented to be able to move a reply (the 2026-09-27 cache-parity result, quoted at boot). Stated as observed; not investigated further here. **Not run:** - AMD/HIP and Intel builds (NVIDIA-only code paths: `vmm.cpp` is CUDA virtual memory). - An NVLink peer pair (this rig is PCIe; `cudaDeviceCanAccessPeer` was true over the root complex). - More than two GPUs. ## Limits - The elastic K/V still excludes layer splits, `--batch` and `--vram-elastic`, as before. - A peer tier's cache is one `cudaMalloc` (not VMM): its size is whatever `--peer-reserve-mib`/`--peer-slots` leave, as before. 🤖 Generated with [Claude Code](https://claude.ai/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4880
No description provided.