Repository navigation
fix(mtp): scope speculative command-buffer caps to Qwen targets - #4386
Merged
Merged
Conversation
jundot#4396 removed debug env switches from production code. Remove the OMLX_MTP_COMMAND_BUFFER_CAPS override added here as well, so the raised caps follow only the target type and the GPU gate.
jundot
approved these changes
Oct 12, 2026
jundot
left a comment
Owner
There was a problem hiding this comment.
The raised caps were only ever measured on Qwen, so keeping them there makes sense. I ran an ABBA on M3 Ultra, and GLM-5.3-Flash came out about the same either way while Gemma 4 didn't lose anything without the raised caps.
| Model (Lightning MTP, greedy, 256 tokens) | Prompt | main | PR | Change |
|---|---|---|---|---|
| GLM-5.3-Flash oQ4e | ~600 tokens | 59.23 tok/s | 59.77 tok/s | +0.9% |
| GLM-5.3-Flash oQ4e | ~13K tokens | 53.66 tok/s | 53.95 tok/s | +0.5% |
| Gemma 4 31B oQ4e | ~700 tokens | 46.98 tok/s | 48.56 tok/s | +3.4% |
| Gemma 4 31B oQ4e | ~16K tokens | 34.75 tok/s | 36.25 tok/s | +4.3% |
Thanks for the careful A/B, LGTM, merging.
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.
Summary
#3797 raises MLX's command-buffer caps to 200 ops / 512 MB around each Lightning MTP and batched DFlash speculative step on M5 and M3-family GPUs. The context manager sits on the shared speculative path, so the raised caps also apply to targets added later, such as GLM-5.3-Flash, where they slow decode.
This PR keeps the raised caps for the Qwen target types those paths were tuned for (
qwen3_5,qwen3_5_moe,qwen3_5_vl,qwen3_6,qwen3_6_moe,qwen4_exp,qwen4_exp_text) and leaves MLX's current caps untouched for other targets. The type is read from the loaded target and itslanguage_modelwrapper (model_type,args,config,text_config); drafter metadata is not consulted. Restoration after each step and the prefill caps are unchanged.There is no env override, following #4396.
docs/TESTING.mddocuments the target selection and the test command.Validation
Hardware: Mac Studio M5 Ultra, 256 GB, macOS 27.
This PR on MLX 0.32.3. Measured at
e6e2fc80(onmainatd1a928dc; the follow-up commit only removes the env override), officialmlx/mlx-metal0.32.3 wheels, native kernels rebuilt from this tree. GLM-5.3-Flash (3.5-bit oQ mixed quantization, MTP draft 3), temperature 0, 256 output tokens. "On" forced the raised caps through the env override thate6e2fc80still had (removed in the follow-up commit), which matchesmainon M5; "off" is this PR's default for GLM. Four ABBA blocks, one per code prompt, each with one JSON and one long-context request (two unique prompts each); 48 measured requests after 16 warm-up requests.Per-block decode change for caps off vs. on, averaged over the 4 blocks:
All 64 responses (48 measured, 16 warm-up) had identical token IDs and text between on and off. Peak process footprint was 165.5 GiB with caps on and 165.3 GiB with caps off.
Earlier measurements on MLX 0.32.2. A local build of upstream
mainata435a373(2026-10-05) plus local patches outside this code path, comparing caps on and off on the same build.GLM-5.3-Flash (3.5-bit oQ mixed quantization, MTP draft 3). "Off" skipped only the
set_command_buffer_capscall. Four ABBA/BAAB blocks after warm-up, 256 output tokens, cold prefix cache. Per-block decode change for caps off vs. on, averaged over the 4 blocks:NLL on 4,608 held-out targets and 36 full-vocabulary logit rows were bit-identical between on and off, and all 82 generated responses were byte-identical. Functional checks passed 9/9 in both arms. Peak process footprint was 165.5 GiB with caps on and 165.4 GiB with caps off.
Qwen3.8-Flash-Next (oQ4 with MTP,
qwen4_exp). Caps forced on and off through a local override. Four code prompts, ABBA, temperature 0, 256 output tokens, 16 measured runs. The geometric-mean decode change for on vs. off was +0.32% (per prompt +1.26%, −0.04%, −0.14%, +0.20%), and output token IDs were identical. This PR therefore keeps the existing Qwen default; it does not claim a Qwen speedup.Tests (M4 Mac mini, GPU detection and the native setter mocked):
python -m pytest -q tests/test_mlx_lm_mtp_patch.py -k "spec_command_buffers or spec_caps"13 passed. The new cases fail on
main, and 3 of them fail if the target check is removed.Not run: the default suite (
python -m pytest) locally, left to CI.Checklist