mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3662] [Engine] support Qwen3.8-Flash-Next Coder (256 experts) on Apple Silicon Metal #4738
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4738
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3662
Author: @chuaaron
Created: 10/21/2026
Status: 🔄 Open
Base:
main← Head:feat/metal-coder📝 Commits (2)
84e19bd[Engine] support Qwen3.8-Flash-Next Coder (256 experts) on Apple Silicon Metalf171715[Engine] Metal: fix fused router tg size for 256 experts, wire streaming expert profile and log prompt path📊 Changes
16 files changed (+395 additions, -173 deletions)
View changed files
📝
.gitignore(+1 -0)📝
metal/kernels/dense_mm.metal(+7 -0)📝
metal/kernels/mm_bench.metal(+6 -0)📝
metal/kernels/moe.metal(+78 -36)📝
metal/kernels/prompt.metal(+46 -0)📝
metal/kernels/router.metal(+78 -36)📝
metal/setup_mac.py(+24 -10)📝
metal/src/engine/prompt_chain.inc(+10 -8)📝
metal/src/engine/stream.cpp(+43 -32)📝
metal/src/engine/stream.h(+2 -0)📝
metal/src/engine/window.cpp(+57 -36)📝
metal/tests/coop_probe.h(+1 -0)📝
metal/tools/stream_experts.py(+12 -10)📝
setup.py(+11 -4)📝
src/program/generate.cpp(+5 -1)📝
strata_control/mac_fit.py(+14 -0)📄 Description
Problem and result
Strata previously supported Qwen3.8-Flash-Next 512-expert models on Apple Silicon (Metal), but attempting to run the Qwen3.8-Flash-Next Coder variant (256 experts) failed at multiple levels:
router.metal,moe.metal,prompt.metal) hardcoded 512 experts with 16-unroll routing and MoE dispatches, causing out-of-bounds indexing or shape mismatches when given a 256-expert model.window.cpp,stream.cpp,stream.h,prompt_chain.inc) hardcoded 512 expert slots for routing logits, buffers, and offsets.#include <MetalPerformancePrimitives/MetalPerformancePrimitives.h>was unconditionally included indense_mm.metalwithout feature detection.With this change:
coderfamily andIQ1_Mare supported on Apple Silicon (Metal).Related discussion
none
Approach
router.metal: addedn_expert == 256routing branch (unroll 8) alongside 512 (unroll 16).moe.metal: addedn_expert == 256MoE calculation branch.prompt.metal: addedroute_topk_256kernel specialization.dense_mm.metal&mm_bench.metal: guardedMetalPerformancePrimitivesinclude andgemm_f16with#if __has_include(<MetalPerformancePrimitives/MetalPerformancePrimitives.h>).stream.h,stream.cpp,window.cpp,prompt_chain.inc: replaced static 512 constants withn_expert_detected dynamically from model metadata.window.cpp: addedsupports_metal4()check to fall back cleanly to decode window prefill on M1-M4 / macOS 15 devices.setup.py,metal/setup_mac.py,strata_control/mac_fit.py: enabledcoderfamily andIQ1_Mon macOS, configured shard file naming and profile defaults.metal/tools/stream_experts.py: readn_expertfrom GGUF metadata instead of assuming 512.Validation
Passed:
python3 tools/test_setup_mac.py-> Ran 24 tests in 0.090s, OK.ninja -C build-metal strata-> clean build without errors../build-metal/strata --tokens "100,101...200" --pack <pack> --native <shard1> --ple-gguf <shard2> --expert-profile data/expert-profile-coder.bin --expert-cache 64 --prefill auto --spec 2 --mtp <mtp_dir> --max-context 65536 --mmap-experts --max-new 5Result:
/v1/chat/completions):Failed:
none observed
Not run:
CUDA / ROCm / SYCL execution (change is isolated to Apple Metal backend and macOS setup scripts; non-Mac code paths unaffected).
Limits
On Apple Silicon without Metal 4 (M1-M4, macOS 15), prompt prefill uses the universal decode window batched prefill path; Metal 4 matrix-unit prefill (
matmul2d) requires macOS 26+ and supported hardware.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.