Repository navigation
gemma4 metal: prefill runs a chunk a call, so a new prompt no longer freezes other streams' decode (#3021) - #3025
Merged
Merged
Conversation
Owner
Author
|
M5 check on this head (Gemma 4 12B, MLX 4-bit, greedy, base-new-new-base):
|
This was referenced Nov 13, 2026
ashhart
force-pushed
the
lead/gemma4-metal-prefill-step
branch
2 times, most recently
from
November 18, 2026 01:16
7d5259d to
d9978c1
Compare
ashhart
force-pushed
the
lead/gemma4-metal-prefill-step
branch
from
November 21, 2026 18:40
d9978c1 to
f888179
Compare
…ecode between chunks For #3021. Gemma 4's Metal backend now declares prefill_step, cancel_prefill and reports_fill, so the lane host fills a new prompt a chunk a round instead of running the whole pass before the next decode round. The chunk cuts are the old loop's, moved into prefill_steps.zig unchanged (512 rows, planned starts, kept marks, never inside an image), and the whole pass runs the same step in a loop. Gemma still declares no chunk_invariant, so the host never caps a chunk. A drafting stream's chunk rows stay in the prompt scratch as the cache's chunk_tap until the next prompt chunk, and featuresFn serves them, so the drafted wrapper absorbs every chunk's rows after its step. A mark at a chunk's end is kept at the next call, after that absorb, so the kept state carries the drafter's context as before. A cancel between chunks keeps the last landed chunk's state. Host tests on a recording fake: one chunk a call at the old loop's cuts, another stream's decode between two chunks, and a drafter absorbing every chunk before a mark is kept. test-gemma4-metal-steps-host joins the Linux nightly host list. Rebased onto current main: the vtable host step is registered beside main's test-uocr step, and the file stays under 600 lines.
# Conflicts: # CHANGELOG.md
ashhart
force-pushed
the
lead/gemma4-metal-prefill-step
branch
from
November 23, 2026 22:10
f888179 to
3161c85
Compare
ashhart
added a commit
to laudney/TensorFold
that referenced
this pull request
Nov 23, 2026
ashhart
added a commit
that referenced
this pull request
Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3021. Gemma 4 on Metal ran a new stream's whole prompt in one go on the lane thread, so every other stream's decode waited for it: about 6 s for an 8K prompt and 26 s at the 32K default cap on the 31B on an M5 Ultra.
Change (
families/gemma4/, Metal backend): the backend now declaresprefill_step,reports_fillandcancel_prefill, so the lane host runs one chunk a call and decode rounds run between chunks.chunkEndis main's loop code). Gemma declares no chunk invariance, so nothing moves the cuts. A chunk runs the sameprompt.run; the last chunk takes the logits copy that used to follow the loop, and no mark can sit at the prompt's end.Tests (
test-gemma4-metal-steps-host, new, in the nightly host list; recording fakes, no GPU): one call runs one chunk at today's cuts; the chunk sequence equals the unstepped run's; a decode round runs between two chunks of a long prompt; a drafter receives every chunk's taps. On main's backend each fails (the whole prompt runs in one call, no decode between chunks,GemmaTapsNotHeld). Keeping a mark before the absorb also fails the drafter test.test-gemma4-metal-vtable-host56/56, the other Gemma host steps 742 pass,compile-gemma4-hostpasses; lean 0 new.Before landing, on an M5: replies equal to main's for one stream (greedy, a ~5K prompt not a multiple of 512, with and without DFlash), for two streams where the second sends a 32K prompt mid-decode, for a resumed turn and a
--visionimage across a chunk boundary; cancel and resend; and stream 1's largest gap between tokens during stream 2's 32K fill (main: the whole fill; this: about one chunk and one round), with no slower time to first token.