Repository navigation
ggml-webgpu: improve MTP inference by using mat-vec path for small batches - #24811
Conversation
| ggml_tensor * dst) { | ||
| // Determine if this is a mat-vec operation | ||
| bool is_vec = (dst->ne[1] == 1); | ||
| bool use_mat_vec = (dst->ne[1] <= 4); |
There was a problem hiding this comment.
Vulkan sets this threshold to 8, but I confirmed that some cases degrade performance on WebGPU when n >= 5. For example, Q2_K and Q5_K degrade at n=5, and all k-quants types degrade at n=8.
| if (key.vectorized) { | ||
| variant += "_vectorized"; | ||
| } | ||
| defines.push_back(std::string("NUM_COLS=1")); |
There was a problem hiding this comment.
I think that it is difficult to use mul_mat_vec_acc.tmpl as is for mul_mat_id, since the tokens for a single selected expert are not contiguous. So this PR doesn't address mul_mat_id, and I'll leave it as future work.
|
@reeselevine, can you check whether it works and measure the performance of this PR on an RTX machine when you have a chance? In my NVIDIA environment (Tesla V100), running the above MTP model produces random incorrect outputs, so I cannot measure the performance myself yet (for MMVQ path). |
|
Interesting, |
|
|
|
Thanks for the addition! I'm having some trouble getting mtp to work on the NVIDIA GPU I have access to, it's on a server with multiple GPUs and it seems like some combination of trying to get WebGPU to use it and MTP support is causing issues... I'll try and look into that at some point here (I'm on a bit of vacation this week), but in the meantime I think we can trust that this should help :). I also think eventually we should look into failures on GPUs like the V100 and Intel GPUs (like this PR: #24887). But no big rush on that. |
|
@reeselevine Thank you for checking this. Yeah, MTP seems to cause some issues on NVIDIA as expected.
I see, I'll investigate when I have a chance. And thank you for the review during your vacation. Enjoy it! :) |
…tches (ggml-org#24811) * ggml-webgpu: improve small batches decoding * Add barrier to the NUM_COLS loop in mul-mat-vec
…tches (ggml-org#24811) * ggml-webgpu: improve small batches decoding * Add barrier to the NUM_COLS loop in mul-mat-vec
…tches (ggml-org#24811) * ggml-webgpu: improve small batches decoding * Add barrier to the NUM_COLS loop in mul-mat-vec
…tches (ggml-org#24811) * ggml-webgpu: improve small batches decoding * Add barrier to the NUM_COLS loop in mul-mat-vec
Overview
This PR improves small-batch decoding performance by applying the mat-vec path to these cases. This is particularly expected to improve the performance of speculative decoding, such as MTP.
The following table shows the performance of token decoding with
llama-serveron native WebGPU on M2 Pro (32 GiB RAM).Qwen 3.5 4B (Q4_K, MTP GGUF)
Based on Qwen/Qwen3.5-4B
Qwen 3.6 27B (Q4_K, MTP GGUF)
Based on ggml-org/Qwen3.6-27B-MTP-BF16-GGUF
I can confirm that MTP decoding performance is significantly improved, and it is slightly better than normal decoding in this benchmark except for one case.
Additional Information
Reproduction (Qwen 3.6 27B):
Quantize with:
llama-quantize Qwen3.6-27B-MTP-BF16.gguf Qwen3.6-27B-MTP-Q4_K_M.gguf Q4_K_MRun llama-server:
Requirements
mul_mat_vec_acc.tmpland to analyze the performance log files.