Repository navigation
[Metal] Gather mm improvement - #4567
Merged
Merged
Conversation
zcbenz
approved these changes
Sep 26, 2026
zcbenz
left a comment
Member
There was a problem hiding this comment.
It is amazing that changing scheduling can make such an improvement!
This was referenced Sep 28, 2026
ashhart
added a commit
to ashhart/TensorFold
that referenced
this pull request
Sep 29, 2026
…DA, expert-aligned prompt tiles - Checkpoint copies and snapshot loads check again before every eviction, and a resumed prompt stops holding the stored prefix it copied; the memory tests pin host RAM, so they pass on any Mac (#74). - #70's 64 GB M5 Pro measurements go into the README and recipes, labelled as 0.3.5.1. - On M1-M4, Flash Next's prompt expert gathers take row tiles that never straddle experts (the scheduling idea of ml-explore/mlx#4567), same bits. - A reader for ModelOpt and compressed-tensors NVFP4, FP8 and MXFP8 weights, W4A16 and W8A16 lane matmuls with exact weights, and Qwen3.8-27B on ModelOpt NVFP4 checkpoints. Fixes #70.
Gajesh2007
pushed a commit
to Layr-Labs/mlx
that referenced
this pull request
Oct 6, 2026
…explore/mlx ml-explore#4567, ml-explore#4572) (#27) * [Metal] Gather mm improvement (ml-explore#4567) (cherry picked from commit a2a09fd) * docs(forkdiff): describe the upstream gather_mm row-tile backport Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * [Metal] gather_qmm improvement (ml-explore#4572) (cherry picked from commit 9008944) * fix(metal): run the unsorted gather route for a retracted expert-tile call The gather_qmm row-tile backport (ml-explore/mlx ml-explore#4572) makes the sorted gather_qmm_rhs kernels read per-expert offsets. Those kernels give a correct result only for sorted indices. Before the backport, the kernel read the index of each row, so the expert-tile route could send a call with unsorted indices (a sortedness retract) to it. gather_qmm_rhs now returns false for a retracted call, and GatherQMM::eval_gpu then runs the unsorted gather route. All other calls are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Anastasiia Filippova <a_filippova@apple.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
davidtai
added a commit
to Layr-Labs/mlx
that referenced
this pull request
Oct 7, 2026
Bring in #27, the gather_mm and gather_qmm row-tile scheduling backport (ml-explore/mlx ml-explore#4567, ml-explore#4572). - quantized_nax.h, affine_gather_qmm_rhs_nax: take main's kernel. Each threadgroup now holds rows of one expert (schedule_row_tile), so the per-tile expert-segment loop is gone. This branch's segment elision ran inside that loop. Without the loop, seg_lo is 0 and seg_hi is sgp_sm, so seg_partial is always false and seg_empty equals main's !sg_active. The sorted-endpoint probe has no probe to skip. Remove kGatherRhsSegmentElide, kGatherRhsSortedEndpointElide and the gather_rhs_load_frag_row / gather_rhs_mma_frag_row helpers, which have no caller. Keep this branch's row-strip simdgroup layout (SGM/SGN, DARKBLOOM_GEMMA4_NAX_GATHER_TILING) on main's kernel, and rewrite the note about how it composes with the row-tile schedule. - fork.yaml: auto-merged; replace the segment-elision bullet with the row-strip layout of the NAX qmm_t and gather-rhs kernels. - quantized.h: auto-merged; main changed the gather_qmm_rhs kernels and this branch changed the QMV kernels, which do not overlap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rcfa
pushed a commit
to rcfa/mlx
that referenced
this pull request
Oct 13, 2026
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.
Description:
In the current
gather_mmkernel, tiles an assigned to thread groups independently from experts assignment. Example:This means that for a tile [5,2,9] we do "as many matmuls as possible":
matmul with expert 0, matmul with expert 1, matmul with expert 2
mlx/mlx/backend/metal/kernels/steel/gemm/kernels/steel_gemm_gather_nax.h
Line 68 in 073d225
It seems suboptimal to do extra K passes, especially for shorter sequences.
Proposed changes:
Instead of tiling independently from the assignment I propose to do similar as in https://github.com/Dao-AILab/quack/blob/main/quack/tile_scheduler.py and change the way thread groups load tiles. Inside
gather_mmwe runschedule_row_tilefunction that given precomputedoffsetsfromrhs_indicesfills the row to start from, expert to load, and the number of valid rows in the tile.Then in the above example instead of 6 passes we do 4.
Note: it seems like a big diff, but it is just the tiling that differs
Results: MoE layer timing on M5Ultra
Model = shape is taken from the models config.
Todo:
Do the same for gather_qmm.