Skip to content

Use the causal mask mode for global-layer prefill attention - #25

Open
tc3oliver wants to merge 1 commit into
recursive-oss:mainfrom
tc3oliver:pr/global-causal-mask
Open

tc3oliver wants to merge 1 commit into
recursive-oss:mainfrom
tc3oliver:pr/global-causal-mask

Conversation

@tc3oliver

@tc3oliver tc3oliver commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

FixedKVCache.make_mask builds 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 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 (main rejects the M4 Max).

rec-mlx serve, cold prompts, 3 runs alternated with the unchanged tree:

Prompt Prefill tok/s TTFT
8K 1546 → 1605 (+3.8%) 5.40 → 5.20 s
32K 1148 → 1184 (+3.1%) 28.8 → 27.9 s

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.py compares "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.py failed 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.

… 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
tc3oliver marked this pull request as ready for review October 24, 2026 09:11
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