Repository navigation
qwen4exp: score QSA blocks through the k-pool indexer - #326
Closed
amangupta-tether wants to merge 4 commits into
Closed
amangupta-tether wants to merge 4 commits into
amangupta-tether wants to merge 4 commits into
Conversation
Closed
Port of ggml-org/llama.cpp aman/qwen4-opt (f72ec5a "llama: fix qwen4exp"). QSA now reuses the GLM5-Next k-pool machinery instead of its own set_input_qsa: blocks are compress_ratio consecutive cells in sequence order, each scored by one cached pooled key (mean of the raw indexer keys, normed and rotated to the M-RoPE position of its first member). Only the blocks a ubatch completes or regroups are re-pooled, and the selection is the top blocks plus the incomplete tail, as in the reference. Adapted to the fork's k-pool API (per-ubatch layout, ubatch-sized get_n_kpool/get_n_kpool_new, merged layouts for shared tokens) rather than upstream's persistent kpool_layout: - indexer_kpool_row / indexer_kpool_by_order hparams; qwen4exp rows are raw key | pooled key - set_input_kpool takes new_pool_pos, and in order mode places a token by the rank of its own cell, so M-RoPE image tokens sharing a position get distinct ranks - qwen4exp reads the pooled slots through views on the indexer storage, as glm5-next does - the unified multi-sequence QSA fallback to dense attention is dropped: pools are per sequence now; test-llama-archs --qsa-unified-multiseq now checks that QSA runs there and still matches dense attention Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
amangupta-tether
force-pushed
the
qwen4exp/01-qsa-kpool
branch
from
October 2, 2026 02:53
f8bf891 to
844082e
Compare
Follow-up from the merged ggml-org#29751: add the QSA selection to the kq_mask in its own shape instead of a flattened 2D view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Graph part of ggml-org#29819 (qwen4exp: fix tests). Padded pools and missing tail cells share the n_kv sentinel, and top_k can fill a short selection with invisible pools that overlap the tail, so the selection scatter wrote some rows from several threads. Map every dead slot to its own dump row n_kv + slot instead. The hybrid-idx half of that change is not needed here: this k-pool code pads the new pool list with at most one entry, so there are no shared padding cells. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
) Graph part of ggml-org#28569 (re-enable -sm tensor for qwen4exp); the fork never disabled -sm tensor for qwen4exp, so the llama-arch.cpp half does not apply. With host-resident embeddings the PLE gather is a CPU node, and hc_init was first reached through layer 0's PLE path after that gather, so the REPEAT stayed on the CPU and the meta split later viewed a host-resident node. Expanding hc_init right after it is built puts the REPEAT directly before the first device node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Port of ggml-org/llama.cpp
aman/qwen4-opt(f72ec5a, "llama: fix qwen4exp") onto temp-11018. First of two stacked PRs; the MTP port follows on top of this one.Rebased from temp-10549 to temp-11018 on 2026-10-02.
What it does
QSA now goes through the GLM5-Next k-pool indexer instead of its own
set_input_qsa:compress_ratioconsecutive cells in sequence order, scored by one cached pooled key (mean of the raw indexer keys, normed and rotated to the M-RoPE position of its first member)Differences from upstream
The fork's k-pool code is the per-ubatch layout from before upstream merged GLM5-Next (ggml-org#27773), not upstream's persistent
kpool_layout. Rather than syncing GLM5-Next, the fix sits on top of the existing API:indexer_kpool_row(qwen4exp rows areraw key | pooled key) andindexer_kpool_by_orderset_input_kpooltakesnew_pool_pos. In by-order mode a token is placed by the rank of its own cell, so M-RoPE image tokens that share a position get distinct ranks. Merged layouts for shared tokens are unchanged.get_n_kpool/get_n_kpool_newsignatures are kept.test-llama-archs --qsa-unified-multiseqnow checks that QSA runs with a unified multi-sequence cache and still matches dense attention, instead of asserting the old dense fallback.Otherwise
qwen4exp.cppis identical to upstream's fixed version, apart from the fork's PLE input (nollama_prefetch_rows).Follow-up commits from upstream
-sm tensorfor qwen4exp.Testing
test-llama-archs:--qsa-unified-multiseq,--glm5-kpool-sequences, and-a qwen4exp|glm5-nexton CPU (NMSE + save/load roundtrip) all pass.SOFT_MAX failed. Plain-a llamaMoE aborts the same way on this branch, and the base did the same on temp-10549, so it isn't from this change.aman/qwen4-opt:38.7 s per pass at 8k.
llama-eval-callbackrun (one op at a time) produces identical sums for all 13,260 named tensors with and without it.Heads-up: #316 also edits
llama-memory-hybrid-idx.{h,cpp}, in different functions. Whichever lands second will need a small rebase.🤖 Generated with Claude Code