Repository navigation
Pick the decode kernel from each row's unpadded length - #9
Draft
ronaldmannak wants to merge 5 commits into
Draft
ronaldmannak wants to merge 5 commits into
ronaldmannak wants to merge 5 commits into
Conversation
In a left-padded batch that reaches the two-pass cutoff, a row shorter than the cutoff now uses the single-pass kernel, as it would alone. The single-pass launch skips the long rows, and both two-pass stages skip the short ones. The cutoff rule moves into two_pass_min_keys, shared with the stock dispatch. Scope: bfloat16, one query, head dimension 128, four query heads per key/value head. There the two-pass block count does not depend on the key count, so the padded row reproduces the solo row exactly. Prototype by Codex; regression test fails on the parent commit for the 4,245-key batch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ronaldmannak
marked this pull request as draft
November 14, 2026 23:32
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.
Stacked on #8.
In a left-padded decode batch, #8 picks the attention kernel from the padded length. A row shorter than the two-pass cutoff (1,024 keys on Max and Ultra chips, 4,096 with grouped queries elsewhere) therefore runs single-pass alone but two-pass once it is padded into a longer batch, and its result changes. This PR picks the kernel per row from its unpadded length, so such a row matches its solo result exactly.
It is scoped to one shape and kept out of #8 on purpose: it adds a launch at the cutoff, and full-model solo parity still depends on quantized matmul (
ml-explore/mlx#4819). Treat it as evidence for the batch-invariance discussion rather than a change to upstream as is.What changed
two_pass_min_keys(devc, grouped_queries), shared with the stock dispatch instead of copied.test_sdpa_vector_left_padding_uses_each_rows_unpadded_length(prototype by Codex): rows of 1,023, 1,024, 4,095 and 4,096 unpadded keys in one 4,245-key batch, covering both cutoffs, plus a 1,023-key batch for the single-pass kernel alone.Evidence
Apple M5 Max (
applegpu_g17s).The new test on the parent commit
d94e146f(#8's head):At this head (
dc49d649):Cost per attention call against #8's head. Qwen3-8B shape (32/8 heads, head dimension 128, bfloat16), single query, 100 chained calls per evaluation, medians of three runs in ABBA order. Microseconds.
The cost is the extra single-pass launch, largest where the attention call itself is short.
Not verified
Not done on purpose
🤖 Generated with Claude Code