Repository navigation
perf(models): run attention-sink prefill in MLX causal and window mode - #3119
Merged
Merged
Conversation
The sink SDPA bridge took only an explicit array mask, so GPT-OSS, Laguna, Falcon-OCR, MiMo v2 Flash and DeepSeek-V4 built a dense f32 prefill band that #3056 and #3097 had removed everywhere else. MLX already accepts mask_mode "causal" and window_size together with sinks. Add fast_scaled_dot_product_attention_with_sinks_causal (a cxx Result, so MLX validation errors do not abort) and let the fused-kernel probe ask with sinks. prefill_sdpa::causal_prefill_attention takes the maskless call where prefill_uses_causal_mode allows it and MLX fuses it, else builds the same band. PrefillAttention gains a sinks flag so prefill_causal_mask and prefill_sliding_window_mask decide with sink geometry. GPT-OSS (single model and pipeline stage), Falcon-OCR, MiMo v2 Flash and all-local DeepSeek-V4 stacks use the shared helpers; Laguna's layers call causal_prefill_attention. The OpenAI privacy filter's symmetric band is unchanged. M5 Max, main vs branch: gpt-oss-20b-mxfp4-q4 at 19,773 tokens peaks 17.86 GB instead of 22.54 GB single pass (prefill 6.63 to 3.62 s) and 13.16 instead of 13.42 GB in 2048-token chunks; laguna-xs.2-4bit at 28,747 tokens 29.25 instead of 35.84 GB; falcon-ocr 4.70 instead of 5.11 GB. Greedy output is byte-identical in every cell. New unit tests compare the causal sink entry and the routed helper with the explicit-mask call and an f64 host reference. Closes #3098
inureyes
force-pushed
the
update/issue-3098-sink-causal-mode
branch
from
November 16, 2026 06:32
a623fcf to
c9c4927
Compare
inureyes
marked this pull request as ready for review
November 16, 2026 06:32
This was referenced Nov 16, 2026
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.
Summary
The attention-sink decoders still built a dense f32 prefill band because the sink SDPA bridge took only an array mask. MLX already accepts
mask_mode = "causal"andwindow_sizetogether withsinks, so this adds that entry and routes the sink models' plain-causal and sliding prefill through it wherever MLX fuses the call.fast_scaled_dot_product_attention_with_sinks_causalbridge entry (cxxResult, so an MLX validation error is anErrrather than an abort). The fused-kernel probe gainshas_sinks, memoized under its own key.mlxcel_core::prefill_sdpa:causal_prefill_attention(q, k, v, scale, window, sinks)takes MLX's causal mode, pluswindow_sizeonce keys outgrow the window, whenprefill_uses_causal_modeallows it and MLX fuses the call (asked with sinks). Otherwise it builds the same band the layer built before. Padded, batched, caller-masked and speculative forwards keep the array.PrefillAttention::with_sinks()letsprefill_causal_maskandprefill_sliding_window_maskdecide with sink geometry. GPT-OSS (single model and pipeline stage, full and sliding layers), Falcon-OCR text prefill, MiMo v2 Flash and all-local DeepSeek-V4 stacks use them. Laguna's layers callcausal_prefill_attentioninstead of building a band per layer.create_causal_maskroster sentence is now 13 files.Measurements (M5 Max, main
00cd2d69vs branch)Greedy output is byte-identical in every cell, so no logit trace was run. laguna-xs.2-4bit has no sinks enabled, so it covers the per-layer route without sinks; falcon-ocr carries sinks on every layer. One run per cell on a shared host; the laguna main single-pass prefill likely includes memory pressure. Details:
docs/benchmark_results/prefill-sink-causal-mode-m5max-2026-11-15.md.Test plan
prefill_sdpa_tests: causal sink entry and routed helper vs the explicit-mask sink call and an f64 host reference (f32 and f16, causal, prior keys, in-window, over-window, head dims 64/128, GQA); without-sinks route vslayers::attention; bad window and mis-shaped sinks returnErrwindow_sdpa_tests,utils::prefill_*,create_causal_mask_roster_count_matches_repoCloses #3098