@@ -181,6 +181,13 @@ def build_ctx(
181181
182182
183183def _make_meta (ctx ):
184+ tile_m = 128
185+ qhead_per_kvhead = ctx ["nheads" ] // ctx ["nheads_kv" ]
186+ arch = torch .cuda .get_device_capability ()[0 ]
187+ if arch == 10 and ctx ["max_seqlen_q" ] * qhead_per_kvhead > tile_m :
188+ q_stage = 2
189+ else :
190+ q_stage = 1
184191 return get_scheduler_metadata (
185192 num_batch = ctx ["batch" ],
186193 max_seqlen_q = ctx ["max_seqlen_q" ],
@@ -189,12 +196,13 @@ def _make_meta(ctx):
189196 nheads_kv = ctx ["nheads_kv" ],
190197 headdim = ctx ["headdim" ],
191198 num_splits = ctx ["num_splits" ],
192- tile_m = 128 ,
199+ tile_m = tile_m ,
193200 tile_n = 128 ,
194201 causal = ctx ["causal" ],
195202 pack_gqa = ctx ["pack_gqa" ],
196203 cu_seqlens_q = ctx ["cu_q" ],
197204 cu_seqlens_k = ctx ["cu_k" ],
205+ q_stage = q_stage ,
198206 )
199207
200208
@@ -322,8 +330,12 @@ def parse_args():
322330 p .add_argument ("--headdim" , type = int , default = 128 )
323331 p .add_argument ("--nheads" , type = int , default = 16 )
324332 p .add_argument ("--nheads-kv" , type = int , default = 2 )
325- p .add_argument ("--pack-gqa" , action = "store_true" , default = True ,
326- help = "Force pack_gqa=True (default). --no-pack-gqa to disable." )
333+ p .add_argument (
334+ "--pack-gqa" ,
335+ action = "store_true" ,
336+ default = True ,
337+ help = "Force pack_gqa=True (default). --no-pack-gqa to disable." ,
338+ )
327339 p .add_argument ("--no-pack-gqa" , dest = "pack_gqa" , action = "store_false" )
328340 p .add_argument ("--seeds" , type = int , default = 3 )
329341 p .add_argument ("--warmup" , type = int , default = 2 )
@@ -434,7 +446,9 @@ def main():
434446 eff = sq * sk - sq * (sq - 1 ) // 2
435447 else :
436448 # clamp to non-negative for queries near 0
437- first_visible_q = - shift # smallest q with sk - sq + q + 1 > 0 is q = sq - sk
449+ first_visible_q = (
450+ - shift
451+ ) # smallest q with sk - sq + q + 1 > 0 is q = sq - sk
438452 visible = sq - first_visible_q
439453 eff = visible * sk - visible * (visible - 1 ) // 2
440454 eff = max (0 , eff )
0 commit comments