Repository navigation
fix(metal): build the GPT-OSS MXFP4 prefill tile into the metallib - #24
Merged
Merged
Conversation
This was referenced Sep 25, 2026
MLX_GPTOSS_MXFP4_PREFILL_TILE=m32n32k32 selects the gather_qmm_rhs tile bm 32, bn 32, bk 32, wm 2, wn 2. fp_quantized.metal did not instantiate that tile. A build with MLX_METAL_JIT=OFF loads kernels only from mlx.metallib, so it could not load the kernel. Add the two instantiations that quantized.cpp can select: mxfp4, group size 32, 4 bits, transposed weights, float and bfloat16. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Say in the GPT-OSS section of fork.yaml that fp_quantized.metal builds the two m32n32k32 prefill-tile kernels ahead of time, so CMake builds with the default MLX_METAL_JIT=OFF can load them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
davidtai
force-pushed
the
fix/mxfp4-prefill-tile-aot
branch
from
September 25, 2026 20:45
54910ff to
5621947
Compare
5 tasks done
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.
Proposed changes
This PR adds two
gather_qmm_rhskernels for the GPT-OSS MXFP4 prefill tile tomlx/backend/metal/kernels/fp_quantized.metal:mxfp4_gather_qmm_rhs_nt_float_gs_32_b_4_bm_32_bn_32_bk_32_wm_2_wn_2mxfp4_gather_qmm_rhs_nt_bfloat16_t_gs_32_b_4_bm_32_bn_32_bk_32_wm_2_wn_2MLX_GPTOSS_MXFP4_PREFILL_TILE=m32n32k32selects the tile bm 32, bn 32, bk 32, wm 2, wn 2 (gptoss_mxfp4_policy.h).quantized.cppselects this tile only for mxfp4, group size 32, 4 bits, transposed weights, and float32 or bfloat16 inputs. These two kernels cover all of these cases.Before this PR, only builds that compile
jit_kernels.cppcould make this kernel. These builds make the kernel from source at run time and do not readmlx.metallib. A CMake build with the defaultMLX_METAL_JIT=OFF(CMakeLists.txt:44) compilesnojit_kernels.cppinstead. It loads kernels only frommlx.metallib, so it failed with "Unable to load function". The C++ testgptoss mxfp4 prefill tiles preserve expert boundaries and partial rows(tests/gptoss_mxfp4_tests.cpp) showed the failure in #22 (run https://github.com/Layr-Labs/mlx/actions/runs/36172106158).The fix goes into the metallib because every CMake build with the default
MLX_METAL_JIT=OFFfails without it: the Python wheel, the C++ test binary and any other CMake consumer. d-inference does not fail without this fix. On Apple platforms its SwiftPM build compilesjit_kernels.cpp:libs/mlx-swift/Package.swiftin d-inference excludesnojit_kernels.cppon every platform (line 284) and excludesjit_kernels.cpponly on platforms without Metal (line 25). Its JIT loader builds this kernel from source at run time.This PR does not change the test. It does not change host code, because
quantized.cppalready asks for these kernel names. It adds one sentence about these kernels to the GPT-OSS section offork.yaml.Runner probe result
Run: https://github.com/Layr-Labs/mlx/actions/runs/36174742752 (success, 22.0 minutes). This is the Fork Tests job of #22 with the same kernel diff, before this branch moved onto
main.macos-26(imagemacos-26-arm64, version 20260907.0351.1). macOS 26.6.2 on an Apple M1 (Virtual) with 3 cores.Test plan
git diffof the kernel commit before and after the rebase ontomain: identical. It adds 4 lines tofp_quantized.metal.mxfp4_gather_qmm_rhs_nt_float_gs_32_b_4_bm_32_bn_32_bk_32_wm_2_wn_2. This is the name in the failed test log of ci: build with Metal and run the tests on pull requests #22./usr/bin/python3 scripts/check_forkdiff.py --upstream-ref refs/remotes/upstream/mainon the head commit: 172 of 172 changed files described.git merge-tree --write-treeof this branch withci/fork-testsand withci/drop-upstream-workflows: no conflicts.mainplus the CI files of ci: build with Metal and run the tests on pull requests #22: https://github.com/Layr-Labs/mlx/actions/runs/36172106158. 289 of 290 C++ test cases pass. The prefill tile test fails.mainas the base.gh api repos/Layr-Labs/mlx/commits/<sha> --jq .commit.verification.verifiedgivestruefor both commits.CONTRIBUTING checklist
pre-commitran on the head commit. TheCheck Lintjob passed in run https://github.com/Layr-Labs/mlx/actions/runs/36187633589.pre-commitdoes not format.metalfiles.gptoss mxfp4 prefill tiles preserve expert boundaries and partial rowsintests/gptoss_mxfp4_tests.cppfails onci/fork-testswithout the fix (run https://github.com/Layr-Labs/mlx/actions/runs/36172106158) and passes with it (run https://github.com/Layr-Labs/mlx/actions/runs/36174742752).MLX_GPTOSS_MXFP4_PREFILL_TILE=m32n32k32selects them. No benchmark is needed.Dependencies
The base branch is
main. This PR merges before #22. Its evidence is run https://github.com/Layr-Labs/mlx/actions/runs/36172106158 (red without the fix, onmainplus the CI files of #22 only) and run https://github.com/Layr-Labs/mlx/actions/runs/36174742752 (green with the identical kernel diff).mainhas no Fork Tests workflow yet, so the checks of this PR do not build with Metal. The next Fork Tests run of #22, after #22 is updated frommain, tests this change onmain.🤖 Generated with Claude Code