Skip to content

Qwen3.8-27B Metal: prompts fill by prefill_step chunks, so live streams keep their rounds - #1303

Closed
jschmied wants to merge 1 commit into
ashhart:mainfrom
jschmied:q27-metal-host-a
Closed

jschmied wants to merge 1 commit into
ashhart:mainfrom
jschmied:q27-metal-host-a

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

Until now the 27B's lane backend had no prefill_step, so the lane host ran each prompt as one whole pass. Every other stream stopped until that pass ended. The prompt pass is now an opening, then one chunk per step on the same cut grid as before. The opening covers GPU-failure recovery, rope, the slot reset, the kept-state restore and the image encode. The host runs the other streams' rounds between chunks. cancel_prefill keeps the last landed chunk's state. Whole passes (the lone driver, warm passes, the disk probe) run the opening and then all the chunks.

Receipts: M3 Pro 36 GB, Qwen3.8-27B MLX 4-bit, z-lab DFlash2 drafter, against main at faccd11c8.

gate result
temp-0 and seeded-sampled replies == main identical at --parallel 4 (--context 16384), and with DFlash2 at --parallel 2 (8192)
drafted == plain DFlash2 greedy == no-drafter greedy
concurrent == solo 2 rounds at 4 (no drafter) and at 2 (DFlash2), every reply equal
resumed == fresh, prompt cache on a second turn equals itself asked again after another request; a repeated 6.8k-token prompt resumed at 6,795
zig build test passes on macOS (Metal) and on Linux (GB10, -Dnvcc)

An 8,684-token prompt submitted while 2 streams decode (--parallel 4, --context 16384):

longest gap in the decoding streams long prompt's first token
main 150.3 s 150 s
this branch 2.9 s (about one 128-row chunk) 166 s

The decoding streams no longer stop. The long prompt pays about 10% for the rounds that now run between its chunks.

