-
Notifications
You must be signed in to change notification settings - Fork 24.1k
TP: fix split state and granularity for fused QKV gemma4, qwen35 #28965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -597,8 +597,20 @@ struct ggml_backend_meta_split_state llama_meta_device_get_split_state(const str | |||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| auto get_split_segments = [&](int axis, uint32_t il) -> std::vector<std::pair<int64_t, uint32_t>> { | ||||||||||||||||
| // TODO: clarify why this is necessary specifically for these models | ||||||||||||||||
| // TODO: deduplicate condition [TAG_SPLIT_QGATE_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) { | ||||||||||||||||
|
|
||||||||||||||||
| // fused full attention layers with Q gate tensors that need n_embd doubled: | ||||||||||||||||
| if (!hparams.is_recr(il) && (std::regex_match(tensor_name, pattern_qkv_weight) || std::regex_match(tensor_name, pattern_qkv_bias))) { | ||||||||||||||||
| const int64_t n_embd = hparams.n_head(il) * hparams.n_embd_head_k(il) * 2; | ||||||||||||||||
| const int64_t n_embd_gqa = hparams.n_embd_v_gqa(il); | ||||||||||||||||
| GGML_ASSERT(hparams.n_embd_k_gqa(il) == n_embd_gqa); | ||||||||||||||||
| GGML_ASSERT(tensor->ne[axis] == n_embd + 2*n_embd_gqa); | ||||||||||||||||
| return {{n_embd, 1}, {n_embd_gqa, 2}}; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const int64_t head_k_dim = hparams.ssm_d_state; | ||||||||||||||||
| const int64_t head_v_dim = hparams.ssm_d_state; | ||||||||||||||||
| const int64_t n_k_heads = hparams.ssm_n_group; | ||||||||||||||||
|
|
@@ -648,9 +660,9 @@ struct ggml_backend_meta_split_state llama_meta_device_get_split_state(const str | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| if (std::regex_match(tensor_name, pattern_qkv_weight) || std::regex_match(tensor_name, pattern_qkv_bias)) { | ||||||||||||||||
| const int64_t n_embd = hparams.n_embd; | ||||||||||||||||
| const int64_t n_embd = hparams.n_head(il) * hparams.n_embd_head_k(il); | ||||||||||||||||
| const int64_t n_embd_gqa = hparams.n_embd_v_gqa(il); | ||||||||||||||||
| GGML_ASSERT(hparams.n_embd_k_gqa() == n_embd_gqa); | ||||||||||||||||
| GGML_ASSERT(hparams.n_embd_k_gqa(il) == n_embd_gqa); | ||||||||||||||||
| GGML_ASSERT(tensor->ne[axis] == n_embd + 2*n_embd_gqa); | ||||||||||||||||
| return {{n_embd, 1}, {n_embd_gqa, 2}}; | ||||||||||||||||
| } | ||||||||||||||||
|
|
@@ -736,6 +748,7 @@ struct ggml_backend_meta_split_state llama_meta_device_get_split_state(const str | |||||||||||||||
| if (std::regex_match(tensor_name, pattern_q_weight) || std::regex_match(tensor_name, pattern_q_bias)) { | ||||||||||||||||
| GGML_ASSERT(segments.size() == 1); | ||||||||||||||||
| // some models have Q gate tensors, for those cases the granularity needs to be doubled: | ||||||||||||||||
| // TODO: deduplicate condition [TAG_SPLIT_QGATE_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) { | ||||||||||||||||
| return {std::lcm(2*n_embd_q, blck_size_perf)}; | ||||||||||||||||
|
|
@@ -763,6 +776,12 @@ struct ggml_backend_meta_split_state llama_meta_device_get_split_state(const str | |||||||||||||||
| } | ||||||||||||||||
| if (std::regex_match(tensor_name, pattern_qkv_weight) || std::regex_match(tensor_name, pattern_qkv_bias)) { | ||||||||||||||||
| GGML_ASSERT(segments.size() == 2); | ||||||||||||||||
| // fused full attention layers need Q gate tensors handled like above: | ||||||||||||||||
| // TODO: deduplicate condition [TAG_SPLIT_QGATE_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) { | ||||||||||||||||
|
Comment on lines
+779
to
+782
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should deduplicate this condition if it has to match the one earlier:
Suggested change
|
||||||||||||||||
| return {std::lcm(2*n_embd_q, blck_size_perf), granularity_kv}; | ||||||||||||||||
| } | ||||||||||||||||
| return {granularity_q, granularity_kv}; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.