Skip to content

qwen: reshape output to 2d instead of 3d - #30823

Merged
ggerganov merged 2 commits into
masterfrom
aman/fix-qwen-graph-multi-seq
Oct 20, 2026
Merged

ggerganov merged 2 commits into
masterfrom
aman/fix-qwen-graph-multi-seq

Conversation

@am17an

@am17an am17an commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR changes the final output shape to be [n, n_tokens * n_seqs] instead of [n, n_tokens, n_seqs] for better performance during multi-seq decode.

Additional information

Requirements

@am17an
am17an requested a review from CISC as a code owner October 19, 2026 17:18
@github-actions github-actions Bot added the model Model specific label Oct 19, 2026

@CISC CISC left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could have sworn there was a reason for it, perhaps outdated?

Comment thread src/models/qwen35.cpp Outdated

// Final reshape: [head_dim, n_heads, n_tokens, n_seqs] -> [n_tokens, n_seqs, n_heads * head_dim]
ggml_tensor * final_output = ggml_reshape_3d(ctx0, attn_out_norm, head_v_dim * num_v_heads, n_seq_tokens, n_seqs);
// Final reshape: [head_dim, n_heads, n_tokens, n_seqs] -> [n_tokens * n_seqs, n_heads * head_dim]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you also fix the comments:

Suggested change
// Final reshape: [head_dim, n_heads, n_tokens, n_seqs] -> [n_tokens * n_seqs, n_heads * head_dim]
// Final reshape: [head_dim, n_heads, n_tokens, n_seqs] -> [n_heads * head_dim, n_tokens * n_seqs]

Comment thread src/models/qwen35.cpp Outdated
Comment on lines 476 to 477

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this reshape still needed?

@am17an am17an added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 20, 2026
@ggerganov
ggerganov merged commit 839a572 into master Oct 20, 2026
20 checks passed
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 24, 2026
MuFengMuXue pushed a commit to MuFengMuXue/llama.cpp-gfx906 that referenced this pull request Oct 26, 2026
* qwen: reshape output to 2d instead of 3d

* remove final reshape, fix comments
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
* qwen: reshape output to 2d instead of 3d

* remove final reshape, fix comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. model Model specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants