Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions tests/python/relax/test_frontend_from_exported_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -5051,31 +5051,41 @@ def main(
verify_model(Linspace(), example_args, {}, Expected)


def test_bfloat16():
# TODO(mshr-h): Add tests for all the dtypes supported in fx frontend
@pytest.mark.parametrize(
"torch_dtype, relax_dtype",
[
(torch.float32, "float32"),
(torch.float16, "float16"),
(torch.bfloat16, "bfloat16"),
(torch.int64, "int64"),
(torch.int32, "int32"),
(torch.bool, "bool"),
],
)
def test_dtypes(torch_dtype, relax_dtype):
example_args = (
torch.randn(10, 10, dtype=torch.bfloat16),
torch.randn(10, 10, dtype=torch.bfloat16),
torch.randint(0, 10, (10, 10)).to(torch_dtype),
torch.randint(0, 10, (10, 10)).to(torch_dtype),
)

class BFloat16Model(Module):
class Model(Module):
def forward(self, lhs: torch.Tensor, rhs: torch.Tensor):
return torch.ops.aten.add(lhs, rhs)

@tvm.script.ir_module
class expected:
class Expected:
@R.function
def main(
lhs: R.Tensor((10, 10), dtype="bfloat16"),
rhs: R.Tensor((10, 10), dtype="bfloat16"),
) -> R.Tuple(R.Tensor((10, 10), dtype="bfloat16")):
lhs: R.Tensor((10, 10), dtype=relax_dtype),
rhs: R.Tensor((10, 10), dtype=relax_dtype),
) -> R.Tuple(R.Tensor((10, 10), dtype=relax_dtype)):
with R.dataflow():
lv: R.Tensor((10, 10), dtype="bfloat16") = relax.op.add(lhs, rhs)
gv: R.Tuple(R.Tensor((10, 10), dtype="bfloat16")) = (lv,)
lv: R.Tensor((10, 10), dtype=relax_dtype) = relax.op.add(lhs, rhs)
gv: R.Tuple(R.Tensor((10, 10), dtype=relax_dtype)) = (lv,)
R.output(gv)
return gv

verify_model(BFloat16Model(), example_args, {}, expected)
verify_model(Model(), example_args, {}, Expected)


if __name__ == "__main__":
Expand Down
28 changes: 19 additions & 9 deletions tests/python/relax/test_frontend_from_fx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5416,26 +5416,36 @@ def main(
verify_model(Norm(p, dim=dim, keepdim=keepdim), input_info, {}, expected)


def test_bfloat16():
# TODO(mshr-h): Add tests for all the dtypes supported in EP frontend
class BFloat16Model(Module):
@pytest.mark.parametrize(
"torch_dtype, relax_dtype",
[
(torch.float32, "float32"),
(torch.float16, "float16"),
(torch.bfloat16, "bfloat16"),
(torch.int64, "int64"),
(torch.int32, "int32"),
(torch.bool, "bool"),
],
)
def test_dtypes(torch_dtype, relax_dtype):
class Model(Module):
def forward(self, lhs: torch.Tensor, rhs: torch.Tensor):
return torch.ops.aten.add(lhs, rhs)

@tvm.script.ir_module
class Expected:
@R.function
def main(
lhs: R.Tensor((10, 10), dtype="bfloat16"),
rhs: R.Tensor((10, 10), dtype="bfloat16"),
) -> R.Tensor((10, 10), dtype="bfloat16"):
lhs: R.Tensor((10, 10), dtype=relax_dtype),
rhs: R.Tensor((10, 10), dtype=relax_dtype),
) -> R.Tensor((10, 10), dtype=relax_dtype):
with R.dataflow():
lv: R.Tensor((10, 10), dtype="bfloat16") = relax.op.add(lhs, rhs)
gv: R.Tensor((10, 10), dtype="bfloat16") = lv
lv: R.Tensor((10, 10), dtype=relax_dtype) = relax.op.add(lhs, rhs)
gv: R.Tensor((10, 10), dtype=relax_dtype) = lv
R.output(gv)
return gv

verify_model(BFloat16Model(), [([10, 10], "bfloat16"), ([10, 10], "bfloat16")], {}, Expected)
verify_model(Model(), [([10, 10], torch_dtype), ([10, 10], torch_dtype)], {}, Expected)


def test_eye():
Expand Down
Loading