[PR #3299] [CLOSED] [Engine] Metal: run Gyro (trellis TQ2_T/TQK6/TQK7) models on Apple Silicon #4554

Closed
opened 2026-11-07 15:37:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3299
Author: @mnott
Created: 10/20/2026
Status: ❌ Closed

Base: main ← Head: metal-gyro


📝 Commits (7)

  • 3de5998 fix(metal): conversation checkpoints validate and park on Metal
  • 286e2e0 fix(macos): memory guard reads available RAM on macOS
  • 750764c fix(metal): validate checkpoints against the Metal window sizes
  • 361d1f7 fix(metal): describe the window's K/V in the session's QsaStates for conversation snapshots
  • 9735e7d fix(metal): session fingerprint reads the MTP file the Metal engine loads
  • 8efbd23 fix(metal): session restore accepts the files this engine saves
  • dd0c130 fix(metal): wrap a Gyro file without its PLE table: the head and tail ranges only, no read-ahead of the table

📊 Changes

12 files changed (+318 additions, -61 deletions)

View changed files

📝 include/strata/core/conversation_file.hpp (+15 -0)
📝 metal/CMakeLists.txt (+7 -1)
📝 metal/src/engine/window.cpp (+102 -42)
📝 metal/src/mtl_rt.h (+5 -0)
📝 metal/src/mtl_rt.mm (+30 -0)
➕ metal/tests/session_limits_test.cpp (+58 -0)
📝 src/core/conversation_file.cpp (+15 -0)
📝 src/core/conversation_file_test.cpp (+21 -0)
📝 src/core/conversation_memory.cpp (+18 -0)
📝 src/core/conversation_state.cpp (+37 -13)
📝 src/core/mtp.cpp (+3 -0)
📝 src/program/generate.cpp (+7 -5)

📄 Description

Gyro-M now runs on the Metal engine. Until now Metal refused Gyro files at load ("no trellis kernels").

This PR builds on #3231 (Mac conversation cache). Its first 4 commits are that PR; the 5 Gyro commits follow.

What's in it

  • Kernels. TQ2_T (the type Gyro-M uses for gate, up and down), TQK6 and TQK7 (Gyro-S): decode GEMV, the v2 prompt expert GEMMs, and the Hadamard rotation. The CPU reference is src/kernels/cpu/tq_cpu.cpp.
  • Engine.
    • native_expert_supported accepts types 144-146.
    • The Hadamard rotations are wired into the decode window and the prompt chain.
    • The trellis gate/up tile uses 16 lanes, because 80 units per row do not split evenly across 32.
  • Single-GGUF Gyro. The PLE table (per_layer_token_embd, ~54 GB, contiguous) sits inside the model file. It is now excluded from the wrapped GPU buffers: only the head and tail ranges are wrapped (37.6 of 92 GB), with no read-ahead on the table. The table is still read with direct I/O. Files with a separate PLE shard (IQ3_S) keep the old path; STRATA_METAL_WRAP_PLE=1 forces it.
  • Tests. metal/tests/tq_parity: 81/81 PASS (rel L2 ~1e-7 against the exact dot; the Hadamard rotation is bit-identical to hadamard_rotate). moe_mm_parity PASS. docs/GYRO.md updated.

Measured (M5 Max, 128 GB)

IQ3_S Gyro-M
Engine footprint ~61-65 GB RSS 23-26 GB + 37.6 GB weights mapped
20k prompt decode, prose / edit 84 / 121 tok/s 73-79 / 110 tok/s
Per-layer expert GEMV (top-10) 57.6 us, 405 GB/s 65-67 us, 190-194 GB/s
Agent coding task (3 parts), one agent 7.4 min 8.1 min
Same task, quality gates (tsc, build, full tests) all pass all pass
  • Two engines on one Mac. Because the mapped weights are shared, two Gyro-M engines fit in 128 GB (2 x 24 GB + 37.6 GB). Running one agent each did 1.28x the work of a single engine; per-engine decode drops to 56-69 tok/s on the shared GPU.
  • Where decode could get faster. It is ALU-bound on the trellis hash/lookup; an int8 LUT is the obvious next step.

Not covered

  • TQK6/TQK7 have not run on a full model (no Gyro-S file).
  • STRATA_METAL_STREAM=1 is encoded for trellis but untested.
  • The kernel source path is compiled in; STRATA_METAL_KERNELS overrides it.

🔄 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/3299 **Author:** [@mnott](https://github.com/mnott) **Created:** 10/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `metal-gyro` --- ### 📝 Commits (7) - [`3de5998`](https://github.com/Niko1221/Strata/commit/3de5998e894ab3995f9625d189797f1f2e096dcb) fix(metal): conversation checkpoints validate and park on Metal - [`286e2e0`](https://github.com/Niko1221/Strata/commit/286e2e0725834e17a93fe613adb9f8ff460657dd) fix(macos): memory guard reads available RAM on macOS - [`750764c`](https://github.com/Niko1221/Strata/commit/750764c1d2bb6b9e911bdbf92d5d3cd2b149b939) fix(metal): validate checkpoints against the Metal window sizes - [`361d1f7`](https://github.com/Niko1221/Strata/commit/361d1f7c4edc4b5292940c838de4771a1806f075) fix(metal): describe the window's K/V in the session's QsaStates for conversation snapshots - [`9735e7d`](https://github.com/Niko1221/Strata/commit/9735e7d9ee2f5558645b739869626ab23aeb25e2) fix(metal): session fingerprint reads the MTP file the Metal engine loads - [`8efbd23`](https://github.com/Niko1221/Strata/commit/8efbd23a14742cc426cd3c5e4b35baa1bd7f2f9e) fix(metal): session restore accepts the files this engine saves - [`dd0c130`](https://github.com/Niko1221/Strata/commit/dd0c130fe9a4370f148f30b25cd546434c5182c5) fix(metal): wrap a Gyro file without its PLE table: the head and tail ranges only, no read-ahead of the table ### 📊 Changes **12 files changed** (+318 additions, -61 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/conversation_file.hpp` (+15 -0) 📝 `metal/CMakeLists.txt` (+7 -1) 📝 `metal/src/engine/window.cpp` (+102 -42) 📝 `metal/src/mtl_rt.h` (+5 -0) 📝 `metal/src/mtl_rt.mm` (+30 -0) ➕ `metal/tests/session_limits_test.cpp` (+58 -0) 📝 `src/core/conversation_file.cpp` (+15 -0) 📝 `src/core/conversation_file_test.cpp` (+21 -0) 📝 `src/core/conversation_memory.cpp` (+18 -0) 📝 `src/core/conversation_state.cpp` (+37 -13) 📝 `src/core/mtp.cpp` (+3 -0) 📝 `src/program/generate.cpp` (+7 -5) </details> ### 📄 Description Gyro-M now runs on the Metal engine. Until now Metal refused Gyro files at load ("no trellis kernels"). **This PR builds on #3231** (Mac conversation cache). Its first 4 commits are that PR; the 5 Gyro commits follow. ## What's in it - **Kernels.** TQ2_T (the type Gyro-M uses for gate, up and down), TQK6 and TQK7 (Gyro-S): decode GEMV, the v2 prompt expert GEMMs, and the Hadamard rotation. The CPU reference is `src/kernels/cpu/tq_cpu.cpp`. - **Engine.** - `native_expert_supported` accepts types 144-146. - The Hadamard rotations are wired into the decode window and the prompt chain. - The trellis gate/up tile uses 16 lanes, because 80 units per row do not split evenly across 32. - **Single-GGUF Gyro.** The PLE table (`per_layer_token_embd`, ~54 GB, contiguous) sits inside the model file. It is now excluded from the wrapped GPU buffers: only the head and tail ranges are wrapped (37.6 of 92 GB), with no read-ahead on the table. The table is still read with direct I/O. Files with a separate PLE shard (IQ3_S) keep the old path; `STRATA_METAL_WRAP_PLE=1` forces it. - **Tests.** `metal/tests/tq_parity`: 81/81 PASS (rel L2 ~1e-7 against the exact dot; the Hadamard rotation is bit-identical to `hadamard_rotate`). `moe_mm_parity` PASS. `docs/GYRO.md` updated. ## Measured (M5 Max, 128 GB) | | IQ3_S | Gyro-M | |---|---|---| | Engine footprint | ~61-65 GB RSS | 23-26 GB + 37.6 GB weights mapped | | 20k prompt decode, prose / edit | 84 / 121 tok/s | 73-79 / 110 tok/s | | Per-layer expert GEMV (top-10) | 57.6 us, 405 GB/s | 65-67 us, 190-194 GB/s | | Agent coding task (3 parts), one agent | 7.4 min | 8.1 min | | Same task, quality gates (tsc, build, full tests) | all pass | all pass | - **Two engines on one Mac.** Because the mapped weights are shared, two Gyro-M engines fit in 128 GB (2 x 24 GB + 37.6 GB). Running one agent each did 1.28x the work of a single engine; per-engine decode drops to 56-69 tok/s on the shared GPU. - **Where decode could get faster.** It is ALU-bound on the trellis hash/lookup; an int8 LUT is the obvious next step. ## Not covered - TQK6/TQK7 have not run on a full model (no Gyro-S file). - `STRATA_METAL_STREAM=1` is encoded for trellis but untested. - The kernel source path is compiled in; `STRATA_METAL_KERNELS` overrides it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:37:21 +07:00
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#4554
No description provided.