[PR #4127] [Engine] Metal: decode and prompt kernels for the pair-trellis expert types TQP5/TQP6/TQP7 #4913

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4127
Author: @mnott
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: pr/metal-tqp-pair-trellis


📝 Commits (7)

  • f4822a1 feat(metal): decode kernels for the pair-trellis expert types TQP5/6/7 (147-149), CPU reference and expert_parity types
  • 05f2fcc [Engine] TQP5/TQP6/TQP7 (ggml 147-149): the pair trellis in the readers, the packer and the CPU reference
  • 25d0feb TQP5/6/7: numpy reference decoder, fork C harness, parity fixtures from the real model
  • c64c509 feat(metal): prompt kernels for the pair-trellis expert types TQP5/TQP6/TQP7
  • e61ca65 feat(metal): the decode window and prompt chain take a router of 256 experts
  • be25b2d fix(metal): deq_tqp reads the pair-trellis stream as 16-bit words (one 64-bit window a lane) instead of 24 byte loads: Coder-L decode 72 -> 85 tok/s
  • 886bc6e build(metal): tqp_parity links the in-repo TQP reference when no fork checkout is given

📊 Changes

42 files changed (+5856 additions, -65 deletions)

View changed files

📝 include/strata/artifact/gguf_reader.hpp (+19 -0)
📝 include/strata/kernels/cpu/tq_cpu.hpp (+9 -4)
📝 metal/CMakeLists.txt (+16 -0)
📝 metal/kernels/moe.metal (+10 -7)
📝 metal/kernels/moe_mm.metal (+34 -0)
📝 metal/kernels/prompt.metal (+7 -7)
📝 metal/kernels/quant.metal (+49 -0)
📝 metal/kernels/router.metal (+7 -7)
📝 metal/src/engine/iq_host.cpp (+6 -3)
📝 metal/src/engine/prompt_chain.inc (+13 -10)
📝 metal/src/engine/window.cpp (+27 -20)
📝 metal/src/ref_quant.cpp (+24 -2)
📝 metal/src/ref_quant.h (+1 -1)
📝 metal/tests/expert_parity.cpp (+2 -2)
➕ metal/tests/tqp_parity.cpp (+112 -0)
➕ metal/tools/gen_tqp_ref.py (+84 -0)
➕ ref/tqp/gen_table.py (+33 -0)
➕ ref/tqp/tq2t_lut_table.h (+516 -0)
➕ ref/tqp/tqp_ref_c.c (+131 -0)
📝 src/kernels/cpu/tq_cpu.cpp (+52 -2)

...and 22 more files

📄 Description

Problem and result

Gyro Coder files (for example Gyro Coder-L TQ3_0) store their experts in the pair-trellis types TQP5/TQP6/TQP7 (GGML types 147-149). v0.2.6 on macOS cannot load such a file: it stops in kernels::cpu::native_fmt / expert_layout_load. With this change the Metal engine loads and runs them.

Overview of our related macOS / Metal contributions: #4128. docs/GYRO.md lists these types (147-149) as the reason Gyro-L is not supported; Gyro-L also runs with this branch (comment below).

Approach

  • Readers, packer and CPU reference for TQP5/6/7; a numpy reference decoder and parity fixtures taken from a real model.
  • Metal decode and prompt kernels for the three types, covered by expert_parity.
  • The decode window and prompt chain accept a router of 256 experts (Gyro Coder routes over 256).
  • deq_tqp reads the pair-trellis stream as 16-bit words (one 64-bit window per lane) instead of 24 byte loads (Gyro Coder-L decode 72 -> 85 tok/s in our earlier measurement on the same machine).
  • tqp_parity links the in-repo TQP reference when no fork checkout is given, so a plain build of all targets succeeds.

Validation

Branch head 886bc6e7d7aa438081c1f42dc42df28e311e3ff0, 7 commits on v0.2.6. Apple Silicon, 128 GB unified memory, Gyro Coder-L TQ3_0, --ple-io direct --spec 2 with the MTP draft.

Passed:

  • Full build (strata and all test targets) on macOS.
  • tqp_parity, route_parity 256, route_parity 512, expert_parity --had-test: pass.
  • Gyro Coder-L loads and generates; greedy 80 tokens identical to the same stack built with these commits plus our other open changes (the reference v0.2.6 cannot load the file).
  • Greedy decode, 256 tokens, 3 alternating runs: reference 113.88 / 113.74 / 113.40 tok/s, this branch 115.22 / 113.79 / 114.87 tok/s.

Failed:

  • none observed

Not run:

  • CUDA, HIP and SYCL kernels for the pair-trellis types (this PR adds the Metal side and the CPU reference).

Limits

The packer and setup scripts are not wired into setup.sh's model list yet, so Gyro Coder and Gyro-L are packed by hand (tools/iq_pack.py).


🔄 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/4127 **Author:** [@mnott](https://github.com/mnott) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/metal-tqp-pair-trellis` --- ### 📝 Commits (7) - [`f4822a1`](https://github.com/Niko1221/Strata/commit/f4822a1adae7c948bba0c7c5adfcf8c6af8c79ab) feat(metal): decode kernels for the pair-trellis expert types TQP5/6/7 (147-149), CPU reference and expert_parity types - [`05f2fcc`](https://github.com/Niko1221/Strata/commit/05f2fcc88ab02a9228641b6e8389fcb8986b2585) [Engine] TQP5/TQP6/TQP7 (ggml 147-149): the pair trellis in the readers, the packer and the CPU reference - [`25d0feb`](https://github.com/Niko1221/Strata/commit/25d0feb32bec91553e8136d58b8f53aa6603e8cb) TQP5/6/7: numpy reference decoder, fork C harness, parity fixtures from the real model - [`c64c509`](https://github.com/Niko1221/Strata/commit/c64c5099015192fe7575dfa319dd67899e1ab590) feat(metal): prompt kernels for the pair-trellis expert types TQP5/TQP6/TQP7 - [`e61ca65`](https://github.com/Niko1221/Strata/commit/e61ca652f0003d8b666f4579120e67cb3f7cf064) feat(metal): the decode window and prompt chain take a router of 256 experts - [`be25b2d`](https://github.com/Niko1221/Strata/commit/be25b2d46284aadda0016986171652d2db74242e) fix(metal): deq_tqp reads the pair-trellis stream as 16-bit words (one 64-bit window a lane) instead of 24 byte loads: Coder-L decode 72 -> 85 tok/s - [`886bc6e`](https://github.com/Niko1221/Strata/commit/886bc6e7d7aa438081c1f42dc42df28e311e3ff0) build(metal): tqp_parity links the in-repo TQP reference when no fork checkout is given ### 📊 Changes **42 files changed** (+5856 additions, -65 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/artifact/gguf_reader.hpp` (+19 -0) 📝 `include/strata/kernels/cpu/tq_cpu.hpp` (+9 -4) 📝 `metal/CMakeLists.txt` (+16 -0) 📝 `metal/kernels/moe.metal` (+10 -7) 📝 `metal/kernels/moe_mm.metal` (+34 -0) 📝 `metal/kernels/prompt.metal` (+7 -7) 📝 `metal/kernels/quant.metal` (+49 -0) 📝 `metal/kernels/router.metal` (+7 -7) 📝 `metal/src/engine/iq_host.cpp` (+6 -3) 📝 `metal/src/engine/prompt_chain.inc` (+13 -10) 📝 `metal/src/engine/window.cpp` (+27 -20) 📝 `metal/src/ref_quant.cpp` (+24 -2) 📝 `metal/src/ref_quant.h` (+1 -1) 📝 `metal/tests/expert_parity.cpp` (+2 -2) ➕ `metal/tests/tqp_parity.cpp` (+112 -0) ➕ `metal/tools/gen_tqp_ref.py` (+84 -0) ➕ `ref/tqp/gen_table.py` (+33 -0) ➕ `ref/tqp/tq2t_lut_table.h` (+516 -0) ➕ `ref/tqp/tqp_ref_c.c` (+131 -0) 📝 `src/kernels/cpu/tq_cpu.cpp` (+52 -2) _...and 22 more files_ </details> ### 📄 Description ## Problem and result Gyro Coder files (for example Gyro Coder-L TQ3_0) store their experts in the pair-trellis types TQP5/TQP6/TQP7 (GGML types 147-149). v0.2.6 on macOS cannot load such a file: it stops in `kernels::cpu::native_fmt` / `expert_layout_load`. With this change the Metal engine loads and runs them. ## Related discussion Overview of our related macOS / Metal contributions: #4128. docs/GYRO.md lists these types (147-149) as the reason Gyro-L is not supported; Gyro-L also runs with this branch (comment below). ## Approach - Readers, packer and CPU reference for TQP5/6/7; a numpy reference decoder and parity fixtures taken from a real model. - Metal decode and prompt kernels for the three types, covered by `expert_parity`. - The decode window and prompt chain accept a router of 256 experts (Gyro Coder routes over 256). - `deq_tqp` reads the pair-trellis stream as 16-bit words (one 64-bit window per lane) instead of 24 byte loads (Gyro Coder-L decode 72 -> 85 tok/s in our earlier measurement on the same machine). - `tqp_parity` links the in-repo TQP reference when no fork checkout is given, so a plain build of all targets succeeds. ## Validation Branch head `886bc6e7d7aa438081c1f42dc42df28e311e3ff0`, 7 commits on `v0.2.6`. Apple Silicon, 128 GB unified memory, Gyro Coder-L TQ3_0, `--ple-io direct --spec 2` with the MTP draft. **Passed:** - Full build (`strata` and all test targets) on macOS. - `tqp_parity`, `route_parity 256`, `route_parity 512`, `expert_parity --had-test`: pass. - Gyro Coder-L loads and generates; greedy 80 tokens identical to the same stack built with these commits plus our other open changes (the reference v0.2.6 cannot load the file). - Greedy decode, 256 tokens, 3 alternating runs: reference 113.88 / 113.74 / 113.40 tok/s, this branch 115.22 / 113.79 / 114.87 tok/s. **Failed:** - none observed **Not run:** - CUDA, HIP and SYCL kernels for the pair-trellis types (this PR adds the Metal side and the CPU reference). ## Limits The packer and setup scripts are not wired into setup.sh's model list yet, so Gyro Coder and Gyro-L are packed by hand (tools/iq_pack.py). --- <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#4913
No description provided.