Repository navigation
Conversation
… attention FixedKVCache.make_mask built a [chunk, offset + chunk] boolean mask for every global-layer prefill chunk. The cache returns exactly offset + chunk keys, so MLX's bottom-right-aligned "causal" mode is the same mask: the output is bit-identical and the fused kernel neither reads the mask nor visits the key tiles above the diagonal.
tc3oliver
marked this pull request as ready for review
October 24, 2026 09:11
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.
FixedKVCache.make_maskbuilds a[chunk, offset + chunk]boolean mask for every global-layer prefill chunk. The cache returns exactlyoffset + chunkkeys, so MLX's bottom-right-aligned"causal"mode is the same mask. The fused kernel then neither reads the mask nor visits the tiles above the diagonal. Output is bit-identical.Split out of #21, which now touches only the sliding layers.
Results
M4 Max (40-core GPU), mlx 0.32.0,
RecursiveSI/flint-int4, on top of #17 (mainrejects the M4 Max).rec-mlx serve, cold prompts, 3 runs alternated with the unchanged tree:A one-process prefill A/B, 3-5 reps per arm, gives -3.4% time at 8K, -2.4% at 32K and -2.6% at 64K. The last-token logits md5 matches.
Tests
engine/tests/test_global_causal_mask.pycompares"causal"with the array mask bit for bit at offsets 0 and 5000, for 2, 5, 8, 9 and 2048 queries. It fails without this change.validate_resident.py: 61/61.make test: engine 67/67, smoke and packaging pass.tests/protocol_test.pyfailed once at its 8-request admission step (connection reset). It runs a scripted engine, so none of this change executes there, and it fails the same way on Support Apple M4 Max with a 40-core worker profile #17 alone.