[GH-ISSUE #4706] [Engine] Support 256-expert pruned models (Coder) on Apple Silicon Metal backend #2152

Open
opened 2026-11-04 01:57:05 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @earthking11 on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4706

Problem Statement

Currently, running the expert-pruned coding model ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF (which removes 50% of routed experts, leaving 256 experts per layer at 3.5 bpw) on Apple Silicon (Metal) fails during the hardware initialization stage with:

strata serve: metal window: the geometry differs from Qwen3.8-Flash-Next's
EngineDied: the engine exited before it was ready

While Strata already ships with data/expert-profile-coder.bin and supports this 256-expert architecture on NVIDIA CUDA/SYCL backends, the Metal backend does not yet support it.

Given that this 29.6 GB resident working set fits comfortably in 32 GB and 64 GB Mac Unified Memory configurations (leaving plenty of headroom for 64K/128K KV caches), bringing support for 256-expert models to Metal would be a massive quality-of-life improvement for Apple Silicon users.


Root Cause Analysis in Metal Backend

  1. Geometry validation in C++ host (metal/src/engine/window.cpp):

    • NEXP is statically defined as a compile-time constant:
      constexpr int N = 2560, HC = 4, LR = 320, NFF = 640, TOPK = 10, NEXP = 512, MAXT = 8;
      
    • In Window::init (line 440), it strictly enforces:
      if (g.n_embd != N || g.hc != HC || g.hc_lr != LR || g.n_ff != NFF || g.n_expert != NEXP || g.n_layers != 48) {
          err = "metal window: the geometry differs from Qwen3.8-Flash-Next's";
          return false;
      }
      
      For the Coder model, g.n_expert == 256, triggering the error.
  2. Hardcoded strides & loop unrolling in Metal shaders:

    • In metal/kernels/router.metal (line 12) & metal/kernels/prompt.metal (line 18):
      The softmax reduction and top-10 selection assume 512 logits across a SIMDgroup of 32 lanes via 16 unrolled iterations (32 * 16 = 512):
      device const float* l = logits + sg * 512;
      float v[16];
      for (int i = 0; i < 16; ++i) v[i] = l[lane + 32 * i];
      
    • Threadgroup sizes and plan_body allocations similarly assume 512 threads per block.

Suggested Approach / Next Steps

  • Add dynamic support (or a dedicated dispatch template specialization) for n_expert == 256 alongside the existing 512-expert path in router.metal and prompt.metal (e.g., 8 unrolled steps instead of 16).
  • Allow Window::init and internal buffer allocations in window.cpp / prompt_chain.inc to accept g.n_expert == 256 when paired with expert-profile-coder.bin.

Environment

  • Device: Apple M1 Max (64 GB Unified Memory)
  • OS: macOS
  • Strata Version: v0.2.8 / 0.1.54-metal
  • Target Model: ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF (Shard 1: 29.6 GB, Shard 2: 28.8 GB)
Originally created by @earthking11 on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4706 ### Problem Statement Currently, running the expert-pruned coding model `ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF` (which removes 50% of routed experts, leaving 256 experts per layer at 3.5 bpw) on Apple Silicon (Metal) fails during the hardware initialization stage with: ```text strata serve: metal window: the geometry differs from Qwen3.8-Flash-Next's EngineDied: the engine exited before it was ready ``` While Strata already ships with `data/expert-profile-coder.bin` and supports this 256-expert architecture on NVIDIA CUDA/SYCL backends, the Metal backend does not yet support it. Given that this 29.6 GB resident working set fits comfortably in 32 GB and 64 GB Mac Unified Memory configurations (leaving plenty of headroom for 64K/128K KV caches), bringing support for 256-expert models to Metal would be a massive quality-of-life improvement for Apple Silicon users. --- ### Root Cause Analysis in Metal Backend 1. **Geometry validation in C++ host (`metal/src/engine/window.cpp`)**: - `NEXP` is statically defined as a compile-time constant: ```cpp constexpr int N = 2560, HC = 4, LR = 320, NFF = 640, TOPK = 10, NEXP = 512, MAXT = 8; ``` - In `Window::init` (line 440), it strictly enforces: ```cpp if (g.n_embd != N || g.hc != HC || g.hc_lr != LR || g.n_ff != NFF || g.n_expert != NEXP || g.n_layers != 48) { err = "metal window: the geometry differs from Qwen3.8-Flash-Next's"; return false; } ``` For the Coder model, `g.n_expert == 256`, triggering the error. 2. **Hardcoded strides & loop unrolling in Metal shaders**: - In `metal/kernels/router.metal` (line 12) & `metal/kernels/prompt.metal` (line 18): The softmax reduction and top-10 selection assume 512 logits across a SIMDgroup of 32 lanes via 16 unrolled iterations (`32 * 16 = 512`): ```metal device const float* l = logits + sg * 512; float v[16]; for (int i = 0; i < 16; ++i) v[i] = l[lane + 32 * i]; ``` - Threadgroup sizes and `plan_body` allocations similarly assume 512 threads per block. --- ### Suggested Approach / Next Steps - Add dynamic support (or a dedicated dispatch template specialization) for `n_expert == 256` alongside the existing 512-expert path in `router.metal` and `prompt.metal` (e.g., 8 unrolled steps instead of 16). - Allow `Window::init` and internal buffer allocations in `window.cpp` / `prompt_chain.inc` to accept `g.n_expert == 256` when paired with `expert-profile-coder.bin`. --- ### Environment - **Device**: Apple M1 Max (64 GB Unified Memory) - **OS**: macOS - **Strata Version**: v0.2.8 / 0.1.54-metal - **Target Model**: `ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-Coder-GGUF` (Shard 1: 29.6 GB, Shard 2: 28.8 GB)
Author
Owner

@github-actions[bot] commented on GitHub (Oct 30, 2026):

Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:

  • Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes".

Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

<!-- gh-comment-id:6523337458 --> @github-actions[bot] commented on GitHub (Oct 30, 2026): Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing: - [ ] Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] decode stops after 2 minutes". Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment `/reopen`. Details: [CONTRIBUTING.md](https://github.com/Niko1221/Strata/blob/main/CONTRIBUTING.md)
Author
Owner

@github-actions[bot] commented on GitHub (Oct 30, 2026):

Thanks, this follows the format now.

<!-- gh-comment-id:6523391837 --> @github-actions[bot] commented on GitHub (Oct 30, 2026): Thanks, this follows the format now.
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#2152
No description provided.