Repository navigation
fix(engine): apply shrinking cache resizes before growing ones in live rebuild (Closes #643) - #650
Open
void-mckenzie wants to merge 1 commit into
Open
void-mckenzie wants to merge 1 commit into
void-mckenzie wants to merge 1 commit into
Conversation
KarrAcaRn
pushed a commit
to KarrAcaRn/FreeToken-ByAI
that referenced
this pull request
Oct 10, 2026
… resizes before growing ones in live rebuild
KarrAcaRn
pushed a commit
to KarrAcaRn/FreeToken-ByAI
that referenced
this pull request
Oct 10, 2026
…ake engine next's dflash and graph-runner fields Assisted-by: Claude Opus 5.5
This branch has not been deployed
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.
Closes #643.
Engine.rebuild_runtime_cacheapplied its three resizes in a fixed MoE -> KV -> mamba orderregardless of direction, and each pool frees only its own old tensors, so a mixed-direction
resize allocated the larger MoE cache while the old KV/mamba pools were still resident.
validate_rebuildprices only the target geometry, so a plan that passed the fit check couldOOM mid-rebuild (and the failed rollback after such an OOM is #526).
The rebuild now compares each pool family's old-vs-new footprint (new
BaseKVCachePool.rebuild_footprintclassmethod reusing thekv_costplumbingvalidate_rebuildalready uses; DSV4 overrides it with_dsv4_pool_sizes+dsv4_pool_bytes, since itskv_costtakes nonum_swa_pages) and runs the shrinkingresizes before the growing ones, preserving MoE -> KV -> mamba order within each phase.
Each pool still frees its own tensors first, so after the shrink phase the resident total is
sum(min(old, new))and the grow phase rises monotonically tosum(new): the transientpeak never exceeds
max(current, target), both of which already fit. All-grow andall-shrink requests keep today's behavior.
Tests
New
tests/engine/test_rebuild_runtime_cache_ordering.py: the issue's scenario (fake poolsunder a shared cap, moe 40/kv 50 -> 60/30, cap 100) raises
torch.OutOfMemoryErrorfrom theMoE-first resize on unfixed main after the fit check passes, and completes after the fix with
peak == target total and the KV realloc ordered before the MoE realloc; plus reverse-direction
and rollback-restore guards.
test_every_kv_pool_answers_the_sizing_surfacegains the hook.tests/engine/+tests/kvcache/test_kv_cache_rebuild.py+tests/kvcache/test_pool_sizing_surface.py:136 passed, 2 pre-existing env-gated skips. DSV4 / hybrid-SWA / V4.1 pool suites: 47 passed.
Hardware
RTX 5090,
nvidia/Qwen3.8-Flash-Next-NVFP4(offload MoE, moe 3400 slots / kv 317440 tok /1.97 GiB free after CUDA graphs), command
ft ctl cache rebuild --moe 4300 --kv 160k:0781324: passes the fit check, OOMs in the MoE grow (420 MiB request, 16 MiBfree); rollback is rejected and the server latches failed (fix(engine): ft ctl cache live resize: OOM during rebuild breaks rollback and wedges the server #526's wedge).
last rebuild ok, pools at moe 4300 /kv 163840, generation verified after the live resize.
The mid-rebuild-OOM rollback failure itself remains #526.