@@ -1003,37 +1003,6 @@ def forward(self, mat1: Tensor, mat2: Tensor) -> Tensor:
10031003 model = model , mat1 = mat1 , mat2 = mat2 , dynamic_shapes = dynamic_shapes
10041004 )
10051005
1006- async def test_mixed_dtypes (self ) -> None :
1007- """Test bmm with mixed f32/f16 inputs.
1008-
1009- Reproduces the EfficientSam pattern: model.half() makes weights f16,
1010- but an explicit dtype=torch.float32 tensor creates f32 that flows
1011- into a bmm with f16 weights.
1012- """
1013-
1014- class MixedBmmModel (nn .Module ):
1015- def __init__ (self ) -> None :
1016- super ().__init__ ()
1017- self .weight = nn .Parameter (torch .randn (3 , 8 , 4 ))
1018-
1019- def forward (self , x : Tensor ) -> Tensor :
1020- # Explicit f32 creation contaminates x via add
1021- f32_val = torch .ones (1 , device = x .device , dtype = torch .float32 )
1022- x = x + f32_val # promotes x(f16) to f32
1023- return torch .bmm (x , self .weight ) # f32 @ f16
1024-
1025- model = MixedBmmModel ().eval ().half ()
1026- x = torch .randn (3 , 4 , 8 , dtype = torch .float16 )
1027-
1028- with torch .autocast (device_type = "cpu" , dtype = torch .float16 ):
1029- exported_program = torch .export .export (model , args = (), kwargs = {"x" : x })
1030- exported_program = exported_program .run_decompositions (
1031- torch .export .default_decompositions ()
1032- )
1033-
1034- converter = TorchConverter ().add_exported_program (exported_program )
1035- converter .to_coreai ()
1036-
10371006
10381007class TestCat :
10391008 """Test suite for aten.cat → coreai.concat conversion."""
@@ -4580,30 +4549,33 @@ async def test_broadcast_mask_lower_rank(self) -> None:
45804549 )
45814550
45824551
4583- @pytest .mark .parametrize ("dynamic" , [False , True ])
45844552@pytest .mark .parametrize (
4585- "x,dim,index" ,
4553+ "x,dim,index,dynamic " ,
45864554 [
45874555 # 2D float32, select along dim 0
4588- (torch .rand (3 , 4 , dtype = torch .float32 ), 0 , 1 ),
4556+ (torch .rand (3 , 4 , dtype = torch .float32 ), 0 , 1 , False ),
4557+ (torch .rand (3 , 4 , dtype = torch .float32 ), 0 , 1 , True ),
45894558 # 2D float32, select along dim 1
4590- (torch .rand (3 , 4 , dtype = torch .float32 ), 1 , 2 ),
4559+ (torch .rand (3 , 4 , dtype = torch .float32 ), 1 , 2 , False ),
45914560 # 3D float16, select along dim 1
4592- (torch .rand (2 , 3 , 4 , dtype = torch .float16 ), 1 , 2 ),
4561+ (torch .rand (2 , 3 , 4 , dtype = torch .float16 ), 1 , 2 , False ),
45934562 # 3D int32, select along dim 2
4594- (torch .randint (0 , 100 , (2 , 3 , 4 ), dtype = torch .int32 ), 2 , 3 ),
4563+ (torch .randint (0 , 100 , (2 , 3 , 4 ), dtype = torch .int32 ), 2 , 3 , False ),
45954564 # 2D int64, select along dim 0
4596- (torch .randint (- 50 , 50 , (4 , 5 ), dtype = torch .int64 ), 0 , 2 ),
4565+ (torch .randint (- 50 , 50 , (4 , 5 ), dtype = torch .int64 ), 0 , 2 , False ),
45974566 # Negative dimension (dim=-1 is last dim, float32)
4598- (torch .rand (3 , 4 , 5 , dtype = torch .float32 ), - 1 , 2 ),
4567+ (torch .rand (3 , 4 , 5 , dtype = torch .float32 ), - 1 , 2 , False ),
45994568 # Negative index (index from end, int32) — exercises dynamic path when dynamic=True
4600- (torch .randint (0 , 100 , (4 , 5 ), dtype = torch .int32 ), 0 , - 1 ),
4569+ (torch .randint (0 , 100 , (4 , 5 ), dtype = torch .int32 ), 0 , - 1 , False ),
4570+ (torch .randint (0 , 100 , (4 , 5 ), dtype = torch .int32 ), 0 , - 1 , True ),
46014571 # 1D tensor select (float32)
4602- (torch .rand (10 , dtype = torch .float32 ), 0 , 5 ),
4572+ (torch .rand (10 , dtype = torch .float32 ), 0 , 5 , False ),
46034573 # 1D tensor, negative index — exercises 1D dynamic path when dynamic=True
4604- (torch .rand (8 , dtype = torch .float32 ), 0 , - 2 ),
4574+ (torch .rand (8 , dtype = torch .float32 ), 0 , - 2 , False ),
4575+ (torch .rand (8 , dtype = torch .float32 ), 0 , - 2 , True ),
46054576 # 3D float32, negative index on last dim — exercises dynamic path when dynamic=True
4606- (torch .rand (2 , 3 , 5 , dtype = torch .float32 ), 2 , - 1 ),
4577+ (torch .rand (2 , 3 , 5 , dtype = torch .float32 ), 2 , - 1 , False ),
4578+ (torch .rand (2 , 3 , 5 , dtype = torch .float32 ), 2 , - 1 , True ),
46074579 ],
46084580)
46094581async def test_select_int (x : Tensor , dim : int , index : int , dynamic : bool ) -> None :
0 commit comments