Skip to content

llama : build the k-pool selection in the causal mask layout - #30480

Merged
ggerganov merged 2 commits into
masterfrom
gg/kpool-select-mask-layout
Oct 14, 2026
Merged

ggerganov merged 2 commits into
masterfrom
gg/kpool-select-mask-layout

Conversation

@ggerganov

Copy link
Copy Markdown
Member

Overview

The glm5-next k-pool indexer folds the causal mask into the selection through a [n_kv, n_tokens] view. That puts a reshape of the mask in front of the add, and a second reshape of the result in front of every layer that reads the selection - including the shared-indexer layers that reuse it.

build_qsa_sel in qwen4exp already builds the selection directly in the causal mask layout (#29751). This does the same in build_kpool_select, passes the selection straight to build_attn_mha in both models (dropping the now-degenerate reshape in build_attn_qsa), and asserts that the selection width matches the input it is taken from.

No numerical change - the two layouts are byte-identical (ggml_view_4d keeps nb[0] as the element size, so the old view_2d plus the caller-side reshape_4d produced the same strides), only the two reshape nodes per indexer layer go away.

Requirements

- the glm5-next indexer folded the causal mask in through a [n_kv, n_tokens]
  view: one reshape of the mask ahead of the add, and one of the result ahead
  of every layer reading the selection, including the shared-indexer layers
- build the selection directly in the mask layout, as qwen4exp already does,
  and drop the now-degenerate reshape in its attention as well
- assert the selection width matches the input it is taken from

Assisted-by: pi:llama.cpp/Qwen3.8-Flash-Next
@github-actions github-actions Bot added the model Model specific label Oct 13, 2026
Comment thread src/models/glm5-next.cpp Resolved
@ggerganov
ggerganov marked this pull request as ready for review October 13, 2026 21:22
@ggerganov
ggerganov requested a review from CISC as a code owner October 13, 2026 21:22
@ggerganov
ggerganov merged commit e7268bf into master Oct 14, 2026
18 checks passed
danielhanchen added a commit to unslothai/llama.cpp that referenced this pull request Oct 14, 2026
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 24, 2026
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
…g#30480)

* llama : build the k-pool selection in the causal mask layout

- the glm5-next indexer folded the causal mask in through a [n_kv, n_tokens]
  view: one reshape of the mask ahead of the add, and one of the result ahead
  of every layer reading the selection, including the shared-indexer layers
- build the selection directly in the mask layout, as qwen4exp already does,
  and drop the now-degenerate reshape in its attention as well
- assert the selection width matches the input it is taken from

Assisted-by: pi:llama.cpp/Qwen3.8-Flash-Next

* cont : remove comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Model specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants