Repository navigation
Metal NAX: port Muse Glimmer small-M K-split affine GEMM and double-buffered NVFP4 GEMM/QMV - #73
Conversation
Address adversarial review findings (H1, M1, M2, L1, L4): - Advance Source/Cmlx/mlx from ce27c709 to 979ad5da (head of Layr-Labs/mlx#73), regenerate mlx-generated/{quantized_nax,fp_quantized_nax}.{h,cpp}, and sync Source/Cmlx/include-framework/mlx-utils.h (adds env::nax_ksplit()). - Gate qmm_t_nax_staged_ksplit_impl via Metal function constant 203 (use_ksplit), controlled by MLX_NAX_KSPLIT (default 1) and automatically disabled when MLX_QMV_BATCH_INVARIANT=1 is set. - Rewrite Tests/MLXTests/NAXQuantizedKernelTests.swift so every shape routes to its target M5 NAX kernel path: - Affine K-split split-K (N=K=2048, M=8..16, biases present) and direct staged qmm_nax (N=K=4160 = 65*64, M=13..16), plus bitwise M=13/16 vs M=17 parity when MLX_NAX_KSPLIT=0 or MLX_QMV_BATCH_INVARIANT=1. - Unbatched (M=512, N=1024) and batched (B=2, M=64, aligned N=128 and unaligned N=96) double-buffered NVFP4 fp_qmm_t_nax. - Peeled fp_qmv_nax (K=N=2048, 6 <= M <= 8 and M=9). - NVFP4 MoE gather (fp_gather_qmm_t_nax and fp_gather_qmm_rhs_nax). - Genuinely misaligned 4B weight / 1B scale offset fallback with bitwise sameBytes parity against the aligned fast paths. - NVFP4 globalScale GEMM route (M=512, N=1024, K=128). - Update fork.yaml with the 979ad5da pin, accurate NVFP4 blast radius (including MoE gather paths), and updated test coverage description.
jonathan308
left a comment
There was a problem hiding this comment.
The kernel work looks right. NVFP4 dequant is bit-identical, the double-buffering is race-free, threadgroup memory fits (18,432 B for staged tiles, 12,288 B for K-split partial sums), and M1–M4 are untouched behind is_nax_available(). Two things I'd want fixed before merge, plus one merge-order item:
- Default
MLX_NAX_KSPLITto 0 (mlx/utils.h:248; used atquantized.cpp:1021/1536andquantized_nax.h:1350). With it on, affine bf16/fp16 at 8–16 rows adds the four partial sums in a different order. M5 output bits then differ from today's production build, and from the same rows computed at 17+ rows. OpenRouter flags output drift, and end-to-end KV-hash parity is still "not proven" per the description. Ship it opt-in and flip the default after a soak test shows parity. - CI has never actually run on this PR. Every Darkbloom self-hosted job sat about 40 minutes with no runner and got cancelled by the watchdog, and the dependent jobs cancelled at 0s. Only CodeQL ran. So lint, clang-format, the C++ tests (including the new
nax_ksplit_disabledcheck) and fork.yaml are all unverified. The branch is also 20 commits behind main. Please rebase and get a green run. - Merge order with my mlx#71 (prefill-row invariance). #71 skips the NAX split-K route inside its scope. But when the split count resolves to 1 (large N, e.g. an lm_head with N ≥ 16384), the call goes
qmm→ staged kernel. K-split would then make 2–16 row prompt chunks round differently from 17+ row chunks. Whichever PR lands second needsprefill_rows <= 0in the K-split gate.
Minor: the tests compare against CPU with a loose tolerance (0.08 for bf16) plus fast-path-vs-fallback bitwise checks. Nothing asserts that the NAX path actually ran on the runner, so an assert or log check would make the bitwise tests meaningful.
…GEMM/QMV Ports the two production-safe NAX Metal kernel optimizations from the Muse Glimmer 30B challenge line (Layr-Labs/mlxfast-muse-glimmer-30b-engine commits 80b35945 and 9976cc74): - quantized_nax.h: qmm_t_nax_staged_ksplit_impl splits each BK=64 step into four 16-column slices across all 4 simdgroups when M <= SM (M <= 16) in qmm_t_nax_staged_impl, reducing FP32 partial tiles in threadgroup memory. - fp_quantized_nax.h: vectorized uint4/uchar2 NVFP4 loads and half2 E2M1 dequantization (fetch_nvfp4/store_nvfp4) with double-buffered Ws in fp_qmm_t_impl/fp_qmm_t_nax, plus dequantize_fp4_x4_scaled and M <= 8 peeled 1-ahead prefetch in fp_qmv_nax, hardened with alignment, K > 0, sizeof(T) == 2, and final-iteration copy guards. Drops the divergent early-return edits to steel_gemm_fused_nax.h and steel_gemm_splitk_nax.h (threadgroup_barrier(mem_flags::mem_none) inside gemm_loop makes per-simdgroup early return MSL UB) and the dead cbv2_array_backing symbol in gather_front.cpp.
Address adversarial review findings (H1, M1, M2, L1, L4): - Gate qmm_t_nax_staged_ksplit_impl via Metal function constant 203 (use_ksplit), controlled by env::nax_ksplit() (MLX_NAX_KSPLIT, default 1) and automatically disabled when MLX_QMV_BATCH_INVARIANT=1 is set. Eliminates the M=16/17 batch-size boundary under batch invariance and provides an explicit kill switch without adding AOT kernel instantiations. - Document MLX_NAX_KSPLIT in docs/src/usage/environment_variables.rst and clarify that sizeof(T) == 2 / sizeof(Wtype) == 2 in fp_quantized_nax.h checks the 16-bit threadgroup tile storage width (Wtype = bfloat across fp_qmm_t_nax, fp_gather_qmm_t_nax, and fp_gather_qmm_rhs_nax for all activation dtypes; activation T in fp_qmm_n_impl). - Add tests/nax_quantized_kernel_tests.cpp and ctest nax_ksplit_disabled covering M5-routed affine K-split (split-K N=K=2048 M=8..16 and direct staged N=K=4160 M=13..16, plus bitwise M=13/16 vs M=17 parity when MLX_NAX_KSPLIT=0), unbatched/batched double-buffered NVFP4 GEMM, peeled 6 <= M <= 8 QMV, NVFP4 MoE gather (fp_gather_qmm_t_nax and fp_gather_qmm_rhs_nax), and genuinely misaligned 4B/1B offset fallback bitwise parity. - Update fork.yaml with the complete file globs and NVFP4 blast radius.
…AX path Address jonathan308's review comments on #73: - Default MLX_NAX_KSPLIT to 0 (opt-in) in mlx/utils.h and update docs/src/usage/environment_variables.rst and fork.yaml so M5 output bits at 8..16 affine rows stay identical to production unless explicitly opted in. - Factor the K-split gate into use_qmm_nax_ksplit(bool allow_ksplit = true) and thread an optional allow_ksplit parameter through qmm() -> qmm_nax(), ready for #71 to pass allow_ksplit = (ref_rows <= 0) when qmm_splitk falls through to qmm at split_k <= 1. - Log GPU architecture and metal::is_nax_available() in tests/nax_quantized_kernel_tests.cpp, assert bitwise M<=16 vs M=17 parity when K-split is off (default) and bitwise K-split dispatch on NAX when MLX_NAX_KSPLIT=1, replace ctest nax_ksplit_disabled with nax_ksplit_enabled (MLX_NAX_KSPLIT=1), and run it in .github/workflows/fork-tests.yml. - Document AGENTS.md (from 56e12b0 on main) under Fork tooling in fork.yaml so Fork Diff Check passes after rebasing onto main.
979ad5d to
500c5d7
Compare
jonathan308
left a comment
There was a problem hiding this comment.
Approving at 500c5d7e. All of my earlier items are fixed:
MLX_NAX_KSPLITdefaults to 0 (mlx/utils.h). Default M5 output bits at 8–16 rows now matchmain.- CI ran fully on this head and passed, including the new
nax_ksplit_enabledctest step. The branch is 3 ahead ofmainand 0 behind. - Merge order with #71:
allow_ksplitis threaded throughqmm→qmm_nax→use_qmm_nax_ksplit. #71 is still a draft, so it lands second and should passref_rows <= 0at theqmm_splitk→qmmfallthrough. - The tests now assert a bitwise difference under
MLX_NAX_KSPLIT=1on NAX hardware, so the dispatch is proven.
Both kernel headers (quantized_nax.h, fp_quantized_nax.h) are byte-identical to 979ad5da, the commit you ran on the M5 Max.
Notes, not blocking:
- The CI runner's GPU has no NAX (
GPU arch: air64_v27, is_nax_available=falsein the build-cpp log). CI only compiles the new kernels; your M5 Max run is the only on-hardware evidence. Please re-run the NAX tests on an M5 after any kernel change. - The NVFP4 double-buffered GEMM and QMV are on by default for every NVFP4 model on M5. They're bit-identical, but there's no speed comparison against
mainyet. Please post one, along with the cause of the M=32 cliff, before we count this as a speed-up. - Nit:
qmm_t_nax_staged_impltreats an undefined FC 203 as K-split on (!is_function_constant_defined(use_ksplit) || use_ksplit). Every current host dispatcher sets it, so nothing reaches this today. Treating undefined as off would be safer. - Remember to re-pin
Source/Cmlx/mlxin mlx-swift#79 once this merges.
Advance Source/Cmlx/mlx from 979ad5da to 4ef15bc7d43527e2018596a23445aa4f0c698662 (merged Layr-Labs/mlx#73 on Layr-Labs/mlx main, including 500c5d7e's opt-in MLX_NAX_KSPLIT=0 default, allow_ksplit plumbing for #71 coordination, and the main empty-CPU-reduction fix from #54): - Sync Source/Cmlx/include-framework/mlx-utils.h so env::nax_ksplit() matches mlx/utils.h (default 0, != 0). - Update Tests/MLXTests/NAXQuantizedKernelTests.swift so unset MLX_NAX_KSPLIT asserts bitwise parity (default disabled), while explicit MLX_NAX_KSPLIT=1 exercises K-split unless MLX_QMV_BATCH_INVARIANT=1 is set. - Verified Source/Cmlx/mlx-generated/ matches 4ef15bc7 (zero Metal kernel header diff vs 979ad5da; check-generated-metal-sources.py passes). - Update fork.yaml with the 4ef15bc7 pin and opt-in default.
Branch
muse-glimmer/challenge-nax-kernels@500c5d7e(3 commits rebased cleanly ontomain@56e12b00). Companion Swift PR: Layr-Labs/mlx-swift#79 (to be re-pinned after#73lands); upstream model-layer PR: Layr-Labs/mlx-swift-lm#580. Ports the production-safe Metal NAX quantized kernel subset fromLayr-Labs/mlxfast-muse-glimmer-30b-engine(80b35945and9976cc74); none ofjonathan308's branches or PRs are touched.Summary
mlx/backend/metal/kernels/quantized_nax.h,mlx/backend/metal/quantized.cpp,mlx/utils.h):qmm_t_nax_staged_ksplit_implfor 16-bit (float16/bfloat16) affine transposed quantized GEMM and split-K (BM=64, BK=64, BN=64, WM=4, WN=1). WhenM <= SM(M <= 16; reachable on M5+ NAX for8 <= M <= 16viaqmm_splitk_naxand12/13 <= M <= 16via directqmm_nax), all 4 simdgroups share the sameMrows and split eachBK=64step into four 16-column slices instead of leaving 3 simdgroups idle, then reduce FP32 partials inWs(12,288 <= 18,432bytes) with uniform threadgroup barrier participation.MLX_NAX_KSPLIT=0) +#71coordination gate: Gated via Metal function constantuse_ksplit(index203) throughuse_qmm_nax_ksplit(bool allow_ksplit = true)inquantized.cpp(allow_ksplit && env::nax_ksplit() && !env::qmv_batch_invariant()). Default isMLX_NAX_KSPLIT=0(opt-in only) so production M5 output bits at8..16rows remain identical tomainuntil an end-to-end soak proves KV-hash parity;MLX_QMV_BATCH_INVARIANT=1always suppresses K-split; andqmm()/qmm_nax()accept an optionalbool allow_ksplit = trueparameter so [Metal] Prefill-row invariance scope: prompt chunks round like the reference rows (opt-in, per thread) #71 only needs to pass/*allow_ksplit=*/ref_rows <= 0whenqmm_splitkfalls through toqmmatsplit_k <= 1(e.g. large-Nlm_head).6 <= M <= 8peeled-prefetch QMV (mlx/backend/metal/kernels/fp_quantized_nax.h):FPQuantizedNAXBlockLoader::fetch_nvfp4/store_nvfp4, double-bufferedWs(kDoubleBuf, 18 KiB) infp_qmm_t_impl/fp_qmm_t_nax, and bit-manipulationdequantize_fp4_x4_scaled+M <= 8(reachable at6 <= M <= 8) peeled 1-ahead prefetch infp_qmv_nax.(K > 0) && ((K & 31) == 0)and 16-bytewl/ 2-bytescalesalignment guards (plusif (kn < K)around the final peeled prefetch shift infp_qmv_nax).sizeof(T) == 2/sizeof(Wtype) == 2checks the 16-bit threadgroup tile storage width (Wtype = bfloatacross transposed/gather kernels for all activation dtypes; activationTinfp_qmm_n_impl) sovec<Wtype, 8>stores remain 16-byte aligned.tests/nax_quantized_kernel_tests.cpplogging the active GPU architecture (metal::device(Device::gpu).get_architecture()) andmetal::is_nax_available(), testing shapes routed to all new M5 NAX paths (affine split-KN=K=2048M=8..16, direct stagedN=K=4160M=13..16, unbatchedM=512, N=1024and batchedB=2, M=64NVFP4 double-buffered GEMM,6 <= M <= 8peeled QMV, NVFP4 MoE gatherfp_gather_qmm_t_nax/fp_gather_qmm_rhs_nax, and genuinely misaligned 4-bytew/ 1-bytescalesoffset fallback bitwise parity).M <= 16vsM = 17prefix parity when K-split is off (the defaultMLX_NAX_KSPLIT=0andMLX_QMV_BATCH_INVARIANT=1), and on NAX hardware (metal::is_nax_available()) asserts bitwise difference underMLX_NAX_KSPLIT=1to proveqmm_t_nax_staged_ksplit_implactually dispatched.nax_ksplit_enabled(MLX_NAX_KSPLIT=1) intests/CMakeLists.txtand wires it into.github/workflows/fork-tests.ymlso CI runs both the default (MLX_NAX_KSPLIT=0) and opt-in (MLX_NAX_KSPLIT=1) paths.MLX_NAX_KSPLIT(default0, opt-in) indocs/src/usage/environment_variables.rstand updatesfork.yaml(including documentingAGENTS.mdfrom56e12b00onmainunder "Fork tooling" soFork Diff Checkpasses cleanly).Omitted / dropped items from
mlxfast-muse-glimmer-30b-engine(4a28444e)steel_gemm_fused_nax.h&steel_gemm_splitk_nax.hearlyreturnonsgp_sm <= 0 || sgp_sn <= 0mlx::steel::gemm_loop(...)(steel/gemm/gemm_nax.h:54), which executesthreadgroup_barrier(mem_flags::mem_none)everykk0iteration — divergent barrier UB.gather_front.cpp(cbv2_array_backing)Layr-Labs/mlx-swift-lm#580uses publicmlx_array_get_buffer_info+mlx_array_data_uint8.Placeholders / pending rollout items
#71is currently an open Draft PR not yet onmain. This PR exposesbool allow_ksplit = trueonqmm()->qmm_nax()->use_qmm_nax_ksplit(allow_ksplit); whichever PR lands second passes/*allow_ksplit=*/ref_rows <= 0atqmm_splitk'ssplit_k <= 1fallthrough toqmm(...)(in addition to#71's existingref_rows == 0guard onqmm_splitk_nax).mlx-swiftpin: After#73merges toLayr-Labs/mlxmain, re-pinSource/Cmlx/mlxin metal: port Muse Glimmer NAX quantized GEMM/QMV kernels mlx-swift#79 to the mergedmainSHA.Blast Radius / What This Could Affect
Shared seams touched
quantized_nax.h(qmm_t_nax_staged_impl->qmm_t_nax_staged_ksplit_impl) +quantized.cpp+mlx/utils.hMLX_NAX_KSPLIT=0). When opted in (MLX_NAX_KSPLIT=1), splitsBK=64across 4 simdgroups whenM <= 16(reachable for8 <= M <= 16viaqmm_splitk_naxand12/13 <= M <= 16viaqmm_nax). Changes FP32 K-reduction summation order (~1 ULP / KV-hash delta vs. stock staged andM >= 17) only whenMLX_NAX_KSPLIT=1.MLX_NAX_KSPLIT=1running 16-bit (bf16/fp16) affine-quantized models at8 <= M <= 16on M5+ NAX. Zero behavior change under default settings.metal::is_nax_available()+use_ksplitFC 203 viause_qmm_nax_ksplit(allow_ksplit)(MLX_NAX_KSPLIT=0default, disabled whenMLX_QMV_BATCH_INVARIANT=1orallow_ksplit=false).fp_quantized_nax.h(FPQuantizedNAXBlockLoader::fetch_nvfp4/store_nvfp4,load_unsafe,fp_qmm_t_impl,fp_qmm_t_nax)uint4/uchar2loads,half2bit-manipulation E2M1 dequantization, and 18 KiB double-bufferedWsinfp_qmm_t_nax(kDoubleBuf = truefor non-hgsNVFP4). 0-ULP bit-identical output (confirmed on M5 Maxapplegpu_g17s).float,fp16,bf16):fp_qmm_t_nax(double-buffered),fp_gather_qmm_t_nax(MoE gather, single-buffered fast path),fp_gather_qmm_rhs_nax(nt/nnsorted MoE hot path, viaload_unsafe()), andfp_qmm_n_nax(16-bitTwhen instantiated; not host-routed today).metal::is_nax_available(),bits == 4 && group_size == 16 && !has_global_scale,K > 0 && (K & 31) == 0, 16Bwl& 2Bscalesalignment.fp_quantized_nax.h(fp_qmv_nax+dequantize_fp4_x4_scaled)half2dequantization + 1-ahead peeled prefetch forM <= 8(reachable at6 <= M <= 8viaqmv_mma). 0-ULP bit-identical output.6 <= M <= 8(N >= 2048) on M5+ NAX (Muse Glimmer 30B NVFP4 and other NVFP4 models).metal::is_nax_available(),bits == 4 && group_size == 16,M <= 8(6 <= M <= 8host-routed);MLX_QMV_BATCH_INVARIANT=1bypassesqmv_mma.Non-interference
MLX_NAX_KSPLIT=0by default, affine NAX output bits at8 <= M <= 16are bit-identical tomain. NVFP4 fast paths are 0-ULP bit-identical to stock.metal::is_nax_available() == false).bits == 4 && group_size == 16excludesgroup_size == 32MXFP4/MXFP8).has_global_scaleNVFP4 /M > 16affine NAX:fp_qmm_t_naxwithhas_global_scalekeeps single-bufferedWsand stock loop;M > 16affine staged NAX runs the unmodified stock loop; sibling models using MXFP4 or non-NAX hardware (GPT-OSS, non-NAX Inkling 2 / Gemma 4 / GLM5-Next / Nemotron / Qwen / MiMo) are unaffected.Rollback / fail-closed profile
MLX_NAX_KSPLIT=0);MLX_QMV_BATCH_INVARIANT=1andallow_ksplit=falseforce FC 203 =falseeven ifMLX_NAX_KSPLIT=1is set.muse-glimmer/challenge-nax-kernelsto restore56e12b00.Before and After
flowchart LR subgraph Before["Before (main @ 56e12b00)"] B1["NAX affine qmm_t_nax_staged_impl (8 <= M <= 16)"] --> B2["Only sgid 0 active; 3 of 4 simdgroups idle"] B3["NAX NVFP4 fp_qmm_t_nax / gather / fp_qmv_nax"] --> B4["Single-buffered Ws; scalar load_unsafe; non-peeled QMV"] end subgraph After["After (500c5d7e)"] A1["NAX affine qmm_t_nax_staged_impl (8 <= M <= 16)"] --> A2{"use_ksplit FC 203<br/>use_qmm_nax_ksplit(allow_ksplit)<br/>(MLX_NAX_KSPLIT=0 default)"} A2 -->|true (opt-in)| A3["qmm_t_nax_staged_ksplit_impl: 4 simdgroups split BK=64 + Ws FP32 reduction"] A2 -->|false (default)| B2 A4["NAX NVFP4 GEMM / MoE gather / QMV"] --> A5["Aligned fast_nvfp4 (double-buffered Ws in fp_qmm_t_nax, bit-manip dequant in gather/QMV) + scalar fallback"] endBefore any rollout
500c5d7e(lint,fork.yaml, C++ Metal tests includingnax_ksplit_enabled, and Python shards).Source/Cmlx/mlxin metal: port Muse Glimmer NAX quantized GEMM/QMV kernels mlx-swift#79 to the mergedLayr-Labs/mlxmainSHA.allow_ksplit = (ref_rows <= 0)inqmm_splitk->qmmwhen [Metal] Prefill-row invariance scope: prompt chunks round like the reference rows (opt-in, per thread) #71 lands.MLX_NAX_KSPLIT=0as the default until an end-to-end real-checkpoint Muse Glimmer 30B soak test on M5 confirms KV-hash / OpenRouter parity, and run a side-by-side NVFP4 microbenchmark against basemain(including attributing theM=32latency cliff).Validation
1. Current Head (
500c5d7e, rebased on56e12b00) — Apple M4 Max (applegpu_g16s, macOS 27.2.1, Metal 410)MLX_METAL_JIT=OFF)cmake --build /tmp/mlx73-build-aot --target mlx-metallib tests -j$(sysctl -n hw.ncpu)MLX_METAL_JIT=ON)cmake --build /tmp/mlx73-build-jit --target mlx -j$(sysctl -n hw.ncpu)MLX_NAX_KSPLIT=0)tests --test-case="*quant*,*qmm*,*qmv*,*NAX*,*nvfp4*,*mxfp*"GPU arch: applegpu_g16s, is_nax_available=false)MLX_NAX_KSPLIT=1,MLX_QMV_BATCH_INVARIANT=1,--cpu)tests --source-file="*nax_quantized_kernel_tests.cpp"in all 3 modesnax_ksplit_enabled+qmv_batch_invariant)ctest --test-dir /tmp/mlx73-build-aot -R '^(nax_ksplit_enabled|qmv_batch_invariant)$' -Vclang-format 21.1.8+cmake-format 0.6.13)uvx clang-format==21.1.8 --dry-run --Werror <8 C++/Metal files>+cmake-format --check tests/CMakeLists.txtfork.yaml& CI workflow checksscripts/check_forkdiff.py+yaml.safe_load+.github/scripts/test-runner-sizes.py(fp8_e4m3, fp4_e2m1)pairs (bf16+fp16)2. Apple M5 Max (
applegpu_g17s,arch_gen=17, 40 GPU cores,metal::is_nax_available() == true, macOS 27.2.1, Metal 4 — measured on979ad5da, identical Metal kernel headers)MLX_METAL_JIT=OFF)cmake --build build --target tests -j$(sysctl -n hw.ncpu)mlx.metallib215 MiB (1,176 compiled NAX kernel symbols), 0 errorsMLX_NAX_KSPLIT=1,MLX_NAX_KSPLIT=0,MLX_QMV_BATCH_INVARIANT=1)./tests/tests --source-file="*nax_quantized_kernel_tests.cpp"in all 3 modesctest(4/4) +./tests/tests --test-case="*quant*,*qmm*,*qmv*,*NAX*,*nvfp4*,*mxfp*"NAXQuantizedKernelTests+ combined#73/#79/#579/#580stackNAXQuantizedKernelTests(4/4 × 3 modes) +mlx-swift-lmsuites (--no-parallel)M5 NAX execution & gate proof (
applegpu_g17s, Affine Q4 bf16gs=64):N=K=2048,M ∈ {8, 12, 16}):KSPLIT=1output differs bitwise fromKSPLIT=0andM=17(confirmingqmm_t_nax_staged_ksplit_implexecuted via FC 203 =true), whileKSPLIT=0matchesM=17bitwise;QMV_BATCH_INVARIANT=1routes todispatch_qmvbelowvector_limit=33.N=K=4160,M ∈ {13, 16}):KSPLIT=1differs bitwise fromKSPLIT=0andM=17, whileKSPLIT=0andQMV_BATCH_INVARIANT=1are bit-identical torows(M=17, 0..m).fp_qmm_t_nax,fp_gather_qmm_t_nax,fp_gather_qmm_rhs_nax) matched 4-bytew/ 1-bytescalesmisaligned fallback bitwise (0 ULP) onapplegpu_g17s.Pre-existing upstream M5 TF32 note (not from
#73/#79): On M5 (arch_gen >= 17), upstream MLX defaultsMLX_ENABLE_TF32=1(mlx/utils.h:269), routing float32 matrix products through NAX TF32 (~1e-3rounding). An independent control build on clean basemlx-swift c633d22/mlx 72dffa2dreproduced the identical 6/17 float32QuantizedLayerTeststolerance failures with TF32 on and 17/17 pass withMLX_ENABLE_TF32=0. Production Muse Glimmer loads weights and runs all matmuls/SDPA inbf16, so TF32 does not apply in production.M5 Max (
applegpu_g17s) NAX Microbenchmarks (bf16,transpose=true, host wall-clock alternatingKS1→KS0→KS1→KS0)Affine Q4 (
bits=4, gs=64) —MLX_NAX_KSPLIT=1vs0A/B:(N×K)MKS=1(µs)KS=0(µs)KS=1 / KS=0)KS=1TFLOPS2048×61442048×61442048×20486144×61446144×20484160×4160M < 13, split-K / QMV)4160×4160split_k=1)6144×6144bits=8, gs=64) —MLX_NAX_KSPLIT=1vs0A/B:2048×6144M=8–16: 1.04–1.09x (medians 1.08x / 1.05x / 1.07x);2048×2048M=8/12/16: 1.04x / 1.00x / 1.03x;6144×2048M=8/12/16: 1.02x / 1.01x / 1.00x;4160×4160M=8/12: 0.98–1.01x (flat), M=13/16: 1.02x / 1.03x;6144×6144M=8..16: 0.95–1.03x across run pairings (medians0.99x / 1.00x / 1.00x, up to ~6% run-to-run variance).bits=4, gs=16) & MXFP8 (bits=8, gs=32) — absolute measurements on#73only (no base72dffa2dA/B run yet):nvfp46144×6144:M=1731 GB/s cache-warm (29.10 µs),M=8538 GB/s cache-warm (39.80 µs),M=1628.5 TFLOPS (42.32 µs),M=329.5 TFLOPS (255.06 µs),M=6445.7 TFLOPS (105.84 µs),M=51253.8 TFLOPS (718.65 µs).mxfp86144×6144:M=1816 GB/s cache-warm (47.74 µs),M=8829 GB/s cache-warm (47.18 µs),M=329.3 TFLOPS (259.30 µs),M=6442.6 TFLOPS (113.31 µs),M=51250.5 TFLOPS (764.93 µs).MLX_NAX_KSPLITonly toggles affine K-split, these NVFP4/MXFP8 figures are absolute measurements on#73and do not yet compare#73against base72dffa2d. Likewise, theM=32latency cliff (255 µsatM=32vs106 µsatM=64on6144×6144) has not been attributed to#73vs. base72dffa2dyet.Skipped / Ignored
500c5d7e).has_naxCHECK_FALSEassertions in500c5d7eon M5 Max (SSH to M5 Max timed out from this host; the exact sameM=8..16vsM=17bitwise divergence underKSPLIT=1and bitwise equality underKSPLIT=0were already proven on M5 Max on979ad5da, whose kernel headers are unchanged).Not proven
mainandM=32cliff attribution: NVFP4/MXFP8 microbenchmarks above are absolute measurements on#73with no side-by-side base A/B run yet.MLX_NAX_KSPLITnow defaults to0).Reviewer Notes
500c5d7e:mlx/utils.h(MLX_NAX_KSPLITdefault changed1->0)mlx/backend/metal/quantized.cpp(use_qmm_nax_ksplit(bool allow_ksplit = true)andallow_ksplitthreaded throughqmm->qmm_naxfor#71ref_rows <= 0coordination)tests/nax_quantized_kernel_tests.cpp,tests/CMakeLists.txt, and.github/workflows/fork-tests.yml(GPU arch /is_nax_available()logging, NAX K-split dispatch assertion, andnax_ksplit_enabledctest wired into CI)fork.yaml(also addsAGENTS.mdfrom56e12b00onmainunder "Fork tooling" soFork Diff Checkpasses)Upstream PR Template / AI Disclosure
AGENTS.mdonLayr-Labs/mlxmain@56e12b00under "Working in our MLX forks", AI-assisted descriptions are permitted in this Layr-Labs fork with explicit disclosure below; a human reviewer should confirm before merge.)use_ksplitgate, hardening guards, C++ tests, review fixes, and this PR description, and ran local M4 Max (m4-max-1) and M5 Max (applegpu_g17s) validation and microbenchmarks at the user's request.