Design:

  • Same cuts: opening() and chunk() split the old loop as it was, so chunk cuts, decoded spans and prompt marks are unchanged. Inside each chunk the drafter still absorbs before the marks are taken (the order gemma4 CUDA: a stepped drafted pass keeps its mark after the drafter absorbed the chunk #1286 fixed for Gemma 4).
  • State between steps: a pass keeps its Fill: the slot, the next chunk's start, the restore's end and its encoded images. runner.images is set for each chunk from the Fill, and a chunk's prompt-mark bank lives within that chunk, as before.
  • Slot 0: promote never moves a stream that is still filling into slot 0.
  • Images: the vision tower's rows are one shared buffer, so one image prompt fills at a time. A second image prompt's first step returns LaneMemory, and the host requeues it.

Not covered: two image prompts filling at once on real weights. Only the logic and its requeue are tested.

Test-only setting: the stock 8 GiB margin beside the weights (qwen27_served.zig room()) leaves room for one 27B stream and a 53 MiB prompt cache on a 36 GB Mac. For these receipts, both main and this branch were built with the same uncommitted override setting the margin to 2 GiB, and served with --prompt-cache-gib 2 --prompt-cache-over-cap. The override is not in the branch.

…ke rounds while a prompt fills

The prompt pass splits into an opening (restore, images) and one chunk a step on the same cut grid; cancel_prefill keeps
the last landed chunk. A stream mid-fill is never promoted into slot 0, and one image prompt fills at a time.
@ashhart

ashhart commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Landed on main (94d9a6a..0941f86) with #1304, both under your authorship. Thank you! On an M3 Ultra with Qwen3.8-27B, six alternating runs of an ~8.7k-token prompt arriving while 2 streams decode: the decoding streams' longest pause went from 28.6 s (every main run) to 0.47 s (every run here). The long prompt's first token went from 28.58 s to 30.85 s (+7.9%, inside your ~10%). All replies were byte-identical. Prefill and the 1-8 stream sweep were unchanged.

- Synthema, Ash's AI Assistant.

@ashhart ashhart closed this Oct 25, 2026
javierbits added a commit to javierbits/TensorFold that referenced this pull request Oct 26, 2026
…lies (ashhart#840)

The ashhart#840 row (Python ashhart#248, @simon-lin88): the native parser refused
--decode-share outright, while the mechanism it feeds already existed —
the lane host's debt share (lane_host_fill.zig) keyed off
TENSORFOLD_PREFILL_SHARE only. The flag now serves: the reply's share x
sets the prompt's p to its complement (0 keeps whole prompts, the CUDA
default; the env stays as the lower override and the flag wins), and it
rides api.Open and api.Info to every lane host.

ashhart#248's pass cap maps onto the chunk level: while a share is active and
replies are decoding, a filling prompt's chunks cap at 512 rows
(Share.short_rows) through prefill_step's max_rows hint, honored by the
core wrappers and the family backends (qwen3_5, qwen27 metal, glm,
flashnext CUDA and HIP, dory, gemma4, kolibri1); without a share or without live decoders
the engines keep their own cuts. ashhart#248's row_s estimator has no native
analog — the debt is owed from measured wall time, so a stand-alone
step needs no calibration.

Co-authored-by: simon-lin88 <[email protected]>

Rebased on 3f1d669: jschmied's ashhart#1303 moved qwen27 metal's prompt fill
into prefill_step chunks, so the max_rows hint re-points at
qwen27_slots.prefillStep/chunk (the cap shortens a chunk; the cut grid,
marks and decode spans still win), and the lane-host inits that the
KV-pages admission reshaped keep the flag beside the served count.
javierbits added a commit to javierbits/TensorFold that referenced this pull request Oct 27, 2026
…lies (ashhart#840)

The ashhart#840 row (Python ashhart#248, @simon-lin88): the native parser refused
--decode-share outright, while the mechanism it feeds already existed —
the lane host's debt share (lane_host_fill.zig) keyed off
TENSORFOLD_PREFILL_SHARE only. The flag now serves: the reply's share x
sets the prompt's p to its complement (0 keeps whole prompts, the CUDA
default; the env stays as the lower override and the flag wins), and it
rides api.Open and api.Info to every lane host.

ashhart#248's pass cap maps onto the chunk level: while a share is active and
replies are decoding, a filling prompt's chunks cap at 512 rows
(Share.short_rows) through prefill_step's max_rows hint, honored by the
core wrappers and the family backends (qwen3_5, qwen27 metal, glm,
flashnext CUDA and HIP, dory, gemma4, kolibri1); without a share or without live decoders
the engines keep their own cuts. ashhart#248's row_s estimator has no native
analog — the debt is owed from measured wall time, so a stand-alone
step needs no calibration.

Co-authored-by: simon-lin88 <[email protected]>

Rebased on 3f1d669: jschmied's ashhart#1303 moved qwen27 metal's prompt fill
into prefill_step chunks, so the max_rows hint re-points at
qwen27_slots.prefillStep/chunk (the cap shortens a chunk; the cut grid,
marks and decode spans still win), and the lane-host inits that the
KV-pages admission reshaped keep the flag beside the served count.
javierbits added a commit to javierbits/TensorFold that referenced this pull request Oct 27, 2026
…lies (ashhart#840)

The ashhart#840 row (Python ashhart#248, @simon-lin88): the native parser refused
--decode-share outright, while the mechanism it feeds already existed —
the lane host's debt share (lane_host_fill.zig) keyed off
TENSORFOLD_PREFILL_SHARE only. The flag now serves: the reply's share x
sets the prompt's p to its complement (0 keeps whole prompts, the CUDA
default; the env stays as the lower override and the flag wins), and it
rides api.Open and api.Info to every lane host.

ashhart#248's pass cap maps onto the chunk level: while a share is active and
replies are decoding, a filling prompt's chunks cap at 512 rows
(Share.short_rows) through prefill_step's max_rows hint, honored by the
core wrappers and the family backends (qwen3_5, qwen27 metal, glm,
flashnext CUDA and HIP, dory, gemma4, kolibri1); without a share or without live decoders
the engines keep their own cuts. ashhart#248's row_s estimator has no native
analog — the debt is owed from measured wall time, so a stand-alone
step needs no calibration.

Co-authored-by: simon-lin88 <[email protected]>

Rebased on 3f1d669: jschmied's ashhart#1303 moved qwen27 metal's prompt fill
into prefill_step chunks, so the max_rows hint re-points at
qwen27_slots.prefillStep/chunk (the cap shortens a chunk; the cut grid,
marks and decode spans still win), and the lane-host inits that the
KV-pages admission reshaped keep the flag beside the served count.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants