@@ -56,7 +56,7 @@ def test_flydsl_top_k_per_row_decode_direct_fill_k2048():
5656 )
5757
5858
59- def test_flydsl_top_k_per_row_decode_long_row_k2048_matches_torch_topk ():
59+ def test_flydsl_top_k_per_row_decode_long_row_k2048_matches_torch_topk_set ():
6060 torch .manual_seed (1 )
6161 next_n = 1
6262 k = 2048
@@ -76,13 +76,10 @@ def test_flydsl_top_k_per_row_decode_long_row_k2048_matches_torch_topk():
7676 )
7777 torch .cuda .synchronize ()
7878
79- expected = torch .topk (logits [:, : int (seq_lens [0 ].item ())], k , dim = - 1 ).indices .to (
80- torch .int32
81- )
82- torch .testing .assert_close (indices .cpu (), expected .cpu ())
79+ _assert_topk_set_equivalent (logits [0 ], indices [0 ], k )
8380
8481
85- def test_flydsl_top_k_per_row_decode_long_row_k512_matches_torch_topk ():
82+ def test_flydsl_top_k_per_row_decode_long_row_k512_matches_torch_topk_set ():
8683 torch .manual_seed (2 )
8784 next_n = 1
8885 k = 512
@@ -102,10 +99,7 @@ def test_flydsl_top_k_per_row_decode_long_row_k512_matches_torch_topk():
10299 )
103100 torch .cuda .synchronize ()
104101
105- expected = torch .topk (logits [:, : int (seq_lens [0 ].item ())], k , dim = - 1 ).indices .to (
106- torch .int32
107- )
108- torch .testing .assert_close (indices .cpu (), expected .cpu ())
102+ _assert_topk_set_equivalent (logits [0 ], indices [0 ], k )
109103
110104
111105def _assert_topk_set_equivalent (logits_row , actual_row , k ):
@@ -187,5 +181,4 @@ def test_flydsl_top_k_per_row_decode_ties_k512_matches_torch_topk_set():
187181 )
188182 torch .cuda .synchronize ()
189183
190- expected = torch .arange (k , device = "cpu" , dtype = torch .int32 )
191- torch .testing .assert_close (indices [0 ].cpu (), expected )
184+ _assert_topk_set_equivalent (logits [0 ], indices [0 ], k )
0 commit comments