…ate-replay kernels
Two new primitive families landing together:
## Spec 041 Phase 1.1 — FlashQuantizedSDPA
Tiled online-softmax SDPA kernel that consumes affine-quantized K and V
triples `(packed_indices, scales, biases)` and dequantises inline per
thread. Same shape/semantics as the unquantized SDPA: GQA / MQA,
causal mask, array mask, sinks fold all supported.
Replaces the discrete `quantizedMM → softmax → quantizedMM` shape at
affine call sites — never materialises the [B, H, L, T] score matrix.
Files:
- `mlx/backend/metal/kernels/flash_quantized_sdpa.h` — template kernel
body, modelled on `sdpa_vector.h` with per-thread inline dequant.
- `mlx/backend/metal/kernels/flash_quantized_sdpa.metal` —
instantiations: float / bfloat16_t / float16_t × {2,3,4,6,8}-bit ×
groupSize 64 × head dims {64, 96, 128, 256, 512}.
- `mlx/backend/metal/flash_quantized_sdpa.cpp` — dispatch + function-
constant setup (mask mode, sinks, causal, transposed queries).
- `mlx/fast.h` / `mlx/fast.cpp` — public `flash_quantized_sdpa(...)`
entry point + `FlashQuantizedSDPA` Primitive.
## Spec 040 — SSMStepRecord + SSMReplay
Mamba / Mamba 2 selective-SSM step with per-step delta-log capture.
- `ssm_step_record`: sequential per-step recurrence. Emits per-step
`(dA, dBx)` log alongside `(y, state_out)`. Masked timesteps fold
`dA=1, dBx=0` so rollback past a masked t is identity-preserving.
- `ssm_replay`: re-folds first `k` log entries onto a snapshot.
Linear in `k`, parallel over `(B, H, dh, ds)`.
Files:
- `mlx/backend/metal/kernels/ssm_replay.metal` — both kernels +
instantiations for Nemotron/Jamba/Granite/FalconH1 shapes:
Dh × Ds ∈ {64×64, 128×128}, H ∈ {16, 32, 48}, G ∈ {1, 2, 4, 8}.
- `mlx/backend/metal/ssm_replay.cpp` — dispatch.
- `mlx/fast.h` / `mlx/fast.cpp` — `ssm_step_record(...)` and
`ssm_replay(...)` entry points.
- `mlx/fast_primitives.h` — Primitive declarations.
Both kernel families compile cleanly via `xcrun metal -c`; mlx library
builds cleanly with the new sources registered in
`backend/metal/CMakeLists.txt`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two new Metal primitive families: FlashQuantizedSDPA (spec 041 phase 1.1) and SSMStepRecord/SSMReplay (spec 040). Both build cleanly and have round-trip tests in mlx-swift-lm. See companion PRs in mlx-c, mlx-swift, mlx-swift-lm.