Skip to content

qwen3_5 metal: prefill runs a chunk a call, so a new prompt no longer stalls other streams' rounds (#3021) - #3090

Merged
ashhart merged 3 commits into
mainfrom
lead/qwen35-metal-prefill-step
Nov 21, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/qwen35-metal-prefill-step

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

What this changes

Qwen3.5-2B on Metal ran a new stream's whole prompt in one call on the lane thread, so with shared rounds every other stream's reply waited for the whole prefill. The backend now declares prefill_step and cancel_prefill beside reports_fill, so the lane host runs one chunk a call and decode rounds run between chunks, as Gemma 4 (#3025), Nemotron (#3054) and LFM2-MoE (#3058) do.

Checks on this head

  • Lean checker: 0 new; every file under 600 lines. zig fmt --check: clean.
  • test-qwen35-metal-steps-host: 7/7; test-qwen35-cache-host: 23/23; check-qwen35-cache-host passes; check-metal-prefill-rest-host passes (it compiles the real prefill, prefill_step and cancel_prefill bodies).
  • Not run here: the Metal device steps. We'll run them on an M5 Mac before landing.

Receipt

  • Main against branch: owed, on an M5 Mac: replies byte-identical to main at T=0 and seeded, including a long prompt arriving while another stream decodes, a prompt-cache resume from a mark and a cancel mid-pass; lone decode and lone TTFT within run-to-run noise.

Checklist

  • The title and description match the head commit.
  • Comments and docstrings are one line.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@ashhart
ashhart force-pushed the lead/qwen35-metal-prefill-step branch from c334f6e to 3517796 Compare November 17, 2026 21:57
ashhart added a commit that referenced this pull request Nov 17, 2026
A new Qwen3.5-2B Metal prompt is filled a chunk at a time between other
streams' decode rounds, at the whole pass's cuts, so replies are
unchanged. Note it under Unreleased (#3090, part of #3021).
ashhart added a commit that referenced this pull request Nov 17, 2026
A new Qwen3.5-2B Metal prompt is filled a chunk at a time between other
streams' decode rounds, at the whole pass's cuts, so replies are
unchanged. Note it under Unreleased (#3090, part of #3021).

# Conflicts:
#	CHANGELOG.md
@ashhart
ashhart force-pushed the lead/qwen35-metal-prefill-step branch from 3517796 to fdf7ba1 Compare November 17, 2026 21:57
ashhart added a commit that referenced this pull request Nov 19, 2026
A new Qwen3.5-2B Metal prompt is filled a chunk at a time between other
streams' decode rounds, at the whole pass's cuts, so replies are
unchanged. Note it under Unreleased (#3090, part of #3021).

# Conflicts:
#	CHANGELOG.md
@ashhart
ashhart force-pushed the lead/qwen35-metal-prefill-step branch from fdf7ba1 to 8c82045 Compare November 19, 2026 01:35
…stalls other streams' rounds

Qwen3.5-2B's Metal backend gains prefill_step and cancel_prefill (#3021).
prefill.run becomes open (main's restore of a kept prefix) and step (one
turn of main's loop), and the whole pass is open plus steps, so both
drivers run the same chunk body and replies are unchanged.

Each call runs one chunk at exactly the whole pass's cuts (the chunk cap,
the next planned start, the next kept mark); Qwen3.5 declares no chunk
invariance, so max_rows is ignored and the cuts never move. The GDN and
conv state live in the stream's cache, so a step carries only its next
row between calls. A cancel keeps the state at the last chunk's end; a
stream that leaves mid-pass is forgotten, its paged lane released.

Host tests on host-backed caches with a sentinel forward: stepped chunks
equal the whole loop's and leave the same state byte for byte, a resumed
pass cuts as main does, a cancel keeps the last chunk's end, and another
stream decodes between two chunks of a long prompt. The new step joins
the macOS host CI list.

Rebased onto main 038e4a2: main added a background-yield check inside
the loop this PR splits into open/step. It is ported into step() right
after the cancel check, keeping the last chunk's end and returning
error.Yielded, as cuda_prefill.zig's chunk() does; run() stays open plus
the step loop.
A new Qwen3.5-2B Metal prompt is filled a chunk at a time between other
streams' decode rounds, at the whole pass's cuts, so replies are
unchanged. Note it under Unreleased (#3090, part of #3021).

# Conflicts:
#	CHANGELOG.md
@ashhart
ashhart force-pushed the lead/qwen35-metal-prefill-step branch from 8c82045 to fb6794a Compare November 21, 2026 03:27
@ashhart
ashhart merged commit 8c534b0 into main Nov 21, 2026
10 of 11 checks passed
@ashhart
ashhart deleted the lead/qwen35-metal-prefill-step branch November 21, 2026 03:27
ashhart added a commit to gilby/TensorFold that referenced this pull request Nov 21, 2026
A new Qwen3.5-2B Metal prompt is filled a chunk at a time between other
streams' decode rounds, at the whole pass's cuts, so replies are
unchanged. Note it under Unreleased (ashhart#3090, part of ashhart#3021).

# Conflicts:
#	CHANGELOG.md
ashhart added a commit to gilby/TensorFold that referenced this pull request Nov 21, 2026
ashhart added a commit that referenced this pull request Nov 21, 2026
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.

1 participant