multimodalart HF Staff commited on
Commit
2c7fffd
·
verified ·
1 Parent(s): 9b71326

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. jeeves_src/model/triton_kernels.py +7 -1
jeeves_src/model/triton_kernels.py CHANGED
@@ -15,6 +15,12 @@ DECODE_ATTENTION_BLOCK_N = 64
15
  CONV_STEP_BLOCK_C = 128
16
 
17
 
 
 
 
 
 
 
18
  @lru_cache
19
  def sm_count(device: torch.device) -> int:
20
  return torch.cuda.get_device_properties(device).multi_processor_count
@@ -198,7 +204,7 @@ def decode_attention(q: torch.Tensor, k_cache: torch.Tensor, v_cache: torch.Tens
198
  _decode_attention_split[(B * Hkv, splits)](q, k_cache, v_cache, mask, partial_o, partial_lse, scale * LOG2E.value, L, keys_per_split,
199
  splits, *q.stride()[:3], *k_cache.stride()[:3], *v_cache.stride()[:3], mask.stride(0),
200
  mask.stride(2), HKV=Hkv, R=R, G=G, D=D, BLOCK_Q=block_q, BLOCK_N=DECODE_ATTENTION_BLOCK_N,
201
- num_warps=4 if D <= 128 else 8, num_stages=2)
202
  _decode_attention_combine[(B * Hkv, R * G)](partial_o, partial_lse, o, splits, *o.stride()[:3], HKV=Hkv, G=G, D=D, BLOCK_Q=block_q,
203
  BLOCK_SPLITS=triton.next_power_of_2(splits), num_warps=4)
204
  return o
 
15
  CONV_STEP_BLOCK_C = 128
16
 
17
 
18
+ @lru_cache
19
+ def _decode_stages(device: torch.device) -> int:
20
+ # Space patch: sm_120 (RTX PRO 6000 Blackwell) has ~99 KB shared memory per block; two stages need 104 KB.
21
+ return 1 if torch.cuda.get_device_capability(device)[0] == 12 else 2
22
+
23
+
24
  @lru_cache
25
  def sm_count(device: torch.device) -> int:
26
  return torch.cuda.get_device_properties(device).multi_processor_count
 
204
  _decode_attention_split[(B * Hkv, splits)](q, k_cache, v_cache, mask, partial_o, partial_lse, scale * LOG2E.value, L, keys_per_split,
205
  splits, *q.stride()[:3], *k_cache.stride()[:3], *v_cache.stride()[:3], mask.stride(0),
206
  mask.stride(2), HKV=Hkv, R=R, G=G, D=D, BLOCK_Q=block_q, BLOCK_N=DECODE_ATTENTION_BLOCK_N,
207
+ num_warps=4 if D <= 128 else 8, num_stages=_decode_stages(q.device))
208
  _decode_attention_combine[(B * Hkv, R * G)](partial_o, partial_lse, o, splits, *o.stride()[:3], HKV=Hkv, G=G, D=D, BLOCK_Q=block_q,
209
  BLOCK_SPLITS=triton.next_power_of_2(splits), num_warps=4)
210
  return o