Skip to content

Commit 1fc0221

Browse files
authored
[CuTe, SM120] Support automatic num_splits (#2758)
* [CuTe, SM120] Support automatic num_splits * [CuTe, SM120] Cover negative automatic num_splits
1 parent bb25ba3 commit 1fc0221

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎flash_attn/cute/interface.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ def _get_fwd_config(
414414
num_n_blocks = (seqlen_k_loaded + tile_n - 1) // tile_n
415415
num_SMs = None
416416
if arch // 10 == 12:
417-
assert num_splits == 1, "SM120 forward only supports num_splits=1"
417+
assert num_splits <= 1, "SM120 forward only supports num_splits=1"
418+
num_splits = 1
418419
elif num_splits < 1:
419420
num_SMs = get_num_sms_for_selection(device.index, arch)
420421
num_splits = num_splits_heuristic(total_mblocks, num_SMs, num_n_blocks, 128)

‎tests/cute/test_flash_attn.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,14 @@ def test_flash_attn_auto_splits_more_tiles_than_sms():
9292

9393

9494
@pytest.mark.skipif(not IS_SM120, reason="SM120-only SplitKV unsupported behavior")
95-
def test_flash_attn_sm120_rejects_splitkv():
95+
@pytest.mark.parametrize("num_splits", [0, -1])
96+
def test_flash_attn_sm120_num_splits(num_splits):
9697
q = torch.randn(1, 16, 4, 64, device="cuda", dtype=torch.bfloat16)
9798
k = torch.randn(1, 16, 1, 64, device="cuda", dtype=torch.bfloat16)
9899
v = torch.randn(1, 16, 1, 64, device="cuda", dtype=torch.bfloat16)
100+
out = flash_attn_func(q, k, v)
101+
out_auto = flash_attn_func(q, k, v, num_splits=num_splits)
102+
torch.testing.assert_close(out_auto, out)
99103
with pytest.raises(AssertionError, match="SM120 forward only supports num_splits=1"):
100104
flash_attn_func(q, k, v, num_splits=3)
101105

0 commit comments

Comments
 (0)