Repository navigation
perf(nemotron-super): fused MTP verify window, window submission, NAX prefill kernels on M5 (onto main) - #323
Merged
Merged
Conversation
…it the window in parts Speculative decode rounds, with tokens and logits unchanged: - The row-exact trunk (MTP verify windows, batched decode) is submitted to the GPU every 12 blocks (NemotronSuperMTPWindowSubmission.everyLayers; DARKBLOOM_NEMOTRON_SUPER_MTP_WINDOW_SUBMIT, 0 builds it whole), so the GPU runs while the rest of the graph is built. Evaluation order only. - The trunk and the MTP head use Super's fused kernels exactly where the target's one-token decode uses them (residual-add + next-norm boundary, Mamba gated norm, one-token SSM step, expert combine, squared ReLU fused into the shared-expert products, the head's fused expert selection with in-range router indices). Each works row by row behind its supports guard, so every row reproduces one-token decode by construction (NemotronSuperMTPFusion.enabled; DARKBLOOM_NEMOTRON_SUPER_MTP_FUSION=0 restores the op chains). M5 Ultra, full checkpoint, 26 A/B prompts greedy: token-identical; realistic decode (code, chat, math, reasoning) median 70.5 -> 79.4 tok/s, the counting benchmark 87.7 -> 102.0 tok/s, the whole set 92.3 -> 82.8 s. Window submission alone gives +10%, fusion +1-2%. Tests compare fused and unfused trunks and heads bit for bit (logits, hidden, committed state), including submission after every layer.
…X GPUs The simdgroup grouped GEMM was tuned on an M3 Ultra; on NAX GPUs (M5 and later) MLX's sorted NAX gather product is faster. Nemotron 3.5 Super prefill on an M5 Ultra: 1,556 -> 2,100 tokens/s on a 12K prompt. The two paths sum in different orders, so this is not bit-identical. Scored teacher-forced against the true next token over 46,070 positions, the NAX path is at least as accurate: top-1 78.16% vs 78.12%, perplexity 2.7238 vs 2.7294. Any change in summation order (TF32 on or off as well) agrees with the other path on ~96% of positions; at the 1,789 positions where these two disagree, the NAX path is right 388 times and the grouped GEMM 371. Non-NAX GPUs keep the grouped GEMM.
…dense projections Prefill on NAX GPUs (M5 and later), bit-identical to the MLX products they replace: - ModelOptNVFP4NAXExperts: a dedicated NVFP4 expert GEMM adapted from the GLM prefill kernel (double-buffered weight tiles decoded eight codes per word, one tile-scan launch, empty fragments skipped, expert scale and relu2 in the epilogue), with the fastest measured plan per projection pinned. It issues MLX's sorted NAX gather's tensor ops in the same order. - fusedRoute: one route launch replaces the argsorts, gathers and scans; fc1 reads the latent rows through the sort order; fc1's epilogue does fc2's NVFP4 activation rounding; the combine reads through the inverse order. - ModelOptNAXDenseLinear: FP8 and NVFP4 dense prefill projections decode their weights inside the NAX GEMM instead of writing a BF16 weight copy per call (FP8) or float32 sums and a separate scale pass (NVFP4); taken only where MLX runs its regular NAX kernel, never for decode rows. M5 Ultra, full checkpoint: 12K-token prefill 2,094 -> 2,255 tokens/s with the expert kernel, 2,471 with the fused route and dense projections; greedy outputs identical on 26 A/B prompts and the teacher-forced score identical at all 46,070 positions. Per MoE layer at a 2,048-token chunk the expert block takes 6.47 instead of 8.85 ms.
…l on M5 Mamba-2 prefill chunks on NAX GPUs run a chunked SSD kernel: one threadgroup per head walks the prompt in 32-token chunks with the head's float32 state resident in registers (as the GLM 5.3 recurrent prefill kernels keep each core's state), and the intra-chunk C.B^T with the decay mask, the intra-chunk and carried-state outputs and the state update run as NAX tensor ops with float32 operands and accumulation. One kernel does the conv-state concatenation, depthwise conv, bias, silu and retained state (bit-identical to the op chain); dt is computed inside the SSD. NemotronSuperMambaPrefill.enabled (on by default on NAX GPUs) restores the previous path when cleared. Not bit-identical. M5 Ultra, full checkpoint: one layer at 2,048 tokens 11.3 -> 8.0 ms (SSD 6.1 -> 1.9 ms); 12K-token prefill 2,471 -> 2,881 tokens/s. Teacher-forced over 46,070 positions: top-1 78.09%, perplexity 2.7275, against 78.12% / 2.7294 for the grouped GEMM build (the accuracy gate's baseline) and 78.16% / 2.7238 for the bit-identical NAX expert build; the perplexity difference is even across positions.
… only
The NAX expert kernels and fused route, the NAX dense projections and the
chunked SSD compile at first use with the OS's Metal compiler. macOS 26's
compiler rejects some of these tensor-op kernels ("unsupported
deferred-static-alloca-size" in the chunked SSD on the CI runner), which MLX
reports as a fatal error. They were validated on macOS 27 (M5 Ultra 27.0.1,
M5 Max 27.0, M3 Ultra 27.2): ModelOptNVFP4NAXExperts.runtimeCompilerSupported
gates their defaults and tests, so earlier systems keep MLX's prebuilt NAX
kernels and every decode change.
jonathan308
added a commit
to Layr-Labs/d-inference
that referenced
this pull request
Oct 21, 2026
Pins mlx-swift-lm 8cf6698b (Layr-Labs/mlx-swift-lm#323: #319's commits replayed onto main; same tree as 9cd8fc43).
jonathan308
added a commit
to Layr-Labs/d-inference
that referenced
this pull request
Oct 21, 2026
Pins mlx-swift-lm main 0351444e (Layr-Labs/mlx-swift-lm#323 squash-merged; contains the parent's 19634dd8 and this branch's speedups) with master's mlx-swift 67dc7528 and mlx ad4745a2.
jonathan308
added a commit
that referenced
this pull request
Oct 22, 2026
Bring in main through #323, including the mlx-swift main pin (67dc7528), GLM-5.3-Flash native support and Nemotron Super kernels. Resolve the tool-call format conflicts by keeping both the Flint and GLM5 parsers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
javiech1
pushed a commit
to javiech1/mlx-swift-lm
that referenced
this pull request
Oct 24, 2026
Store GatedDelta convolution state contiguously and advance array-cache metadata after each recurrent step, matching upstream mlx-lm behavior for Qwen3.5/Qwen3-Next style models. Keep left-padding masks active after recurrent cache state initialization, add coverage for ArraysCache metadata advancement, and align Qwen3 RoPE setup with the shared rope initializer.
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.
Summary
Decode and prefill speedups for Nemotron 3.5 Super on M5 (NAX) GPUs. The two decode changes are bit-identical (same tokens, same logits). The prefill change alters summation order and passes the accuracy-vs-truth gate (below).
Window submission (
NemotronSuperMTPWindowSubmission.everyLayers, default 12;DARKBLOOM_NEMOTRON_SUPER_MTP_WINDOW_SUBMIT=0restores whole-window evaluation): the row-exact trunk (MTP verify windows, batched decode) is submitted to the GPU every 12 blocks, so the GPU runs while the rest of the window's graph is built. Only the evaluation order changes.Verify-window and draft-head fusion (
NemotronSuperMTPFusion.enabled, default on;DARKBLOOM_NEMOTRON_SUPER_MTP_FUSION=0restores the op chains): the verify window, batched decode and the MTP head use Super's existing fused kernels exactly where the target's one-token decode uses them: residual-add + next-norm boundary, the Mamba gated norm, the one-token SSM step, the MoE combine, squared ReLU fused into the shared-expert and routed fc1 products, and the head's fused expert selection with in-range router indices. Every fused kernel works row by row, behind itssupports*guard, so each window row reproduces one-token decode by construction. About 20% fewer kernels per round.Prefill on NAX GPUs (
ModelOptNVFP4GroupedGEMM.isEnablednow defaults to off when NAX is available): routed NVFP4 expert products use MLX's sorted NAX gather instead of the simdgroup grouped GEMM tuned on the M3 Ultra. Non-NAX GPUs are unchanged.Follows #318 (prefill memory fix, merged as
66f556b7). Supersedes the misdirected merge of #319.Before
After
Measured (M5 Ultra, full checkpoint, shipped grouped GEMM and MTP depth)
Same probe binary with the switches flipped; shipped MTP depth; one client.
Prefill accuracy gate (not bit-identical). Teacher-forced over 46,070 positions of a mixed corpus, scored against the true next token:
The scorer is deterministic (repeat runs 100.000% identical). Any summation-order change, TF32 included, agrees with the other path at ~96% of positions; that is Nemotron's numeric noise floor, not an accuracy loss. Where the two expert paths disagree (1,789 positions), the NAX path is right 388 times and the grouped GEMM 371 times.
Testing
scripts/nemotron-qualificationSDK template, debug): 307 tests in 76 suites pass (--no-parallel; in parallel, the process-memory residency suite can be disturbed by a concurrently allocating suite that is not part of this PR). New:NemotronSuperMTPBatchedWindowTests.fusedTrunkMatchesUnfusedTrunk(logits, hidden and committed state, bit for bit, up to 18 rows),NemotronSuperMTPGraphTests.fusedGraphHeadMatchesUnfusedHead(fp32/bf16), NVFP4/FP8 squared-ReLU row-exactness, the multi-row gated norm on strided gate slices, and head selection.swift-format formatmakes no changes.Refactor pass
A dedicated review found no blocking issues. Applied: window submission is now covered by a test (submission after every layer vs the unfused whole window), the env switches are
static let, the zero-index cache is bounded by the row-exact maximum, the squared-ReLU mirror is folded intosuperRowExactProjection(squaredReLU:),residualPartsis shared, the backbone's residual norm uses the sameboundaryhelper, one guarded combine helper, doc fixes and test nits.Update: NAX expert kernels, fused route, NAX dense projections (
770555d1)Bit-identical to the MLX NAX products they replace: greedy outputs identical on 26 A/B prompts, and the teacher-forced score identical at all 46,070 positions.
3798463a)Per MoE layer at a 2,048-token chunk: expert block 8.85 → 6.47 ms. Super SDK harness: 315 tests pass at this commit (serial).
Update: chunked NAX Mamba prefill (
c6aa5665) — accuracy-gated, not bit-identical770555d1, bit-identical to MLX NAX)Passes the owner's gate (top-1 within 0.05 pts of shipped, perplexity within +0.1% of shipped). Against the bit-identical NAX build it is −0.06 pts / +0.13% perplexity, spread evenly across window positions (no growth with context). One Mamba layer at 2,048 tokens: 11.3 → 8.0 ms (SSD 6.1 → 1.9 ms).
NemotronSuperMambaPrefill.enabled = falserestores the previous path. Super SDK harness: 318 tests pass.