debug(mlx): root-cause Mac batched-decode bug to MLX core quantized/rope kernel (B>1, L=1) — full ablation - #134
Merged
Conversation
…mma-4 batch>1 decode divergence Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…on (layer-0 row>0 divergence) Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…ce cache write vs SDPA Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…rks around mx.fast.scaled_dot_product_attention batch>1+GQA bug) Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.com>
…antized/rope kernel at L=1 B>1 (ruled out rotation/cache/shared-kv/embed/mask/SDPA); not Python-patchable, upstream MLX Co-authored-by: FluffyAIcode <FluffyAIcode@users.noreply.github.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.
What
Followed the upstream investigation as requested (per-layer logits diff + patch-and-verify) and fully root-caused the Mac batched-decode recall break.
Per-layer localization (Mac M4)
mlx_batched_layer_diff_diag.py: at decode step 1, batched row 0 is bit-exact vs serialized; row 1+ diverge from layer 0, with layer-0 input identical (embedding correct).Ablations — every Python-level cause ruled out
SinkWindowKVCachefirst_kv_shared_idx=30)Noneat this offsetmx.fast.scaled_dot_product_attentionRoot cause
Identical layer-0 input + concat cache + manual SDPA, prefill (L=327) correct but decode (L=1, B>1) broken for rows>0 → an MLX core-kernel bug for 4-bit-quantized batched single-token decode (
mx.quantized_matmul/mx.fast.ropeatB>1, L=1). Below the Python layer — not patchable in this repo; it's an upstream MLX issue (now precisely characterized for a report). CUDA is unaffected (HF transformers, no MLX quantized kernels — §3.5/§3.7 keep recall 1.0).Honest outcome
I could not fix it this round — the bug is in MLX's compiled kernels, not our Python. The
--manual-sdpapatch I tried (a legitimate candidate) did not resolve it, which is itself the evidence that ruled SDPA out. Per the conditional request, I'm not opening a separate "fix" feature PR/ADR (no fix achieved); instead this PR records the complete root-cause + reusable diagnostic suite. Recall-safe Mac multi-tenant stays serialized.Files
scripts/research/mlx_batched_layer_diff_diag.py(+--kakeya-cache),mlx_batched_multitenant_bench.py(+--manual-sdpa)mlx-batched-layer-diff[-concat],mlx-batched-manual-sdpadocs/adr/0014-…md§3.7 full root-cause chain; evidence JSONsTesting
pytest tests/inference_engine/bridge/test_manifest.py(24 passed)