Skip to content

model: MTP support for Qwen3-Next - #25589

Merged
yomaytk merged 9 commits into
ggml-org:masterfrom
yomaytk:qwen3next-mtp
Aug 3, 2026
Merged

yomaytk merged 9 commits into
ggml-org:masterfrom
yomaytk:qwen3next-mtp

Conversation

@yomaytk

@yomaytk yomaytk commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

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.gguf file.

Also, pass the optional .scale tensors 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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - I used AI for reviewing, refactoring and benchmarking, and to help me understand the MTP implementation.

@yomaytk
yomaytk requested a review from CISC as a code owner July 12, 2026 15:39
@github-actions github-actions Bot added model Model specific conversion labels Jul 12, 2026
Comment thread src/models/qwen3next.cpp
// 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],

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This function is not used in this file, and the same function is defined in delta-net-base.cpp, so I removed it.

@yomaytk

yomaytk commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

@am17an could you review this when you have a chance?

@yomaytk
yomaytk requested a review from am17an July 12, 2026 16:05

@am17an am17an left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The cpp changes look fine

Comment thread conversion/qwen.py
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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread conversion/qwen.py
model_arch = gguf.MODEL_ARCH.QWEN35


@ModelBase.register("Qwen3_5MoeForConditionalGeneration", "Qwen3_5MoeForCausalLM")
class Qwen3_5MoeTextModel(_Qwen35MtpMixin, _Qwen35MRopeMixin, _LinearAttentionVReorderBase):
class Qwen3_5MoeTextModel(_Qwen35MRopeMixin, _LinearAttentionVReorderBase):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I confirmed that Qwen3.5 and Qwen3.5-MoE still convert correctly with this change.

@engrtipusultan

Copy link
Copy Markdown

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

@yomaytk

yomaytk commented Jul 14, 2026 •

Copy link
Copy Markdown
Member Author

@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.
For example, you can run the command as follows.
python3 convert_hf_to_gguf.py /path/to/Qwen3-Next --mtp --outfile Qwen3-Next-MTP-only-BF16.gguf --outtype bf16

@yomaytk

yomaytk commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

Comment thread gguf-py/gguf/constants.py Resolved
Comment thread src/models/qwen3next.cpp Resolved
@yomaytk

yomaytk commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@CISC Thanks! rebased and addressed the comment.

Comment thread src/models/qwen3next.cpp Resolved
Comment thread src/models/qwen3next.cpp Resolved
yomaytk and others added 2 commits August 3, 2026 16:08
Co-authored-by: Sigbjørn Skjæret <[email protected]>
Co-authored-by: Sigbjørn Skjæret <[email protected]>
@yomaytk yomaytk added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Aug 3, 2026
@yomaytk

yomaytk commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@CISC sorry, can I get approval again before merging?

@yomaytk
yomaytk merged commit 4ed2b13 into ggml-org:master Aug 3, 2026
26 of 28 checks passed
@yomaytk
yomaytk deleted the qwen3next-mtp branch August 3, 2026 08:15
@d-shehu

d-shehu commented Aug 3, 2026

Copy link
Copy Markdown

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
No MTP: 94 t/s
MTP: 59 t/s.

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:

  1. Converted from Qwen 3 Safe tensor per instructions (slow)
  2. Qwen3-Next-80B-A3B-Instruct-MTP-only-BF16.gguf (slower)
  3. Qwen3-Next-80B-A3B-Instruct-MTP-only-Q8_0.gguf (slowest)

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!

@yomaytk

yomaytk commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

@d-shehu
Thanks for testing. I noticed that the published Q8_0 MTP gguf seems to be corrupted, so I re-uploaded it, and I confirmed that using the new Q8_0 version provide the performance improvement on my M5. The main model is unsloth’s Qwen3-Next Q4_K_M gguf.

baseline:

code_python        pred= 192 draft=   0 acc=   0 rate=n/a tok/s=90.9
  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=90.8
  summarize          pred= 192 draft=   0 acc=   0 rate=n/a tok/s=91.0
  qa_factual         pred= 192 draft=   0 acc=   0 rate=n/a tok/s=90.3
  translation        pred=  34 draft=   0 acc=   0 rate=n/a tok/s=92.7
  creative_short     pred= 192 draft=   0 acc=   0 rate=n/a tok/s=90.8
  stepwise_math      pred= 192 draft=   0 acc=   0 rate=n/a tok/s=90.4
  long_code_review   pred= 192 draft=   0 acc=   0 rate=n/a tok/s=90.4

MTP with Q8_0 draft model:

code_python        pred= 192 draft= 118 acc= 109 rate=0.924 tok/s=119.4
  code_cpp           pred= 192 draft= 122 acc= 110 rate=0.902 tok/s=120.3
  explain_concept    pred= 192 draft= 109 acc=  90 rate=0.826 tok/s=101.8
  summarize          pred= 192 draft= 113 acc=  97 rate=0.858 tok/s=108.7
  qa_factual         pred= 192 draft= 111 acc= 100 rate=0.901 tok/s=111.2
  translation        pred=  34 draft=  22 acc=  18 rate=0.818 tok/s=98.3
  creative_short     pred= 192 draft=  89 acc=  75 rate=0.843 tok/s=95.0
  stepwise_math      pred= 192 draft= 126 acc= 120 rate=0.952 tok/s=120.6
  long_code_review   pred= 192 draft= 106 acc=  90 rate=0.849 tok/s=98.2

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 MTL0

So, The MTP improves the performance at least on my M5, but it might cause the regression on vulkan for any reason.
I’m curious about whether other qwen models (e.g., qwen3.5-35B-A3B) with mtp draft model improve the performance on you machine, so could you check the performance on those models if possible?

@d-shehu

d-shehu commented Aug 6, 2026

Copy link
Copy Markdown

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.

satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
* 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]>
cubetitled-ui pushed a commit to cubetitled-ui/llama.cpp that referenced this pull request Aug 14, 2026
* 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]>
brittlewis12 pushed a commit to brittlewis12/llama.cpp that referenced this pull request Aug 17, 2026
* 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]>
thecodacus pushed a commit to thecodacus/llama.cpp that referenced this pull request Sep 7, 2026
* 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]>
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conversion 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.

5 participants