TP: fix split state and granularity for fused QKV gemma4, qwen35 - #28965
Conversation
required for gemma4 with --fuse-qkv, where n_embd is 5376 but Q is 8192.
ggerganov
left a comment
There was a problem hiding this comment.
What is the effect before and after this PR?
| // fused full attention layers need Q gate tensors handled like above: | ||
| if (ud->model->arch == LLM_ARCH_QWEN3NEXT || ud->model->arch == LLM_ARCH_QWEN35 || ud->model->arch == LLM_ARCH_QWEN35MOE || | ||
| ud->model->arch == LLM_ARCH_QWEN4EXP) { |
There was a problem hiding this comment.
We should deduplicate this condition if it has to match the one earlier:
| // fused full attention layers need Q gate tensors handled like above: | |
| if (ud->model->arch == LLM_ARCH_QWEN3NEXT || ud->model->arch == LLM_ARCH_QWEN35 || ud->model->arch == LLM_ARCH_QWEN35MOE || | |
| ud->model->arch == LLM_ARCH_QWEN4EXP) { | |
| // fused full attention layers need Q gate tensors handled like above: | |
| // TODO: deduplicate with the condition in `get_split_segments` [TAG_SPLIT_FUSED_QKV_QWEN] | |
| if (ud->model->arch == LLM_ARCH_QWEN3NEXT || ud->model->arch == LLM_ARCH_QWEN35 || ud->model->arch == LLM_ARCH_QWEN35MOE || | |
| ud->model->arch == LLM_ARCH_QWEN4EXP) { |
| if (ud->model->arch == LLM_ARCH_QWEN3NEXT || ud->model->arch == LLM_ARCH_QWEN35 || ud->model->arch == LLM_ARCH_QWEN35MOE || | ||
| ud->model->arch == LLM_ARCH_QWEN4EXP) { |
There was a problem hiding this comment.
| if (ud->model->arch == LLM_ARCH_QWEN3NEXT || ud->model->arch == LLM_ARCH_QWEN35 || ud->model->arch == LLM_ARCH_QWEN35MOE || | |
| ud->model->arch == LLM_ARCH_QWEN4EXP) { | |
| // TODO: clarify why this is necessary specifically for these models | |
| // TODO: deduplicate [TAG_SPLIT_FUSED_QKV_QWEN] | |
| if (ud->model->arch == LLM_ARCH_QWEN3NEXT || ud->model->arch == LLM_ARCH_QWEN35 || ud->model->arch == LLM_ARCH_QWEN35MOE || | |
| ud->model->arch == LLM_ARCH_QWEN4EXP) { |
On master both gemma4 and qwen35/qwen35moe crash for models exported with I don't really have benchmarks, but I seem to get +2% tg on Qwen 3.6 35B-A3B with fused QKV on 4 cards (Q8_0: 70.86 -> 72.4), although both numbers use additional patches (force enabling cudagraphs on P100 which is only a net positive for MoE's on 4 cards or more).
My understanding is that attn_q contains both q and gate tensors, which is why it has double the elements and needs double the granularity. |
|
@ggerganov I added a tag like your suggestions although I named it The change to segmentation for qwen was necessary as the current code assumes the layout for recurrent layers for QKV tensors and no segmentation was necessary for other layers until now. |
…l-org#28965) * model: calculate split states for attn_qkv from n_head * n_embd_head_k required for gemma4 with --fuse-qkv, where n_embd is 5376 but Q is 8192. * model: handle fused full attention layers for qwen35/qwen35moe * model: add TODO: [TAG_SPLIT_QGATE_QWEN]
…l-org#28965) * model: calculate split states for attn_qkv from n_head * n_embd_head_k required for gemma4 with --fuse-qkv, where n_embd is 5376 but Q is 8192. * model: handle fused full attention layers for qwen35/qwen35moe * model: add TODO: [TAG_SPLIT_QGATE_QWEN]
Overview
#22780 adds the option to fuse QKV for models which previously had either no QKV tensors (
gemma4) or for which QKV tensors only existed for specific layers (qwen35,qwen35moe, ...).Gemma 4 31B:
n_embdis 5376 but Q is 8192 (raisingGGML_ASSERT(tensor->ne[axis] == n_embd + 2*n_embd_gqa);), so calculate fromn_head * n_embd_head_kinstead.Qwen 27B/35B-A3B: added a copy of the default qkv handler for full attention layers, with
n_embddoubled for Q gate tensors, and add the doubling inget_split_granularityas well.Additional information
I tested Gemma 4 31B, Qwen 3.8 27B and Qwen 3.6 35B-A3B on 4 P100 cards.
Requirements