This is an automated email from the ASF dual-hosted git repository.
tlopex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new d785894d2f [Relax][PyTorch] Use make_tensor in exported program tests
(#19989)
d785894d2f is described below
commit d785894d2f281e4baac1288c8248744860f92d81
Author: Masahiro Hiramori <[email protected]>
AuthorDate: Mon Jul 13 05:13:46 2026 +0900
[Relax][PyTorch] Use make_tensor in exported program tests (#19989)
This PR uses `torch.testing.make_tensor` where it provides a clear
testing benefit in the PyTorch exported-program frontend tests.
- Generate boolean masks directly instead of comparing random float
tensors
- Generate parametrized dtypes directly instead of creating integer
tensors and converting them with `.to()`
- Specify the CPU device explicitly
---
.../python/relax/test_frontend_from_exported_program.py | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/tests/python/relax/test_frontend_from_exported_program.py
b/tests/python/relax/test_frontend_from_exported_program.py
index f093cf324d..1f78e941e4 100644
--- a/tests/python/relax/test_frontend_from_exported_program.py
+++ b/tests/python/relax/test_frontend_from_exported_program.py
@@ -6387,7 +6387,10 @@ def test_masked_fill():
R.output(gv)
return gv
- example_args = (torch.randn(128, 128, dtype=torch.float32),
torch.rand(128, 128) < 0.5)
+ example_args = (
+ torch.randn(128, 128, dtype=torch.float32),
+ torch.testing.make_tensor((128, 128), dtype=torch.bool, device="cpu"),
+ )
verify_model(Masked_Fill(), example_args, {}, Expected)
@@ -6409,7 +6412,10 @@ def test_masked_fill_inplace():
R.output(gv)
return gv
- example_args = (torch.randn(128, 128, dtype=torch.float32),
torch.rand(128, 128) < 0.5)
+ example_args = (
+ torch.randn(128, 128, dtype=torch.float32),
+ torch.testing.make_tensor((128, 128), dtype=torch.bool, device="cpu"),
+ )
verify_model(Masked_Fill_Inplace(), example_args, {}, Expected)
@@ -7813,7 +7819,7 @@ def test_where():
R.output(gv)
return gv
- condition = torch.randint(0, 2, (5, 3), dtype=torch.bool)
+ condition = torch.testing.make_tensor((5, 3), dtype=torch.bool,
device="cpu")
x = torch.randn(5, 3, dtype=torch.float32)
y = torch.randn(5, 3, dtype=torch.float32)
@@ -8281,8 +8287,8 @@ def test_linspace():
)
def test_dtypes(torch_dtype, relax_dtype):
example_args = (
- torch.randint(0, 10, (10, 10)).to(torch_dtype),
- torch.randint(0, 10, (10, 10)).to(torch_dtype),
+ torch.testing.make_tensor((10, 10), dtype=torch_dtype, device="cpu",
low=0, high=10),
+ torch.testing.make_tensor((10, 10), dtype=torch_dtype, device="cpu",
low=0, high=10),
)
class Model(Module):