Repository navigation
Description
Area
[Engine] (speed, kernels, models, the server and API)
What do you want to do?
Improve strata-poly Metal performance, memory safety, and out-of-the-box ergonomics for 16 GB Apple Silicon Macs (Apple9 / M4) running MoE models (specifically Inkling-2-Mini), while keeping Apple10 (M5 Ultra) and non-Metal backends regression-free.
Following CONTRIBUTING.md, I want to align scope with maintainers before splitting this work into 4 focused PRs (rebased onto main / v0.2.20-poly.10, df2c3ff; opened as drafts where shared cross-backend engine files need CUDA/HIP/SYCL CI):
-
PR 1 ([Engine] optimize Metal Inkling decode fusion and Apple9 prefill GEMM #458) — Lossless Metal decode fusion & Apple9 prefill GEMM tuning (
[Engine])- On-chip threadgroup SRAM fused MoE
gate_up + SiTU + Q8_1(poly_mul_k1_gu_situ_q8), low-VGPR Apple9 decode kernels (poly_mul_k0/k1/k9),Q2_0LUT / custom quantized dots, smaller Apple9poly_mmtiles +kTile={16,32}split, vectorizedink_control3_gate_v4/poly_gemv_v4, and UMA zero-blitoutput_rows_q8/d_picks_readback. - 100% mathematically lossless; benefits both Apple9 (M4) and Apple10 (M5 Ultra).
- On-chip threadgroup SRAM fused MoE
-
PR 2 ([Engine] guard 16 GB Apple Silicon Metal memory headroom and tune Inkling setup defaults #457) — 16 GB Apple Silicon Metal memory headroom guard & Inkling setup presets (
[Engine])- Guard Metal
metal_cover/ balanced VRAM reservation with an OS headroom cap on 16 GB Macs to prevent memory-pressure thrashing and OOMs. - Tune 16 GB Apple Silicon Inkling setup presets (
--no-draft --prompt-batch 512 --attn-requant q5_k --kv q8_0) inengine/metal/setup_mac.pyandterminal/tools/metal_poly_setup.py, with unit tests interminal/tools/test_metal_poly_setup.pyandengine/metal/poly_tests/memory_growth.cpp.
- Guard Metal
-
PR 3 ([Engine] add opt-in Apple Silicon CPU SME2 (Accelerate BNNS) concurrent MoE prefill #459) — Opt-in Apple Silicon CPU SME2 (
AccelerateBNNS) concurrent MoE prefill ([Engine])- Zero-copy unified-memory heterogeneous MoE prefill: concurrently execute ~25% of prefill expert rows (prioritizing uncached cold experts) on Apple Silicon CPU SME2 via
AccelerateBNNS (FP16 x FP16 -> FP32to avoid NVFP4 raw-accumulator overflow, plus FP16 activation clamp and 25-type NEON FP16 dequantizers), while the Metal GPU processes the remaining experts in parallel. - Kept strictly opt-in by default (
STRATA_POLY_SME_PREFILL=1/STRATA_POLY_SME_SHARE=0.25) so the default path stays byte-identical unless maintainers prefer auto-enabling it on Apple9FEAT_SME=1Macs (8–10 GPU cores).
- Zero-copy unified-memory heterogeneous MoE prefill: concurrently execute ~25% of prefill expert rows (prioritizing uncached cold experts) on Apple Silicon CPU SME2 via
-
PR 4 ([Engine] add opt-in Metal GPU-native dynamic expert pruning (--gpu-skip-weight, --gpu-route-top, --tail-renorm) #460) — Opt-in Metal GPU-native dynamic expert pruning (
[Engine])- Zero-CPU-sync pruning inside Metal
poly_route(--gpu-skip-weight,--gpu-route-top,--gpu-skip-min,--tail-renorm) withid < 0early exits and NaN/OOB guards across downstream kernels, plus hostmoe()/moe_defer()parity (including Gemma 4 pre-escaleordering) and fail-fast error on non-Metal builds. - Strictly opt-in (off by default, byte-identical default path).
- Zero-CPU-sync pruning inside Metal
Prototype measurements before rebasing (built from 4106d1a -> local 03340da)
- Local 16 GB M4 (
Mac16,12, fanless 13" MacBook Air, 8-core Apple9 GPU, 16 GiB UMA,FEAT_SME=1,FEAT_SME2=1, macOS 26.6.2):Inkling-2-Mini-UD-Q2_K_XL.gguf(9.1 GB, 3072/3072 experts in VRAM):- Baseline before changes:
16.8 tok/sdecode (default draft) /18.6 tok/s(no-draft); 4K prefill~81 tok/s(~51s); 8K prefill~78 tok/s(~105s). - PR 1 + PR 2 (100% lossless, GPU-only): short decode
22.1–22.5 tok/s(+20% lossless), 4K prefill160.1 tok/s(25.1s). -
- PR 3 (SME2
share=0.25, 100% lossless): 4K prefill195.5 tok/s(21.0s), 7,680-token (~8K) prefill192.7 tok/s(39.9s), post-8K decode18.88 tok/s.
- PR 3 (SME2
-
- PR 4 (opt-in pruning +
--tail-renorm):23.52 tok/s(--gpu-skip-weight 0.08),23.90 tok/s(--gpu-route-top 6, 99.2% top-1 agreement on 128 teacher-forced steps),24.45 tok/s(--gpu-route-top 5),26.10 tok/s(--gpu-skip-weight 0.10). At--gpu-route-top 4(27.47 tok/s), multi-step logic degrades; omitting--tail-renormat0.08causes a logic reasoning failure while keeping--tail-renormpasses all math/logic/coding checks.
- PR 4 (opt-in pruning +
- Baseline before changes:
Inkling-2-Mini-GSQ-RCO-IQ3_S.gguf(11.4 GB, ~2,563/3,072 experts in VRAM):- Warm 4K prefill:
64.9 tok/s(61.8s, SME off) ->88.6 tok/s(45.3s, +36.5%, SMEshare=0.25with cold-expert priority); post-4K decode5.8 -> 9.5 tok/s(steady-state13.58 tok/s). - Cold-start short decode with PR 4 (
--gpu-skip-weight 0.08 --tail-renorm):9.66 -> 12.03 tok/s(+24.5%, VRAM swaps254 -> 104).
- Warm 4K prefill:
- Apple M5 Ultra (Apple10 GPU + Metal 4, regression check):
ctest -L poly: 50 / 50 passed,q36_metal_parity: 0 mismatches.Inkling-2-Mini-UD-Q2_K_XLno-draft decode improved from83.3–85.9to87.7–90.5 tok/s, 4K/8K prefill steady at2,176–2,215 tok/s(SME2 stays off on Apple10).
(Unrelated Linux CI test_setup_qwen4 case-sensitivity fix submitted separately in #461.)
Scope questions for maintainers
- Does splitting this work into the 4 PRs above match what you prefer to review?
- For PR 2, are the 16 GB Apple Silicon Inkling setup defaults (
--no-draft,--prompt-batch 512,--attn-requant q5_k,--kv q8_0) and the OS headroom cap acceptable as defaults on<= 16 GBMacs? - For PR 3, should CPU SME2 concurrent prefill land strictly opt-in first (proposed), or auto-enable on Apple9
FEAT_SME=1Macs with <= 10 GPU cores?
What do you do today instead?
Today on a 16 GB M4 Mac running Inkling-2-Mini-UD-Q2_K_XL or IQ3_S, users hit:
- Slow long-context prefill (
~81 tok/sat 4K, ~105s wait at 8K) because large Apple10poly_mmtiles underperform on 8-core Apple9 GPUs and M4's CPU SME2 unit sits idle. - Sub-optimal decode (
16.8 tok/swith draft enabled, ~35% bandwidth lost to unfused intermediate memory round-trips). - Manual trial-and-error to avoid 16 GB macOS unified-memory thrashing (tuning
--vram-reserve-mib,--no-draft,--attn-requant q5_k,--kv q8_0,--prompt-batch 512). - No GPU-native way on Metal to trade tail-expert compute for higher decode throughput without CPU-GPU sync stalls.
Activity
NightRain233 commentedon Dec 6, 2026
Status Update — Rebased onto
origin/main(0794bc5) & Full Metal Validation CompleteAll 4 split PRs for
Inkling-2-Minion 16 GB Apple Silicon (Apple9 M4) have been cleanly rebased ontoorigin/main(0794bc5, including #498 and #464), with zero merge conflicts (MERGEABLE) and full Metal Release build +ctest -L polyverification on Apple M5 Ultra (Apple10) on every exact commit.PR Status & Recommended Review Order
0794bc5)4de93c2MERGEABLE)> 20 GiBMacs & non-Metal unchanged51/51 ctest,test_metal_poly_setup22/22,docs6/69953d89MERGEABLE)_fast/_fast4/_k1/_k1g51/51 ctest(incl.mv_parity,inkling_parity,qwen4_parity),settings_register,docs6/61298d88MERGEABLE)STRATA_POLY_SME_PREFILL=1); default byte-identical52/52 ctest(incl.poly_sme_prefill_parity25/25 quant types + NVFP4 >65k + FP16 clamp),docs6/6262f6a6MERGEABLE)--gpu-skip-weight/--gpu-route-top); default byte-identical51/51 ctest(incl.basic_parity,quantized_parity,inkling_parity),settings_register,docs6/6(Note: both #458 and #460 add a virtual hook to
Engineand bumpkPolyEngineAbiRev2 -> 3; whichever merges second only needs a trivial rebase onengine.hpp.)Summary of Verified Hardware Results
Physical 16 GB Apple M4 (
Mac16,12, fanless 13" MacBook Air, 8-core Apple9 GPU, 16 GiB UMA, macOS 26.6.2) & Apple M5 Ultra (64-core Apple10, 256 GiB UMA):Inkling-2-Mini-UD-Q2_K_XLdecode (100% lossless, M4)16.8(draft) /18.6 tok/s(--no-draft)22.13–22.5 tok/s--no-draft(+32–34% vs default)UD-Q2_K_XLdecode (opt-in--gpu-route-top 6 --tail-renorm, M4)16.8 tok/s23.90 tok/s99.2%128-step Top-1; 4/4 math/logic/coding PASS)UD-Q2_K_XLdecode (opt-in--gpu-skip-weight 0.10 --tail-renorm, M4)16.8 tok/s26.10 tok/s96.9%Top-1; 4/4 PASS;--tail-renormrequired)UD-Q2_K_XL4K prefill (100% lossless, GPU + opt-in SME20.25, M4)~81 tok/s(~51s)195.5 tok/s(21.0s)160.1 tok/sGPU-only;+10.1%single-var SME2 A/B)UD-Q2_K_XL~8K prefill (7,680tok, lossless, GPU + SME2, M4)~78 tok/s(~105s)192.7 tok/s(39.9s)18.88 tok/spost-8K decode)Inkling-2-Mini-IQ3_S4K prefill (warm A/B, SME2 off vs0.25, M4)64.9 tok/s(61.8s)88.6 tok/s(45.3s)5.8 -> 9.5 tok/s)IQ3_Scold decode (opt-in--gpu-skip-weight 0.08 --tail-renorm, M4)9.66 tok/s(254 swaps)12.03 tok/s(104 swaps)13.58 tok/s)UD-Q2_K_XLregression check (Apple M5 Ultra,--no-draft)83.3–85.9 tok/s87.7–90.5 tok/s4K/8Kprefill steady2,176–2,215 tok/s; SME2 off on Apple10)Why Drafts & Next Steps Needed from Maintainers
Per
CONTRIBUTING.md, all 4 PRs modify shared cross-backend engine files (engine/src/poly/) and were built/tested on Apple Silicon macOS only (CUDA, HIP, SYCL, and MSVC builds were not run locally). They are therefore kept as Draft until maintainers confirm scope and let me know which PRs to flip Ready for Review forrun-backendsCI.(Companion Qwen4-35B-A3B Metal optimization series is tracked in #472, with pure-Metal #511 already Ready for Review.)