MTP: option to use re-quantized output tensor for better TG performance#1809
Merged
Conversation
ahoplock
reviewed
May 16, 2026
| } | ||
| return true; | ||
| } | ||
| if (arg == "--mtp-requantized-output-tensor" || arg == "-mtprot") { |
There was a problem hiding this comment.
I know it's already merged at this point but you have this as --mtp-requantize-output-tensor (missing 'd') in line 3036 and in the PR description.
|
Pure magic, thanks for this, TG throughput jumped ~24% average — massive win 💪 Setup
Run command: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR improves TG performance for Qwen3.5/3.6 models by 5-10% when using MTP. The performance gain depends on the quantization type of the model output tenor (see below).
The output tensor of the Qwen3.5/3.6 models is giant due to the very large vocabulary (248320). For the 27B dense variant the output tensor has 1.27 billion elements! The MTP layer uses the output tensor of the main model. The other tensors in the MTP layer are small in comparison: about 425 million for the 27B dense variant. This means that when generating draft tokens the bulk of the time is spent in the matrix multiplication with the output tensor. As TG is memory bound, one can expect increased MTP performance by decreasing the size of the output tensor. But using fewer bits for the output tensor will also decrease the quality of the main model. Hence, it is better to create a new output tensor, to be used only by the MTP layer, that is quantized with fewer bits than the original output tensor. This is what this PR does.
Initially I was trying to add an additional output tensor for the MTP layer while quantizing (or re-quantizing) the model. But adding an extra tensor to an existing GGUF context proved more difficult than expected, so I (for now) abandoned this approach. Instead, the additional output tensor is created on-the-fly while loading the model when
is added to the command line.
new_typeis the name of the quantization type as defined inggml(the name must match exactly), e.g.,iq4_ks, q4_0, etc.Picking the quantization type is a matter of experimentation. The fewer bits are used, the faster the draft generation. But as the quality of the quantization decreases with decreasing bits, one might expect that the acceptance rate will also decrease, which will then reduce observed TG performance. In the testing I have done, using
-mtprot iq4_ksprovided in the range of 10% improvement for Qwen3.6-27B-Q8_0 (so, the output tensor isQ8_0) without actually decreasing acceptance rate within statistical uncertainty.Beware
IQ2_KS). I will try to add the ability to do the re-quantization offline withllama-quantizein a follow up PR.-mtprot iq4_ksabout 645 MiB are required. Hence, don't use this option if short on RAM/VRAM (or, if you still decide to use it, don't complain if you get OOM).