← TinyGPT · docs · devlog · roadmap · speedup
source: docs/research/wave_2_5_kernel_audit.md · view on GitHub ↗

Wave 2.5 kernel audit — BUILD / DEFER / DROP

Date: 2026-05-31 Question: For each of 5 proposed low-level kernel items, is it worth the engineering vs MLX-Swift / CoreML / Apple defaults? Outcome: 4 of 5 collapse — most “Wave 2.5” Metal kernel work goes away. One real win, one viable adoption on M5+, three drops, one defer.

Verdicts at a glance

ItemVerdictEffortReason (1 line)
Flash Attention Metal kernelDROPMLX-Swift MLXFast.scaledDotProductAttention already fused FA-style; all 9 of our call sites hit the fast path
Int8 matmul Metal kernel (W8A8)DEFER / adopt cider on M5+1-2 days adoptMininglamp-AI/cider ships this; needs M5 cooperative_tensor. M3/M4 has no hardware path
Int4 packed matmul Metal kernelDROPMLX quantized_matmul is hand-tuned int4. Custom = 0-5% delta
ANE+GPU heterogeneous routingDEFER3-6 weeksResearch-grade. Gated on Apple Stateful Models API (rumored late 2026). Real win when screen-watching specialist ships
WebGPU subgroup matmulBUILD3-5 days2-5× browser train. Scaffolding exists (webgpu/train_sg.wgsl)

1. Flash Attention Metal kernel — DROP

MLX-Swift’s MLXFast.scaledDotProductAttention is already a fused FlashAttention-style Metal kernel: do_causal mode is built in, no host-side mask allocation, tiled, matches Apple MPSGraph.

Evidence:

Verdict: Building our own FA Metal kernel is research-grade work (4-8 weeks of sustained kernel-tuning) for a 10-20% delta on inputs we don’t run. MLX/Apple have effectively solved this for our workloads. The repo’s existing custom FA2-forward in WGSL (browser side) is where our FA effort belongs.

2. Int8 matmul Metal kernel (W8A8) — DEFER / adopt cider on M5+

MLX’s quantize is weight-only; true W8A8 inference needs INT8 activations + INT8×INT8→INT32 GEMM. The open-source Mininglamp-AI/cider project ships exactly this as MLX custom primitives and reports 1.2-1.9× faster prefill, ~8% decode on M5 Pro (Qwen3-VL-2B).

Hardware constraint: cider explicitly disables itself on M4 and earlier because it relies on mpp::tensor_ops::matmul2d from Metal 4’s cooperative_tensor API — INT8 GEMM hardware acceleration is M5-only. On M3/M4 there is no hardware path; fallback to packed-int dot products is slower than bf16.

Decode benefit is small because LLM decode is memory-bound; the int8 win at long context is dominated by KV cache (still fp16) per ml-explore/mlx#3209.

Verdict: If the target Mac is M5/M5 Pro, adopt cider (1-2 days integration). Building from scratch = 2-3 weeks to recreate what cider already published. tinygpt’s primary dev machine is M5 Pro (confirmed 2026-05-31), so this is viable and is the largest single Mac-speed lever currently available.

3. Int4 packed matmul Metal kernel — DROP

MLX’s quantized_matmul is int4 by default and is already a hand-tuned Metal kernel — what mlx-lm, llmcheck.net, and the ml-explore/mlx#3209 benchmarks all measure.

Evidence:

Verdict: Building a competing int4 kernel is pure-implementation grunt-work for a 0-5% delta. MLX already solved this.

4. ANE + GPU heterogeneous routing — DEFER

The only item with a real product-shaped win — but research-grade.

Evidence:

The honest pattern: ANE wins on prefill and always-on background work; GPU wins on low-latency decode. Maps perfectly onto the agent runtime + screen-watching specialist in Wave 2.6.

Engineering reality:

Verdict: tinygpt already has a CoreML fp32 path (365 pass/s ANE forward measured). Extending to int4 stateful models is gated on Apple shipping the Stateful Models API. Defer until at least one full specialist ships; revisit when Stateful Models lands OR when battery-life-driven always-on becomes the demo. Pairs naturally with the screen-watching specialist work in Wave 2.6.

5. WebGPU subgroup matmul — BUILD

The one clear win.

Evidence:

Implementation shape:

Verdict: 3-5 days implementation-grade work. Realistic delta: 2-5× on flagship browser training where matmul dominates. Cleanest ROI of the five.

Recommendation summary

If 2 weeks solo:

  1. Ship the WebGPU subgroup matmul (item 5, 3-5 days, 2-5× browser train)
  2. Spend the rest evaluating cider’s W8A8 on actual M5+ hardware (item 2, adopt if numbers hold)
  3. Drop items 1 and 3 outright
  4. Write a one-page “ANE routing — revisit when Stateful Models API ships” decision-log for item 4

As executed (2026-05-31):

Sources