You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MLX: a long prefill stalls every running stream's decode until it finishes (4 × 16K prompts: earlier streams drop to 1–3 tok/s) #72
Summary. With several requests on one MLX server, a newly admitted request's prefill runs to completion before any other stream takes another decode step. Prefills themselves run one at a time, which is reasonable: one prefill already saturates the GPU. But streams that were already decoding freeze for each later prefill. For several agents sharing a server, every long incoming prompt pauses everyone else for its whole prefill: about 40 s per 16K tokens on this machine.
Setup as in #70 (M5 Pro 64 GB, 0.3.5.1, tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit --name bench, DFlash2). The startup concurrency line said "up to 8 requests share each round; memory budget 40.7 GB … 4.1 GB in use elsewhere".
Repro. Four distinct prompts are sent at the same moment. Each is 16,427–16,428 rendered tokens, from different slices of the llama.cpp fixture with a unique nonce line. Settings: max_tokens 128, greedy, ignore_eos, thinking off. The numbers below are each request's serve.logdone line.
Order admitted
Own prefill=
TTFT
Engine tok/s for its 128 tokens
1
39.6 s
39.7 s
1.0
2
40.1 s
79.8 s
1.5
3
40.2 s
120.0 s
2.8
4
40.4 s
160.4 s
22.4
Stream 1 has its first token at 39.7 s, then needs about 128 s for 128 tokens: it only moves between the three later prefills. Wall time for all four was 166.5 s. Stream 4, which faces no later prefill, decodes at a normal 22.4 tok/s.
The contrast is the shared-prefix case, where requests share a 3,840-token system block and only the ~20-token tails are prefilled. There the same server scales cleanly (C=8: 151.5 tok/s aggregate, 1.15 s median TTFT). So round sharing works; what's missing is interleaving a long prefill with the other streams' rounds.
Ask. Chunk long prefills and run a decode round for the live streams between chunks, like chunked prefill in vLLM and SGLang. The 2,048-token chunk plan already exists for the prompt cache and could be the natural boundary. Even one decode round per chunk would turn the 1.0 tok/s above into something close to the solo rate. If this is a deliberate exactness or scheduling trade-off, a line in the README's concurrency section would help people who put several agent sessions on one Mac.
Same Mac, fixture and repro as above. This time: TensorFold 0.3.6.2 (71377a5), mlx 0.32.3, tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit --name bench with DFlash2. The startup concurrency line said "memory budget 37.5 GB … 7.3 GB in use elsewhere … 15 streams of 8,192 tokens fit now".
Four distinct prompts of 16,423–16,424 rendered tokens each, sent at once, 128 tokens, greedy, ignore_eos, thinking off. The numbers are each request's serve.logdone line.
Order admitted
Own prefill=
TTFT
Engine tok/s for its 128 tokens
0.3.5.1 tok/s
1
40.37 s
40.45 s
1.0
1.0
2
40.86 s
81.31 s
1.4
1.5
3
40.95 s
122.26 s
2.7
2.8
4
41.09 s
163.35 s
24.8
22.4
Wall time was 169.3 s (0.3.5.1: 166.5 s). Prefills still run one at a time, and each one still stalls the streams that were already decoding.
The shared-prefix case is also unchanged and still scales. A 3,840-token system block plus short tails reached 149.5 tok/s aggregate at C=8, with a 1.18 s median TTFT (0.3.5.1: 151.5 and 1.15 s). So the stall is specific to a long prefill running while other streams are live.
Thanks @benwilson, your repro pinned this down. On MLX the server prefilled each queued prompt whole before any
running reply got another round, and it kept admitting queued prompts while lanes were free. With four long
prompts at once, the earlier replies only moved between the later prefills: your 1.0 / 1.5 / 2.8 tok/s.
0.3.6.3 fills one prompt at a time, one planned chunk at a time (2,048 tokens for the 27B), and running replies
take rounds between the chunks. Each chunk gives the rounds a quarter of its time, so while prompts wait the
replies get about a fifth of the GPU. Chunk boundaries don't move, so every reply is still exactly its solo run,
drafted or not.
Your case on an M3 Ultra (60-core GPU), 27B 4-bit + DFlash2: one reply decoding while three distinct 17K-token
prompts arrive together.
0.3.6.2
0.3.6.3
running reply's longest pause
164 s
6.8 s
its speed while the prompts prefill
~0 tok/s
11.4 tok/s (62 alone)
first tokens of the three prompts
55 / 109 / 163 s
67 / 135 / 202 s
longest pause of the first two after their first token
109 / 55 s
6.2 / 6.1 s
prompt throughput
319 tok/s
257 tok/s
The cost is prompt speed: while replies decode, prompts get about four fifths of the GPU, so the last prompt's first
token comes about 25% later. The longest pause is one chunk plus one round, 6-7 s for the 27B on this GPU and less
on faster ones. If you'd rather keep the old order, start the server with --decode-share 0 and prompts prefill
whole before any reply moves; a higher value gives running replies more of the time between chunks. A request on
its own is unaffected: on the same machine, first tokens and decode speed came out within 0.05% and 0.25% of
0.3.6.2. Your numbers from the M5 Pro with the same four prompts would help.
Verified on the M5 Pro 64 GB with 0.3.6.3: fixed, with numbers close to your M3 Ultra table. Same setup as my 0.3.6.3 note on #71: TensorFold 0.3.6.3 (1911880), mlx 0.32.2, tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit --name bench with DFlash2, 20-core M5 Pro GPU. I ran each shape twice on 0.3.6.3, with the default --decode-share and with --decode-share 0 as the same-machine "before".
Your shape: one reply decoding (4,096 tokens, greedy) while three distinct prompts of 16,423–16,424 rendered tokens arrive together, 3 s after its first token. Everything is streamed, and pauses are gaps between the reply's text pieces.
--decode-share 0
default (0.25)
running reply's longest pause
127.9 s
6.1 s
its speed while the prompts prefill (estimated from characters)
0.1 tok/s
17.9 tok/s (its solo run: 90.7)
first tokens of the three prompts
42.1 / 84.9 / 127.8 s
49.6 / 101.7 / 156.2 s
longest pause of the first two after their first token
85.9 / 43.1 s
5.2 / 5.4 s
prompt throughput
385.7 tok/s
315.5 tok/s (−18%)
each concurrent reply equals its solo run (token_sha)
4/4
4/4
My original repro: four distinct prompts of 16,425–16,427 tokens (16,423–16,424 in the 0.3.6.2 row) at once, 128 tokens each, all cold. Engine tok/s per request, in admission order:
1st
2nd
3rd
4th
wall
0.3.6.3, --decode-share 0
1.0
1.4
2.6
28.8
174.4 s
0.3.6.3, default
10.1
6.8
5.2
45.1
186.9 s
0.3.6.2 (earlier re-test)
1.0
1.4
2.7
24.8
169.3 s
--decode-share 0 reproduces 0.3.6.2's numbers almost exactly, so the comparison is fair. The default trades about 7% of wall time (18% of prompt throughput in your shape) for replies that never stall more than about 6 s here, which matches your "one chunk plus one round, 6-7 s for the 27B on this GPU" on the M3 Ultra. The reply kept about 20% of its solo speed while the prompts prefilled, close to your 11.4 of 62. Exactness held through all of it. The same build also passed bench_concurrent --alone --serial 180/180, 8/8 release checks, and 4/4 with a real 8,192-token resume (see #71).
Activity
benwilson commentedon Sep 29, 2026
Re-tested on 0.3.6.2: unchanged.
Same Mac, fixture and repro as above. This time: TensorFold 0.3.6.2 (
71377a5), mlx 0.32.3,tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit --name benchwith DFlash2. The startup concurrency line said "memory budget 37.5 GB … 7.3 GB in use elsewhere … 15 streams of 8,192 tokens fit now".Four distinct prompts of 16,423–16,424 rendered tokens each, sent at once, 128 tokens, greedy,
ignore_eos, thinking off. The numbers are each request'sserve.logdoneline.prefill=tok/sfor its 128 tokenstok/sWall time was 169.3 s (0.3.5.1: 166.5 s). Prefills still run one at a time, and each one still stalls the streams that were already decoding.
The shared-prefix case is also unchanged and still scales. A 3,840-token system block plus short tails reached 149.5 tok/s aggregate at C=8, with a 1.18 s median TTFT (0.3.5.1: 151.5 and 1.15 s). So the stall is specific to a long prefill running while other streams are live.
ashhart commentedon Sep 29, 2026
Thanks @benwilson, your repro pinned this down. On MLX the server prefilled each queued prompt whole before any
running reply got another round, and it kept admitting queued prompts while lanes were free. With four long
prompts at once, the earlier replies only moved between the later prefills: your 1.0 / 1.5 / 2.8 tok/s.
0.3.6.3 fills one prompt at a time, one planned chunk at a time (2,048 tokens for the 27B), and running replies
take rounds between the chunks. Each chunk gives the rounds a quarter of its time, so while prompts wait the
replies get about a fifth of the GPU. Chunk boundaries don't move, so every reply is still exactly its solo run,
drafted or not.
Your case on an M3 Ultra (60-core GPU), 27B 4-bit + DFlash2: one reply decoding while three distinct 17K-token
prompts arrive together.
The cost is prompt speed: while replies decode, prompts get about four fifths of the GPU, so the last prompt's first
token comes about 25% later. The longest pause is one chunk plus one round, 6-7 s for the 27B on this GPU and less
on faster ones. If you'd rather keep the old order, start the server with
--decode-share 0and prompts prefillwhole before any reply moves; a higher value gives running replies more of the time between chunks. A request on
its own is unaffected: on the same machine, first tokens and decode speed came out within 0.05% and 0.25% of
0.3.6.2. Your numbers from the M5 Pro with the same four prompts would help.
benwilson commentedon Sep 29, 2026
Verified on the M5 Pro 64 GB with 0.3.6.3: fixed, with numbers close to your M3 Ultra table. Same setup as my 0.3.6.3 note on #71: TensorFold 0.3.6.3 (
1911880), mlx 0.32.2,tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit --name benchwith DFlash2, 20-core M5 Pro GPU. I ran each shape twice on 0.3.6.3, with the default--decode-shareand with--decode-share 0as the same-machine "before".Your shape: one reply decoding (4,096 tokens, greedy) while three distinct prompts of 16,423–16,424 rendered tokens arrive together, 3 s after its first token. Everything is streamed, and pauses are gaps between the reply's text pieces.
--decode-share 0token_sha)My original repro: four distinct prompts of 16,425–16,427 tokens (16,423–16,424 in the 0.3.6.2 row) at once, 128 tokens each, all cold. Engine
tok/sper request, in admission order:--decode-share 0--decode-share 0reproduces 0.3.6.2's numbers almost exactly, so the comparison is fair. The default trades about 7% of wall time (18% of prompt throughput in your shape) for replies that never stall more than about 6 s here, which matches your "one chunk plus one round, 6-7 s for the 27B on this GPU" on the M3 Ultra. The reply kept about 20% of its solo speed while the prompts prefilled, close to your 11.4 of 62. Exactness held through all of it. The same build also passedbench_concurrent --alone --serial180/180, 8/8 release checks, and 4/4 with a real 8,192-token resume (see #71).feat: Flash Next NVFP4 on CUDA, replies that keep decoding while prom…