Skip to content

llama : reserve the incremental QSA graph per KV stream - #306

Merged
Nathanw1014 merged 2 commits into
masterfrom
hb/qsa-reserve-nstream
Nov 20, 2026
Merged

Nathanw1014 merged 2 commits into
masterfrom
hb/qsa-reserve-nstream

Conversation

@Nathanw1014

Copy link
Copy Markdown

Overview

Since #299, every Qwen3.8-Flash-Next server with -np 2 or more and a per-slot KV cache (the default, no -kvu) aborts at load with GGML_ASSERT(n_tokens % n_stream == 0) in build_qsa_top_k, from graph_reserve.

#299 added reserve_qsa_routes, which reserves the prefix and fast QSA routes with graph_reserve(n, 1, ...): one sequence. With a non-unified cache the qwen4exp graph splits the tokens across n_seq_max streams, so the 1-token reservation cannot divide. This reserves with one sequence per stream (kv_unified ? 1 : n_seq_max), the same probe reserve_token_ranges already uses; graph_reserve rounds the token count up to a multiple of it. No graph or math change; unified caches and -np 1 reserve exactly as before.

Independent of #304 (different hunk of src/llama-context.cpp; the two merge cleanly in either order).

Measurements

Device:     Ryzen AI Max+ 395 / Framework Desktop
Memory:     64 GB LPDDR5X-8000
Power:      platform_profile balanced
BIOS:       UMA split 512 MB
Kernel:     6.17.0-35-generic, amdgpu.gttsize=59392 ttm.pages_limit=15204352 amd_iommu=off
Backend:    Vulkan RADV, Mesa 26.2.4
Build:      -DGGML_VULKAN=ON -DGGML_NATIVE=OFF -DCMAKE_BUILD_TYPE=Release -DLLAMA_USE_PREBUILT_UI=OFF
Baseline:   b9f3c0e87 (master); bisect pair 4032d8f07 (#298 merge) vs 9a237d6cb (#299 merge)
Change:     338cd96ea
Model:      Qwen3.8-Flash-Next trunc8 UD-Q4_K_XL (8 layers) + unsloth MTP Q8_0 (mtp-Qwen3.8-Flash-Next-Q8_0.gguf)

Server load test: llama-server -c 32768 -fa on --cache-ram 0, then one 8-token greedy completion.

build -np 1 -np 2 -np 4 -np 4 + MTP -np 4 -kvu + MTP
4032d8f (#298 merge) not run loads not run not run not run
9a237d6 (#299 merge) not run abort not run not run not run
b9f3c0e (master) not run abort abort abort not run
this PR loads loads loads loads loads

All loads in this PR give the same greedy text. Load memory is unchanged (GTT peak 14.9 GB, 19.4 GB with the MTP head, vs 15.1 / 19.7 GB on 762a42c before #299).

Correctness: ctest -L main: 36/36 passed. test-qwen4exp-mtp-cache-only (the test #299 fixed) passes with GGML_SCHED_DEBUG_REALLOC=1, so the incremental route is still reserved. Full default build (no --target) passes.

Requirements

  • I have read and agree with the contributing guidelines
  • This change is Strix Halo specific, or justified by measurements on Strix Halo. General llama.cpp improvements
    belong in halo-box/llama.cpp instead
  • AI usage disclosure: AGENT-AUTHORED. Claude bisected the regression, wrote the change and ran the tests; I reviewed it.
  • What was NOT verified: ROCm and CPU backends (the change is backend independent), the full Flash-Next model (trunc8 stands in, the MTP model is the real one), and long context together with llama : size the fork's per-token graph budgets from n_ubatch again #304.

Written with Claude, tested by me.

Assisted-by: Claude Opus 5.5

Nathanw1014 and others added 2 commits November 20, 2026 09:18
reserve_qsa_routes (#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

@dzannotti dzannotti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified on Strix Halo (gfx1151), ROCm, with a real Qwen3.8-Flash-Next (qwen4exp, full model) + the shared MTP draft, rebased on master 058a058:

  • master with -np 2 (per-slot KV, -ub 2048 so #301 does not hit first): aborts at load with GGML_ASSERT(n_tokens % n_stream == 0) in build_qsa_top_k.
  • this PR (with #304), -np 2 -c 563200 -ub 4096: loads; two parallel requests (an 8k prompt and a 57656-token passkey prompt) both complete and the passkey is retrieved.
  • -np 1 output with this PR is bit-identical to the build without it.

Approved.

@Nathanw1014
Nathanw1014 merged commit 1fe05fa into master Nov 20, 2026
9 checks passed
@Nathanw1014
Nathanw1014 deleted the hb/qsa-reserve-nstream branch November 20, 2026 12:45
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