Skip to content

llama-memory-hybrid-idx : graph reservation takes the QSA route of an empty cache - #262

Merged
Nathanw1014 merged 1 commit into
halo-box:masterfrom
rcfa:pr/qsa-reserve-empty-cache
Nov 9, 2026
Merged

Nathanw1014 merged 1 commit into
halo-box:masterfrom
rcfa:pr/qsa-reserve-empty-cache

Conversation

@rcfa

@rcfa rcfa commented Nov 7, 2026

Copy link
Copy Markdown

Overview

After a memory update, llama-context reserves its graphs again from a full-cache context (init_full). With an MTP
draft, the first decode after a slot restore is such an update. That context only reserves graphs, but
qsa_scalar_visibility and qsa_position_prefix read the live cells. Suppose an image conversation is resident
next 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

Device:     Ryzen AI 9 HX PRO 370 / Radeon 890M (gfx1150, Strix Point - NOT Strix Halo) / Minisforum N5 PRO, BIOS 1.05
Memory:     96 GB DDR5-5600 (2 x 48 GB SO-DIMM, ECC)
Power:      BIOS defaults; amdgpu power_dpm_force_performance_level=auto; cpufreq governor powersave (amd-pstate)
BIOS:       UMA split 48 GB
Kernel:     7.2.15+kali-amd64, amdgpu params: amdgpu.gttsize=73728 ttm.pages_limit=8650752
Backend:    Vulkan RADV, Mesa 26.1.6 (libvulkan1 1.4.363)
Build:      -DGGML_VULKAN=ON -DLLAMA_CURL=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_RPATH_USE_ORIGIN=ON (gcc 16.2)
Baseline:   master 62a3f4144, built and run in the same session from the same worktree, separate bin directories
Change:     b33a33058
Model:      ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF, IQ3_XXS; MTP: shared head mtp-Qwen3.8-Flash-Next-shared-Q4_K_M
            (Unsloth); mmproj F16 (Unsloth)

Repro on this PR's own base:

  1. Server 1: 2048 tokens of text in slot 0, then an image chat and its follow-up in slot 1. Save both slots and stop.
  2. Server 2: restore both slots, then send the image chat's follow-up again. GTT is sampled every 0.5 s.

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

server 2, the follow-up after the restore master 62a3f41 this PR
GTT before -> peak 6.19 -> 17.15 GiB 6.20 -> 6.27 GiB
growth +10.95 GiB +0.08 GiB
decode, 19 tokens 15.53 t/s 16.37 t/s
answer "The number following 'scrub errors' is 3, and the circle is red." the same

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, this
change 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's
OOM killer took other processes first. That is why the table above uses -c 131072.

Correctness:

  • The follow-up's answer is the same on master and on this PR. A reservation only sizes buffers.
  • GTT at load is unchanged (6.19 / 6.20 GiB). At load the cache is empty, so the reserve took this route already.
  • test-qsa-prefix, test-qsa-recover and test-qsa-fast pass on master and on this PR (CPU, no device).
  • No ggml op, kernel or graph changes, so test-backend-ops does not apply.
  • Not run: the corpus logit comparison and llama-bench. A single-sequence run never reserves after a memory update
    with image cells resident, so neither reaches the changed path.
  • Status: TARGET PASS for the repro.

Requirements

  • I have read and agree with the contributing guidelines
  • This change is Strix Halo specific, or justified by measurements on Strix Halo: it fixes the fork's qwen4exp QSA
    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.
  • AI usage disclosure: AGENT-AUTHORED. Claude (Claude Code) traced the bug, wrote the fix, this description and the
    repro tools, and ran every measurement. The commit carries Assisted-by: Claude Code. rcfa reviewed and owns it.
  • What was NOT verified:
    • Strix Halo (gfx1151), ROCm, CUDA and CPU-only builds. The change is backend-independent host code.
    • A decode that really needs the masked route after this change. It still grows the buffers when it runs, as on
      master; we did not measure that case separately.
    • Models other than Qwen3.8-Flash-Next.
  • Related: llama-memory-hybrid-idx : no abort on image cells sharing a tail slot when unranked #261, the companion fix for the MTP draft's abort on image cells (same file, merges cleanly with
    this one).

🤖 Generated with Claude Code

… 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 Nathanw1014 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  1. A ~2k text prompt in slot 0.
  2. An image chat and a follow-up in slot 1.
  3. Save both slots, stop the server, start it again, restore both slots.
  4. Send the image follow-up to slot 1 again, sampling mem_info_gtt_used every 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.

@Nathanw1014
Nathanw1014 merged commit 8acea9a into halo-box:master Nov 9, 2026
1 check passed
@rcfa
rcfa deleted the pr/qsa-reserve-empty-cache branch November 27, 2026 19:19
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.

2 participants