Repository navigation
Qwen3.8-27B serves concurrent requests: shared rounds across runner slots, DFlash2 for one stream, and tf-qwen27-bench - #578
Conversation
|
Thank you, @BobClawblaw. A status update while the gate finishes. On an M3 Ultra, one stream gives the same tokens as main and runs as fast (greedy within about 1%). A sampled request now drafts, at 47 to 119 tokens a second instead of 20 to 21, with the same tokens for the same seed. Greedy drafted output equals One question for you: at the default |
|
Thank you for running it on an M3 Ultra. Yes. Almost all of the 17 GB is each extra slot's K/V rows. At 32k that is about 2 GB a slot across the 16 attention layers, plus its taps ring. The DeltaNet pool is small next to that. I'll make the runner allocate a slot's K/V buffers and taps ring the first time a stream is bound to that slot, and add them to the residency set then. Only slot 0 will be allocated and wired at open. After that, a slot keeps its memory for reuse rather than being freed when it goes idle, so a burst of requests doesn't allocate and wire again each time. If the memory check fails when a slot is first used, the request waits for a slot that is already allocated, as it waits today when |
|
I pushed the change you asked about (90d2ab9), and rebased onto main, so the branch has moved under your gate run:
M5 Ultra, On this head, everything matches its reference:
|
90d2ab9 to
b68a432
Compare
|
The branch moved again: b68a432 is the same three commits rebased onto main 56150e6. One behaviour change beyond the rebase, so your gate run sees it:
Related: #639 (GLM's streams sharing one MLA pool) meets the same situation, a request with no room yet, before admission instead ( |
… shared rounds on real weights Session gains `slot` (0 by default, so every caller is unchanged). tf-qwen27-streams decodes N streams of unequal prompts alone, in a one-slot runner and in their own slot of an N-slot runner, then together in shared rounds whose windows run 1 to 5 rows with every other round's last draft wrong, and compares every kept row's logits bytes and draw with the stream alone. On an M5 Ultra: 4 streams, 188 rows; 8 streams, 504 rows; all equal.
…d the drafter on slot 0 of a wider runner The drafter's committed taps become a Ring (tap_ring.zig) that a lane can own too, so a slot's kept state carries the taps a drafted request needs. snapshot.zig saves, restores and moves any slot's DeltaNet states, K/V rows and ring; the old drafter-based save/restore stay as wrappers, so the serial host and its tests are unchanged. Draft and Generation no longer require a one-slot runner: their rounds already name slot 0.
…them A family that prefills a reply's earlier rows with decode arithmetic, as the serial host's decode_chunk does, sets LaneHost.decoded_rows: each request's decode_spans then key its cache lookups and keeps and reach the backend on the stream, with the cache on or off, so a resumed prompt and a fresh one compute the same rows the same way. With info.warm_turns also set, a prompt-only request (max_tokens 0) prefills and keeps its state without drawing a token. Neither is set by Nemotron, GLM or the 2B, which behave as before. engine_api exports cache_modes for a family's reply keeps.
…lots, DFlash2 for one stream The 27B moves from the serial host to the lane host. A request alone takes the DFlash2 serial loop as before (the lone driver); when another arrives it is handed to the lane core, and every stream decodes in shared rounds, one runner slot each, up to --parallel (8 by default, fewer when their caches do not fit). The stream in slot 0 keeps drafting DFlash2 trees in shared rounds: its kept rows reach the drafter from the verify's taps before the keep. When slot 0's stream finishes, another stream's state moves there and drafts from its next round. Other streams verify copies. Sampled requests draw from the top-k candidates first (the 2B's draw, the same token), so they draft too. Prompt reuse and warm turns work per slot; a finished reply is kept for the next turn. On an M5 Ultra (macOS 27.0.1), --parallel 8 --context 8192, tools/bench_concurrent.py --alone --serial, 128 tokens: 252 of 252 checks equal (each concurrent reply equals its run alone, each run alone equals "draft": false). Aggregate tok/s at 1/2/4/8 streams: greedy code 199/182/213/245, greedy chat 142/141/160/196, sampled code 142/187/192/250, sampled chat 124/107/139/190.
…tions floor, and shared rounds by stream count ashhart#528's tf-qwen35-bench for the 27B engine. Each projection shape of the checkpoint is timed at 1, 8, 16 and 32 rows on the shipped split and every other split the lane kernel takes, with '=' where the bytes equal the shipped split's; then every projection of a one-row step in one command buffer; then shared decode rounds of 1, 2, 4 and 8 streams, one row each, verified and kept as the lane core does, with wall and verify-GPU ms a round.
The runner allocates slot 0's K/V rows at open and each later slot's when a stream is first bound to it (Runner.initReady, ensure), with that slot's taps ring. The served host checks the room beside the weights and the 8 GiB margin first and adds the new buffers to the residency set. A slot keeps its memory once taken. When a slot's memory does not fit yet, the backend says error.LaneMemory and the lane host puts the request back at the head of the queue, admitting no further lanes until a running one frees. --parallel 8 at 32k on an M5 Ultra: 44 GB footprint at open, 66 GB once all eight slots have run (before: every slot at open).
b68a432 to
0a52928
Compare
|
Thank you, @BobClawblaw. Concurrent requests for the 27B are in 1.0.6: merge We gated it on two M3 Ultras, where every stream runs in the lane core, and an M5 Max, where a lone greedy request runs
Our follow-ups, each its own commit after your merge:
Two things for later, no need to hold anything for them:
Thanks again! |
lane_host.zig was at 596 lines with ashhart#578 and ashhart#596 still to add; the lesson queue and its idle-only step are their own job. A move, with words() made public and the two lock wrappers inlined.
…nds across runner slots, DFlash2 for one stream, and tf-qwen27-bench On the 1.0.6 candidate: the stream spec and the fake backend carry ashhart#596's grammar beside ashhart#578's decode spans and memory lanes, and the lane host gives a stream both. ashhart#596 gave the 2B's draw a grammar mask; the 27B's lane backend passes none, as it serves no structured output. Thanks @BobClawblaw.
…its comments are one line each qwen27_lanes.zig was 763 lines after ashhart#578. A stream's prompt into its slot, a slot's taps ring, restore, a slot's memory on first use, a free slot, unbind, promote and the lone stream's serial loop move unchanged (their calls to each other become direct calls), so it is 590 lines. Comments in the backend, the served host, tap_ring, lane_host and the 27B bench are one line under 120 columns; keepReply has its own comment back, and lane_host's loneFits comment is indented as zig fmt writes it.
lane_host.zig was 641 lines once ashhart#578's warm turns and memory requeue met ashhart#623's prompt chunks. The status read and the two counters behind it (tokens delivered in the last 2 s, each live stream's tokens) move unchanged, so it is 592 lines. lean_check reports main's 542 problems.
…hout tensor units, as in 1.0.5 ashhart#578's lane host gives every stream a copy proposer, and on an M1 to M4 a lone 27B request stays on the lane core, so copied text took the place of the drafter's tree in some rounds and landed less often: one or two more rounds per 256 code tokens, 138 against 146 tok/s on an M3 Ultra. Model.lone_copies (default on) lets a family keep copies to shared rounds; the 27B turns it off unless TF_QWEN27_COPIES=1, the 1.0.5 opt-in.
… alone The lane backend counts, by a node's own log-probability under the drafter, the DFlash2 nodes offered with their parent row kept and those the target drew there, and allocation trims each tree by the chances these give. Since sampled requests draft (ashhart#578), their rounds went into the same counts, which never forget, so a greedy request read the sampled ones' history too. On an M3 Ultra, the release gate's second greedy code reply after two drafted sampled prose replies took 33 rounds instead of 26 (146.4 against 159.8 tok/s), with the same tokens. The counts move to qwen27_landing.zig as two tables, greedy rounds' and every round's: a greedy stream's chances read the first and a sampled stream's the second, which is the table it read before. With the depth rule's greedy twins, the gate order's greedy code replies decode as in the greedy-only order (34 and 26 rounds, 143.9 and 159.7 tok/s) and the sampled ones as before (123.5 and 123.9).
… alive goes tf-qwen27-served-check, tf-qwen27-dflash-served-check, tf-qwen27-reuse and tf-qwen27-lanes-* built against qwen27_host.zig, which stopped serving when ashhart#578 put the 27B on the lane host. They now build against qwen27_served.zig, the host the server opens. Its `open` loads a checkpoint and calls a new `attach`, which serves a model already in memory (and a drafter bound to it), so the synthetic checks run the same code as a served request. The checks keep their contracts where the served host keeps them: - served: 8 greedy tokens equal the direct session after a chunked prompt. - dflash-served: drafted, EOS, plain, sampled, custom-stop, BF16 and prepared-q4 requests give the CLI's tokens and final state, on the serial loop and with TF_QWEN27_LANES=1. Sampled and custom-stop requests draft now (ashhart#578), so only "draft": false must report no drafts. A cancel lands at the end of a round: the reply is a prefix of the expected one and the state is the CLI's at its length. The round-callback section and the zero-token request tested the serial host's batch delivery, which nothing serves any more; reuse covers prompt-only passes, which are warm passes on the served host. - reuse: the fresh run turns off both the store and the backend's reply keep. qwen27_host.zig and qwen27_lane_decode.zig had no other users and are removed, with the drafter's batch delivery, which only they called. On an M5 Ultra: the three synthetic checks pass (dflash-served on both paths), tf-qwen27-reuse on Qwen3.8-27B MLX-4bit with DFlash2 passes 9 of 9 by default and with TF_QWEN27_LANES=1, and tf-qwen27-lanes-run gives equal tokens (2 of 2).
… alive goes tf-qwen27-served-check, tf-qwen27-dflash-served-check, tf-qwen27-reuse and tf-qwen27-lanes-* built against qwen27_host.zig, which stopped serving when ashhart#578 put the 27B on the lane host. They now build against qwen27_served.zig, the host the server opens. Its `open` loads a checkpoint and calls a new `attach`, which serves a model already in memory (and a drafter bound to it), so the synthetic checks run the same code as a served request. The checks keep their contracts where the served host keeps them: - served: 8 greedy tokens equal the direct session after a chunked prompt. - dflash-served: drafted, EOS, plain, sampled, custom-stop, BF16 and prepared-q4 requests give the CLI's tokens and final state, on the serial loop and with TF_QWEN27_LANES=1. Sampled and custom-stop requests draft now (ashhart#578), so only "draft": false must report no drafts. A cancel lands at the end of a round: the reply is a prefix of the expected one and the state is the CLI's at its length. The round-callback section and the zero-token request tested the serial host's batch delivery, which nothing serves any more; reuse covers prompt-only passes, which are warm passes on the served host. - reuse: the fresh run turns off both the store and the backend's reply keep. qwen27_host.zig and qwen27_lane_decode.zig had no other users and are removed, with the drafter's batch delivery, which only they called. On an M5 Ultra: the three synthetic checks pass (dflash-served on both paths), tf-qwen27-reuse on Qwen3.8-27B MLX-4bit with DFlash2 passes 9 of 9 by default and with TF_QWEN27_LANES=1, and tf-qwen27-lanes-run gives equal tokens (2 of 2).
lane_host.zig was at 596 lines with ashhart#578 and ashhart#596 still to add; the lesson queue and its idle-only step are their own job. A move, with words() made public and the two lock wrappers inlined.
…nds across runner slots, DFlash2 for one stream, and tf-qwen27-bench On the 1.0.6 candidate: the stream spec and the fake backend carry ashhart#596's grammar beside ashhart#578's decode spans and memory lanes, and the lane host gives a stream both. ashhart#596 gave the 2B's draw a grammar mask; the 27B's lane backend passes none, as it serves no structured output. Thanks @BobClawblaw.
…its comments are one line each qwen27_lanes.zig was 763 lines after ashhart#578. A stream's prompt into its slot, a slot's taps ring, restore, a slot's memory on first use, a free slot, unbind, promote and the lone stream's serial loop move unchanged (their calls to each other become direct calls), so it is 590 lines. Comments in the backend, the served host, tap_ring, lane_host and the 27B bench are one line under 120 columns; keepReply has its own comment back, and lane_host's loneFits comment is indented as zig fmt writes it.
lane_host.zig was 641 lines once ashhart#578's warm turns and memory requeue met ashhart#623's prompt chunks. The status read and the two counters behind it (tokens delivered in the last 2 s, each live stream's tokens) move unchanged, so it is 592 lines. lean_check reports main's 542 problems.
The author rebased ashhart#578 onto main after our merge; this keeps the PR's current head in the history with no change to the tree.
…hout tensor units, as in 1.0.5 ashhart#578's lane host gives every stream a copy proposer, and on an M1 to M4 a lone 27B request stays on the lane core, so copied text took the place of the drafter's tree in some rounds and landed less often: one or two more rounds per 256 code tokens, 138 against 146 tok/s on an M3 Ultra. Model.lone_copies (default on) lets a family keep copies to shared rounds; the 27B turns it off unless TF_QWEN27_COPIES=1, the 1.0.5 opt-in.
… alone The lane backend counts, by a node's own log-probability under the drafter, the DFlash2 nodes offered with their parent row kept and those the target drew there, and allocation trims each tree by the chances these give. Since sampled requests draft (ashhart#578), their rounds went into the same counts, which never forget, so a greedy request read the sampled ones' history too. On an M3 Ultra, the release gate's second greedy code reply after two drafted sampled prose replies took 33 rounds instead of 26 (146.4 against 159.8 tok/s), with the same tokens. The counts move to qwen27_landing.zig as two tables, greedy rounds' and every round's: a greedy stream's chances read the first and a sampled stream's the second, which is the table it read before. With the depth rule's greedy twins, the gate order's greedy code replies decode as in the greedy-only order (34 and 26 rounds, 143.9 and 159.7 tok/s) and the sampled ones as before (123.5 and 123.9).
… alive goes tf-qwen27-served-check, tf-qwen27-dflash-served-check, tf-qwen27-reuse and tf-qwen27-lanes-* built against qwen27_host.zig, which stopped serving when ashhart#578 put the 27B on the lane host. They now build against qwen27_served.zig, the host the server opens. Its `open` loads a checkpoint and calls a new `attach`, which serves a model already in memory (and a drafter bound to it), so the synthetic checks run the same code as a served request. The checks keep their contracts where the served host keeps them: - served: 8 greedy tokens equal the direct session after a chunked prompt. - dflash-served: drafted, EOS, plain, sampled, custom-stop, BF16 and prepared-q4 requests give the CLI's tokens and final state, on the serial loop and with TF_QWEN27_LANES=1. Sampled and custom-stop requests draft now (ashhart#578), so only "draft": false must report no drafts. A cancel lands at the end of a round: the reply is a prefix of the expected one and the state is the CLI's at its length. The round-callback section and the zero-token request tested the serial host's batch delivery, which nothing serves any more; reuse covers prompt-only passes, which are warm passes on the served host. - reuse: the fresh run turns off both the store and the backend's reply keep. qwen27_host.zig and qwen27_lane_decode.zig had no other users and are removed, with the drafter's batch delivery, which only they called. On an M5 Ultra: the three synthetic checks pass (dflash-served on both paths), tf-qwen27-reuse on Qwen3.8-27B MLX-4bit with DFlash2 passes 9 of 9 by default and with TF_QWEN27_LANES=1, and tf-qwen27-lanes-run gives equal tokens (2 of 2).
… alive goes tf-qwen27-served-check, tf-qwen27-dflash-served-check, tf-qwen27-reuse and tf-qwen27-lanes-* built against qwen27_host.zig, which stopped serving when ashhart#578 put the 27B on the lane host. They now build against qwen27_served.zig, the host the server opens. Its `open` loads a checkpoint and calls a new `attach`, which serves a model already in memory (and a drafter bound to it), so the synthetic checks run the same code as a served request. The checks keep their contracts where the served host keeps them: - served: 8 greedy tokens equal the direct session after a chunked prompt. - dflash-served: drafted, EOS, plain, sampled, custom-stop, BF16 and prepared-q4 requests give the CLI's tokens and final state, on the serial loop and with TF_QWEN27_LANES=1. Sampled and custom-stop requests draft now (ashhart#578), so only "draft": false must report no drafts. A cancel lands at the end of a round: the reply is a prefix of the expected one and the state is the CLI's at its length. The round-callback section and the zero-token request tested the serial host's batch delivery, which nothing serves any more; reuse covers prompt-only passes, which are warm passes on the served host. - reuse: the fresh run turns off both the store and the backend's reply keep. qwen27_host.zig and qwen27_lane_decode.zig had no other users and are removed, with the drafter's batch delivery, which only they called. On an M5 Ultra: the three synthetic checks pass (dflash-served on both paths), tf-qwen27-reuse on Qwen3.8-27B MLX-4bit with DFlash2 passes 9 of 9 by default and with TF_QWEN27_LANES=1, and tf-qwen27-lanes-run gives equal tokens (2 of 2).
The two things #520 and #528 asked to carry over to the 27B engine: concurrent streams, and
tf-qwen35-benchastf-qwen27-bench. (The small-projection fusions from #520 are already in the engine: z+b+a, k+v and gate+up are each one projection.)What changes
--parallel, fewer when their caches do not fit.qwen35.backend.draw, the same token as the full row), so a sampled request runs DFlash2 rounds too; the serial host decoded them plain.snapshot.zigsaves, restores and moves any slot's state, and the drafter's committed taps become aRingeach slot keeps, so a kept state carries what a drafted request needs. The old drafter-based save and restore remain as wrappers.lane_host.zig):decoded_rowspasses each request'sdecode_spansto the cache and the backend, with the cache on or off, as the serial host'sdecode_chunkdoes; withinfo.warm_turnsa prompt-only request prefills and keeps without drawing. Nemotron, GLM and the 2B set neither and are unchanged. A finished reply is kept for the next turn.LibraryLoad:get_destination_cooperative_tensorrejects an operand type that still carriesthread. Two kernels (the prompt attention's products, the lane projection's reg fetch) pass the types throughmetal::remove_addrspace_t, asnax.hdoes. Types only.tf-qwen27-streams: N streams alone (in a one-slot runner and in their slot of an N-slot runner), then together in shared rounds of 1-5-row windows with wrong last drafts dropped; every kept row's logits bytes and draw are compared with the stream alone.tf-qwen27-bench: each projection shape at 1/8/16/32 rows on the shipped K split and the others,=where the bytes equal the shipped split's; the projections-only one-row step; shared rounds of 1/2/4/8 streams.The serial host (
qwen27_host.zig) stays in the tree:tf-qwen27-served-check,tf-qwen27-dflash-served-checkandtf-qwen27-reusedrive it. They could move to the lane host in a follow-up if you prefer one host.Checks
M5 Ultra, 256 GB, macOS 27.0.1, Zig 0.17.0,
TensorFold/Qwen3.8-27B-MLX-4bit@22d8d538,z-lab/Qwen3.8-27B-DFlash2@50307d4c, onf6dbc6f.Exactness
tf-qwen27-streams: 4 streams, 188 rows; 8 streams, 504 rows; all equal.tools/bench_concurrent.py --alone --serial,--parallel 8 --context 8192, 128 tokens, levels 1/2/4/8, greedy and sampled: 252 of 252 checks equal (each concurrent reply equals its run alone, each run alone equals"draft": false). Again after rebasing onf6dbc6f, 64 tokens, levels 1/4/8: 210 of 210.tools/zig/reuse_served.pyrecord (cache on) / replay (--prompt-cache-gib 0) / compare,--context 32768: every reply equal to the cache-off server, drafted equal to"draft": falseon 23 of 23. The gate still prints 16 rows as not cached as planned. 14 are drafted turns that resumed further in than its plan, at the kept reply (prompt and reply, keyed by their decode spans), with equal tokens. 2 are scenario E, whose 34,260-token prompt exceeds the--context 32768I ran.tf-qwen27-lanes-check(synthetic),test-qwen27,zig build test: pass.Speed (aggregate tok/s, 128 tokens,
bench_concurrent.py):One stream,
tools/bench_openai.py --tokens 256 --reps 3, against 1.0.3 with only the macOS fix:tf-qwen27-benchon this chip: plain shared rounds take 21.5 ms for one stream and 27.1 ms for eight (46.6 to 295 tok/s), so the served 8-stream greedy figure leaves about 15% in the lane core and slot 0's trees. The projections-only one-row step is 16.8 ms GPU over 321 calls. One finding for you rather than this PR: on an M5 Ultra other K splits than the M5 table's are much faster but change the bytes (down54 to 31 µs at split 8,gdn_qkv33 to 20 µs at split 4), so a per-chip table would be your call.