|
9 | 9 | from packaging import version |
10 | 10 |
|
11 | 11 | from vllm.model_executor.layers.mamba.ops.triton_helpers import fast_exp |
| 12 | +from vllm.platforms import current_platform |
12 | 13 | from vllm.triton_utils import tl, triton |
13 | 14 |
|
14 | 15 | TRITON_22 = version.parse(triton.__version__) >= version.parse("2.2.0") |
15 | 16 |
|
16 | 17 |
|
| 18 | +def _drop_racy_wgmma_configs(configs: list[triton.Config]) -> list[triton.Config]: |
| 19 | + """Drop the configs that Triton miscompiles on sm90. |
| 20 | +
|
| 21 | + With whole warpgroups (num_warps % 4 == 0) and BLOCK_SIZE_M % 64 == 0, |
| 22 | + `tl.dot(cb, x)` lowers to wgmma with `cb` in registers. With |
| 23 | + num_stages > 1, Triton leaves that wgmma running across the loop |
| 24 | + back-edge while the next iteration overwrites the registers of `cb`, |
| 25 | + which writes NaN/Inf into whole output rows. |
| 26 | + """ |
| 27 | + if not (current_platform.is_cuda() and current_platform.is_device_capability(90)): |
| 28 | + return configs |
| 29 | + return [ |
| 30 | + c |
| 31 | + for c in configs |
| 32 | + if c.num_stages == 1 |
| 33 | + or c.num_warps % 4 != 0 |
| 34 | + or c.kwargs["BLOCK_SIZE_M"] % 64 != 0 |
| 35 | + ] |
| 36 | + |
| 37 | + |
17 | 38 | @triton.autotune( |
18 | | - configs=[ |
19 | | - # ================================================================= |
20 | | - # Higher warp count configs for better latency hiding |
21 | | - # More warps = more instructions in flight = better memory latency hiding |
22 | | - # ================================================================= |
23 | | - triton.Config( |
24 | | - {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
25 | | - num_stages=2, |
26 | | - num_warps=8, |
27 | | - ), |
28 | | - triton.Config( |
29 | | - {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
30 | | - num_stages=2, |
31 | | - num_warps=8, |
32 | | - ), |
33 | | - triton.Config( |
34 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
35 | | - num_stages=2, |
36 | | - num_warps=8, |
37 | | - ), |
38 | | - # Smaller tiles with more stages for software pipelining |
39 | | - triton.Config( |
40 | | - {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
41 | | - num_stages=3, |
42 | | - num_warps=4, |
43 | | - ), |
44 | | - triton.Config( |
45 | | - {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 64}, |
46 | | - num_stages=2, |
47 | | - num_warps=4, |
48 | | - ), |
49 | | - # ================================================================= |
50 | | - # Low register pressure configs (num_stages=1) for large dstate |
51 | | - # ================================================================= |
52 | | - triton.Config( |
53 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 64}, |
54 | | - num_stages=1, |
55 | | - num_warps=4, |
56 | | - ), |
57 | | - triton.Config( |
58 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
59 | | - num_stages=1, |
60 | | - num_warps=4, |
61 | | - ), |
62 | | - triton.Config( |
63 | | - {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
64 | | - num_stages=1, |
65 | | - num_warps=4, |
66 | | - ), |
67 | | - triton.Config( |
68 | | - {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
69 | | - num_stages=1, |
70 | | - num_warps=4, |
71 | | - ), |
72 | | - # num_stages=2 configs - moderate register pressure |
73 | | - triton.Config( |
74 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 64}, |
75 | | - num_stages=2, |
76 | | - num_warps=4, |
77 | | - ), |
78 | | - triton.Config( |
79 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
80 | | - num_stages=2, |
81 | | - num_warps=4, |
82 | | - ), |
83 | | - triton.Config( |
84 | | - {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
85 | | - num_stages=2, |
86 | | - num_warps=4, |
87 | | - ), |
88 | | - # Original configs for larger dstate values |
89 | | - triton.Config( |
90 | | - {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 256, "BLOCK_SIZE_K": 64}, |
91 | | - num_stages=3, |
92 | | - num_warps=8, |
93 | | - ), |
94 | | - triton.Config( |
95 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 256, "BLOCK_SIZE_K": 32}, |
96 | | - num_stages=4, |
97 | | - num_warps=4, |
98 | | - ), |
99 | | - triton.Config( |
100 | | - {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 128, "BLOCK_SIZE_K": 32}, |
101 | | - num_stages=4, |
102 | | - num_warps=4, |
103 | | - ), |
104 | | - triton.Config( |
105 | | - {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
106 | | - num_stages=4, |
107 | | - num_warps=4, |
108 | | - ), |
109 | | - triton.Config( |
110 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 128, "BLOCK_SIZE_K": 32}, |
111 | | - num_stages=4, |
112 | | - num_warps=4, |
113 | | - ), |
114 | | - triton.Config( |
115 | | - {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 64}, |
116 | | - num_stages=4, |
117 | | - num_warps=4, |
118 | | - ), |
119 | | - triton.Config( |
120 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 128, "BLOCK_SIZE_K": 64}, |
121 | | - num_stages=4, |
122 | | - num_warps=4, |
123 | | - ), |
124 | | - triton.Config( |
125 | | - {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
126 | | - num_stages=4, |
127 | | - num_warps=4, |
128 | | - ), |
129 | | - triton.Config( |
130 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
131 | | - num_stages=5, |
132 | | - num_warps=2, |
133 | | - ), |
134 | | - triton.Config( |
135 | | - {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
136 | | - num_stages=5, |
137 | | - num_warps=2, |
138 | | - ), |
139 | | - triton.Config( |
140 | | - {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
141 | | - num_stages=4, |
142 | | - num_warps=2, |
143 | | - ), |
144 | | - ], |
| 39 | + configs=_drop_racy_wgmma_configs( |
| 40 | + [ |
| 41 | + # ================================================================= |
| 42 | + # Higher warp count configs for better latency hiding |
| 43 | + # More warps = more instructions in flight = better memory latency hiding |
| 44 | + # ================================================================= |
| 45 | + triton.Config( |
| 46 | + {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
| 47 | + num_stages=2, |
| 48 | + num_warps=8, |
| 49 | + ), |
| 50 | + triton.Config( |
| 51 | + {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
| 52 | + num_stages=2, |
| 53 | + num_warps=8, |
| 54 | + ), |
| 55 | + triton.Config( |
| 56 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
| 57 | + num_stages=2, |
| 58 | + num_warps=8, |
| 59 | + ), |
| 60 | + # Smaller tiles with more stages for software pipelining |
| 61 | + triton.Config( |
| 62 | + {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
| 63 | + num_stages=3, |
| 64 | + num_warps=4, |
| 65 | + ), |
| 66 | + triton.Config( |
| 67 | + {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 64}, |
| 68 | + num_stages=2, |
| 69 | + num_warps=4, |
| 70 | + ), |
| 71 | + # ================================================================= |
| 72 | + # Low register pressure configs (num_stages=1) for large dstate |
| 73 | + # ================================================================= |
| 74 | + triton.Config( |
| 75 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 64}, |
| 76 | + num_stages=1, |
| 77 | + num_warps=4, |
| 78 | + ), |
| 79 | + triton.Config( |
| 80 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
| 81 | + num_stages=1, |
| 82 | + num_warps=4, |
| 83 | + ), |
| 84 | + triton.Config( |
| 85 | + {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
| 86 | + num_stages=1, |
| 87 | + num_warps=4, |
| 88 | + ), |
| 89 | + triton.Config( |
| 90 | + {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
| 91 | + num_stages=1, |
| 92 | + num_warps=4, |
| 93 | + ), |
| 94 | + # num_stages=2 configs - moderate register pressure |
| 95 | + triton.Config( |
| 96 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 64}, |
| 97 | + num_stages=2, |
| 98 | + num_warps=4, |
| 99 | + ), |
| 100 | + triton.Config( |
| 101 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
| 102 | + num_stages=2, |
| 103 | + num_warps=4, |
| 104 | + ), |
| 105 | + triton.Config( |
| 106 | + {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
| 107 | + num_stages=2, |
| 108 | + num_warps=4, |
| 109 | + ), |
| 110 | + # Original configs for larger dstate values |
| 111 | + triton.Config( |
| 112 | + {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 256, "BLOCK_SIZE_K": 64}, |
| 113 | + num_stages=3, |
| 114 | + num_warps=8, |
| 115 | + ), |
| 116 | + triton.Config( |
| 117 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 256, "BLOCK_SIZE_K": 32}, |
| 118 | + num_stages=4, |
| 119 | + num_warps=4, |
| 120 | + ), |
| 121 | + triton.Config( |
| 122 | + {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 128, "BLOCK_SIZE_K": 32}, |
| 123 | + num_stages=4, |
| 124 | + num_warps=4, |
| 125 | + ), |
| 126 | + triton.Config( |
| 127 | + {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
| 128 | + num_stages=4, |
| 129 | + num_warps=4, |
| 130 | + ), |
| 131 | + triton.Config( |
| 132 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 128, "BLOCK_SIZE_K": 32}, |
| 133 | + num_stages=4, |
| 134 | + num_warps=4, |
| 135 | + ), |
| 136 | + triton.Config( |
| 137 | + {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 64}, |
| 138 | + num_stages=4, |
| 139 | + num_warps=4, |
| 140 | + ), |
| 141 | + triton.Config( |
| 142 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 128, "BLOCK_SIZE_K": 64}, |
| 143 | + num_stages=4, |
| 144 | + num_warps=4, |
| 145 | + ), |
| 146 | + triton.Config( |
| 147 | + {"BLOCK_SIZE_M": 128, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
| 148 | + num_stages=4, |
| 149 | + num_warps=4, |
| 150 | + ), |
| 151 | + triton.Config( |
| 152 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 32, "BLOCK_SIZE_K": 32}, |
| 153 | + num_stages=5, |
| 154 | + num_warps=2, |
| 155 | + ), |
| 156 | + triton.Config( |
| 157 | + {"BLOCK_SIZE_M": 32, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
| 158 | + num_stages=5, |
| 159 | + num_warps=2, |
| 160 | + ), |
| 161 | + triton.Config( |
| 162 | + {"BLOCK_SIZE_M": 64, "BLOCK_SIZE_N": 64, "BLOCK_SIZE_K": 32}, |
| 163 | + num_stages=4, |
| 164 | + num_warps=2, |
| 165 | + ), |
| 166 | + ] |
| 167 | + ), |
145 | 168 | key=["chunk_size", "hdim", "dstate", "IS_CAUSAL"], |
146 | 169 | ) |
147 | 170 | @triton.jit |
|
0 commit comments