Commit a2d6335
committed
fix: add head_dim=256 to fused SDPA full attention kernel
sdpa_full_supported_head_dim only included {64, 80, 128}. Models with
head_dim=256 (Qwen3.5 family) fell back to the unfused naive attention
path which materializes the full score matrix as a single matmul.
At 32K+ context this creates 8+ GB single allocations that crash
Metal's buffer allocator.
Add head_dim=256 to the dispatch gate and instantiate steel_attention
kernel with bd=256. The Metal kernel template handles arbitrary BD
via template parameter — no kernel code changes needed.
Verified: 32K, 64K, 128K context on M2 Ultra with Qwen3.5-122B-A10B.1 parent 46c181b commit a2d6335
3 files changed
Lines changed: 51 additions & 8 deletions
File tree
- mlx/backend/metal
- kernels/steel/attn/kernels
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| |||
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
13 | 21 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
17 | 43 | | |
18 | 44 | | |
19 | 45 | | |
| |||
26 | 52 | | |
27 | 53 | | |
28 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
29 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
30 | 67 | | |
31 | 68 | | |
32 | 69 | | |
| |||
62 | 99 | | |
63 | 100 | | |
64 | 101 | | |
65 | | - | |
| 102 | + | |
66 | 103 | | |
67 | 104 | | |
68 | 105 | | |
69 | 106 | | |
70 | 107 | | |
71 | | - | |
| 108 | + | |
72 | 109 | | |
73 | 110 | | |
74 | 111 | | |
| |||
78 | 115 | | |
79 | 116 | | |
80 | 117 | | |
81 | | - | |
| 118 | + | |
| 119 | + | |
82 | 120 | | |
83 | 121 | | |
84 | 122 | | |
| |||
90 | 128 | | |
91 | 129 | | |
92 | 130 | | |
| 131 | + | |
93 | 132 | | |
| 133 | + | |
| 134 | + | |
94 | 135 | | |
95 | 136 | | |
96 | 137 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
620 | 620 | | |
621 | 621 | | |
622 | 622 | | |
623 | | - | |
| 623 | + | |
| 624 | + | |
624 | 625 | | |
625 | 626 | | |
626 | 627 | | |
| |||
0 commit comments