Repository navigation
Conversation
jvmenen
pushed a commit
to jvmenen/MTPLX
that referenced
this pull request
Oct 19, 2026
… 8-bit verify results, attention research
jvmenen
pushed a commit
to jvmenen/MTPLX
that referenced
this pull request
Oct 21, 2026
Contributor
Author
|
Closing this. MLX main now has ml-explore/mlx#4682 (bff10220c, after v0.32.4): from 8 rows an affine NAX qmm with split-K takes over from |
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.
Why
Mixed-precision checkpoints keep some layers at 8 bits. On Qwen3.8-27B Optimized-Speed these are the 48 GDN out-projections, the MLP of the last 8 layers and
lm_head. When a verify window is wide (a context-copy block: 13, 17 or 25 rows), stock MLX runs those 8-bit matmuls on kernels that do not use the M5's tensor units:qmv_wide, which reads the weights again for every few rows (lm_headat 9 rows: 11.3 ms against 7.1 ms at 13 rows);qmm_splitksplits K whenever the 32x32 tile grid has 256 or fewer threadgroups. For outputs of 5120 (the GDN out-projection and the MLP down-projection) that is every window up to 32 rows, so they run onqmm_t_splitkat 2.6 to 2.7 times their weight-read time (GDN out-projection 0.31 ms against a 0.12 ms floor).The 4-bit layers already have NAX lanes for these windows; the 8-bit layers are what is left.
How it works, in plain terms
The weights are read once per matmul whatever the number of rows, so extra input rows cost almost nothing. The lane appends zero rows to the input until MLX's own dispatch picks its NAX tile (
qmm_t_nax), runs the stockmx.quantized_matmul, and keeps only the real rows. Wide outputs need 13 rows (the qmv limit; one 32-row tile), narrow outputs 33 (two tiles, so split-K is no longer chosen). A small function mirrors MLX's dispatch rule (mlx_qmm_takes_nax, MLX 0.32.2 to 0.32.4, generation-17 GPUs) to decide the row count; where stock already reaches the NAX tile (the wide shapes from 13 rows) nothing changes. No new kernel: the numbers come from MLX's own NAX matmul, which differs fromqmv_wideand split-K only in accumulation order.What changes
mtplx/nax_verify.py:q8_nax_pad_enabled,mlx_qmm_takes_nax,q8_nax_pad_rows,nax_qmm_q8_padded, and a branch in the 8-bit path of the QuantizedLinear patch for 12 to 32 verify rows (never in prefill, bf16/fp16 affine only, NAX hardware only, honours the self-check kill switch).MTPLX_Q8_NAX_PAD=1turns it on (default off).MTPLX_Q8_NAX_PAD_MIN_ROWSmoves the floor (default 12; below 9 rows a narrow shape is never padded, since two tiles cost more thanqmv_widethere).mtplx/kernel_selfcheck.py: laneqmm_q8_nax_pad, probed whenever the switch is on, whatever the model's main bit width (mixed models report 4 bits); a mismatch turns the lane off for the process.tests/test_nax_verify.py(dispatch mirror on the Qwen3.8 shapes, off by default bit-identical to stock, routing only for wide verify rows, not in prefill, the row floor) andtests/test_kernel_selfcheck.py(probe present only with the switch, corruption falls back).Results
M5 Pro (20-core GPU), Qwen3.8-27B Optimized-Speed, MLX 0.32.4, production verify core (
linear-gdn-from-conv-tape).Per matmul (ms, stock / padded):
Whole verify forward in the model (median of 12 alternating runs, real prompt):
The 9 and 10-row windows were padded in a first version: the matmuls alone are faster there, but the whole forward was 0.4 to 2.9% slower, so the default floor is 12.
Parity:
Tests
tests/test_nax_verify.pyandtests/test_kernel_selfcheck.py: pass (switch off and on).