Repository navigation
llama-memory-hybrid-idx : graph reservation takes the QSA route of an empty cache - #262
Merged
Merged
Conversation
… empty cache A full-cache context (init_full) only reserves graphs, but qsa_scalar_visibility and qsa_position_prefix read the live cells. With an image conversation resident next to another sequence, the reserve that follows a memory update (the first decode after a slot restore) took the masked route at its worst-case shape, [n_kv, n_ubatch] over the whole cache, and ggml-alloc kept those buffers for the rest of the run. The reservation context now checks the ubatch against no cells, as at load. A masked graph that a decode really needs still grows the buffers when it runs. Flash-Next on gfx1150 (Vulkan, -c 524288 -np 4 -kvu -ub 2048, q8_0 K/V, MTP, mmproj): a text slot and an image chat saved, the server restarted, both restored, then the image chat's follow-up. Before: GTT went from 20.94 to 33.39 GiB, the follow-up decoded at 0.14 t/s in the memory pressure that followed, and a 64k-token prefill after it ran at 34 t/s. With this change: +0.08 GiB, 16.7 t/s, the same answer, and the prefill at 298 t/s (GTT peak 21.37 GiB). Assisted-by: Claude Code
Nathanw1014
approved these changes
Nov 9, 2026
Nathanw1014
left a comment
There was a problem hiding this comment.
Thanks for this. Approving: we reproduced the GTT growth on gfx1151 with your server line, and #262 fixes it.
Repro (Strix Halo, master 62a3f41)
Your server line verbatim (Flash-Next UD-IQ3_XXS, shared MTP Q4_K_M draft, mmproj, -np 4 -kvu --cache-ram 2048 -ub 2048), plus --slot-save-path, thinking off.
- A ~2k text prompt in slot 0.
- An image chat and a follow-up in slot 1.
- Save both slots, stop the server, start it again, restore both slots.
- Send the image follow-up to slot 1 again, sampling
mem_info_gtt_usedevery 0.5 s.
| build | GTT before -> peak during the follow-up | follow-up answer |
|---|---|---|
| master | 61.20 -> 72.15 GiB (+10.95) | "3 red" |
| master + #262 | 61.20 -> 61.28 GiB (+0.08) | "3 red" |
Both answers match a -np 1 run of the same chat. The growth was the same in an earlier run with thinking on.
We didn't measure speed beyond the 24-token follow-up, so we can't say anything about throughput.
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.
Overview
After a memory update, llama-context reserves its graphs again from a full-cache context (
init_full). With an MTPdraft, the first decode after a slot restore is such an update. That context only reserves graphs, but
qsa_scalar_visibilityandqsa_position_prefixread the live cells. Suppose an image conversation is residentnext to another sequence. The scalar visibility check then fails, and the reserve takes qwen4exp's masked route at its
worst-case shape,
[n_kv, n_ubatch]over the whole cache. ggml-alloc keeps those buffers for the rest of the run.With this PR, the reservation context checks the ubatch against no cells, as at load. A masked graph that a decode
really needs still runs and grows the buffers then, as before.
Measurements
Repro on this PR's own base:
Server:
GGML_VK_MMV_NO_SPLIT=1 llama-server -m IQ3_XXS -ngl 99 --load-mode none --lazy-mode on-direct -c 131072 -np 4 -kvu --cache-ram 2048 --no-cache-idle-slots -ub 2048 --mmproj mmproj-F16 --spec-type draft-mtp -md mtp-shared-Q4_K_M -ngld 99 --spec-draft-n-max 2 --slot-save-path DIR(f16 K/V, greedy).Without the draft (no MTP), master did not grow either (+0.00 GiB, same sequence). The reserve after a restore needs
the speculative target.
On our production server (
-c 524288 -ub 2048, q8_0 K/V through #219 plus Vulkan q8_0 selected-key kernels, thischange on top), the same follow-up moved GTT from 20.94 to 33.39 GiB before the fix. It then decoded at 0.14 t/s in the
memory pressure that followed, and a 64k-token prefill after it ran at 34 t/s. With the fix: +0.08 GiB, 16.7 t/s, the
same answer, and the 64k prefill at 298 t/s (GTT peak 21.37 GiB). An attempt at that pool on master (IQ3_S, f16,
-c 524288) ran the 96 GB host out of memory. GTT pages are not charged to the process or its cgroup, so the kernel'sOOM killer took other processes first. That is why the table above uses
-c 131072.Correctness:
test-qsa-prefix,test-qsa-recoverandtest-qsa-fastpass on master and on this PR (CPU, no device).test-backend-opsdoes not apply.llama-bench. A single-sequence run never reserves after a memory updatewith image cells resident, so neither reaches the changed path.
Requirements
memory, which only this fork has. It costs the most on a large unified memory pool like Strix Halo's. Our
measurements come from Strix Point (gfx1150), not Strix Halo.
repro tools, and ran every measurement. The commit carries
Assisted-by: Claude Code. rcfa reviewed and owns it.master; we did not measure that case separately.
this one).
🤖 Generated with Claude Code