|
8 | 8 | # Copyright (c) 2023-2026, Songlin Yang, Yu Zhang, Zhiyuan Li |
9 | 9 |
|
10 | 10 |
|
| 11 | +import time |
| 12 | + |
11 | 13 | import torch |
12 | 14 |
|
13 | 15 | from aphrodite import _custom_ops as ops |
@@ -192,31 +194,40 @@ def attn_res( |
192 | 194 | block_l, num_warps = 1, 4 |
193 | 195 | else: |
194 | 196 | block_l, num_warps = 4, 8 |
195 | | - _attn_res_kernel[(num_tokens,)]( |
196 | | - prefix, |
197 | | - delta, |
198 | | - blocks, |
199 | | - norm_weight, |
200 | | - qk_weight, |
201 | | - output_norm_weight, |
202 | | - output, |
203 | | - prefix.stride(0), |
204 | | - 0 if delta is None else delta.stride(0), |
205 | | - blocks.stride(0), |
206 | | - blocks.stride(1), |
207 | | - output.stride(0), |
208 | | - num_blocks, |
209 | | - hidden_size, |
210 | | - block_write_idx, |
211 | | - eps, |
212 | | - output_norm_eps, |
213 | | - HAS_DELTA=delta is not None, |
214 | | - WRITE_BLOCK=block_write_idx >= 0, |
215 | | - APPLY_OUTPUT_NORM=output_norm_weight is not None, |
216 | | - BLOCK_L=block_l, |
217 | | - BLOCK_D=triton.next_power_of_2(hidden_size), |
218 | | - num_warps=num_warps, |
219 | | - num_stages=2, |
220 | | - launch_pdl=current_platform.is_arch_support_pdl(), |
221 | | - ) |
| 197 | + for attempt in range(3): |
| 198 | + try: |
| 199 | + _attn_res_kernel[(num_tokens,)]( |
| 200 | + prefix, |
| 201 | + delta, |
| 202 | + blocks, |
| 203 | + norm_weight, |
| 204 | + qk_weight, |
| 205 | + output_norm_weight, |
| 206 | + output, |
| 207 | + prefix.stride(0), |
| 208 | + 0 if delta is None else delta.stride(0), |
| 209 | + blocks.stride(0), |
| 210 | + blocks.stride(1), |
| 211 | + output.stride(0), |
| 212 | + num_blocks, |
| 213 | + hidden_size, |
| 214 | + block_write_idx, |
| 215 | + eps, |
| 216 | + output_norm_eps, |
| 217 | + HAS_DELTA=delta is not None, |
| 218 | + WRITE_BLOCK=block_write_idx >= 0, |
| 219 | + APPLY_OUTPUT_NORM=output_norm_weight is not None, |
| 220 | + BLOCK_L=block_l, |
| 221 | + BLOCK_D=triton.next_power_of_2(hidden_size), |
| 222 | + num_warps=num_warps, |
| 223 | + num_stages=2, |
| 224 | + launch_pdl=current_platform.is_arch_support_pdl(), |
| 225 | + ) |
| 226 | + break |
| 227 | + except FileNotFoundError: |
| 228 | + if attempt == 2: |
| 229 | + raise |
| 230 | + # Concurrent Triton compilation can briefly expose an incomplete |
| 231 | + # cache entry on filesystems without fully atomic replacement. |
| 232 | + time.sleep(0.1 * (attempt + 1)) |
222 | 233 | return output |
0 commit comments