[PR #4886] [Engine] Metal: IQ1_M expert gate/up in the GSQ packs (the missing type-29 instantiations, #2537) #5232

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4886
Author: @Spinoza0
Created: 11/1/2026
Status: 🔄 Open

Base: main ← Head: metal-iq1m-gsq-v029


📝 Commits (1)

  • 2518043 metal moe: instantiate IQ1_M's expert gate/up (the GSQ packs' experts)

📊 Changes

3 files changed (+27 additions, -1 deletions)

View changed files

📝 metal/kernels/moe.metal (+1 -0)
📝 metal/kernels/moe_mm.metal (+2 -1)
📝 metal/kernels/quant.metal (+24 -0)

📄 Description

Problem and result

Metal has no IQ1_M path for the GSQ packs' expert gate/up: the kernel library lacks the type-29 instantiations, so a run of such a pack fails at kernel load — mtl: no function moe_gu_29_32_1_4 on the decode window, and mm_gu2_29_16_64_16_2 once a prompt reaches the matrix units. After the change the same model runs, and every batch slot is IDENTICAL to its solo run.

#2537 — the same missing Metal path for IQ1_M in the GSQ IQ2_XS file, closed by the 0.2.0-beta tracker reset (not rejected).

Approach

Three files, 27 lines, kernel instantiations only:

  • metal/kernels/moe.metal: GU_SET(T_IQ1_M).
  • metal/kernels/moe_mm.metal: MM_GU_SET(T_IQ1_M) and MM_GU2_SET(T_IQ1_M). The v1/v2 prompt paths stage weights through stage_w's generic DW<F>, which decodes through deq<F>, so the instantiations are enough.
  • metal/kernels/quant.metal: deq<T_IQ1_M> — the only symbol the linker was missing. fmt<T_IQ1_M> (TAB = 1) and load_tab<T_IQ1_M>'s no-op stay as they are: the tile reads the module's iq1s_grid constant, so the arithmetic matches ggml's dequantize_row_iq1_m (nibble j = grid-row byte j + 1, the rows' bytes are -1/0/1, so nibble minus one is the signed byte j). Checked against the table itself: row 1 0xffffffffffffff01 → 0x00000002, row 2 0xffffffffffff0000 → 0x00000011, row 3 → 0x00000020.

Nothing else is touched: no host code, no server, no CLI, no defaults. Every other pack's path is byte-identical, because the new instantiations are only reached by tensors of type 29.

Validation

