[PR #4238] [Engine] Metal: faster routed-expert gate/up tiles on M1/M2 (8,1,2 for the K quants) #4968

Open
opened 2026-11-07 16:31:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4238
Author: @catalinb13
Created: 10/26/2026
Status: 🔄 Open

Base: main ← Head: metal-m1-kexperts-tile


📝 Commits (10+)

  • b158818 metal: the request's sampling (the CUDA sampler's chain, on the CPU over the window's head logits)
  • 0d6e5ba tests: tools/metal_sampling_test.py (the request's sampling through --serve: reproducible seeds, picks draw for draw against a reference sampler on the dumped logits, penalties, logit_bias) and metal/tests/engine/host_sampler_parity.cpp
  • 3a49b02 docs: Mac sampling (MAC.md Sampling: the keys, the order, seeds, the host pick's cost, greedy vs sampled decode)
  • 093ed30 metal: release prompt scratch buffers before workspace growth
  • 02e9f27 fix(serve): stop reporting stale cache occupancy after refused parking
  • b9252ed Merge current main and exercise prompt growth without caller autorelease pools
  • 9844762 conversation cache: --conversation-cache-min-tokens WRITE[,READ] gates parked reads
  • 1be9c7d metal: opt-in fp16-slab expert path (mpp) for streaming prompt chunks
  • 1d7f1b5 gap harness + attribution rounds 1-4; kprof gate reverted to baseline
  • a9b951b metal: M1 Max A/B hooks (STRATA_METAL_GEMV_TILE/MOE_TILE/GDN_SCAN); decode copy-overlap on by default on Metal

📊 Changes

341 files changed (+53789 additions, -1723 deletions)

View changed files

📝 .gitignore (+3 -0)
📝 docs/BATCHING.md (+77 -2)
➕ docs/DECODE_2X_PLAN.md (+179 -0)
📝 docs/DETAILS.md (+2414 -1196)
📝 docs/MAC.md (+257 -238)
➕ gap/arms-base.txt (+13 -0)
➕ gap/arms-final.txt (+7 -0)
➕ gap/arms-kprof.txt (+2 -0)
➕ gap/arms-needle.txt (+5 -0)
➕ gap/arms-needle2.txt (+7 -0)
➕ gap/arms-needle3.txt (+2 -0)
➕ gap/arms-profile.txt (+9 -0)
➕ gap/arms-round10.txt (+9 -0)
➕ gap/arms-round11.txt (+9 -0)
➕ gap/arms-round12.txt (+7 -0)
➕ gap/arms-round13.txt (+15 -0)
➕ gap/arms-round14.txt (+13 -0)
➕ gap/arms-round15.txt (+13 -0)
➕ gap/arms-round16.txt (+17 -0)
➕ gap/arms-round17.txt (+15 -0)

...and 80 more files

📄 Description

Problem and result. On the M1/M2 family the routed-expert gate/up GEMMs ran with the M5's 32-lane, 4-group tile. The M1 Max reads far better with 8 lanes and 2 groups: the compute-bound bench is 2.8x faster (117 us a layer against 327 at one token), the live host 2-5%. The engine now picks 8,1,2 for Q4_K/Q5_K/Q6_K gate/up on M1/M2; every other pack and the M5 layout keep the current tiles.

Approach. Two tile-gate hunks in the window's expert paths (the decode moe_block and the mtp/mtp-style window): where the tile is chosen, gemv_m12_ (this branch's existing M1/M2 flag from the GEMV work) and the K-family quant select gl=8, gs=2. The matching down tile (4,2,4) measured a wash at the 1-3-token decode windows, so it stays an opt-in: STRATA_METAL_MOE_DN2=1.

Validation (passed). expert_parity --bench --sweep for the full tile list (Q4_K gate/up, Q5_1 down; kept in the fork's docs table). Parity: expert_parity --gucfg 8,1,2 --dncfg 4,1,4 rel L2 1.6e-07, and 4,2,4 down rel L2 2.5e-07. Live A/B on the 82.5 GB Q4_K host at 98-101K depth, bracketed arms per the fork's doctrine (baseline before and after; candidate wins only if its worst arm beats the anchors' best): 8,1,2 = 20.64, 20.8, 22.31, 21.67 tok/s; 32,1,4 forced = 19.6, 21.05, 19.6, 21.05. DN2 A/B: 21.98 against 21.51 (wash). Harness suite: 17/18 parity binaries pass; fuse_parity fails the same way with and without this change (pre-existing, not touched here).

Limits. Measured on an M1 Max 64 GB (M1/M2 path); no M1/M2 other than the Max was exercised, no M5 change. Metal-only files; CUDA/HIP/SYCL untouched.

Stacked on the fork's open Metal PR series (#2645/#3783/#3287) — the branch carries the same base as those.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4238 **Author:** [@catalinb13](https://github.com/catalinb13) **Created:** 10/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `metal-m1-kexperts-tile` --- ### 📝 Commits (10+) - [`b158818`](https://github.com/Niko1221/Strata/commit/b158818c33d010eca4c933a10ffbe4414620438e) metal: the request's sampling (the CUDA sampler's chain, on the CPU over the window's head logits) - [`0d6e5ba`](https://github.com/Niko1221/Strata/commit/0d6e5ba3413da4a82a18d2807c99e0897bd701de) tests: tools/metal_sampling_test.py (the request's sampling through --serve: reproducible seeds, picks draw for draw against a reference sampler on the dumped logits, penalties, logit_bias) and metal/tests/engine/host_sampler_parity.cpp - [`3a49b02`](https://github.com/Niko1221/Strata/commit/3a49b029e80aa5d63eae8752c47198bf096483f5) docs: Mac sampling (MAC.md Sampling: the keys, the order, seeds, the host pick's cost, greedy vs sampled decode) - [`093ed30`](https://github.com/Niko1221/Strata/commit/093ed3077e8f03ae54ffc302ac0b1af37592b38e) metal: release prompt scratch buffers before workspace growth - [`02e9f27`](https://github.com/Niko1221/Strata/commit/02e9f272264b8df363ddc9f3eb177d945d5d84fb) fix(serve): stop reporting stale cache occupancy after refused parking - [`b9252ed`](https://github.com/Niko1221/Strata/commit/b9252edc5368b452a530b32d017e30f8a19e107a) Merge current main and exercise prompt growth without caller autorelease pools - [`9844762`](https://github.com/Niko1221/Strata/commit/9844762a97fb326bc3338624ff2ba512c5108bad) conversation cache: --conversation-cache-min-tokens WRITE[,READ] gates parked reads - [`1be9c7d`](https://github.com/Niko1221/Strata/commit/1be9c7deb2e8114e3c658e6d8505b905e8ddd38c) metal: opt-in fp16-slab expert path (mpp) for streaming prompt chunks - [`1d7f1b5`](https://github.com/Niko1221/Strata/commit/1d7f1b5bc348678edd117b8acd6fcb885ff0598e) gap harness + attribution rounds 1-4; kprof gate reverted to baseline - [`a9b951b`](https://github.com/Niko1221/Strata/commit/a9b951bc7806a4d6712a9fe9febce04a7bb31b83) metal: M1 Max A/B hooks (STRATA_METAL_GEMV_TILE/MOE_TILE/GDN_SCAN); decode copy-overlap on by default on Metal ### 📊 Changes **341 files changed** (+53789 additions, -1723 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+3 -0) 📝 `docs/BATCHING.md` (+77 -2) ➕ `docs/DECODE_2X_PLAN.md` (+179 -0) 📝 `docs/DETAILS.md` (+2414 -1196) 📝 `docs/MAC.md` (+257 -238) ➕ `gap/arms-base.txt` (+13 -0) ➕ `gap/arms-final.txt` (+7 -0) ➕ `gap/arms-kprof.txt` (+2 -0) ➕ `gap/arms-needle.txt` (+5 -0) ➕ `gap/arms-needle2.txt` (+7 -0) ➕ `gap/arms-needle3.txt` (+2 -0) ➕ `gap/arms-profile.txt` (+9 -0) ➕ `gap/arms-round10.txt` (+9 -0) ➕ `gap/arms-round11.txt` (+9 -0) ➕ `gap/arms-round12.txt` (+7 -0) ➕ `gap/arms-round13.txt` (+15 -0) ➕ `gap/arms-round14.txt` (+13 -0) ➕ `gap/arms-round15.txt` (+13 -0) ➕ `gap/arms-round16.txt` (+17 -0) ➕ `gap/arms-round17.txt` (+15 -0) _...and 80 more files_ </details> ### 📄 Description **Problem and result.** On the M1/M2 family the routed-expert gate/up GEMMs ran with the M5's 32-lane, 4-group tile. The M1 Max reads far better with 8 lanes and 2 groups: the compute-bound bench is 2.8x faster (117 us a layer against 327 at one token), the live host 2-5%. The engine now picks 8,1,2 for Q4_K/Q5_K/Q6_K gate/up on M1/M2; every other pack and the M5 layout keep the current tiles. **Approach.** Two tile-gate hunks in the window's expert paths (the decode moe_block and the mtp/mtp-style window): where the tile is chosen, `gemv_m12_` (this branch's existing M1/M2 flag from the GEMV work) and the K-family quant select gl=8, gs=2. The matching down tile (4,2,4) measured a wash at the 1-3-token decode windows, so it stays an opt-in: `STRATA_METAL_MOE_DN2=1`. **Validation (passed).** `expert_parity --bench --sweep` for the full tile list (Q4_K gate/up, Q5_1 down; kept in the fork's docs table). Parity: `expert_parity --gucfg 8,1,2 --dncfg 4,1,4` rel L2 1.6e-07, and 4,2,4 down rel L2 2.5e-07. Live A/B on the 82.5 GB Q4_K host at 98-101K depth, bracketed arms per the fork's doctrine (baseline before and after; candidate wins only if its worst arm beats the anchors' best): 8,1,2 = 20.64, 20.8, 22.31, 21.67 tok/s; 32,1,4 forced = 19.6, 21.05, 19.6, 21.05. DN2 A/B: 21.98 against 21.51 (wash). Harness suite: 17/18 parity binaries pass; `fuse_parity` fails the same way with and without this change (pre-existing, not touched here). **Limits.** Measured on an M1 Max 64 GB (M1/M2 path); no M1/M2 other than the Max was exercised, no M5 change. Metal-only files; CUDA/HIP/SYCL untouched. Stacked on the fork's open Metal PR series (#2645/#3783/#3287) — the branch carries the same base as those. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4968
No description provided.