Repository navigation
Conversation
…of line Every decode step over a quantized KV cache passes through quantizedCacheAttention and takes the quantized branch. With the route's body inlined there, MiniCPM5 1B with 8-bit KV decoded 2-3 % slower on an M5 iPad (pipelined decode). Counters showed the branch never ran in those turns, and the matmul kernel counts were unchanged. With the body in an @inline(never) function, decode matched a build without the route (+1.2 % [-0.09, +2.55] vs the previous pin), and the long-prompt prefill gain stayed. Refs numen-tech/gemma4-qat#1725
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 50308b8224
ℹ️ 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".
| /// MiniCPM5 1B with 8-bit KV decoded 2-3 % slower on an M5 iPad (pipelined decode), | ||
| /// although the counters showed this branch never ran in those turns and the matmul kernel | ||
| /// counts were unchanged. Out of line, decode matched the build without this route, and | ||
| /// the prefill gain stayed (numen-tech/gemma4-qat#1725). |
There was a problem hiding this comment.
Condense the helper's benchmark commentary
The new helper includes a nine-line documentation block with device-specific benchmark results and counter observations, contrary to the root AGENTS.md requirements to “Keep code comments concise (usually 1-2 lines)” and “Avoid redundant or excessive inline commentary.” Keep a short explanation that @inline(never) protects decode performance, and leave the experimental details in the commit message, where they are already recorded.
AGENTS.md reference: AGENTS.md:L45-L46
Useful? React with 👍 / 👎.
|
Closing on the owner's decision of 2026-11-16. The branch Final measurement on the real pin: M5 iPad, MiniCPM5 1B, Automatic 8-bit KV, 2 ABBA rounds, 16 pairs, thermal nominal. A is gemma4-qat main ad8437138. B is fork-sync-1692 merged with that main and pinned to this branch (50308b8).
So moving the route out of line did not remove the decode loss. The earlier +1.2 % reading was against an older base and did not hold. The short-turn decode code is the same in both arms, and short turns never call the route (0 calls per short turn, 48 per long turn). Same-build controls on the same iPad show launch-to-launch variance of this size (gemma4-qat#1725 carries the numbers), so this PR fixes nothing measurable. gemma4-qat#1725 goes back to mlx-swift-lm 1f926a4 (revert commit b2317d916). |
Moves the body of the quantized-cache prefill route (dequantize K/V, then fused SDPA, from upstream's
quantizedCacheAttention) into an@inline(never)private function. The route's behavior is unchanged.Why
numen-tech/gemma4-qat#1725 moves the gemma4-qat pin to the #9 sync (1f926a4), which brought in upstream's route. On an M5 iPad, MiniCPM5 1B with 8-bit KV then decoded more slowly than on the previous pin (d949227). Each row below is one build, measured against main with
tools/bench/device_ab.py: 2 ABBA rounds, 8 prompts, 16 pairs, all thermal nominal.Int.max)What the other legs showed:
-BenchTraceKernels 1) were the same in both arms.-NumenPipelineDecode 0), the sync build was +1.1 % [-0.14, +2.43].My reading is that the inlined route body changed the compiled code of the hot
quantizedCacheAttention, which every decode step over a quantized cache calls. Putting the body out of line keeps that function's decode branch as it was. The mechanism is inferred, not measured. Not measured: a control comparing two builds of identical source (build-to-build noise), and devices other than the M5 iPad.Tests
xcodebuild test -scheme mlx-swift-lm-Package -destination platform=macOS -skipPackagePluginValidationon the M3 Max:testDequantizedPrefillAttentionRouteGatesandtestAttentionKVStateQuantizedRouteSharesPrefillDispatch.Ordering with the open gemma4-qat PRs
This PR branches from
numen/main5d2d0c4 (the merge of #11, after #10), the revision numen-tech/gemma4-qat#1731 and #1732 pin.numen/maincarries GatedDelta fast route: activation-dtype inputs, 9+ rows only (gemma4-qat#1693) #10, GatedDelta: opt-in float16 recurrent state storage (gemma4-qat#1697 spike) #11 and this change. numen-tech/gemma4-qat#1725 moves its pin from 1f926a4 to that merge.swift/Package.resolved. Whichever gemma4-qat PR lands last takes the newest revision.Refs numen-tech/gemma4-qat#1725 (epic numen-tech/gemma4-qat#1709).