Revision tested: 25180433 — this patch rebased onto main (9f7d977d, 208 commits since the 2026-11-03 revision a9ec74af; the battery below re-runs on 2026-11-05 with the same commands and machine), built with cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release -DMETAL_CPP_DIR=<metal-cpp> -DSTRATA_GGML_DIR=<llama.cpp> checkout. Environment: Apple M4 Pro 48 GB, macOS 27.0.1, Qwen3.8-Flash-Next-GSQ-RCO-IQ2_XS (the experts' gate/up in IQ1_M), kernels read from the patched tree (STRATA_METAL_KERNELS), extra args --pcie-frac 0 --adapt-every 1000000 --no-prefill-borrow --vram-reserve-mib 1024 (in a local serve_iq2_xs.json copy of strata-iq2_xs.json).

Passed

  • Compilation: ninja -C build-metal strata → the build exits 0.
  • python3 tools/batch_test.py --exe build-metal/strata --config serve_iq2_xs.json --batch 2 --n 2 --max-new 24 → every slot IDENTICAL to its solo run (passed on 2026-11-03, confirmed again on 2026-11-05, same tokens).
  • python3 tools/batch_test.py … --batch 4 --n 4 --max-new 8 → all 4 slots IDENTICAL (passed on 2026-11-03, confirmed again on 2026-11-05).
  • python3 tools/batch_interleave_test.py --exe build-metal/strata --config serve_iq2_xs.json --extra "--vram-reserve-mib 1536" → 10/10 IDENTICAL on 2026-11-03 (slots A/B/C, next-turn from a slot, BYIELD, F/F2 checkpoints), including the 4888-token prompt read through mm_gu2_29. On 2026-11-05 one run (started with the machine's memory healthy) passed the whole flow again, and every step that completed in the other runs was again IDENTICAL; those runs ended at a pre-existing abort unrelated to this change — see Failed below.
  • python3 tools/serve_load.py http://127.0.0.1:8083 --clients 2 --rounds 3 --max-tokens 128 → 23.2 tok/s aggregate warm on 2026-11-03; on 2026-11-05, 0 errors, 19.1 tok/s warm (round 3 at 20.3).

Failed (2026-11-05, this revision, environment)

  • The interleave run ended at the engine's restart guard twice today: strata metal runtime: a copy touches a device allocation of 7043.4 MB that was given back (STRATA_METAL_KEEP_HOST_WEIGHTS=1 keeps it) — the same script point (the BGEN 1 window after the give-away), the same line. An abort in metal/src/gpu/runtime.cpp's given-back check during a conversation park/save; that code is untouched by this PR (.metal kernel symbols only) and unchanged since the 2026-11-03 revision, where the same test passed 10/10. It reproduced only when macOS reported little free RAM at the failed copy (13.2 GB available); the one run of the day started with 34.2 GB available passed the whole flow.
  • Three same-day attempts ended at the engine's #29 watchdog instead: with macOS memory residue the engine's "available" fell to ~5 GB, the expert arena collapsed to 1.0 GB (planned 17.9) and decode fell to ~5 tok/s (a 0.1.45-line control engine decoded at the usual ~15-20 tok/s on the same files and commands the same afternoon).

Why this abort is a separate bug, not this change: the diff adds kernel instantiations only — no host code — so it cannot reach runtime.cpp's given-back check or the park/save copy that trips it, and the identification above (free RAM at the copy decides, 34.2 GB passes the whole flow) makes the machine state the variable while the patch stays constant. An A/B on this very workload against unpatched main is impossible by construction: without the type-29 instantiations this pack cannot load at all (mtl: no function moe_gu_29_32_1_4 — exactly what this PR fixes), so the abort becomes reachable only once this patch lets the pack run; it is not introduced by the running. The clean reproduction for a maintainer would be the same test on a pack whose expert type main already covers (IQ3_XXS or Q5_0): this machine has no such pack local.

Failed (before the change, same hardware and workload)

  • tools/batch_test.py --batch 2 on unpatched v0.2.9: the engine died at kernel load — mtl: no function moe_gu_29_32_1_4 … was not found in the library (the test driver then got a BrokenPipe).
  • tools/batch_interleave_test.py with only GU_SET(T_IQ1_M) added: the engine died on the 4888-token prompt with no function mm_gu2_29_16_64_16_2; the same test passed after MM_GU_SET/MM_GU2_SET were added.

Not run

  • CUDA, HIP and SYCL builds: the three changed files are Metal-only, no other backend compiles them.
  • mm_gu3/mm_gu4 shapes for type 29 — they need a W4<T_IQ1_M>, and this configuration never requests them; left unverified on purpose.

Limits

The patch only adds kernel instantiations and one decoder specialization: it changes no defaults, no settings and no user-visible behavior for any other pack. mm_gu3/mm_gu4 for type 29 are left out because this configuration never requests them.

Working variant

Fork branch with this patch: https://github.com/Spinoza0/Strata/tree/metal-iq1m-gsq-v029


🔄 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/4886 **Author:** [@Spinoza0](https://github.com/Spinoza0) **Created:** 11/1/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `metal-iq1m-gsq-v029` --- ### 📝 Commits (1) - [`2518043`](https://github.com/Niko1221/Strata/commit/2518043375eb16cc02b16eb82b45530139955330) metal moe: instantiate IQ1_M's expert gate/up (the GSQ packs' experts) ### 📊 Changes **3 files changed** (+27 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `metal/kernels/moe.metal` (+1 -0) 📝 `metal/kernels/moe_mm.metal` (+2 -1) 📝 `metal/kernels/quant.metal` (+24 -0) </details> ### 📄 Description ## Problem and result Metal has no IQ1_M path for the GSQ packs' expert gate/up: the kernel library lacks the type-29 instantiations, so a run of such a pack fails at kernel load — `mtl: no function moe_gu_29_32_1_4` on the decode window, and `mm_gu2_29_16_64_16_2` once a prompt reaches the matrix units. After the change the same model runs, and every batch slot is IDENTICAL to its solo run. ## Related discussion [#2537](https://github.com/Niko1221/Strata/issues/2537) — the same missing Metal path for IQ1_M in the GSQ IQ2_XS file, closed by the 0.2.0-beta tracker reset (not rejected). ## Approach Three files, 27 lines, kernel instantiations only: - `metal/kernels/moe.metal`: `GU_SET(T_IQ1_M)`. - `metal/kernels/moe_mm.metal`: `MM_GU_SET(T_IQ1_M)` and `MM_GU2_SET(T_IQ1_M)`. The v1/v2 prompt paths stage weights through `stage_w`'s generic `DW<F>`, which decodes through `deq<F>`, so the instantiations are enough. - `metal/kernels/quant.metal`: `deq<T_IQ1_M>` — the only symbol the linker was missing. `fmt<T_IQ1_M>` (`TAB = 1`) and `load_tab<T_IQ1_M>`'s no-op stay as they are: the tile reads the module's `iq1s_grid` constant, so the arithmetic matches ggml's `dequantize_row_iq1_m` (nibble j = grid-row byte j + 1, the rows' bytes are -1/0/1, so nibble minus one is the signed byte j). Checked against the table itself: row 1 `0xffffffffffffff01` → `0x00000002`, row 2 `0xffffffffffff0000` → `0x00000011`, row 3 → `0x00000020`. Nothing else is touched: no host code, no server, no CLI, no defaults. Every other pack's path is byte-identical, because the new instantiations are only reached by tensors of type 29. ## Validation Revision tested: `25180433` — this patch rebased onto `main` (`9f7d977d`, 208 commits since the 2026-11-03 revision `a9ec74af`; the battery below re-runs on 2026-11-05 with the same commands and machine), built with `cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release -DMETAL_CPP_DIR=<metal-cpp> -DSTRATA_GGML_DIR=<llama.cpp> checkout`. Environment: Apple M4 Pro 48 GB, macOS 27.0.1, Qwen3.8-Flash-Next-GSQ-RCO-IQ2_XS (the experts' gate/up in IQ1_M), kernels read from the patched tree (`STRATA_METAL_KERNELS`), extra args `--pcie-frac 0 --adapt-every 1000000 --no-prefill-borrow --vram-reserve-mib 1024` (in a local `serve_iq2_xs.json` copy of `strata-iq2_xs.json`). **Passed** - Compilation: `ninja -C build-metal strata` → the build exits 0. - `python3 tools/batch_test.py --exe build-metal/strata --config serve_iq2_xs.json --batch 2 --n 2 --max-new 24` → every slot IDENTICAL to its solo run (passed on 2026-11-03, confirmed again on 2026-11-05, same tokens). - `python3 tools/batch_test.py … --batch 4 --n 4 --max-new 8` → all 4 slots IDENTICAL (passed on 2026-11-03, confirmed again on 2026-11-05). - `python3 tools/batch_interleave_test.py --exe build-metal/strata --config serve_iq2_xs.json --extra "--vram-reserve-mib 1536"` → 10/10 IDENTICAL on 2026-11-03 (slots A/B/C, next-turn from a slot, BYIELD, F/F2 checkpoints), including the 4888-token prompt read through `mm_gu2_29`. On 2026-11-05 one run (started with the machine's memory healthy) passed the whole flow again, and every step that completed in the other runs was again IDENTICAL; those runs ended at a pre-existing abort unrelated to this change — see **Failed** below. - `python3 tools/serve_load.py http://127.0.0.1:8083 --clients 2 --rounds 3 --max-tokens 128` → 23.2 tok/s aggregate warm on 2026-11-03; on 2026-11-05, 0 errors, 19.1 tok/s warm (round 3 at 20.3). **Failed (2026-11-05, this revision, environment)** - The interleave run ended at the engine's restart guard twice today: `strata metal runtime: a copy touches a device allocation of 7043.4 MB that was given back (STRATA_METAL_KEEP_HOST_WEIGHTS=1 keeps it)` — the same script point (the `BGEN 1` window after the give-away), the same line. An abort in `metal/src/gpu/runtime.cpp`'s given-back check during a conversation park/save; that code is untouched by this PR (.metal kernel symbols only) and unchanged since the 2026-11-03 revision, where the same test passed 10/10. It reproduced only when macOS reported little free RAM at the failed copy (13.2 GB available); the one run of the day started with 34.2 GB available passed the whole flow. - Three same-day attempts ended at the engine's #29 watchdog instead: with macOS memory residue the engine's "available" fell to ~5 GB, the expert arena collapsed to 1.0 GB (planned 17.9) and decode fell to ~5 tok/s (a 0.1.45-line control engine decoded at the usual ~15-20 tok/s on the same files and commands the same afternoon). Why this abort is a separate bug, not this change: the diff adds kernel instantiations only — no host code — so it cannot reach `runtime.cpp`'s given-back check or the park/save copy that trips it, and the identification above (free RAM at the copy decides, 34.2 GB passes the whole flow) makes the machine state the variable while the patch stays constant. An A/B on this very workload against unpatched `main` is impossible by construction: without the type-29 instantiations this pack cannot load at all (`mtl: no function moe_gu_29_32_1_4` — exactly what this PR fixes), so the abort becomes *reachable* only once this patch lets the pack run; it is not introduced by the running. The clean reproduction for a maintainer would be the same test on a pack whose expert type `main` already covers (IQ3_XXS or Q5_0): this machine has no such pack local. **Failed (before the change, same hardware and workload)** - `tools/batch_test.py --batch 2` on unpatched v0.2.9: the engine died at kernel load — `mtl: no function moe_gu_29_32_1_4 … was not found in the library` (the test driver then got a BrokenPipe). - `tools/batch_interleave_test.py` with only `GU_SET(T_IQ1_M)` added: the engine died on the 4888-token prompt with `no function mm_gu2_29_16_64_16_2`; the same test passed after `MM_GU_SET`/`MM_GU2_SET` were added. **Not run** - CUDA, HIP and SYCL builds: the three changed files are Metal-only, no other backend compiles them. - `mm_gu3`/`mm_gu4` shapes for type 29 — they need a `W4<T_IQ1_M>`, and this configuration never requests them; left unverified on purpose. ## Limits The patch only adds kernel instantiations and one decoder specialization: it changes no defaults, no settings and no user-visible behavior for any other pack. `mm_gu3`/`mm_gu4` for type 29 are left out because this configuration never requests them. ## Working variant Fork branch with this patch: https://github.com/Spinoza0/Strata/tree/metal-iq1m-gsq-v029 --- <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#5232
No description provided.