Commit Graph
3 Commits
Author SHA1 Message Date
Niko1221 388a1554f0 expert cache: evict the slots a part-way shrink lost
With --vram-elastic, a VRAM command shrinks the expert cache by giving its
last segments back to the driver. When the driver refused a segment part way,
the segments released before the refusal were already gone, but the command
returned its error before the residency table was updated. The engine kept
serving with experts still listed in slots that were no longer mapped, and the
prompt path's loan could still sit past the end of the live slots.

Now the residency entries past what stays mapped are evicted after every
shrink, refused or not, the table is uploaded again and the loan moves down
to the end of the slots left; then the error goes out as before.

Also: when the unmap of a segment succeeded and only the release of its
handle failed, the segment was still counted as mapped. It now counts as
unmapped at once; the handle stays and is released again by the next grow
or at close.

The eviction is a pure function (strata/core/residency_trim.hpp) with its own
CPU test. expert_cache_segmented_test refuses an unmap and a release part way
through a shrink, through a test-only hook that the engine never sets
(strata/core/expert_cache_refuse.hpp), and checks the slots kept, the entries
evicted and a full grow afterwards. A shrink the driver accepts behaves as
before.
2026-11-14 04:49:38 +01:00
Niko1221 3d6793a408 tests: expert_cache_segmented_test skips on a HIP build, where --vram-elastic is CUDA-only (#1475) 2026-10-09 03:15:12 +02:00
Niko1221 89bad9a4ec Hot VRAM resize, opt-in: a segmented expert cache, VRAM <reserve>, POST /v1/vram (#533)
--vram-elastic (the config's "vram_elastic": true) allocates the expert cache as one
reserved address range backed by physical segments (CUDA virtual memory management,
512 MiB each, --vram-segment-mib), so every slot keeps its address. Between
requests, the engine command `VRAM <reserve_mib>` gives the last segments back to
the driver until that much VRAM is free (their experts become CPU misses, the prompt
path's loan moves down and its chunk shrinks to fit), or maps them again and puts
the same experts back when more is free. `VRAM` alone: the start's reserve. The
server's POST /v1/vram {"reserve_mib": N | null} sends it after a running request,
keeps it for an engine that is unloaded, and /v1/status shows the cache's size.
Never automatic. One NVIDIA GPU only (no layer split, helper caches, --peer-device
or the resident low-RAM mode); HIP refuses the flag.

RTX 5070, Q2_0 (4.8 GiB cache): reserve 6000 -> 4.3 GiB freed in 78 ms, decode
44 -> 33 tok/s; grown back in 92 ms, the answers token for token the ones before.
Without the flag the cache is the one cudaMalloc it was (same answers with and
without the flag until a VRAM command).
2026-10-03 18:52:00 +02:00