Skip to content

llama : reserve the incremental QSA graph at its worst case (fixes test-qwen4exp-mtp-cache-only) - #299

Merged
dzannotti merged 1 commit into
masterfrom
hb/qsa-reserve
Nov 19, 2026
Merged

dzannotti merged 1 commit into
masterfrom
hb/qsa-reserve

Conversation

@dzannotti

@dzannotti dzannotti commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Fixes the last red check on master: test-qwen4exp-mtp-cache-only (CI (vulkan) / ubuntu-llvmpipe, CI (cpu) / windows / x64-openblas). Root cause from #298, section 3.

The incremental QSA route (a qwen4exp ubatch on the tracked prefix) builds its own graph structure. sched_reserve never built it, because the reservation context asked the live prefix, which is false for an empty cache. The first incremental ubatch therefore planned that structure at the current n_kv, and the next one with a larger n_kv planned it again. With more than one scheduler buffer (ROCm, Vulkan, CPU+BLAS) that is a re-plan and a backend sync per n_kv step; GGML_SCHED_DEBUG_REALLOC=1 aborts on it.

Change

  • llama_memory_hybrid_idx_context: a reservation context can be set to the prefix or fast route; the live path is unchanged.
  • llama_context::reserve_qsa_routes: reserves both routes at 1 token, at the largest ubatch the route allows (512 for fast) and at the end of each token range the live pass found (no new probing), with and without outputs. The MTP cache-only graph exists only with zero outputs, so graph_reserve no longer asserts n_outputs >= 1.

No kernel, graph or math change: the same graphs run, only their buffers are planned up front.

Verification

Strix Halo (gfx1151), ROCm 10.1 and RADV, master 4032d8f07 vs this branch 46e03cdeb, same flags.

Correctness:

  • GGML_SCHED_DEBUG_REALLOC=1 ctest -L main: CPU, Vulkan0, ROCm0 36/36 (master 35/36 on Vulkan0 and ROCm0: test-qwen4exp-mtp-cache-only); lavapipe with the CI env (subset qwen4exp / llama-context / draft-vocab / llama-archs) 5/5 (master 4/5).
  • CI dispatched on this branch: CI (vulkan) ubuntu-llvmpipe and CI (cpu) windows / x64-openblas pass.
  • Qwen3.8-Flash-Next Gyro-M TQ2_0, llama-debug final f32 logits + prompt tokens on the four tests/corpus files at -ub 512 and -ub 2048: byte-identical, ROCm and Vulkan (16/16 pairs). Greedy decode 256 tokens identical on both backends.
  • llama-server with the shared MTP draft (--spec-draft-n-max 3, -c 32768 -b/-ub 2048), 2.3k and 16k-token prompts, arms base/fix/fix/base, 3 requests each: identical text and drafted/accepted counts on both backends.

Performance (all within run-to-run spread):

ROCm Vulkan
llama-bench PP2048 d0 / 12k / 32k / 64k, -r 3, alternated x2 -0.36 / +0.06 / +0.06 / -0.05 % -0.67 / -0.13 / -0.07 / -0.17 %
tg128 +0.01 % +0.01 %
server MTP tok/s 2.3k / 16k -0.02 / +0.05 % -0.14 / -0.19 %
server prompt time 2.3k / 16k +0.03 / -0.03 % +0.03 / +0.01 %

Costs and limits:

  • The extra reservations run with the first sched_reserve; in llama-server that lands on the first request: about +0.3 s once (ROCm 4.15 -> 4.47 s, Vulkan 3.63 -> 3.91 s for the first 2.3k prompt).
  • Same-size graph re-plans in the server runs: Vulkan 40 -> 20 per 8 requests, ROCm 40 -> 40. The ones left come from a different structure: the bounded indexer scorer that real prompt positions select, which the reservation (all positions 0) never builds. On a real model the allocator's 6 cached plans also evict some of the extra reserved structures. Not addressed here; follow-up.

Assisted-by: Claude Opus 5.5

🤖 Generated with Claude Code

https://claude.ai/code/session_01YKmjzcT1LTvKtbw9EzBVGE

@github-actions github-actions Bot added the ggml label Nov 18, 2026
The incremental QSA route (a ubatch on the tracked prefix, qwen4exp) builds
its own graph structure, and sched_reserve never built it: the reservation
context took the live prefix test, which is false for an empty cache. The
first incremental ubatch then planned that structure at the current n_kv,
and the next one with a larger n_kv had to plan it again. On a scheduler
with more than one buffer (ROCm, Vulkan, CPU+BLAS) that is a re-plan and a
backend sync per n_kv step, and GGML_SCHED_DEBUG_REALLOC aborts on it:
test-qwen4exp-mtp-cache-only failed on ROCm0, Vulkan0, CI llvmpipe and CI
Windows CPU+BLAS.

A reservation context can now be told to take the prefix route or the
fast route. sched_reserve reserves both at 1 token, at the largest ubatch
the route allows and at the end of each token range the live pass found,
with and without outputs (the MTP cache-only graph exists only without
outputs, so graph_reserve accepts zero outputs).

Assisted-by: Claude Opus 5.5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YKmjzcT1LTvKtbw9EzBVGE
@dzannotti
dzannotti marked this pull request as ready for review November 19, 2026 02:49
@dzannotti
dzannotti merged commit 9a237d6 into master Nov 19, 2026
20 checks passed
@dzannotti
dzannotti deleted the hb/qsa-reserve branch November 19, 2026 02:51
dzannotti pushed a commit to rcfa/strix-llama.cpp that referenced this pull request Nov 21, 2026
reserve_qsa_routes (halo-box#299) reserved the prefix and fast QSA routes with one
sequence. With a non-unified KV cache and more than one slot the qwen4exp
graph splits the tokens across n_seq_max streams, so the 1-token reservation
hit GGML_ASSERT(n_tokens % n_stream == 0) in build_qsa_top_k and every
Flash-Next server with -np >= 2 and no -kvu aborted at load.

Reserve with one sequence per stream, as reserve_token_ranges already does;
graph_reserve rounds the token count up to a multiple of it.

Assisted-by: Claude Opus 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant