Skip to content

Preserve row parity in Metal batched decode - #6

Closed
ronaldmannak wants to merge 2 commits into
mainfrom
codex/metal-batched-decode-parity
Closed

ronaldmannak wants to merge 2 commits into
mainfrom
codex/metal-batched-decode-parity

Conversation

@ronaldmannak

Copy link
Copy Markdown
Owner

What changes

  • Add opt-in left_padding counts to fast SDPA. With single-query BF16 Metal decode at head dimension 128, GQA ratio 4, and a physical KV length of at least 4,096, pass one starts its K/V reads at each row’s first valid key. It writes partials in logical block order, so left padding no longer rotates the inputs to the second reduction. The second pass and existing calls are unchanged. Other shapes and backends use a boolean mask.
  • Add MLX_DISABLE_QMV_WIDE=1 to route eligible Metal quantized projections through ordinary qmv. This is an opt-in workaround for the different rounding in qmv_wide, which remains enabled by default.

The attention change addresses a separate issue from quantized projection. Exact parity is scoped to comparisons that select the same attention kernel and block count. Adopting the padding input in mlx-swift-lm requires separate C and Swift bindings.

Validation

  • Built MLX and ran the regressions on an M5 Max. The cancellation-sensitive SDPA fixture had 4,096 of 8,192 output values differ from solo with the ordinary padding mask and matched exactly with left_padding.
  • Stock quantized dispatch differed from singleton output at 1 of 1,536 BF16 values and 1,341 of 1,536 FP32 values in the targeted fixture. The qmv fallback matched every value in both tests.
  • The SDPA suite passed on Metal (37 passed, 2 skipped). The CPU fallback and existing qmv_wide test also passed. Ran the stream argument check and git diff --check.

The earlier Swift replay used a local prototype of the attention change with both fixed join schedules. With qmv_wide disabled, it matched the solo choices for all 4,096 tokens and both index-172 logit vectors exactly. Those end-to-end results are from the prototype.

@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-12T08:29:35.672793Z 84b6f9a PR opened
ℹ️ 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.

@ronaldmannak

Copy link
Copy Markdown
Owner Author

superseded by #8

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