mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #2323] [Bug]: Mac (M2 Max, macOS 26.3): garbage output — gdn_step for 2+ tokens is never dispatched (pipeline max 448 threads < 512); qsa_prompt.metal fails to compile #938
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#938
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?
Originally created by @botbizs on GitHub (Oct 13, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2323
What happened
Fresh
./setup.sh --model IQ3_Son an M2 Max (main ated4773e, engine 0.1.44-metal). The engine starts, but every reply is garbage (e.g."""ZEROxmlxmlxml...,#文哲ntaxntax...) and MTP accepts 0 drafts.STRATA_METAL_PROMPT=window,STRATA_HC_Q8=0,STRATA_METAL_FUSE=0do not change it.I tracked it down to two separate problems.
1.
gdn_stepwithGDN_NTOK >= 2does not run at all on M2 Maxgdn_parity(built frommetal/tests) fails on this Mac:The test prints
max_threadsonly for thentok = 1specialization. Per specialization on the M2 Max:The kernel is dispatched with 512 threads, so the 2+ token variants are silently not executed: a marker written after the token loop stays 0, and there is no command-buffer error. Every verify window / prompt window longer than one token therefore runs on stale outputs. My guess is that M2 has a smaller register budget than M4/M5, where you tested.
Fix: force the compiler to fit 512 (or 1024 for
gdn_step8) threads:After this change,
gdn_parityreports ALL PASS (ntok 1–4: y rel L2 ~1.7e-07, history exact, partial commits bitwise), andgdn_prompt_paritypasses too. It would probably also be worth checkingpipeline.max_threads >= tgat dispatch time and failing loudly instead of silently.2.
qsa_prompt.metaldoes not compile with the macOS 26.3 MetalPerformancePrimitives headersThe first longer prompt kills the engine (
exit(3)) with:The cause is the copy
auto tot = acc;inqsa_flash. Getting a second destination tensor instead compiles:(
totis zeroed right after, so the copy is only there for its type.) Note:qsa_prompt_paritythen hangs the GPU on M2 (kIOGPUCommandBufferCallbackErrorHang), also withCOOP_K4=0; I did not dig further. The engine itself (no M5 layout → no flash) runs fine.Result with both fixes (via
STRATA_METAL_KERNELS=<patched copy>)Correct answers, MTP accepting drafts (e.g. 65 of 101). IQ3_S on M2 Max 96 GB,
--spec 2, temp 0, 3 runs each:The prompt runs on the prompt chain with "the older expert / attention kernels (no M5 layout)".
Other parity tests on this Mac all pass: gemv, expert, gr, gr2, qsa, route, sample, fuse, pair, mma, prompt, dense_mm.
moe_mm_parityreportsno function mm_gu_42_16_64_16_2(probably a test-only issue).Both diffs are above (full patch is the two hunks shown).
Strata version, GPU, OS: 0.1.44-metal (main
ed4773e) · Apple M2 Max 96 GB · macOS 26.3.1@Niko1221 commented on GitHub (Oct 14, 2026):
Thank you, this is a superb report: the per-specialization limits (512 / 448 / 448), the marker that stayed 0, the patch, and the proof that it works. We had only the M4 and M5 to test on.
What 0.1.44.1 does:
gdn_stepcarries[[max_total_threads_per_threadgroup(IB * 128)]](512 forgdn_step, 1024 for the 8-token variant), so everyGDN_NTOKspecialization is asked to fit the launch size. We used the exact launch size instead of 1024 for all (a higher limit asks for fewer registers than needed). Your patch with 1024 is the safe fallback: ifgdn_paritystill prints 448 for some specialization on your M2 Max, tell us.maxTotalThreadsPerThreadgroup >= threads per threadgroup(the engine graph, the prompt chain, the parity tests, the runtime dispatch) and stops the engine with a message naming the kernel, the limit, the size needed and the GPU.STRATA_METAL_MAX_THREADS_CAP=448forces the condition for a test; on an M4 it stops with, for example, 'the kernel gdn_step{2=8} can run at most 448 threads per threadgroup on this GPU (Apple M4), but the dispatch asks for 512'.gdn_parityprints and checks the limit of GDN_NTOK 1..8.qsa_prompt.metal: your second-destination-tensor form, applied.On an M4 the answers are unchanged (Q2_0, byte-identical to 0.1.44 in 4 runs of 200 tokens, with and without MTP), all parity programs pass (
moe_mm_parityfails on 0.1.44 and on the fix alike: it asks for a tile the kernel file does not instantiate, a test-only issue as you suspected), andgdn_stepspeed is unchanged (5 interleaved pairs).Not done: the
qsa_prompt_parityhang on M2. The engine only usesqsa_flashwhere the M5 matrix layout is detected (or withSTRATA_METAL_PROMPT_QSA=flash), so an M2 does not reach it by default; we did not investigate the hang.Please try 0.1.44.1 on your M2 Max (
./update.shorgit pull+ setup) and tell us whether the answers are right and MTP accepts drafts without your patched kernel copy.@kingdonb commented on GitHub (Oct 14, 2026):
Thanks for the quick 0.1.44.1 hotfix! The shader fix and
require_fitthreadgroup assertions worked great on our M2.One follow-up from our testing on a 24 GB M2: while the 96 GB M2 Max has multi-gigabyte arena chunks, on 16–24 GB Macs with
--mmap-experts, arena chunks shrink to ~0.8 GB. Prompts still failed withmetal prompt: no arena region for the prompt buffersbecause the existing standalone allocation fallback sat inside the chunk loop.I have a small follow-up PR that shares the standalone
mmapfallback when no chunk fits, which gets 24 GB M2 machines generating at 3.7–4.1 tok/s.@nullspeech commented on GitHub (Oct 14, 2026):
Confirmed on a second M2 Max, and on the older SDK: macOS 15.8 (96 GB M2 Max, so the Command Line Tools' macOS 15
SDK - no
MTLGPUFamilyMetal4symbol and noMetalPerformancePrimitivesheaders anywhere on this machine). 0.1.44.1(
296b59d2) fixes it here too, so the attribute is not a macOS 26-only trick.gdn_parityon this machine, same source tree, kernel unchanged except for the attribute:I took the same route by hand before I saw the release (optnone on
gdn_step, which also lifts the limit to 1024), sohere is the cost of that alternative - please do not adopt it, the attribute is strictly better:
gdn_parity --bench, 36 distinct layer states rotated, so nothing sits in the SLC. The 1-token path gives nothing up,and the multi-token windows are ~2x faster than the only workaround that worked.
require_fitverified with your test hook -STRATA_METAL_MAX_THREADS_CAP=448 ./gdn_parityprintsfor every specialization. Silent-but-wrong turning into a message that names the kernel, the limit and the launch size
is worth keeping on its own; the next person with a GPU that reports something odd gets an answer in one line instead
of a week of parity harnesses.
Engine end to end (IQ3_S,
--spec 2 --mtp, 65536 context,STRATA_METAL_PROMPT=window), same 64-token prompt read:0.1.44 with the windows silently frozen gives garbage; with the optnone workaround it reads at 26.0 tok/s and a
2362-token prompt at 47.8; on 0.1.44.1 the same 64-token read is 1081 ms = 59.2 tok/s, a 2321-token prompt reads at
58.1 tok/s (and answers the counting question in it correctly, with 2316 of 2321 reused on the repeat), and a 200-token
answer generates at 35.8 tok/s with 106 of 124 drafts accepted. Not paired runs, but the 2x on the prompt read is the
multi-token windows losing their optnone penalty, which is what the table above predicts.
Two things still stand between an older-SDK Mac and a working install, and neither is #2323:
mtl_rt.mm'ssupportsFamily:MTLGPUFamilyMetal4does not compile against the macOS 15 SDK,because the enum constant only exists in the 26 headers; the Metal runtime on 15.8 is not the problem (15.0 is your
documented floor). What I carry locally is two lines -
enum { STRATA_MTL_GPU_FAMILY_METAL4 = 5002 };and a cast atthe one call site, still behind
@available(macOS 26.0, *)- and I have to re-apply it after every pull. Say theword and I'll send it as a PR.
dense_mm.metal,moe_mm.metal,mm_bench.metalandqsa_prompt.metal#include <MetalPerformancePrimitives/MetalPerformancePrimitives.h>unconditionally, and thatheader ships only with the 26 SDK (this machine's SDK is 15.5, the framework is not in
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/), so any route that compiles them(
prompt_gemm_init/pc_setup, i.e. anything that is notSTRATA_METAL_PROMPT=window) takes the engine down withmtl: compile failed: ... 'MetalPerformancePrimitives/MetalPerformancePrimitives.h' file not foundand exit 3 - seenon 0.1.44, and nothing about that include or about
compile()'sstd::exit(3)changed in 0.1.44.1.Context:: supports_metal4()is inmtl_rt, but no file undermetal/src/enginecalls it, so the engine cannot notice themissing support and step down by itself. The window path is correct and useful here (the 2321-token prompt above is
answered right), it just isn't the fast one, so a Mac that stays on 15.x has to know the env var exists. Would
#if __has_include(<MetalPerformancePrimitives/...h>)around those four includes, plus asupports_metal4()probethat picks the window route when MPP is absent, be acceptable? Then the fallback is the engine's choice instead of
project lore.
Thanks for turning this around in a day - the M2 Max is answering correctly now.
@Depechie commented on GitHub (Oct 14, 2026):
I'm running strata 0.1.44.1 on a M2 with 32 GB mem and also running into "metal prompt: no arena region for the prompt buffers".
Correct to assume we still need to wait for a next release to get it working?
@qiuzan2001 commented on GitHub (Oct 15, 2026):
For the follow-up question ("metal prompt: no arena region for the prompt buffers" on 24-32 GB Macs): that case is not in 0.1.44.1 (
296b59d2). The fix is open PR #2345, which adds the fallback for arena chunks too small for the prompt's buffers (measured there on a 24 GB M2), so it needs that PR merged or applied locally. The originalgdn_stepbug of this issue is fixed in 0.1.44.1 by5ce99945, as confirmed above on two M2 Max machines.@nullspeech commented on GitHub (Oct 15, 2026):
M2 Max / 96 GB / macOS 15.8 — numbers from the machine that cannot reach the prompt chain, for the record.
Setup. Strata 0.1.44.1-metal, Qwen3.8-Flash-Next IQ3_S (78 GB gguf, experts streamed),
--expert-cache 64 --prefill auto --spec 2 --mtp --max-context 65536 --mmap-experts. On 15.8MetalPerformancePrimitivesis absent from both the SDK and/System/Library/Frameworks, soprompt_gemm_initdies at runtime withmtl: compile failed: ... file not foundand this box runsSTRATA_METAL_PROMPT=window+COOP_K4=0.1. Same M2 Max, same model, llama.cpp's Metal backend — no MPP anywhere in it.
Pack:
Qwen3.8-Flash-Next-AD-4.27bpw-Q4_K_M-M64(91 GB, 33 shards), i.e. heavier than the pack Strata streams here. From 6 weeks of server logs, usingprompt eval time(tokens processed after cache, so directly comparable to the HUD's(prompt_tokens - reused) / prompt_ms):Single sessions: 286.78 tok/s on a 20926-token prompt and 265.28 on 30619 (
gguf-mtp-20261006-182929.log,n_threads = 8). Decode in the same logs: median 24.9 tok/s over 3324 samples of ≥20 tokens, p90 34.4.2. What the window path gets on this machine: 52.0–59.6 tok/s on a cold 1355-token prompt (temp 0, same convention). Strata's decode here (34.6–35.5 tok/s) is already above llama.cpp's p90, so the machine is not short of bandwidth or of CPU — only the prompt read is 3–4× behind, and it is behind on a path that has no GEMM in it at all.
3.
STRATA_PREFILL_CPU_SHAREmeasured here, and it is free. Paired A/B, reverse order in round 2 (this Mac drifts ~±8% warm), engine restarted between arms, 1355-token cold prompt:=auto+_MAX=8192Decode unchanged (34.7/35.1 vs 34.1/33.7) — the CPU work does not steal from the token path. On a window-path Mac the CPU is otherwise idle during a prompt, so the 1024 gate looks like the wrong default there.
4. PR #2609, measured on this machine (only the test target built; nothing deployed):
gemv_parity130 PASS / 0 FAIL — everygemv_wide.metalkernel bitwise its stock twin, windows bitwise equal to one-token calls, and both--sweepruns printALL BITWISE. Best tile vs today's, this M2 Max:So the tiles are a genuine M1/M2 win, but they accelerate the window path's projections — which is what the 52–59 tok/s is made of, not the wall itself.
The ask, restated: a prompt chain whose matmul is not MPP (simdgroup_matrix is already used by
mma.metaland compiles fine on 15.x). The same silicon, with llama.cpp's simdgroup_matrix backend on a heavier pack, reads 190–290 tok/s — so what is missing on 15.x Macs is a kernel path, not performance headroom.@nullspeech commented on GitHub (Oct 17, 2026):
Housekeeping from the macOS 15.8 confirmation above (96 GB M2 Max, second data point, 2026-10-14): this looks fixed, and the issue is still open.
5ce99945("Metal: gdn_step fits its launch size, every dispatch checks maxTotalThreadsPerThreadgroup, qsa_prompt compiles on macOS 26.3 (#2323)", 2026-10-13) shipped in v0.1.44.1;831ba47acarries the runtime half of the same two kernels for M1 Max into v0.1.45.gdn_parityon our 0.1.44.1-metal build (M2 Max, macOS 15.8): everygdn_steppipeline gets the 512 threads the kernel needs forGDN_NTOK 1..8, and ntok 1-4 all PASS (worst rel L2 1.76e-07 ony, 1.30e-07 on state, history exactly 0, partial commits bitwise equal) —ALL PASS.So if the thread was kept open only for the dispatch-limit work, it reads as done. I cannot speak for the
--mmap-expertshalf kingdonb added inf037612b— that targets 16-24 GB Macs and is not reachable from 96 GB. Leaving the close call to @Niko1221 and @Excavatory.@nullspeech commented on GitHub (Oct 17, 2026):
Following up on the macOS 15.8 reports above (96 GB M2 Max, same box) — we found why the chain cannot start here, built a fix, measured it, and opened a PR: #2987 (draft, based on
296b59d2/ v0.1.44.1, 11 files undermetal/, +399/−28).Cause, for the record. It is not the GPU and not the instruction set. Every
matmul2dkernel is reached through an unguarded#include <MetalPerformancePrimitives/MetalPerformancePrimitives.h>, and that header only ships with a Metal 4 SDK. On macOS 15.8Context::compile()therefore fails fordense_mm.metal/moe_mm.metal/prompt.metal/qsa_prompt.metal, the failure is fatal at init (exit 3), and the config has to carrySTRATA_METAL_PROMPT=window.simdgroup_matrix<half,8,8>+simdgroup_multiply_accumulateis Apple7+ and has always worked on this chip: with the guards applied, the repo's own probe measures 7.22 TFLOP/s at 4096³ and 6.89 at the dense prompt shape (rel L2 2.75e-07 vs the fp32 reference), printingdevice Apple M2 Max, metal4 0.Result (one binary,
STRATA_METAL_LEGACY=1vs the window path, 1023-token prompts, five alternating runs each): prefill 58 → 177 tok/s median (3.02×), TTFT 20.6–26.4 s → 8.8–14.4 s, decode unchanged to slightly better (26.8/26.4 → 29.0/27.3). Server-level, a 4252-token prompt: 55.3 → 159.4 tok/s. Prompts under_PROMPT_GEMM_MIN= 64 are unchanged because they never reach the chain.dense_mm_parity67 PASS / 0 FAIL,prompt_parityandgdn_parityall PASS,moe_mm_parity --v2PASS for every format this pack routes — and the legacy tiles report identical error numbers to the upstream tiles, so the tile changes are speed-only.One honest caveat, because it is the next question. We also ran
llama-server(b11408,-ngl 999,-c 65536, MTP draft) against the identical GGUF file on this machine to see where the ceiling actually is: it prefills 285.6 tok/s at 4220 prompt tokens, 267.6 at 1609, where this branch reaches 160–172. So the branch recovers ~3× of this engine's own 4.9× deficit on the old SDK, it does not overtake llama.cpp — and the deficit is spread across the chain rather than one kernel (llama.cpp's whole 1024-token chunk costs ~3.6 s at that rate; gate/up alone is 2.93 s here, plus 1.21 s of gdn projections). Anyone landing #2987 should read it as "make the chain reachable on pre-Metal-4 SDKs", not "close the gap to other engines". Decode is a wash: llama.cpp's 1596 completed production requests on this box median 30.1 tok/s, ours 24–31 depending on whether the sample is a 64-token tail or a full generation.The PR is a draft because the branch sits on v0.1.44.1 and
mainhas 13 later commits undermetal/(themaxBufferLengthwrap bounds the MoE kernels where the twins live), plusmaindoes not build on a Mac today at all (#2860; #2895 looks like the fix). Say the word and I will rebase ontomainand re-run the gates. Themsl_has_mpp()oracle — asking the compiler for the header instead of trusting the GPU family, which answers "Metal 4" on an M2 under a macOS 26 beta — is the part worth merging even if the tiles stay a follow-up, and I can split it that way.@nullspeech commented on GitHub (Oct 18, 2026):
Follow-up on the legacy (
simdgroup_matrix) branch from #2987 — this one is mostly a negative result, written up so nobody spends a weekend re-deriving it. 96 GB M2 Max, macOS 15.8, IQ3_S Qwen pack, engine at v0.1.44.1.1.
STRATA_METAL_GEMV_NR=2pays only at exactly two rows, and regresses at three. I measured the rule atwindow.cpp:578withtoken_chain(GPU-only median, 30 reps, mirrored NR1→NR2→NR2→NR1 so a warming machine cannot fake a result).ntok = 1is a provably no-op control arm, because the gate requiresntok > 1— it reads 0.8%, which is the instrument floor:The mechanism matches:
Rr = 2shares one x load across two rows' weight loads, which is exactly amortised at two rows; at three rows the secondRrgroup re-loads weights for a third row while x is already SLC-resident, so you pay thread-group pressure and save nothing. Suggested one-liner: gate onntok == 2instead ofntok > 1. Under MTP--spec 2a full draft is a 3-row window, i.e. the arm where NR=2 is slower — which is why the server sees no benefit (below) even though the tile really is 11.8% better at 2 rows.2. Neither
STRATA_METAL_PROMPT_CHUNK=8192norGEMV_NR=2moves the live server, and an apparent +20% win was session drift. Same driver, same seed, prompts of 4220/2652/1609 tokens, two reps, six boots:The 8192/2 row that looked like a 20% win did not repeat with the same config, and the 8192/1 boot prints
for chunks of 4213 rows— so a 4220-token prompt is one chunk there and it prefills no faster than three chunks of 2048.drafts accepted 25 of 38is identical in every boot, so it isn't draft luck; it's thermal. Lesson for anyone benchmarking on a laptop: a whole session can sit 15–20% off another session of the same binary and same config, and a single before/after pair across a restart is worthless. The honest production number for this branch is 158–172 prefill / 24–27 decode at 4220 tokens.3. The legacy expert GEMM's tile space is exhausted — the remaining gap to llama.cpp is not a tile choice. Swept in one process (each 4096-token arm is 21–27 s, so in-process pairing is the only way to read it),
mm_gu2_* / mm_down2_*over TM × TN × TK × SG, restricted to tiles every format in the pack instantiates:16_32_32_2, dn16_64_32_2The load-bearing row is TM=32: it takes the per-expert tile count from 5 to 3 at ~82 tokens/expert, i.e. it removes most of the redundant dequant, and it is slower. So "the twins are dequant-bound and a taller M tile fixes it" is wrong on this chip, and
gu2_tile()'s!mpp → "_16_32_32_2"/dn2_tile() → "_16_64_32_2"are already the best legal choice. That, plus point 2, means the 1.7× we still carry against llama.cpp on the identical file lives in the kernels, not in any tile or env knob.One trap worth recording for whoever sweeps next: this pack is format-mixed per layer — gate/up is {IQ3_XXS, IQ3_S, IQ2_S, IQ4_XS} and down is {IQ4_NL, Q2_0} across the 48 layers, while a chunk carries one tile value in
meta[2]/[5]. Requesting a tile that any present format lacks aborts at init (no function mm_gu2_23_32_32_32_2,exit 3), so the sweep space is the intersection, not the product.4. Small bug:
STRATA_METAL_PROFILEis unobservable in normal operation. The per-window-size table is printed only fromWindow::~Window()(window.cpp:1302). Every engine I stopped with SIGTERM exited without ever printing it, so the flag silently does nothing for a long-running server — it needs anatexit/signal path. (It also means I could not confirm the liveTmix from the log, which is why point 1 phrases the spec-2 window as inference rather than measurement.)Not claiming anything new about prefill here — #2987's +3.0× stands and the llama.cpp comparison in my last comment is unchanged. The harness seams for points 1–3 (sweepable
prompt_chain,GEMV_NRintoken_chain) are ~95 lines of test-only code; say the word and I'll put them in a branch so these axes can be re-run instead of re-guessed.@Niko1221 commented on GitHub (Oct 29, 2026):
Thank you again for this report. Fixed in 0.1.44.1:
gdn_stepis asked to fit its launch size, every Metal dispatch checks the pipeline limit, andqsa_promptcompiles on macOS 26.3. Theno arena region for the prompt bufferscase on 16 to 32 GB Macs was fixed in 0.1.45 (the prompt's buffers get their own allocation when no arena chunk fits). Confirmed on two M2 Max machines in this thread.Release: https://github.com/Niko1221/Strata/releases/tag/v0.1.44.1
@botbizs commented on GitHub (Oct 29, 2026):
bro. Thank you for that
чт, 29 окт. 2026 г., 11:36 Niko @.***>: