Repository navigation
perf: accelerate GPT-OSS MXFP4 decode on M4 Max - #14
Merged
Merged
Conversation
This was referenced Sep 5, 2026
13 tasks done
4 of 10 tasks
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.
GPT-OSS 20B gathered MXFP4 decode uses width 2880, which misses the existing fast vector kernel's 512-element alignment. Add a masked-tail variant: five full blocks followed by 320 values, read only by the 20 participating lanes. Preserve FP32 accumulation and the existing gathered indices/strides.
Enable this route automatically only on physical M4 Max architecture
applegpu_g16s, with exact MXFP4/group32/4-bit/E32/K2880/N2880-or5760 and FP32/BF16 gates.MLX_GPTOSS_MXFP4_DECODE_FAST_TAIL=0restores the original route. Unsupported calls retain the general path. A separately measured 32x32x32 sorted prefill tile remains opt-in throughMLX_GPTOSS_MXFP4_PREFILL_TILE=m32n32k32.flowchart LR subgraph Before A[GPT-OSS decode: K2880] --> B[gather_qmv alignment check] B --> C[General gathered MXFP4 kernel] C --> D[Next-token logits] end subgraph After E[GPT-OSS decode: K2880] --> F[gather_qmv shape and physical-device gates] F -->|Measured shape/device| G[gather_qmv_fast_tail: 2560 + 320] F -->|Fallback or rollback| H[Existing kernel] G --> I[Next-token logits] H --> I endValidation: actual Swift GPU tests cover ragged expert boundaries, partial rows, varying scale exponents, FP32/BF16, B=1/2/4/8, sparse tail-edge values, and a bit-exact unsupported-K fallback. The C++ doctest additions were not separately built; the production C++ bridge and generated Metal source were built and exercised by the Swift suite. Two ABBA cycles measured roughly 2–3% more short-context aggregate decode throughput at B=1/2/4, with exact generated sequences. Floating-point reduction order changes, so bit identity is not promised for every input. The prefill option is not a universal default.
The dependent MLX-Swift PR includes the matching generated
fp_quantized.cppand source pin. No production deployment.