33
44import flag_gems
55
6- from .accuracy_utils import ALL_FLOAT_DTYPES as ORIG_ALL_FLOAT_DTYPES
6+ from .accuracy_utils import ALL_FLOAT_DTYPES as ORIG_FLOAT_DTYPES
77from .accuracy_utils import SCALARS , gems_assert_close , to_reference
88from .conftest import QUICK_MODE
99
1818 (15 , 160 , 1024 ),
1919 (495 , 5333 , 71 ),
2020 ]
21- FLOAT_DTYPES = ORIG_ALL_FLOAT_DTYPES
21+ FLOAT_DTYPES = ORIG_FLOAT_DTYPES
2222
2323GNK_SHAPES = [(16 , 512 , 2048 ), (16 , 2560 , 2048 ), (64 , 2048 , 128 )]
2424
3737@pytest .mark .parametrize ("scalar" , SCALARS )
3838@pytest .mark .parametrize ("dtype" , FLOAT_DTYPES )
3939def test_baddbmm (monkeypatch , M , N , K , scalar , dtype ):
40- if dtype == torch .float64 and torch .cuda .get_device_capability ()[0 ] < 9 :
41- pytest .skip ("tl.dot does not support fp64 on compute capability < 9.0" )
4240 if flag_gems .vendor_name == "mthreads" and dtype in [torch .float16 , torch .bfloat16 ]:
4341 monkeypatch .setenv ("MUSA_ENABLE_SQMMA" , "1" )
4442 batch = 4
@@ -62,8 +60,6 @@ def test_baddbmm(monkeypatch, M, N, K, scalar, dtype):
6260@pytest .mark .parametrize ("scalar" , SCALARS )
6361@pytest .mark .parametrize ("dtype" , FLOAT_DTYPES )
6462def test_baddbmm_backward (M , N , K , scalar , dtype ):
65- if dtype == torch .float64 and torch .cuda .get_device_capability ()[0 ] < 9 :
66- pytest .skip ("tl.dot does not support fp64 on compute capability < 9.0" )
6763 batch = 2
6864 mat1 = torch .randn (
6965 (batch , M , K ), dtype = dtype , device = flag_gems .device , requires_grad = True
@@ -95,27 +91,3 @@ def test_baddbmm_backward(M, N, K, scalar, dtype):
9591 gems_assert_close (res_in_bias , ref_in_bias , dtype , reduce_dim = K )
9692 gems_assert_close (res_in_grad1 , ref_in_grad1 , dtype , reduce_dim = N )
9793 gems_assert_close (res_in_grad2 , ref_in_grad2 , dtype , reduce_dim = M )
98-
99-
100- MIXED_DTYPE_PAIRS = [
101- (torch .float16 , torch .float32 ),
102- (torch .float32 , torch .float16 ),
103- ]
104-
105-
106- @pytest .mark .baddbmm
107- @pytest .mark .parametrize ("M, N, K" , MNK_SHAPES )
108- @pytest .mark .parametrize ("dtype_a, dtype_b" , MIXED_DTYPE_PAIRS )
109- def test_baddbmm_mixed_dtype (M , N , K , dtype_a , dtype_b ):
110- batch = 4
111- mat1 = torch .randn ((batch , M , K ), dtype = dtype_a , device = flag_gems .device )
112- mat2 = torch .randn ((batch , K , N ), dtype = dtype_b , device = flag_gems .device )
113- bias = torch .randn ((N ,), dtype = dtype_a , device = flag_gems .device )
114- ref_mat1 = to_reference (mat1 , True )
115- ref_mat2 = to_reference (mat2 , True )
116- ref_bias = to_reference (bias , True )
117-
118- ref_out = torch .baddbmm (ref_bias , ref_mat1 , ref_mat2 )
119- res_out = flag_gems .baddbmm (bias , mat1 , mat2 )
120-
121- gems_assert_close (res_out , ref_out , torch .float32 , reduce_dim = K )
0 commit comments