Pull requests / #3310

#3310 [Engine] choose how many expert slots a prompt loan keeps

open · @gopinath87607 · 0 comments · View on GitHub

Server & APIMulti-GPUAMD / HIPNVIDIA / CUDALinux

Description

> **Why this PR was recreated.** The original (#2833) was opened from the `gopinath87607/Strata` fork. Deleting that fork deleted its branches, and GitHub closes every pull request whose branch lived in a deleted fork - a closed PR whose source branch is gone cannot be reopened. This is the same work from a new fork, rebased onto current `main` (`e88ee39d`); the conflict with upstream's `chunk_vram` prompt planner in `generate.cpp` was resolved. It replaces the closed #2833, which was closed by the fork's deletion, not by a maintainer.

## Problem and result

When a prompt chunk borrows the expert cache's tail, the auto lend caps what it borrows at 90% of the cache. On a small cache that cap, not the number of slots the prompt needs left resident, picked the chunk, and there was no way to choose it. After this change, `STRATA_PREFILL_KEEP=N` (128 by default) is the one reader of the slots a loan must leave resident: on the Q8_0 four-way's 691- and 937-slot stages it leaves 563 and 809 slots where the cap would leave 621 and 843. Unset, every use is 128, exactly as before.

## Related discussion

The original pull request and its discussion: #2833 (closed when its fork was deleted; this PR replaces it). The work comes from the Maya checkout (`project-maya`), local commit `71c1ca7` (2026-10-15).

## Approach

`STRATA_PREFILL_KEEP=N` (**128 by default**): the expert-cache slots a loan must leave resident while a prompt chunk borrows the cache's tail. On a small cache it is this number, not the auto lend's 90% cap, that picks the chunk. `STRATA_GLM_PREFILL_KEEP` is accepted as the same knob.

**The clamp is up, not down**: a lend has to leave the elastic K/V a region to grow into (its floor is `STRATA_KV_GROW_FLOOR`, 128 by default), so a smaller `N` is clamped to that floor and the start says so - lower both together to lend more of the cache and let the chunk grow at the K/V's expense. A larger `N` keeps more experts resident for the prompt's own tokens and buys a smaller chunk.

The number is the same one the auto scan, the per-stage lend regions, the serve loan, the smallest cache a start accepts and the vram-elastic reserve used before; this change routes all of them through one reader of the variable.

Unset, every use is 128, exactly as before - this is by construction, not a measurement, and this PR's default run is byte-identical on that path. With the variable set to 128 (its default) the numbers are also unchanged.

## Validation

Tested revision: `badfccd7`, one commit on current `main` (`e88ee39d`). Environment: Linux, CUDA 13.2 (V13.2.86), `sm_86` + `sm_120`; the build machine is the Q8_0 4-way rig (2x RTX 3060 12 GB, 2x RTX 5060 8 GB).

**Passed:**
- `git rebase e88ee39d` - the conflict in `generate.cpp` with upstream's `chunk_vram` prompt planner was resolved; the branch's diff is this feature only.
- `ninja -C build strata` at `badfccd7` - exit 0 (CUDA 13.2, `sm_86` + `sm_120`).
- `-fsyntax-only` on `src/program/generate.cpp` with the build's own flags - clean; one pre-existing unused-variable warning in unrelated code. This was run before the rebase; the full build above covers the rebased head.
- Maya checkout, local commit `71c1ca7` (not this engine, not run by us here; `STRATA_GLM_RESERVE_MB=400`, a four-way split, a 99,758-token conversation): the binding part reached an 8192-token chunk; a 49,152-token piece went 61,762 -> 57,507 ms (-6.9%) and a whole five-piece read 161,291 -> 158,938 ms, on the live split (5060/5060/3060/3060). It was not a free win there either: a 16,384-token piece that went from three chunks to two lost 3% (28,716 -> 29,651 ms), since the parts run a chunk as a chain and there is less left to overlap.

**Failed:**
- none observed.

**Not run:**
- A binding-cap A/B on our rig at a `STRATA_PREFILL_KEEP` other than 128: the four-way Q8_0 runs so far used 128, which is this default.
- Serving the rebased head: only the build was re-run after the rebase; no GPU run was made at `badfccd7`.
- HIP and SYCL builds: no toolchain on this machine. `generate.cpp` carries no per-backend code, so both builds compile the same change.

## Limits

- No number is claimed for our rig; the measurement above is the Maya checkout's, on its split and its rig.
- Lowering `N` below `STRATA_KV_GROW_FLOOR` does nothing unless the floor is lowered too; the start says when it clamps.
- A larger `N` buys a smaller chunk, so it trades prompt throughput for expert residency.
- HIP and SYCL are unverified beyond the fact that the file has no per-backend code.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Related on this site

Quick links to related pages.