Repository navigation
Conversation
make_act() reuses a pooled activation only on an exact size match, and released buffers go back to a global pool that is never freed. Sizes follow the step token count, so a server keeps one set of buffers for every prompt or last-chunk length it has seen, and its heap grows without a practical bound. model::run now frees the pool when a prompt finishes. Buffers are still reused across layers, passes and steps within the call, and decode keeps its small fixed-size set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Not ready yet. |
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
With
inkling-2:mini,flm servekeeps host memory for every prefill step length it has not seen before, and never frees it. On a server that gets prompts of varying length, the anonymous heap grows without a practical bound: about 80 MB per request with--prefill-chunk-len 512, and about 730 MB per request with the default chunking. In one production day it went from ~22 GB to ~52 GB.Cause
make_act()ininkling2_host.cppreuses a pooled activation only when its size matches exactly. Theshared_ptrdeleter puts the vector back into a global pool and nothing ever frees it (v1.0.14 L172-L195, unchanged onmainat b806c121). Activation sizes follow the step token count T, and also the two halves when T >= 256. So each new prompt length, or each new last-chunk length, adds a full set of buffers for the life of the process.Fix
model::runfrees the pooled activations when a prompt (n > 1) finishes. Within a call, buffers are still reused across layers, passes and steps, which is what the pool was added for. Decode (n == 1) keeps its small, fixed-size set. Only released buffers are in the pool, and the swap-and-delete happens under the pool mutex, so buffers still in use, on any thread, are never touched. They return to the pool as before.Measurements
Strix Halo (Ryzen AI MAX+ 395), XRT 2.25, FLM 1.0.14,
flm serve inkling-2:mini --ctx-len 32768 --prefix-slots 0. The engine was built from v1.0.14 withbuild_inkling2.sh(g++-13), with and without this patch. The inkling2 sources are identical onmain.The heap is RssAnon + VmSwap of
flm serve, measured after each of 30 prompts of random length (seeded, the same for every build, 1.4k-4.7k tokens,max_tokens40).--prefill-chunk-len 512.soOutputs are unchanged. Three fixed prompts (31, 1517 and 4293 tokens, temperature 0, top_k 1, seed 1234, 96 tokens) give byte-identical output (reasoning and content) with the shipped
.so, the rebuilt v1.0.14 and the patched build. The rebuilt and patched builds were checked both on a fresh server and after the 30-prompt run.Same class of bug as #903 (Gemma 4 E4B memory growing with each new context length), fixed in #1044.
Fixes #1214.
🤖 Generated with Claude Code