Skip to content

fix(inkling2): free pooled prompt activations after each prefill - #1215

Closed
erpalma wants to merge 1 commit into
ROCm:mainfrom
erpalma:fix-inkling2-act-pool
Closed

erpalma wants to merge 1 commit into
ROCm:mainfrom
erpalma:fix-inkling2-act-pool

Conversation

@erpalma

@erpalma erpalma commented Dec 1, 2026

Copy link
Copy Markdown

Problem

With inkling-2:mini, flm serve keeps 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() in inkling2_host.cpp reuses a pooled activation only when its size matches exactly. The shared_ptr deleter puts the vector back into a global pool and nothing ever frees it (v1.0.14 L172-L195, unchanged on main at 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::run frees 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 with build_inkling2.sh (g++-13), with and without this patch. The inkling2 sources are identical on main.

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_tokens 40).

--prefill-chunk-len 512 heap after 1 → 30 requests growth, last 10 requests prefill median (random / same prompt x5)
shipped .so 2163 → 4404 MB +78 MB/req 570.5 / 572.6 tok/s
v1.0.14 rebuilt 2206 → 4743 MB +78 MB/req 568.7 / 571.4 tok/s
this patch 1860 → 2192 MB +2.6 MB/req 569.4 / 569.0 tok/s
default chunking, 6 prompts of 2.6k-4.7k tokens heap after 1 → 6 prefill median
v1.0.14 rebuilt 2560 → 6192 MB 1106 tok/s
this patch 1908 → 2292 MB 1106 tok/s

Outputs 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

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>
@erpalma erpalma closed this Dec 1, 2026
@erpalma
erpalma deleted the fix-inkling2-act-pool branch December 1, 2026 14:08
@erpalma

erpalma commented Dec 1, 2026

Copy link
Copy Markdown
Author

Not ready yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inkling-2:mini: host memory grows with every new prompt length and is never freed (activation pool)

1 participant