Skip to content

Match solo Metal decode across attention and quantized dispatch boundaries - #7

Closed
ronaldmannak wants to merge 4 commits into
codex/metal-batched-decode-parityfrom
codex/metal-decode-solo-parity
Closed

ronaldmannak wants to merge 4 commits into
codex/metal-batched-decode-parityfrom
codex/metal-decode-solo-parity

Conversation

@ronaldmannak

@ronaldmannak ronaldmannak commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #6.

A left-padded decode row can cross the Metal single-pass/two-pass cutoff when it joins a batch, even though its own keys and values have stayed the same. Single-pass attention also groups keys by physical position. This change uses logical key positions in both kernels and selects the same path each row would use at its unpadded length. Mixed batches use GPU-side row selection. If the padded single-pass pipeline cannot launch a 1,024-thread group, the padded call uses two-pass attention. The optimized path covers single-query BF16 attention with head dimension 128 and a GQA ratio of four. Other shapes and backends continue to use the mask path.

For transposed affine quantized matmul, MLX_QUANTIZED_MATMUL_MATCH_SINGLE_ROW=1 preserves the singleton Metal kernel’s arithmetic. For eligible aligned affine 4-bit BF16 and FP16 projections at four or more rows, it shares packed weight loads across pairs of activation rows. Other exact projections use the singleton vector path. The option is off by default and can cost throughput at wider batch sizes, so it can be scoped to decode evaluation. This provides a reference for the batch-invariance discussion in ml-explore/mlx#4819.

The TF32 test failures in the report reproduced on both the parent of #6 and #6 with identical failing cases. The standard pytest configuration disables TF32 for these comparisons.

Validation

  • Built with Metal and ran the SDPA suite and targeted quantized regressions on an M5 Max (41 passed, 2 skipped).
  • The new SDPA regression fails on Preserve row parity in Metal batched decode #6 for mixed lengths and for a physically short left-padded batch. Both cases match solo exactly with this change.
  • The quantized regression compares with stock singleton outputs across quad, vector, MMA, split-K, and QMM dispatch boundaries, including strided inputs and broadcast weights.
  • In synchronized M5 Max microbenchmarks, the mixed-length attention case took 76.1 µs per call versus 67.8 µs on Preserve row parity in Metal batched decode #6. This is an attention operation timing.

The updated quantized path passed 63 Metal tests with one skip. The previous and updated builds produced identical bits over 6,271,984 projection outputs in each of stock and exact mode.

The native tiled kernel was also tested on the two published Qwen3-8B-4bit fixed-join schedules using the Swift ml-explore#785 replay at e46c414 on M5 Max. Exact mode was scoped to decode. All 4,096 greedy tokens and both full BF16 logit vectors at index 172 matched solo. For the diverging schedule with fixed histories, two warmed A/B pairs with order reversed gave:

Scope Previous exact kernel Tiled exact kernel Paired gain
Full replay 79.89 tok/s 81.34 tok/s +1.81%
Four rows decoding 143.09 tok/s 149.20 tok/s +4.27%

Published prompt and schedule fixtures

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T16:34:45.703145Z 96f07b3 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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