Skip to content

Commit bd14e8f

Browse files
authored
Support Latest Version of PyTorch (#38)
* Allowing using most recent version of PyTorch * Remove test which is no longer valid with new PyTorch version.
1 parent cd21d5a commit bd14e8f

2 files changed

Lines changed: 16 additions & 44 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies = [
2020
"packaging",
2121
"scipy",
2222
"sympy",
23-
"torch>=2.8.0,<=2.11.0",
23+
"torch>=2.8.0,<=2.13.0",
2424
"typing-extensions",
2525
"strenum",
2626
"rich>=13.0,<16.0",

tests/ops/test_ops.py

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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

10381007
class 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
)
46094581
async def test_select_int(x: Tensor, dim: int, index: int, dynamic: bool) -> None:

0 commit comments

Comments
 (0)