feat: lower SDPA-with-sinks blocks in the native Expr compiler - #194
Merged
Conversation
Closes the final cluster on the Expr op-coverage checklist (#188) — the two gpt-oss attention-sink blocks reachable from Emily.Fast.attention_with_sinks. Two new opcodes (FastSDPASinks=121, FastSDPAMaskSinks=122) dispatch through the same mx::fast::scaled_dot_product_attention entry point the existing FastSDPA / FastSDPAMask opcodes use, with the extra `sinks` operand wired into the kernel's `sinks` arg and the mask_mode discriminator preserved ("causal"/"" for the sinks-only variant, "array" for the masked-with-sinks variant) — same shape as Emily.Backend.fast_scaled_dot_product_attention_with{,_mask_and}_sinks. Tests in compiler_equivalence_test.exs cover the three reachable combinations: sinks-only non-causal, sinks-only causal, and mask+sinks. Each asserts bit-identical to the evaluator.
37 tasks
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
Closes the final cluster on #188 — the two gpt-oss attention-sink blocks reachable from
Emily.Fast.attention_with_sinks.Two new opcodes:
FastSDPASinks(121) — operands[q, k, v, sinks]; iattrs[[scale_bits], [causal]]. Dispatchesmx::fast::scaled_dot_product_attention(q, k, v, scale, mask_mode, nullopt, optional(sinks), s)withmask_modetoggled between"causal"and""by the iattr — same shape asEmily.Backend.fast_scaled_dot_product_attention_with_sinks/6.FastSDPAMaskSinks(122) — operands[q, k, v, mask, sinks]; iattrs[[scale_bits]];mask_mode = "array". MirrorsEmily.Backend.fast_scaled_dot_product_attention_with_mask_and_sinks/7.Both reuse the existing
mx::fast::scaled_dot_product_attentionentry point — the same kernelFastSDPA/FastSDPAMaskalready use — so the native and evaluator paths land on the same bits.Probe (
scripts/expr_op_coverage.exs) is unchanged at 2 misses — those are the unlowerable-by-designcount_leading_zeros/population_count. The sinks blocks aren't Nx-public ops so the probe doesn't surface them, but with this PR every cluster on #188 is empty.Test plan
mix precommitclean (730 tests, 79 properties, 40 doctests, 0 failures — 3 new equivalence tests).New equivalence tests in
compiler_equivalence_test.exscover the three reachable combinations:Emily.Fast.scaled_dot_product_attention(q, k, v, sinks: s).causal: true.Emily.Fast.scaled_dot_product_attention_with_mask(q, k, v, mask, sinks: s).Each asserts bit-identical to the evaluator (same
assert_equivhelper the other SDPA-block tests use).sinksis the standard per-head 1-D shape{n_heads}the existing SDPA tests use.Opcode parity test green —
kOpcodeCountbumped 121 → 123 in lockstep with@opcodes.Follows the same pattern as #189 / #190 / #191 / #192 / #193.