Repository navigation
llama : reserve the incremental QSA graph per KV stream - #306
Merged
Merged
Conversation
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
approved these changes
Nov 20, 2026
dzannotti
left a comment
Collaborator
There was a problem hiding this comment.
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 2048so #301 does not hit first): aborts at load withGGML_ASSERT(n_tokens % n_stream == 0)inbuild_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 1output with this PR is bit-identical to the build without it.
Approved.
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
Since #299, every Qwen3.8-Flash-Next server with
-np 2or more and a per-slot KV cache (the default, no-kvu) aborts at load withGGML_ASSERT(n_tokens % n_stream == 0)inbuild_qsa_top_k, fromgraph_reserve.#299 added
reserve_qsa_routes, which reserves the prefix and fast QSA routes withgraph_reserve(n, 1, ...): one sequence. With a non-unified cache the qwen4exp graph splits the tokens acrossn_seq_maxstreams, so the 1-token reservation cannot divide. This reserves with one sequence per stream (kv_unified ? 1 : n_seq_max), the same probereserve_token_rangesalready uses;graph_reserverounds the token count up to a multiple of it. No graph or math change; unified caches and-np 1reserve exactly as before.Independent of #304 (different hunk of
src/llama-context.cpp; the two merge cleanly in either order).Measurements
Server load test:
llama-server -c 32768 -fa on --cache-ram 0, then one 8-token greedy completion.-np 1-np 2-np 4-np 4+ MTP-np 4 -kvu+ MTPAll 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 withGGML_SCHED_DEBUG_REALLOC=1, so the incremental route is still reserved. Full default build (no--target) passes.Requirements
belong in halo-box/llama.cpp instead
Written with Claude, tested by me.
Assisted-by: Claude Opus 5.5