Repository navigation
[Engine] Inkling 2: give expert-cache VRAM back while serving - #319
Open
okada-shogo wants to merge 1 commit into
Open
okada-shogo wants to merge 1 commit into
okada-shogo wants to merge 1 commit into
Conversation
…erving strata-poly's expert cache is already in 64 MiB VMM pieces under one address range (CUDA and HIP), and mind_vram() resizes it at each request's start. With the new opt-in --vram-elastic (the config's "vram_elastic": true, which the server now passes to strata-poly): - the whole reserve stays free: when another program took a quarter of it (64 MiB at least) the cache gives at least that back in whole pieces, and when a piece and 128 MiB more are free it takes them again; - what an elastic shrink took out comes back first on the grow, so the cache after a shrink and a grow holds the same experts (gave_back_); - an idle watch: every 2 s while the engine waits for a line with no batch slot writing, the same check runs (STRATA_VRAM_WATCH=0: off, STRATA_VRAM_WATCH_MS); a freeze gives way to it as it does to the VRAM command; - the VRAM command resizes a piece at a time instead of filling the cache again; - HIP: under WSL2 (librocdxg) a released piece's VRAM comes back at the release, so the kept pieces are not unmapped and mapped again for every shrink (decided once, never under WSL2); no piece is asked for unless its bytes and 256 MiB more are free (an allocation past the card hangs there). Without the flag nothing changes. Placement only. The server's desktop note recommends "vram_elastic": true for strata-poly on an AMD desktop instead of a fixed 3072 MiB reserve. The idle check follows strata-poly's own Engine::mind_vram (VecSzn); the WSL2 measurements come from the HIP port of the Qwen engine's --vram-elastic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
On an AMD card that drives a desktop, the advice so far was a fixed
--vram-reserve-mib 3072. With Inkling 2 Minion an RX 9070 XT that left 1,043 of 3,072 experts in VRAM, against 2,335 without it, for the whole run.
strata-poly's expert cache is already mapped in 64 MiB VMM pieces, and it already resizes when a request starts.
What was missing: nothing watches the free VRAM while the engine is idle, it only gives VRAM back once less than half
the reserve is free, and
POST /v1/vramfills the whole cache again.With
"vram_elastic": true(engine flag--vram-elastic, opt-in, NVIDIA and AMD), the cache keeps its whole reservefree while it serves, also while idle. When another program takes VRAM, the cache gives pieces back. When that VRAM is
free again, the cache takes it back, the experts it gave up first. Without the flag nothing changes.
Inkling 2 Mini IQ4_NL, frozen experts (
STRATA_FREEZE_EXPERTS=1), greedy, 302-token prompt, 128 tokens; a secondprocess takes VRAM while the engine is idle, then ends:
Decode tok/s, the same request at each step (one run each; most experts are on the CPU on these cards, so the decode
is CPU-bound and the spread between runs is as large as the change):
Related discussion
#560 and #516 (AMD desktop OOM), #533 (the Qwen engine's
--vram-elastic). The check follows strata-poly's ownEngine::mind_vram(VecSzn).Approach
--vram-elastickeeps the whole reserve free, instead of half of it. When another program took a quarter of thereserve (64 MiB at least), the cache gives at least that much back in whole pieces. When a piece and 128 MiB more are
free, it grows again. The two thresholds never meet, so the cache does not go up and down by itself.
grow holds the same experts. A shrink and a grow use the existing
shrink_cache/grow_cachebookkeeping(
settle_swaps, the mirror,refill_). No expert is marked cached before its bytes are copied.step takes at most 1 GiB, so a request that arrives waits at most that long. A freeze (
STRATA_FREEZE_EXPERTS) givesway to it, as it does to
POST /v1/vram.STRATA_VRAM_WATCH=0turns it off;STRATA_VRAM_WATCH_MSsets the period.POST /v1/vramwith the flag resizes piece by piece to the asked number, instead of refilling the cache.remaps the kept pieces, the cycle that took seconds before. On native amdgpu this is checked once, at the first
shrink. Under WSL2 no expert-cache piece is asked for unless its bytes and 256 MiB more are free, because an
allocation past the card hangs there instead of failing.
--vram-elasticto strata-poly when the config says"vram_elastic": true. On an AMD desktop thestart note recommends that instead of
--vram-reserve-mib 3072.Each run, frozen identity (tokens vs the run without the flag)
--vram-elastic, no resize--vram-elasticrunVRAM 6000VRAM(back)| RTX 2070 | no flag / flag without resize | SAME (all 3) | | | | |
| RTX 2070 |
--vram-elasticexperts | 565 | 284 | 540 | 149 | 540 || RTX 2070 | tokens | SAME | differs | SAME | differs | SAME |
| RX 9070 XT, native | no flag / flag without resize | SAME (all 3) | | | | |
| RX 9070 XT, native |
--vram-elasticexperts | 1,645 | 1,153 | 1,635 | 1,295 | 1,635 || RX 9070 XT, native | tokens | SAME | differs | SAME | differs | SAME |
| RTX 2070 Super | experts | 559 | 284 | 534 | 149 | 534 |
| RTX 2070 Super | tokens vs the same run's full cache | - | differs | SAME | differs | SAME |
On the RTX 2070 Super the run without the flag loaded 560 experts and the two runs with it 559 (the desktop's VRAM
moved by a few MiB between starts). With one expert fewer the tokens differ from token 77 on, in both runs with the
flag alike; each run with the flag is SAME with itself before the shrink and after the grow, and the flag without a
resize is SAME as the flag's full cache. On the two Linux cards with equal counts the flag without a resize is SAME
as no flag.
The RTX 2070 grows back to 540, not 565: the first request's buffers took about 140 MiB of the reserve after the load,
and the cache keeps the whole reserve free.
A smaller cache computes the missing experts on the CPU, which can round differently from the GPU: the shrunk request
was SAME in this run and differed in an earlier one with the same cache size. The 6000 MiB request differs for the same
reason. The cache after the grow back is SAME.
Merge notes:
keepinelastic_card()toreserve_mib_ + rec_room_mib_, so the elastic grow does not take back the piece [Engine] Retry instead of failing when a CUDA graph is out of VRAM #301 gave the recordings.vmm_unmap()for VRAM that comes back at the release. Theyconflict there. Whichever lands second keeps [Engine] AMD on WSL2: remove a 4 s stall when the cache shrinks #302's check (
vmm_release_frees(), every map) first and this PR'sone-time measure (
readdress, the expert cache with the flag) after it.free0is read when either check needs it.Validation
Revision: port/poly-vram-elastic faa1456 on simplex/main 36e654b.
Passed:
space (HIP 7.2.53211) in an Ubuntu 24.04 container,
kit.sh(reserve 4000 MiB, other program 2,816 MiB,--threads 11). The engine found that amdgpu keeps released VRAM until the addresses are freed ("comes back only withits addresses") and mapped the kept pieces again for each shrink: no abort, every run rc=0, results above.
kit.sh(three engines: no flag, the flag without resize, the flag with a second process taking 2,816 MiB andending), results above.
running),
job-2070.sh, results above.python3 -m unittest serve.test_vram serve.test_vision_elastic serve.test_server.DesktopVramNote: OK.strata-poly.Failed:
Not run:
Limits
GET /v1/statuskeeps the figures of the lastPOST /v1/vramafter an idle resize.--vram-pool(the engine says the flag is off).🤖 Generated with Claude Code