{"slug": "up-to-211-faster-matrix-multiplication-on-modern-apple-silicon", "title": "Up to 211% faster matrix multiplication on modern Apple Silicon", "summary": "The experimental library mlx-tachyon reports up to 211% faster matrix multiplication on Apple Silicon by combining sub-cubic, finite-ring modular CRT and Hadamard-INT8 kernels targeting Apple M5-series Neural Accelerators via MLX and Metal 4. The library's fast_matmul_fp64 runs 12.2×–13.7× faster than Apple M5 Max CPU Accelerate FP64 at rel_L2 = 5.91e-15, while its no_quant mode delivers up to 69.0 effective TFLOP/s on 15360³ bfloat16/float16, a +30% to +49% wall-clock speedup over mx.matmul. A drop-in tachyonize(model) accelerates Qwen3-style training steps by +10.0% (2L 1.3B) to +20.5% (1L 8B) with identical 3-seed loss (mean_gap = -0.0010); on M1–M4 or CPU the library detects the absence of Metal 4 NAX at runtime and falls back to mx.matmul with a warning.", "body_md": "**Sub-cubic, finite-ring modular CRT, and Hadamard-INT8-NAX matrix multiplication kernels for Apple Silicon (MLX / Metal 4).**\n\n`mlx-tachyon` is an experimental-to-production research library for [Apple MLX](https://github.com/ml-explore/mlx) targeting Apple M5-series Neural Accelerators (`mpp::tensor_ops::matmul2d`). On M1–M4 or CPU environments, it detects the lack of Metal 4 NAX at runtime and falls back cleanly to `mx.matmul` with a warning.\n\nApple's built-in `mx.matmul` already reaches ~93% of M5 Max's nominal 16-bit `mlx-tachyon` explores **algorithmic** ways to improve speed or precision on top of Apple Silicon's hardware:\n\n1. \n**Floating-point without INT8 quantization (`mode=\"no_quant\"`):**  - \n**`EqFP16-NAX` (`float32`):** Exact IEEE-754 power-of-2 row equilibration across$10^{\\pm 38}$ dynamic range + FP16 NAX with FP32 accumulation (`rel_L2 = 2.93e-4` vs`FP64` ,`+29%` to`+41%` faster than MLX's default relaxed`float32` on M5).\n  - \n**Auto-compiled pure-dyadic Smirnov** Performs$\\langle 3,3,6; 40 \\rangle$ :$40/54 = 0.741\\times$ $1.350\\times$ fewer), delivering up to**69.0 effective TFLOP/s** (`51.1` actual hardware TFLOP/s) on$15360^3$ `bfloat16` /`float16` (`+30%` to`+49%` wall-clock speedup over`mx.matmul` ).\n2. \n3. \n**Finite-ring modular sub-cubic arithmetic (`mode=\"strict_fp32\"` & `fast_matmul_fp64`):**  - Executes pure-dyadic Smirnov $\\langle 3,3,6; 40 \\rangle$ *inside* pairwise-coprime**odd** residue rings$\\mathbb{Z}/m_s\\mathbb{Z}$ (`0.000e+0` bit-exact homomorphism vs direct CRT — eliminating floating-point sub-cubic instability), reconstructed via 72-bit triple-float CRT on 8-bit integer NAX cores.\n  - Delivers **strict IEEE-754 `float32`** (` rel_L2 = 3.82e-7` ,`+26%` to`+70%` faster than M5 Max's strict-FP32 NAX path) and**15-digit IEEE-754 `float64`** (` rel_L2 = 5.91e-15` ,`max|err| = 9.38e-16` ) at**5.9–6.8 effective TFLOP/s** (**12.2×–13.7× faster** than Apple M5 Max CPU Accelerate`FP64` on$6144^3$ –$9216^3$!).\n4. Executes pure-dyadic Smirnov \n5. \n**Lossy INT8 LLM training kernels (`mode=\"fast_train\"` & `tachyonize(model)`):**  - Maps `bfloat16` /`float16` /`float32` onto M5 Max's 122.4 TOPS INT8 NAX using bilinear diagonal channel balancing ($\\Lambda \\Lambda^{-1} = I$ ), vectorized atomic-max column transforms, and optional reproducible unbiased stochastic rounding (`~1.2%` rel L2 noise, zero bias).\n  - Drop-in `tachyonize(model)` accelerates real end-to-end Qwen3-style training steps (including RMSNorm, QK-Norm, RoPE, causal SDPA, cross-entropy, backward, and AdamW) by**+10.0%** (2L`1.3B` ) to**+20.5%** (1L`8B` ) with identical 3-seed loss (`mean_gap = -0.0010` ) and gradient norms.\n6. Maps \n7. \n**High-precision 2-slice Ozaki (`mode=\"high_prec\"`):**  - 2-slice residual RHT-INT8 (` rel_L2 = 8.23e-5` vs`FP64` ), ~9.3× closer to`FP64` than MLX's default relaxed`float32` on M5.\n8. 2-slice residual RHT-INT8 (\n\n**Experimental modes:** `mode=\"experimental_ultra\"` (Direct-INT8 Smirnov-40, `~3.1%` rel L2) and opt-in `allow_experimental=True` Kronecker `~1.7e-3` in `fp16` at `~6.2%` in INT8 at \n\n$\\langle 6,6,12; 280 \\rangle$ ($\\ge 18432^3$ ,$\\ge 24576^3$ ) are explicitly marked experimental due to narrow activation thresholds or higher approximation noise.\n\n| Workload | Recommended API | Expected Error vs FP64 | Expected Wall-Clock Gain | \n|---|---|---|---|\n| **Dense `float64` scientific computing (** | `fast_matmul_fp64(A, B)` | `5.9e-15` (15-digit IEEE) | **12×–13.7×** vs CPU Accelerate`FP64` | \n| **Strict IEEE-754 `float32` (** | `fast_matmul(..., mode=\"strict_fp32\")` | `3.8e-7` | **+26% to +70%** vs strict-FP32 NAX | \n| **Relaxed `float32` dense GEMMs (** | `fast_matmul(..., mode=\"no_quant\")` | `2.9e-4`*(vs MLX M5 `7.7e-4`)* | **+29% to +72%** vs MLX` fp32` | \n| **Large `fp16`/` bf16` GEMMs (** | `fast_matmul(..., mode=\"no_quant\")` | `8.4e-4` (`fp16` ) /`1.8e-3` (`bf16` ) | **+18% to +49%** vs MLX`fp16` /`bf16` | \n| **LLM training (`>= 1B–8B`, `bf16`)** | `tachyonize(model, stochastic=True)` | `~1.2e-2` (unbiased, zero drift) | **+10% to +20.5%** end-to-end step (`+41%` linear ops on 8B) | \n| **Single-token decode (`M = 1`) or small matrices (`< 1024`)** | Native `mx.matmul` | — | No gain (auto-falls back cleanly) | \n\n**Hardware & MLX Pin:** Tested on **Apple M5 Max (`applegpu_g17s`, 128 GB unified memory, macOS 27.2.1)** with **MLX `0.32.4`** (` pyproject.toml` pins `mlx>=0.32.0,<0.34.0`). On M1–M4 Macs, `has_metal4_nax()` returns `False` and `fast_matmul` falls back cleanly to `mx.matmul`.\n\n```\ngit clone https://github.com/davedx/mlx-tachyon.git\ncd mlx-tachyon\npip install -e .\n```\n\nYou don't need to memorize algorithm names — pass `max_rel_err=...` and `return_info=True` to see the exact path taken, padding applied, expected error range, and physical-ops ratio:\n\n``` python\nimport mlx.core as mx\nfrom mlx_tachyon import fast_matmul, fast_matmul_fp64\n\nA = mx.random.normal((4096, 4096)).astype(mx.float32)\nB = mx.random.normal((4096, 4096)).astype(mx.float32)\n\n# Let mlx-tachyon choose the fastest path meeting your error contract\nC, info = fast_matmul(A, B, layout=\"NT\", max_rel_err=1e-3, return_info=True)\nprint(info)\n# DispatchInfo(path='eq_fp16_nax', ..., expected_rel_err=(0.00025, 0.00035), actual_hw_ops_ratio=1.0, reason='ok')\n\n# Or pick a mode explicitly (supports 2D and batched 3D+ inputs, deterministic seed for SR)\nA_bf = A.astype(mx.bfloat16)\nB_bf = B.astype(mx.bfloat16)\nC_train = fast_matmul(A_bf, B_bf, layout=\"NT\", mode=\"fast_train\", stochastic=True, seed=42)\n\n# 15-digit IEEE-754 double precision on GPU (accepts NumPy float64 arrays)\nimport numpy as np\nC64, info64 = fast_matmul_fp64(np.random.randn(2048, 2048), np.random.randn(2048, 2048), return_info=True)\npython\nimport mlx.nn as nn\nfrom mlx_tachyon import tachyonize\n\n# Replaces eligible nn.Linear / CastLinear layers with FastLinear (preserves fp32 master weights & skips lm_head/embed)\nreport = tachyonize(model, min_features=1024, skip_names=(\"lm_head\", \"embed\"), stochastic=True, seed=42)\nprint(\"Swapped layers:\", len(report[\"replaced\"]))\n```\n\nAll single-GEMM benchmarks below were measured on an idle **Apple M5 Max (`applegpu_g17s`)**, macOS 27.2.1, MLX `0.32.4`. We report **both** *Effective TFLOP/s* (**Actual Physical Hardware Ops/s** (`actual_hw_ops_ratio × Effective`) alongside measured relative L2 error vs `FP64`.\n\nBefore comparing `float32` paths, we empirically probed what MLX `0.32.4` `mx.matmul(float32)` actually computes on `applegpu_g17s` using `x = 1 + 0.75 · 2⁻¹⁰ = 1.0007324219`:\n\n- **`mx.matmul(float32)` returned `1.0000000000`** — confirming MLX defaults to Metal 4's` relaxed_precision=true` NAX path on M5, which**truncates `float32` inputs toward zero to a 10-bit TF32-like mantissa** (`rel_L2 = 7.68e-4` vs`FP64` ).\n- **IEEE `float16` round-to-nearest-even (`EqFP16-NAX`) returned `1.0009765625`** (` rel_L2 = 2.93e-4` vs`FP64` , 2.6× lower error than truncate-to-zero TF32).\n- **Strict IEEE-754 `float32` NAX** (`relaxed_precision=false` ) runs at**11.2–14.8 TFLOP/s** on M5 Max. Below we compare against*both* baselines explicitly.\n\n| Mode / Path | Shape & Dtype | Baseline (vs) | Effective TFLOP/s | Actual HW Ops/s | Wall-Clock Gain | Measured `rel_L2` vs FP64 | \n|---|---|---|---|---|---|---|\n| **`fast_matmul_fp64`** (` CRT S=14 + Smirnov` ) | `9216³`` fp64` | CPU Accelerate `FP64` (`0.49 TF` ) | **6.79 TF** | 70.4 TOPS (INT8) | **13.73×** | **`5.91e-15`***(15-digit IEEE)* | \n| **`mode=\"strict_fp32\"`** (` CRT S=7 + Smirnov` ) | `9216³`` fp32` | NAX strict `fp32` (`11.24 TF` ) | **14.16 TF** | 73.4 TOPS (INT8) | **+26.0%***(up to +46%)* | **`3.82e-7`***(strict IEEE)* | \n| **`mode=\"high_prec\"`** (` Ozaki-2` 2-slice) | `4096³`` fp32` | MLX relaxed `fp32` (`40.3 TF` ) | **~48 TF** | ~144 TOPS (INT8) | **~+19%** | **`8.23e-5`***(9.3× < MLX M5)* | \n| **`mode=\"no_quant\"`** (` EqFP16-NAX` ) | `4096×4096×14336`` fp32` | MLX relaxed `fp32` (`34.6 TF` ) | **48.83 TF** | 48.83 TF (FP16) | **+41.3%** | **`2.93e-4`***(2.6× < MLX M5)* | \n| **`mode=\"no_quant\"`** (` Smirnov336` ,`40/54` ) | `15360³`` bf16` | MLX `bf16` (`52.16 TF` ) | **68.99 TF** | 51.10 TF (FP16) | **+32.3%** | **`1.83e-3`***(MLX `bf16`: `1.66e-3`)* | \n| **`mode=\"no_quant\"`** (` Smirnov336` ,`40/54` ) | `18432³`` fp16` | MLX `fp16` (`46.16 TF` ) | **68.86 TF** | 51.01 TF (FP16) | **+49.2%** | **`8.35e-4`***(MLX `fp16`: `2.07e-4`)* | \n| *Experimental:*`Kronecker-280` (`280/432` ) | `24576³`` fp16` | MLX `fp16` (`42.37 TF` ) | **77.00 TF** | 49.91 TF (FP16) | **+81.7%** | **`1.68e-3`** | \n\n| Mode / Path | Workload & Dtype | Baseline (MLX `bf16` ) | Effective TFLOP/s | Actual HW Ops/s | Wall-Clock Gain | Measured `rel_L2` / Cosine | \n|---|---|---|---|---|---|---|\n| **`mode=\"fast_train\"`** (` DB-RHT-INT8-NAX` ) | 11-workload geomean ( `NT/NN/TN` )`bf16` | 40–59 TF | **75–110.5 TF** | 75–110.5 TOPS | **+38% to +43%** | **`1.19e-2`** (` cos=0.99993` ) | \n| **`mode=\"fast_train\"`** (21-GEMM 8B layer) | Full Llama-3-8B fwd+bwd linear ops `bf16` | `110.72 ms` | **68.24 TF** | 68.24 TOPS | **+41.0% (1.41×)** | **`1.19e-2`** (` cos=0.99993` ) | \n| *Experimental:*`mode=\"experimental_ultra\"` | `18432³`` bf16` (`Smirnov-40` INT8) | `48.50 TF` | **129.09 TF** | 95.62 TOPS | **+166.2% (2.66×)** | **`3.09e-2`** (` cos=0.99952` ) | \n| *Experimental:*`Kronecker-280` INT8 | `24576³`` bf16` (`280/432` INT8) | `42.26 TF` | **131.50 TF** | 85.23 TOPS | **+211.2% (3.11×)** | **`6.19e-2`** (` cos=0.99809` ) | \n\n- \n**Full Qwen3-style LLM Training Step (`examples/bench_llm_e2e_step.py`, via `tachyonize(model)`):** Includes RMSNorm, QK-Norm, RoPE, fused causal SDPA, SwiGLU MLP, cross-entropy loss, full backward pass, and`fp32` AdamW update:\n  - \n`760m-wide` (2L,`d=1536, ffn=4096, M=4096` ):`43,395 → 45,355 tok/s` (**+4.5%** end-to-end; higher on full 24L models where embeddings/LM head amortize).\n  - \n`1.3b-wide` (2L,`d=2048, ffn=5632, M=4096` ):`29,098 → 32,010 tok/s` (**+10.0%** end-to-end).\n  - \n`llama3-8b` (1L,`d=4096, ffn=14336, M=4096` ):`13,172 → 15,878 tok/s` (**+20.5%** end-to-end, even without shared-input RHT reuse).\n  - \n**3-Seed Convergence & Stability (120 AdamW steps, `fp32` master weights + `bf16` compute):** Native`1.8621 ± 0.3305` vs Tachyon`1.8611 ± 0.3092` (**mean gap `-0.0010`** ), with gradient-norm` mean/max` matching to within`0.17%` (`2.339/7.099` vs`2.341/7.097` ).\n- \n- \n**Real FP64 Linear Solver (`examples/fp64_iterative_refinement.py`):** Mixed-precision FP32-LU + GPU` fast_matmul_fp64` iterative refinement on dense$4096 \\times 4096$ systems converges to full machine precision (**`backward_err = 1.32e-16`** ,**` rel_err = 1.05e-14`** ; GPU residual GEMM beats CPU Accelerate` FP64` above$N = 4096$ and reaches**12–14×** at$6144^3$ –$9216^3$).\n\nSee [`BENCHMARKING.md`](https://github.com/davedx/mlx-tachyon/blob/main/BENCHMARKING.md) for timing methodology & caveats, [`VERIFICATION.md`](https://github.com/davedx/mlx-tachyon/blob/main/VERIFICATION.md) for 5-seed 95% CI error bars & raw spot checks, and [`RESEARCH_REPORT.md`](https://github.com/davedx/mlx-tachyon/blob/main/RESEARCH_REPORT.md) for full derivations.\n\n```\nmlx-tachyon/\n├── mlx_tachyon/                    # Installable Python package (v0.3.0)\n│   ├── __init__.py                 # Public API: fast_matmul, fast_matmul_fp64, FastLinear, tachyonize\n│   ├── core.py                     # DispatchInfo, max_rel_err contracts, 3D/batched & safety guards\n│   ├── hw.py                       # Runtime M5/Metal 4 NAX detection & explicit int32/extent guards\n│   ├── kernels.py                  # Deterministic cached .metal template loader\n│   ├── smirnov336.py               # Auto-compiler for Smirnov <3,3,6; 40>\n│   ├── modular_crt.py              # Finite-Ring Modular Sub-Cubic CRT-RNS-NAX (strict_fp32 & fp64)\n│   ├── kronecker280.py             # Experimental Register-Fused Kronecker <6,6,12; 280>\n│   ├── metal/                      # Readable, diffable .metal headers & kernel templates\n│   └── third_party/                # Upstream CeCILL-B Smirnov <3,3,6; 40> program & license\n├── tests/                          # 25 unit & property-based tests + error-bar report runner\n│   ├── error_metrics.py            # Full-matrix bias/stddev/quantiles, 95% CI & raw sampling\n│   ├── test_correctness.py         # All modes, layouts, dtypes, gradients & adversarial inputs\n│   ├── test_properties.py          # All remainders mod 3/6/12/24/48/64/128, contracts & guards\n│   └── verify_report.py            # CLI runner (`python3 -m tests.verify_report`)\n├── examples/                       # Real end-to-end application benchmarks\n│   ├── bench_llm_e2e_step.py       # Full Qwen3-style training step (tok/s) & 3-seed convergence\n│   └── fp64_iterative_refinement.py# Mixed-precision FP32-LU + GPU FP64 iterative refinement solver\n├── benchmarks/                     # MLX baseline & DCE-proof M5 Max silicon probes\n├── experiments/                    # All 14 chronological research & prototype scripts\n├── results/                        # Raw JSON benchmark & training logs\n├── BENCHMARKING.md                 # How performance is measured, DCE guards & caveats\n├── VERIFICATION.md                 # Unit test results, 95% CI error bars & raw spot checks\n├── RESEARCH_REPORT.md              # Full technical report & roofline analysis\n├── NOTICE                          # Third-party software & academic attributions\n├── LICENSE                         # MIT License\n└── pyproject.toml\n# 1. Full 25-test correctness, property-based & 5-seed error-bar suite (~20s GPU)\npython3 -m tests.verify_report\n\n# Include huge 6144x6144x12288 & 9216^3 dispatch tests\npython3 -m tests.verify_report --large --seeds 5\n\n# 2. Real end-to-end LLM training step & 3-seed stability check\npython3 examples/bench_llm_e2e_step.py\n\n# 3. Real FP64 iterative-refinement linear solver demo\npython3 examples/fp64_iterative_refinement.py\n\n# 4. Baseline & DCE-proof hardware probes\npython3 benchmarks/benchmark_baseline.py\npython3 benchmarks/probes/probe_dce_proof.py\n```\n\nSee [`NOTICE`](https://github.com/davedx/mlx-tachyon/blob/main/NOTICE) for full software and academic attributions, including the upstream CeCILL-B V1 pure-dyadic Smirnov [`mlx_tachyon/third_party/FMMa_3_3_6.m`](https://github.com/davedx/mlx-tachyon/blob/main/mlx_tachyon/third_party/FMMa_3_3_6.m)) by Jean-Guillaume Dumas, Clément Pernet, and Alexandre Sedoglavic (`jgdumas/Fast-Matrix-Multiplication`, based on A. V. Smirnov 2013), Karstadt & Schwartz (2017/2020), Ozaki et al. (2012/2025), Fawzi et al. / AlphaTensor (2022), and Apple MLX / Metal 4.\n\n`mlx-tachyon` is released under the **MIT License** ([`LICENSE`](https://github.com/davedx/mlx-tachyon/blob/main/LICENSE)); included third-party file `FMMa_3_3_6.m` remains under **CeCILL-B V1** ([`Licence_CeCILL-B_V1-en.txt`](https://github.com/davedx/mlx-tachyon/blob/main/mlx_tachyon/third_party/Licence_CeCILL-B_V1-en.txt)).", "url": "https://wpnews.pro/news/up-to-211-faster-matrix-multiplication-on-modern-apple-silicon", "canonical_source": "https://github.com/davedx/mlx-tachyon", "published_at": "2026-12-03 08:16:05+00:00", "updated_at": "2026-12-03 08:47:31.976531+00:00", "lang": "en", "topics": ["machine-learning", "ai-infrastructure", "ai-chips", "ai-research"], "entities": ["mlx-tachyon", "Apple", "MLX", "Metal 4", "Apple M5", "Qwen3"], "also_reported_by": [], "takeaway": "On M5 Max, fast_matmul_fp64 reaches 5.9e-15 rel_L2 error at 12.2×–13.7× the speed of CPU Accelerate FP64, and no_quant mode hits up to 69.0 effective TFLOP/s on 15360³ bf16/fp16, +30% to +49% over mx.matmul.", "recommendation": {"advice": "On Apple M5 hardware, route dense fp16/bf16 GEMMs through mlx-tachyon's no_quant mode and fp64 work through fast_matmul_fp64 to gain up to 49% and 13.7× respectively, keeping the mx.matmul fallback for M1–M4.", "playbook": "inference-serving", "playbook_url": "https://wpnews.pro/playbooks/inference-serving"}, "alternates": {"html": "https://wpnews.pro/news/up-to-211-faster-matrix-multiplication-on-modern-apple-silicon", "markdown": "https://wpnews.pro/news/up-to-211-faster-matrix-multiplication-on-modern-apple-silicon.md", "text": "https://wpnews.pro/news/up-to-211-faster-matrix-multiplication-on-modern-apple-silicon.txt", "jsonld": "https://wpnews.pro/news/up-to-211-faster-matrix-multiplication-on-modern-apple-silicon.jsonld"}}