Repository navigation
model: MTP support for Qwen3-Next - #25589
Conversation
| // input dim: [x, y, c, b] | ||
| // output dim: [x, y, 1, b] | ||
| static ggml_tensor * get_slice_2d(ggml_context * ctx0, ggml_tensor * t, int64_t c) { | ||
| return ggml_view_4d(ctx0, t, t->ne[0], t->ne[1], 1, t->ne[3], |
There was a problem hiding this comment.
This function is not used in this file, and the same function is defined in delta-net-base.cpp, so I removed it.
|
@am17an could you review this when you have a chance? |
am17an
left a comment
There was a problem hiding this comment.
The cpp changes look fine
| if len(parts) == 4 and parts[1] == "layers" and parts[2].isdecimal(): | ||
| mtp_idx = int(parts[2]) | ||
| name = f"model.layers.{cls._original_block_count + mtp_idx}.{parts[3]}" | ||
| cls.opt_num_mtp_layers = max(cls.opt_num_mtp_layers, mtp_idx + 1) |
There was a problem hiding this comment.
Qwen3-Next's HF config doesn't include mtp_num_hidden_layers (unlike Qwen3.5), so I added opt_num_mtp_layers, which is computed from the checkpoint's mtp.* tensors.
| model_arch = gguf.MODEL_ARCH.QWEN35 | ||
|
|
||
|
|
||
| @ModelBase.register("Qwen3_5MoeForConditionalGeneration", "Qwen3_5MoeForCausalLM") | ||
| class Qwen3_5MoeTextModel(_Qwen35MtpMixin, _Qwen35MRopeMixin, _LinearAttentionVReorderBase): | ||
| class Qwen3_5MoeTextModel(_Qwen35MRopeMixin, _LinearAttentionVReorderBase): |
There was a problem hiding this comment.
I confirmed that Qwen3.5 and Qwen3.5-MoE still convert correctly with this change.
|
Do you have any MTP only GGUF created for Qwen3-Next-80B-A3B. I have already Qwen3-Next-80B-A3B downloaded I would like to test with MTP only GGUF |
|
@engrtipusultan Unfortunately, I haven’t uploaded the MTP-only gguf to HF hub yet, but I think you can convert the already downloaded Qwen3-Next model to it with this PR. |
|
@engrtipusultan I uploaded mtp-only gguf (bf16, q8_0) here: https://huggingface.co/yomaytk/Qwen3-Next-80B-A3B-Instruct-MTP-HEAD-GGUF, so I think you can test using this. |
Co-authored-by: Sigbjørn Skjæret <[email protected]>
|
@CISC Thanks! rebased and addressed the comment. |
Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Sigbjørn Skjæret <[email protected]>
|
@CISC sorry, can I get approval again before merging? |
|
I paired my converted MTP layer with Unsloth Qwen 3 Next model (Q4 KM) resulted in 50% reduction in speed, best case after tweaking the settings. Other settings resulted in even slower TG. I also tried yomaytk's converted GGUFs. As slow or slower. TG Removing MTP arguments restored performance so it's not a regression in code, etc. Main Model: Unsloth Qwen3-Next-80B-A3B-Instruct Q4 KM Draft Models:
Spec Dec Arguments: --spec-type draft-mtp --spec-draft-n-max 4 --spec-draft-p-min 0.6 --spec-draft-ngl 999 --device-draft Vulkan0,Vulkan1 This is with a dual R9700 (Vulkan), 5950x on Ubuntu Server 24.04 headless / minimized. All layers on GPU! |
|
@d-shehu baseline: MTP with Q8_0 draft model: The command is as follows: ./build_metal_release/bin/llama-server -m Qwen3-Next-80B-A3B-Instruct-Q4_K_M.gguf \
-md Qwen3-Next-80B-A3B-Instruct-MTP-only-Q8_0.gguf --spec-draft-n-max 2 --spec-draft-p-min 0.6 \
-ngl all --spec-type draft-mtp --port 8933 -dev MTL0So, The MTP improves the performance at least on my M5, but it might cause the regression on vulkan for any reason. |
|
Thanks for your hard work! I checked your latest MTP GGUF with a few variations on --spec-draft-n-max as well as --spec-draft-ngl ... etc. Enabling MTP slows down TG from 93 t/s to 70-73 t/s. I tested with dual R9700 running Vulkan with split layer mode. I'd chalk it up diffs in quant but I get the same slowdown when I convert my own MTP GGUF from safe tensor with same quant as Unsloth's. With ROCM, I did see an improvement from 56.1 to 81 t/s. But Vulkan layer split seems to significantly outperform ROCm so it's still faster to just do the former without MTP. Anyways, perf is good enough without MTP. Perhaps other folks with similar HW will test / verify. Thanks again. |
* mtp for qwen3nex * fix for python type-check * Fix to compute num_mtp from directly mtp layer * define opt_num_mtp_layers in _QwenMtpMixin and fix some comments * Fix for python type check * Update gguf-py/gguf/constants.py Co-authored-by: Sigbjørn Skjæret <[email protected]> * rebase and add load_mtp flags * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> --------- Co-authored-by: Sigbjørn Skjæret <[email protected]>
* mtp for qwen3nex * fix for python type-check * Fix to compute num_mtp from directly mtp layer * define opt_num_mtp_layers in _QwenMtpMixin and fix some comments * Fix for python type check * Update gguf-py/gguf/constants.py Co-authored-by: Sigbjørn Skjæret <[email protected]> * rebase and add load_mtp flags * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> --------- Co-authored-by: Sigbjørn Skjæret <[email protected]>
* mtp for qwen3nex * fix for python type-check * Fix to compute num_mtp from directly mtp layer * define opt_num_mtp_layers in _QwenMtpMixin and fix some comments * Fix for python type check * Update gguf-py/gguf/constants.py Co-authored-by: Sigbjørn Skjæret <[email protected]> * rebase and add load_mtp flags * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> --------- Co-authored-by: Sigbjørn Skjæret <[email protected]>
* mtp for qwen3nex * fix for python type-check * Fix to compute num_mtp from directly mtp layer * define opt_num_mtp_layers in _QwenMtpMixin and fix some comments * Fix for python type check * Update gguf-py/gguf/constants.py Co-authored-by: Sigbjørn Skjæret <[email protected]> * rebase and add load_mtp flags * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> --------- Co-authored-by: Sigbjørn Skjæret <[email protected]>
* mtp for qwen3nex * fix for python type-check * Fix to compute num_mtp from directly mtp layer * define opt_num_mtp_layers in _QwenMtpMixin and fix some comments * Fix for python type check * Update gguf-py/gguf/constants.py Co-authored-by: Sigbjørn Skjæret <[email protected]> * rebase and add load_mtp flags * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> * Update src/models/qwen3next.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> --------- Co-authored-by: Sigbjørn Skjæret <[email protected]>
Overview
This PR adds MTP support for Qwen3-Next.
The following table shows the performance change against several prompts with a converted
Qwen3-Next-80B-A3B-Instruct-MTP-Q4_K_M.gguffile.Also, pass the optional
.scaletensors to the attention / MoE FFN matmuls in the trunk graph (matching qwen35moe).M5 Max Metal
Normal
$ llama-server -m Qwen3-Next-80B-A3B-Instruct-MTP-Q4_K_M.gguf -ngl all --port 8933 code_python pred= 192 draft= 0 acc= 0 rate=n/a tok/s=91.0 code_cpp pred= 192 draft= 0 acc= 0 rate=n/a tok/s=91.0 explain_concept pred= 192 draft= 0 acc= 0 rate=n/a tok/s=91.2 summarize pred= 192 draft= 0 acc= 0 rate=n/a tok/s=90.9 qa_factual pred= 192 draft= 0 acc= 0 rate=n/a tok/s=90.6 translation pred= 34 draft= 0 acc= 0 rate=n/a tok/s=92.4 creative_short pred= 192 draft= 0 acc= 0 rate=n/a tok/s=90.3 stepwise_math pred= 192 draft= 0 acc= 0 rate=n/a tok/s=90.3 long_code_review pred= 192 draft= 0 acc= 0 rate=n/a tok/s=90.5 Aggregate: { "n_requests": 9, "total_predicted": 1570, "total_draft": 0, "total_draft_accepted": 0, "aggregate_accept_rate": null, "wall_s_total": 18.14 }MTP
$ llama-server -m Qwen3-Next-80B-A3B-Instruct-MTP-Q4_K_M.gguf --spec-type draft-mtp -ngl all --port 8080 code_python pred= 192 draft= 155 acc= 139 rate=0.897 tok/s=128.6 code_cpp pred= 192 draft= 155 acc= 139 rate=0.897 tok/s=132.6 explain_concept pred= 192 draft= 167 acc= 135 rate=0.808 tok/s=98.3 summarize pred= 192 draft= 167 acc= 134 rate=0.802 tok/s=99.0 qa_factual pred= 192 draft= 159 acc= 138 rate=0.868 tok/s=112.5 translation pred= 34 draft= 30 acc= 23 rate=0.767 tok/s=98.2 creative_short pred= 192 draft= 192 acc= 126 rate=0.656 tok/s=78.1 stepwise_math pred= 192 draft= 144 acc= 143 rate=0.993 tok/s=157.7 long_code_review pred= 192 draft= 166 acc= 135 rate=0.813 tok/s=96.7 Aggregate: { "n_requests": 9, "total_predicted": 1570, "total_draft": 1335, "total_draft_accepted": 1112, "aggregate_accept_rate": 0.833, "wall_s_total": 15.47 }MTP (with optional parameters)
$ llama-server -m Qwen3-Next-80B-A3B-Instruct-MTP-Q4_K_M.gguf \ --spec-type draft-mtp -ngl all -c 35000 -np 1 -b 2048 -ub 1024 --temp 0 \ --spec-draft-n-max 2 --spec-draft-p-min 0.6 --port 8080 code_python pred= 192 draft= 125 acc= 123 rate=0.984 tok/s=130.9 code_cpp pred= 192 draft= 119 acc= 117 rate=0.983 tok/s=126.4 explain_concept pred= 192 draft= 115 acc= 111 rate=0.965 tok/s=115.0 summarize pred= 192 draft= 113 acc= 110 rate=0.973 tok/s=114.7 qa_factual pred= 192 draft= 118 acc= 114 rate=0.966 tok/s=119.2 translation pred= 34 draft= 22 acc= 21 rate=0.955 tok/s=116.2 creative_short pred= 192 draft= 84 acc= 82 rate=0.976 tok/s=97.9 stepwise_math pred= 192 draft= 125 acc= 125 rate=1.000 tok/s=142.7 long_code_review pred= 192 draft= 104 acc= 97 rate=0.933 tok/s=105.9 Aggregate: { "n_requests": 9, "total_predicted": 1570, "total_draft": 925, "total_draft_accepted": 900, "aggregate_accept_rate": 0.973, "wall_s_total": 14.21 }Requirements