mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #4771] [Engine] Mac (M5 Max): DeepSeek V4.1 decode stalls on the GPU busy spin; DS4_BUSY_CAP=2000 gives 18 tok/s instead of 6.7 #2185
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#2185
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 @sblocktechnologies on GitHub (Oct 31, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4771
Area
[Engine] (speed, kernels, models, the server and API)
Desktop app, Terminal or source?
Terminal (the
stratacommand)What happened
DeepSeek-V4.1-Flash IST-DAS 2.00 bpw on an M5 Max with 128 GB decodes at 5 to 6.7 tok/s with the shipped defaults, against the 15 to 18 tok/s that docs/DEEPSEEK_MAC.md reports for the same Mac. Setting
DS4_BUSY_CAP=2000brings it to 14 to 19 tok/s with the same answers.With
DS4_CPU_LOG=1, the CPU lane takes 9.7 ms a call (3.3 ms an expert), butcpu_experts_iq's own phases (prefetch, quant, gate_up, down) add up to about a fifth of that. The rest of the timed span is aroundds4_busy_begin()/ds4_busy_end().ds4_busy_begin()waits on the previous spin's command buffer ([g_busy.last waitUntilCompleted]), so it looks as if the spin kernel runs to its cap here instead of leaving when the host sets the flag. That last part is my reading ofmetal/src/mtl_rt.mm, not something I measured directly.Engine CLI, same pack and prompt ids, 96 tokens, shipped
profile-2.00.binwith--profile-readonly:DS4_BUSY=0DS4_BUSY_CAP=2000DS4_BUSY_CAP=500DS4_BUSY_CAP=100DS4_SKIP_CPU=1(timing only)Through the server (
/v1/chat/completions, greedy, thinking off) withDS4_BUSY_CAP=2000and the engine's own expert share (67.9 GB): 14.3 to 19.0 tok/s on short and code answers, a 3,000-token prompt read at 268 tok/s. Without it, the same requests ran at 5.0 to 6.5 tok/s.Things that did not change the speed: stopping the other VMs on the Mac, 69 GB free at start, the shipped expert profile read-only, engine 0.1.53 (Strata 0.2.7, 4.89 tok/s) against 0.1.54 (4.91 tok/s), and
--cpu-threads9, 12 or 16.Expected: the shipped default to reach the documented speed on this Mac, or a documented setting for it. I have not tried other Macs, so I can't say whether this is specific to the M5 Max or to this macOS version.
Smallest steps or command that reproduce it
Compare the
decode:andcpu lane calls:lines.Reproduction status
Reproduced locally
Strata version
Strata 0.2.8 · engine 0.1.54 (strata-dsv41 build
36f6663c25, 0.1.54-metal); also engine 0.1.53 (build55a557bb6d)Graphics card, memory and system
Apple M5 Max (40-core GPU) · 128 GB unified memory · macOS 26.7.2 · internal SSD
Model, size and settings
DeepSeek-V4.1-Flash IST-DAS 2.00 bpw (installed by
strata launch --family deepseek41 --model ist-das-2.00bpw), 8K context, vision off, DSpark off (Mac default), Full quality (6 experts)Logs
Default:
DS4_BUSY_CAP=2000:Investigated with an AI coding assistant; every number above is from a real run on this machine.
@Niko1221 commented on GitHub (Oct 31, 2026):
Thank you for the detail. A probe shows that on our M5 Max the spin kernel does not see the flag the host writes while it runs: the flag is set 2 ms after launch and the kernel still ends at its cap (with cap 100000, 42 ms on average from the set to the end, against 52 ms when the flag is never set; an atomic read-modify-write, a fence and
coherent(device)change nothing). So a spin lasts its cap, and the cap of 20000 is about 10.5 ms here.We then ran DeepSeek itself, which we could not do before: the pinned ISTA-DASLab 2.00 bpw set (IQ2_XXS shards + Engram), the shipped profile, an M5 Max with 128 GB, nothing else running, three interleaved pairs, fresh process each run, decode tok/s (median):
The first pair was slower for every cap (cold file cache); on the other two the default was the fastest in each class. So here the default gives 14-16 tok/s and the lower caps are slower, which is not what you see (5-6.7 at the default, 18 at 2000). We have not changed the default. The engine uses 4-5 CPU cores while it decodes, whatever the cap. The generated tokens also differed between runs of the same cap (the expert placement moves as the engine runs), so we could not use them to compare caps.
To find out what differs on your Mac, could you send: the chip and core count, the RAM, the disk (internal SSD or external) and where the model files are, the output of one run with
DS4_CPU_LOG=1(the per-token phase times) at the default and atDS4_BUSY_CAP=2000, and whether the first answers of a run were on a cold file cache (first start after a reboot or after other large files were read) or repeated? Whether anything else was using the Mac (a browser, another model server) matters too.@HildebrandYu commented on GitHub (Nov 1, 2026):
Independent data point on the same Mac, with the 2.25 bpw set instead of 2.00:
DS4_BUSY_CAP=2000helps, but it lands two orders of magnitude below your numbers, so the busy cap does not look like the whole story.Setup: M5 Max 128 GB, macOS 27.0.1, engine
strata-dsv41 0.1.55-metal build 4cf0d8cd3809, Strata 0.2.8 terminal, packdeepseek-v4.1-flash-ist-das-2.25bpw(274 GB), weights on a quota-limited APFS volume (1 TB quota, 89 % used) rather than the default data folder,--context 32k, greedy,--no-tui --yes.Measured through
/v1/chat/completions(single request, 41-token prompt, 12–16 generated; numbers are the engine's own serve log lines):--ssd-cache 32DS4_BUSY_CAP=2000Placement (engine log,
DS4_BUSY_CAP=2000run): expert share 67.9 GB, 8398 of 15360 experts on the CPU lane (81.5 GB, in place in the model's files), 9 threads, CPU lane 33–37 % of the experts — i.e. the same share docs/DEEPSEEK_MAC.md describes.Two things that make this not just a slower copy of your report:
1 generated in 10 ms (97.33 tok/s)and26 ms (38.16 tok/s). It is only sustained decoding that collapses.--vram-experts 80never finished starting (450 s, thenruntime control returned an invalid response), and--cpu-threads 6is ignored (log keeps 9 threads).What the log says about I/O:
the experts VRAM leaves over (~46.9 GB) are read in place from the model's files ... (0.0 GB of RAM free to keep them: the most-routed 46.9 GB read ahead). An uncached (F_NOCACHE) sequential read of the pack on this machine is 3.27 GiB/s, so the disk itself is fine — but every decode step appears to re-read ≈ 800 MB (2.25 bpw = 110 MB/token per DEEPSEEK_MAC.md, ~7× that at this rate).So: your 6.7 → 18 tok/s movement looks like the busy-spin fix working; on 2.25 bpw we see 0.08 → 0.26. If the extra factor is the pack size times the cold-cache behaviour,
--ssd-cachedid not absorb it.Happy to run anything else on this box (it is idle, 128 GB, nothing else loaded) — e.g. the same CLI
--ids ... --n 96comparison on 2.25 bpw, or with--profile-readonly, or with the weights moved to the default data folder to rule the volume out.@HildebrandYu commented on GitHub (Nov 1, 2026):
Addendum — the engine's own Metal timing lines point at command-buffer latency, not memory or disk:
Three short runs (2.25 bpw, 32k context, expert share 67.9 GB): the GPU does 0.23–0.32 s of actual work while the host waits 94–314 s for it, i.e. the GPU is idle ~99.9 % of wall time and each
waitUntilCompletedcosts 35–117 ms for ~0.1 ms of GPU work.That is consistent with the busy-spin mechanism in the title, and it argues against the expert-cache/I-O theory: with the GPU starved this way, no amount of RAM or SSD bandwidth can matter.
Also tested on this box, for the record:
strata launch --tune quick(the official DeepSeek tuner): "Your computer already runs DeepSeek best with the standard settings (0.2 tokens a second); nothing changed" — its DSpark candidate did not finish.chat_template_kwargs.enable_thinking=false): 10 tokens in 72.9 s = 0.14 tok/s, same as with thinking on, so it is per-token latency, not reasoning length.--ssd-cache 32: worse (0.08 tok/s).@sblocktechnologies commented on GitHub (Nov 3, 2026):
Thanks for testing it on your M5 Max. I reran it your way, and the gap is still there on this Mac with a warm cache and with nothing else running.
What you asked for:
profile-2.00.binwith--profile-readonly. The IST-DAS 2.00 bpw IQ2_XXS shards with Engram. (My copy has a patch applied to the attention output weights. The pack'stensors.txtmatches the stock one except for paths, so the tensor types and sizes are the same.)Engine CLI, the command from the issue, 96 tokens, three interleaved pairs, a fresh process each run, median decode tok/s:
DS4_BUSY_CAP=2000Through
strata serve(greedy, thinking off, 200 tokens max), three interleaved server starts per setting, median decode tok/s:One CLI run per cap, with
DS4_CPU_LOG=1:The CPU lane time per call tracks the cap down to about 2000, and below that it stays at about 2 ms. At 20000 it's about 9.5 ms, close to your 10.5 ms spin. So here every CPU-lane call seems to wait out a full spin, which fits your finding that the spin runs to its cap. Lower caps then cost GPU time instead (routing waits rise below 2000).
In the quiet runs the output tokens were identical across all seven runs at both caps, and every run put the same 3242 of 22800 experts on the CPU lane. Default quiet run:
Same with
DS4_BUSY_CAP=2000:Could you send the
cpu lane calls:andCPU lane: N of 22800 expertslines from one of your default runs? If your CPU lane is also about 9.5 ms a call at the default, I'd expect your decode to be as slow as mine, so I'm curious whether yours is closer to 2 ms or makes far fewer calls a token.@HildebrandYu, your case looks different from mine. My host waits are about 0.6 to 0.7 ms each (6135 waits, 3.6 to 4.2 s in all) against your 35 to 117 ms, and the cap only changes the CPU-lane time. Also, the
mtl: … ms GPUfigure reads about 300 ms in all my runs, whether the decode took 18 s or 6 s, so I don't think it measures total GPU time. You have 33 to 37% of experts on the CPU lane, read in place from a nearly full quota volume (mine is about 16% from the internal data volume), so I'd try your second idea first: the weights in the default data folder.