perf(inference): chunked batched prefill for long prompts on Metal#188
Open
ohdearquant wants to merge 1 commit into
Open
perf(inference): chunked batched prefill for long prompts on Metal#188ohdearquant wants to merge 1 commit into
ohdearquant wants to merge 1 commit into
Conversation
Replaces the per-token prefill loop with a chunked batched Metal path for long prompts, removing per-token GPU dispatch overhead during prefill. Decode unchanged; prefill argmax parity preserved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
chunked batched prefill for long prompts (Metal)
Replaces the per-token prefill loop with a chunked, batched Metal path for long
prompts. Long-context prompts no longer pay a GPU dispatch per token during prefill.
Why
For prompts longer than the prefill window, the old path fell back to a per-token
loop — one GPU dispatch per token — which dominated time-to-first-token on long
contexts. This chunks the request and batches the per-chunk work.
Result (Qwen3.5-0.8B, Apple Silicon Metal, 1000-token prompt)
~1.86× prefill, bit-exact (parity max_abs_diff = 0.000000). Decode path unchanged.
Notes
parallel GatedDeltaNet scan.
unwrap().Stack: #188 (this) → #189 (batched attention) → #190 (GDN parallel scan)