Skip to content

perf(mlx): rebase MLX fork onto upstream 225e9c6e6 (#4953 fusion, #4802/#4781/#4682 NAX, #4893 D=256 SDPA, #4961 small-M GEMM) - #442

Merged
Brooooooklyn merged 3 commits into
mainfrom
perf/mlx-upstream-rebase-2026-11-29
Nov 29, 2026
Merged

Brooooooklyn merged 3 commits into
mainfrom
perf/mlx-upstream-rebase-2026-11-29

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Rebases the crates/mlx-sys/mlx submodule from 76276123a (upstream base bebd6422f, 17 patches) to 84be893fe (mlx-node/rebase-2026-11-29, upstream base 225e9c6e6, +184 upstream commits, 15 linear patches).

ml-explore/mlx main  225e9c6e6 (2026-11-29)
        │
        │  + 9 patches   fn-d1 (dropped #4568 / #4728 / #4892; squashed CUDA ctor into patch 1)
        │  + 1 patch     thread-scoped TF32
        │  + 1 patch     per-graph compile_with_mode
        │  + 3 patches   CUDA cuBLASLt/WDDM/NVRTC, dynamic graph toggle, NVRTC include paths
        │  + 1 patch     harden #4802 int8 NAX affine quantization (Splash guards + bf16-only gate)
        ▼
mlx-node/mlx         84be893fe  ◄── crates/mlx-sys/mlx

Key Upstream & Fork Changes

  • Metal JIT & kernel perf: #4953 compiled graph multi-consumer fusion, #4802 default-on INT8 NAX affine prefill (M >= 32), #4781 affine_qmv_nax, #4682 TF32 qmm_splitk_nax, #4893 D=256 q >= 512 Metal SDPA, #4961 small-M 32×32 Steel GEMM tiles, #5006 float32 hadamard_n, #5016 Compiled::output_shapes broadcast fix.
  • Fork Patch 15 (84be893fe) — #4802 INT8 NAX hardening: adds Splash's bit-level NaN/Inf quiet-NaN propagation, 2^-100 subnormal floor, precise::divide + [-127, 127] char clamp, finite sum_hi guard in quantized_nax.h, and restricts use_qmm_int_nax to bfloat16 (preventing float16 group-sum overflow above 65504).
  • Bridge & packaging updates: #4734 scaled_dot_product_attention window_size & portable SDPA FC 304; #4568 CustomKernel::state() index shift & fast::CompileOptions; #4647 get_default_max_ops_mb_per_buffer & live get_env_int in mlx_segmented_sdpa.cpp; #4893 q >= 512 D=256 predicate; #5003 Windows CMAKE_INSTALL_BINDIR="." (build key 4f58dd63); C++20 bridge standard; metallib-select.ts new-pin markers (sdpa_split_reduce, affine_qmv_nax, affine_qmm_t_int_nax, affine_qmv_nax_).
  • kquant_qmv_t64 KQ_AFFINE fix: FP32 partial sum in load_vector for KQ_AFFINE only (a4g64@t64 M=1 error 5.52e-3 -> 0.00e0, zero K-quant kernel bits changed).
  • Golden update: re-captured only promoted (MLX F32 QuantizedMatmul graph) lines in all 14 affine_mixed_{matmul,shapeless}.applegpu_*.txt files; 0 native lines changed.
  • Prebuilt MLX manifest: crates/mlx-sys/mlx-prebuilt.json pinned to published 84be893fe6d6 releases for macOS (mlx-prebuilt-84be893fe6d6-3d951e0b), Linux arm64 CUDA (mlx-prebuilt-84be893fe6d6-23ca1e3b), and Windows arm64 CUDA (mlx-prebuilt-84be893fe6d6-4f58dd63).

ABBA Benchmarks (Apple M5 Max, 40-core GPU, 128 GiB, macOS 27.2.1)

Microbenchmarks & Operator Benchmarks

Benchmark Shape / Case Old (76276123a) New (48ddeaaee / 84be893fe) Speedup
#4953 JIT silu_bwd (3+→1 kernel) 2 / 32 / 128 MB — — 1.37× / 1.67× / 2.19×
#4953 JIT swiglu_bwd 8 / 32 / 64 MB — — 1.42× / 2.04× / 2.20×
#4953 JIT gelu_approx_bwd / multi_out_gate_fwd 32 MB — — 1.44× / 1.47×
Metal QMM affine Q4 (17408×5120) M=8 / 16 / 512 — — 1.32× / 1.37× / 1.34×
Metal QMM affine Q8 (17408×5120) M=8 / 16 / 64 / 512 — — 1.10× / 1.30× / 1.34× / 1.47×
Metal QMM MXFP4 (17408×5120) M=8 / 16 / 512 — — 1.75× / 1.47× / 1.16×
#4893 qwen35_paged_prefill_operator_bench ctx=16384, q=512 22.71 ms (564.3 MB) 12.68 ms (146.9 MB) 1.79× (3.84× less RAM)
#4893 qwen35_paged_prefill_operator_bench ctx=65536, q=1024 62.33 ms 63.31 ms parity

End-to-End Models (ABBA)

Model & Mode Workload Old (76276123a) New Delta
Qwen 3.8 27B UD-Q4_K_XL (DFlash2) 6k (6,219 in, 512 out) decode 46.69 tok/s 48.87 tok/s +4.7% (acceptTotal=2.954 exact)
Qwen 3.8 27B UD-Q4_K_XL (DFlash2) 6k prefill 744.2 tok/s 761.3 tok/s +2.3%
Qwen 3.8 27B UD-Q4_K_XL (AR BF16 KV) 6k decode / warm prefill 23.48 / 746.3 tok/s 23.55 / 752.3 tok/s parity
Gemma-4-E2B-it-4bit 620 in prefill / decode 5,530 / 148.0 tok/s 6,559 / 151.2 tok/s +18.6% prefill / +2.1% decode
Qwen3-0.6B BF16 SFT (ckpt=true, b=2×512) step time 1114.8 ms 1089.1 ms +2.4% (exact loss 9.98818)

Accuracy & Verification

  • Teacher-forced NLL/KL (2,680 tokens, --kv-format bf16 --activations bf16):
    • qwen3.5-4b-nvfp4-mtp: vs BF16 teacher KL 0.05119 -> 0.05081; vs self-OLD KL 3.35e-3, top-1 97.46%
    • qwen3.5-9B-unsloth: vs self-OLD KL 1.47e-3, top-1 97.76%
  • Golden route-back proof (MLX_QMM_SPLITK_MIN_M=34): 10,469 promoted cases / 80,628,416 elements across all 7 GPU routes: 0 mismatches; host f64 across 1,861 moved cases: max|e| 29 -> 29, rel L2 1.662457e-03 -> 1.693176e-03.
  • Tests run on 84be893fe after rebasing onto origin/main (97fa4804c):
    • MLX C++ ./tests: 336/336 (6,043 assertions)
    • mlx-sys build.rs prebuilt_tests: 11/11
    • yarn build:native + vp test __test__/core/: 127/127
    • kquant_suite: 87/87 (incl. #437 split-K float32 regressions)
    • affine_mixed_golden_gate: 16/16 across native + all 7 simulated GPU routes
    • segmented_sdpa_golden_gate (3/3), qwen35_d256_sdpa (2/2), portable_d256_sdpa (2/2), bridge_metallib_names, kquant_metallib_names, mlx-paged-attn, mlx-core --lib (qwen4_exp, paged_int8_query_tests, gguf_planes, target_schedule_tests, kquant_tiled_tests, merged_draft_projections_match_separate_bits)
    • cargo clippy --locked -p mlx-core -p mlx-sys -p mlx-paged-attn --all-targets -- -D warnings, cargo fmt --all -- --check, vp fmt --check, vp lint --type-aware, yarn typecheck — all pass.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eb91871e-0aa6-4937-bfc8-7b9407b2b9d1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T09:18:02.246809Z 7c9a9eb PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Brooooooklyn
Brooooooklyn force-pushed the perf/mlx-upstream-rebase-2026-11-29 branch from 7c9a9eb to d8590a8 Compare November 29, 2026 09:18
…02/#4781/#4682 NAX, #4893 D=256 SDPA, #4961 small-M GEMM)

Moves the `crates/mlx-sys/mlx` submodule from `76276123a` (base `bebd6422f`,
17 patches) to `84be893fe` (`mlx-node/rebase-2026-11-29`, base `225e9c6e6`,
15 linear commits):

- Drops fork patches superseded upstream: custom-kernel source/hash cache
  (`#4568`), CUDA cuDNN `clear_streams` (`#4892`), and affine `qmv_wide`
  nv6-8 (`#4728`); squashes the CUDA `CustomKernel` ctor fix into patch 1.
- Adapts remaining patches for upstream `#4953` (`mlx/compile/compile.cpp`),
  `#4885` (unlocked `cache_memory_locked` / `memory_limit_locked` inside
  `CudaAllocator`), `#4647` (`config::get`, `get_default_max_ops_mb_per_buffer`),
  `#4882` (`wait_for_capacity`), and `#4711`/`#4745`/`#4868`.
- Adds fork patch 15 (`84be893fe`) hardening upstream `#4802`
  (`affine_quantize_rows`) with Splash's NaN/Inf bitmask propagation,
  `2^-100` subnormal floor, `precise::divide`, `clamp(-127, 127)`, and
  restricting `use_qmm_int_nax` to `bfloat16` (preventing `float16`
  `sum_hi` overflow above `65504`).
- Updates `mlx-sys` bridge for `#4734` (`scaled_dot_product_attention`
  `window_size`, portable SDPA FC 304), `#4568` (`CustomKernel::state()`
  indices and `fast::CompileOptions`), `#4647` (`get_default_max_ops_mb_per_buffer`,
  live `get_env_int` in `mlx_segmented_sdpa.cpp`), `#4893` (D=256 SDPA
  `q >= 512` predicate), `#5003` (Windows `CMAKE_INSTALL_BINDIR="."`),
  C++20 bridge standard, and `metallib-select.ts` new-pin markers.
- Fixes `kquant_qmv_t64` `load_vector` FP32 partial sum for `KQ_AFFINE`
  (`a4g64@t64` `M=1`) without touching any K-quant kernel bits, and updates
  upstream-affected tests, `gguf_planes` `ROUTE_SOURCES`, and docs.
…e (#4682, #4787, #4860, #4890)

Re-captures only `promoted` (MLX F32 `QuantizedMatmul` graph) digest lines
across all 14 `affine_mixed_{matmul,shapeless}.applegpu_*.txt` fixtures;
every `native` line and every dispatch counter is byte-identical.

Route-back proof (`MLX_QMM_SPLITK_MIN_M=34`, old `76276123a` vs new `48ddeaaee`,
verified bit-identical on `84be893fe` across all 7 GPU routes):
- 10,469 promoted cases / 80,628,416 elements across all 7 GPU routes: 0 mismatches.

Upstream attribution (1,861 moved promoted cases: 1,803 matmul + 58 shapeless):
- NAX routes (`g17s`/`g17d`/`g17g`, 599 cases): `#4682` (`bff10220c`) TF32
  `qmm_splitk_nax`; `max|err|` unchanged (`29 -> 29`), `rel L2`
  `1.665637e-03 -> 1.716309e-03`.
- Non-NAX routes (`g17p`/`g16s`/`g14s`/`g14d`, 1,262 cases): `#4787`
  (`ba8c005c1`), `#4860` (`6d38ff93d`), `#4890` (`5cabdf509`)
  `affine_qmv_mma`; `max|err|` unchanged (`15.99 == 15.99`), `rel L2`
  unchanged to 7 digits (`1.657645e-03 -> 1.657645e-03`).

Host f64 reference summary across all 1,861 moved cases:
- elems moved: 2,460,749 / 33,779,712 (closer/farther: 1,823 / 2,458,926)
- max|e|: 29 -> 29
- rel L2: 1.662457e-03 -> 1.693176e-03
@Brooooooklyn
Brooooooklyn force-pushed the perf/mlx-upstream-rebase-2026-11-29 branch from d8590a8 to f427557 Compare November 29, 2026 10:15
@Brooooooklyn
Brooooooklyn merged commit e744300 into main Nov 29, 2026
24 checks passed
@Brooooooklyn
Brooooooklyn deleted the perf/mlx-upstream-rebase-2026-11-29 branch November 29, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant