Commit 79da7db
metal: bring v2 f16 attention to MLX-faithful exp/sentinel pattern
Per `feedback_ferrite_metal_mlx_only.md` rule 7, both v2 attention
variants must match MLX `sdpa_vector` bit-exact:
- `exp` → `metal::fast::exp`
- `-INFINITY` → `Limits<U>::finite_min` (= `-FLT_MAX` for f32 accum)
The bf16 sibling (`attention_via_cache_v2_bf16_specialized`) was
already updated; the f16 variant lagged with bare `exp` + `-INFINITY`
at three sites (online softmax + per-simdgroup combine).
Drift on the f16 path is small in steady-state usage but compounds
across long sequences and degrades agreement with the bf16 sibling
at mixed-dtype model swaps. Patching the f16 kernel restores the
contract spelled out in the kernel header comment ("port of MLX
sdpa_vector").
Goldens unchanged: 68/68 ferrite-forward metal lib tests pass,
including the f16 numerical-correctness check
`attention_via_cache_matches_cpu_golden`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent cc42495 commit 79da7db
1 file changed
Lines changed: 10 additions & 5 deletions
Lines changed: 10 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
155 | 156 | | |
156 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
| |||
185 | 189 | | |
186 | 190 | | |
187 | 191 | | |
188 | | - | |
| 192 | + | |
| 193 | + | |
189 | 194 | | |
190 | | - | |
191 | | - | |
| 195 | + | |
| 196 | + | |
192 | 197 | | |
193 | 198 | | |
194 | 199 | | |
| |||
214 | 219 | | |
215 | 220 | | |
216 | 221 | | |
217 | | - | |
| 222 | + | |
218 | 223 | | |
219 | 224 | | |
220 | 225 | | |
| |||
0 commit comments