Repository navigation
perf(native): fused causal SDPA for full-attention prompt chunks - #1540
Conversation
Bump libs/mlx-swift-lm to the CBv2 change that attends a full-attention prompt chunk with one `.causal` SDPA call whenever MLX serves the head geometry with a fused kernel (head_dim 64/72/80/96/128 on every Apple GPU; head_dim 256 on NAX from 1024 queries), instead of 128-query blocks with explicit masks. GPT-OSS full layers and the Qwen full-attention layers of M5 solo prefill stripes take the new route; Gemma 4 does not. The SDK pin moves from 19634dd8 to ff327738: SDK main (#316, #312, #315, #317, #318) plus the change. SDK main requires mlx-swift 81f58d79 (nested MLX 71271f08), so libs/mlx-swift moves from 6923a80f and libs/mlx from cb77239b; the Metal library built from the nested MLX is byte-identical. Document the SDK-read kill switch DARKBLOOM_TTFT_FUSED_CAUSAL_PREFILL=0 in the configuration reference and the prompt-chunk attention route in the inference architecture, and add a changelog fragment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refactor pass over the fused causal prefill change. Pin libs/mlx-swift-lm to fd17d026, the head of the paired SDK branch: one refactor commit over ff327738 that changes comments and the route's test, not compiled code. The route follows layer geometry, so it also reaches the Nemotron 3.5 Lightning attention layers (head_dim 128, every chip) and the head_dim 256 full-attention layers of the other Qwen-family models in M5 solo prefill stripes. The changelog fragment now names them and says they were not measured. The inference and configuration rows note that Qwen4 QSA blocks build no absolute mask and that live packed paged KV keeps its own prompt path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review SummaryThis 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. |
Threat model review — advisoryReviewed head Review not completed for this head. Previous findings are superseded, not confirmed resolved. Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging. Coverage: 0/31 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned. Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens. Saved findings and earlier report · Historical findings are not confirmed resolved. Bedrock: 0 request(s), 0 uncached + 0 cache-read + 0 cache-write input / 0 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately. |
The paired SDK PR branch (ttft/fused-causal-prefill) was published on SDK main 0351444e, which also carries mlx-swift-lm #323 and #325 that d-inference master does not pin yet. Pin ttft/fused-causal-prefill-pin (6d1321ce) instead: the same commits cherry-picked onto 0351444e, the SDK commit master pins, so this PR adds only this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d-inference master now pins SDK main 0351444e (#1531), the base the paired SDK PR branch (ttft/fused-causal-prefill) was published on, so the PR head is already the right pin and the cherry-picked ttft/fused-causal-prefill-pin copy is redundant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refresh before review: master moved (Nemotron Super and SDK pin updates; it now pins SDK 0351444e, mlx-swift 67dc7528 and MLX ad4745a2). Keep master's mlx-swift and MLX pins and pin libs/mlx-swift-lm to fd17d026 (the paired SDK PR head). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Layr-Labs/mlx-swift-lm#327 squash-merged as 1bee5728 ("perf(cbv2): one fused causal SDPA per full-attention prompt chunk (#327)"). Move the gitlink from the PR branch head fd17d026 to that commit on SDK main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0ee7a5b0e5
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Refresh before review: master moved (Nemotron Super and SDK pin updates; it now pins SDK 889fe3cc, mlx-swift 67dc7528 and MLX ad4745a2). Keep master's mlx-swift and MLX pins and pin libs/mlx-swift-lm to . Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cd8243245e
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The fused causal prompt-attention route lowers the prefill transient (Qwen3.5-9B on M5 Ultra at 32K: 13.86 -> 12.03 GB peak) but only inference.md described it. Record in hardware-support.md what the route drops, and that the activation reserve, measured floors, minimum load KV and slot grants intentionally stay unchanged, with the reasons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
inference.md and configuration.md changed for the fused causal prompt attention route; set their freshness stamps to the UTC date of the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd6e963fb0
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -0,0 +1,5 @@ | |||
| ### Fused causal prompt attention | |||
There was a problem hiding this comment.
Before this commit is submitted, recreate it with an accepted signature: fresh evidence beyond the earlier comment is that the actual reviewed head 744d6ba3280dfafde8e2c8ae627968afc176aba4 has no gpgsig header and git verify-commit exits 1, so it cannot display as GitHub-Verified as required for every PR commit.
AGENTS.md reference: AGENTS.md:L161-L162
Useful? React with 👍 / 👎.
Brings #1535 (native Flint, prefill projection optimization), #1539 (GPT-OSS bf16 SDK pin), #1540 (fused causal SDPA for full-attention prompt chunks) and #1542. libs/mlx-swift-lm stays on the cluster SDK 5d7f7510, which contains master's pin 889fe3cc; that was the only conflict. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Pins the paired Layr-Labs/mlx-swift-lm PR (
fd17d026, branchttft/fused-causal-prefill): CBv2 attends a full-attention prompt chunk with one fused.causalSDPA call instead of 128-query blocks whenever MLX serves its head geometry with a fused kernel (head_dim 64/72/80/96/128 on every Apple GPU; head_dim 256 on M5 NAX chips from 1024 queries). The route follows layer geometry: GPT-OSS full-attention layers on every chip and the Qwen3.5/3.8 dense full-attention layers of M5 solo prefill stripes take it and were measured; Nemotron 3.5 Lightning attention layers (head_dim 128, every chip) and the head_dim 256 layers of Qwen 3.5/3.6 MoE, Bonsai 9B and Qwen4 Flash-Next dense prefill (M5) take it unmeasured. Gemma 4, sliding windows, softcaps, vision spans and live packed paged KV do not.14661d9b→fd17d026: SDKmain@66f556b7(Layr-Labs/mlx-swift-lm#316, #312, #315, #317, #318) plus the route (ff327738) and its refactor-pass commitlibs/mlx-swift-lm6923a80f→81f58d79, which SDKmainrequires (Layr-Labs/mlx-swift#52, #57)libs/mlx-swiftcb77239b→71271f08, the MLX thatmlx-swift81f58d79nests. The Metal library built from it is byte-identical (SHA-256fb1ba8f9…)libs/mlxDARKBLOOM_TTFT_FUSED_CAUSAL_PREFILLrow in the engine and scheduler tabledocs/reference/configuration.mddocs/architecture/inference.mdchangelog.d/fused-causal-prefill-attention.mdKill switch:
DARKBLOOM_TTFT_FUSED_CAUSAL_PREFILL=0, read by the SDK once per process. The LaunchAgent does not forward it, so it applies to foreground providers only.Commits:
e2885e5f3and the refactor-pass commit193823342, onmaster@eaaf5e615(#1529).Before
flowchart TB subgraph PB["Behavior: cold prompt prefill on the provider"] direction LR rb["Request<br/>GPT-OSS 20B, 32K-token prompt"]:::input --> eb["CBv2 engine<br/>full-attention layers in 128-query blocks"]:::slow eb --> tb["Cold TTFT on M3 Ultra<br/>19.5 s"]:::state end subgraph GB["Code flow: pinned native libraries"] direction LR lb["libs/mlx-swift-lm<br/>14661d9b"]:::stock --> sb["libs/mlx-swift<br/>6923a80f"]:::stock sb --> mb["nested MLX cb77239b<br/>libs/mlx cb77239b"]:::stock db["docs: no prompt-chunk<br/>attention route"]:::stock end PB ~~~ GB style PB fill:#f8fafc,stroke:#64748b,color:#0f172a style GB fill:#f8fafc,stroke:#64748b,color:#0f172a classDef input fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a classDef stock fill:#e5e7eb,stroke:#4b5563,color:#111827 classDef slow fill:#fee2e2,stroke:#b91c1c,color:#7f1d1d classDef state fill:#ede9fe,stroke:#6d28d9,color:#3b0764 linkStyle default stroke:#475569,stroke-width:1.5px linkStyle 4 stroke:noneAfter
flowchart TB subgraph PA["Behavior: cold prompt prefill on the provider"] direction LR ra["Request<br/>GPT-OSS 20B, 32K-token prompt"]:::input --> ea["CBv2 engine<br/>one fused .causal call per<br/>eligible full-attention chunk"]:::new ea --> ta["Cold TTFT on M3 Ultra<br/>17.4 s, output bit-identical"]:::state ka["DARKBLOOM_TTFT_FUSED_CAUSAL_PREFILL=0<br/>foreground only"]:::decision -. "restores" .-> oa["128-query blocks"]:::stock end subgraph GA["Code flow: pinned native libraries"] direction LR la["libs/mlx-swift-lm<br/>fd17d026: SDK main + route"]:::new --> sa["libs/mlx-swift<br/>81f58d79, required by SDK main"]:::changed sa --> ma["nested MLX 71271f08<br/>libs/mlx 71271f08<br/>metallib byte-identical"]:::changed da["docs: configuration.md row,<br/>inference.md row, changelog.d"]:::new end PA ~~~ GA style PA fill:#f8fafc,stroke:#64748b,color:#0f172a style GA fill:#f8fafc,stroke:#64748b,color:#0f172a classDef input fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a classDef stock fill:#e5e7eb,stroke:#4b5563,color:#111827 classDef new fill:#dcfce7,stroke:#15803d,color:#14532d classDef changed fill:#cffafe,stroke:#0e7490,color:#164e63 classDef state fill:#ede9fe,stroke:#6d28d9,color:#3b0764 classDef decision fill:#fef3c7,stroke:#b45309,color:#78350f linkStyle default stroke:#475569,stroke-width:1.5px linkStyle 5 stroke:noneLegend: blue is input, grey is unchanged, red is the cost removed, green is new, cyan is a pin moved because SDK
mainneeds it, amber is the kill switch, purple is the observable result.Measured effect
Logs are in
pr/attn-fused/of the TTFT session scratchpad on the M5 Ultra (/private/tmp/claude-501/-Users-gaj-Documents-Builds-Darkbloom/8eacbef9-e1dd-444e-98a8-972bc1d30258/scratchpad/pr/attn-fused/). Each A/B runs one binary with and without the kill switch, arms interleaved; times are cold engine TTFT in ms (darkbloom benchmark --scheduler-prefill).evidence/m3u/prefill.logevidence/m5u-impl/V1.outbd676704(shared GPU)logs/gpu-ticket.logM3 Ultra load test, GPT-OSS 20B (rate 0.1/s for 300 s, seed 7, 4 in flight, 32 requests, one run per arm;
evidence/m3u/load.log): TTFT p50/p90/p99 7.33/15.98/23.03 s → 6.35/13.13/20.28 s; decode p50 52.1 → 53.8 tok/s; no errors. On M5 Ultra, Qwen3.5-9B peak MLX memory at 32,768 tokens drops from 13.86 GB to 12.03 GB (evidence/m5u-impl/V2.out,logs/gpu-ticket.log).Output: GPT-OSS 20B teacher-forced scoring is bit-identical with and without the route (M3 Ultra inputs 2/3/4: every per-token score bit,
evidence/m3u/tf-compare.txt; M5 Ultra inputs 3/4: same NLL as the productionmasterbinary,evidence/m5u-impl/SA.out). Qwen3.5-9B greedy generation on M5 Ultra, 64 tokens after an 1,846-token prompt, is token-identical with and without the route (logs/gpu-ticket.log).Validation
M5 Ultra, PR clone, toolchain from
toolchains/env.sh(Swift 6.4 CLT, Metal toolchain from Xcode 27.1).nice -n 15 swift build -c release --product darkbloom(fromprovider-swift/)darkbloomSHA-256bd676704…(logs/provider-build.log)scripts/fetch-metallib.sh releasemlx.metallibfrom nested MLX71271f08, SHA-256fb1ba8f9…, the same bytes as the metallib built frommaster's nested MLXcb77239blogs/gpu-ticket.log)swift test --skip-build, focused attention suites plus 8 suites with head_dim 256 layers)make docs-impact-check BASE=origin/mastermake docs-checkpython3 scripts/changelog.py check(make changelog-check)make provider-testLimitations
V1.out/V2.outruns use the implementation buildd92dbc8e, which has the same route code asff327738on the older pins (14661d9b,6923a80f);fd17d026changes only comments and tests on top.Landing order
libs/mlx-swift-lmhere to the squash commit. SDKmainmoved to0351444eduring preparation (GLM-5.3-Flash native: NVFP4 hybrid, fused serving kernels, MTP, images mlx-swift-lm#314, Harden Swift optional inference sites #325, Update Privacy Policy and ToS legal copy (June 2026) #323) and pinsmlx-swift67dc7528(nested MLXad4745a2); if the squash includes them, movelibs/mlx-swiftandlibs/mlxto that pin and its nested MLX, rebuild the metallib (ad4745a2changes quantized kernels, not the SDPA dispatch the route mirrors) and rerunmake docs-impact-checkandmake docs-check.mainhead that contains every landed change.Refactor pass
An independent refactor subagent (d-inference
AGENTS.md, "Required Refactor Pass") reviewed this branch before publication and added one commit,193823342:libs/mlx-swift-lmtofd17d026, the head of the SDK branch. Its refactor commit changes comments (with unchanged line numbers) and the route's test, not compiled code; see the SDK PR's refactor pass.inference.mdandconfiguration.mdrows: Qwen4 QSA paged blocks build no absolute mask, and live packed paged KV keeps its own prompt path.main@0351444e, and arrow color in both figures so edges stay visible in the dark theme.Reviewed and kept: the configuration row's place in the engine table (the SDK reads the switch at runtime, so it does not belong with the retired names), and the
DARKBLOOM_TTFT_prefix, which sibling TTFT PRs share.Validation of
193823342:make docs-impact-check BASE=origin/mastermake docs-checkmake changelog-check,make changelog-previewfd17d026(M5 Ultra)ff327738; the details are in the SDK PRmmdc11.15.0 on both figures, default and dark themesfd17d026differs fromff327738, whichbd676704was built from, only in comments and test code🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.