From efb67883a724874030cd9e133996954e9a7ae229 Mon Sep 17 00:00:00 2001 From: "Guan-Ming (Wesley) Chiu" <105915352+guan404ming@users.noreply.github.com> Date: Sat, 27 Dec 2025 12:57:46 +0800 Subject: [PATCH 1/3] test(relax): Add test case for op attributes in AST printer --- tests/python/relax/test_ast_printer.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/python/relax/test_ast_printer.py b/tests/python/relax/test_ast_printer.py index 6a65b1b751c7..541358061b1f 100644 --- a/tests/python/relax/test_ast_printer.py +++ b/tests/python/relax/test_ast_printer.py @@ -414,7 +414,23 @@ def f( op_call_text, ) - # TODO: add testcase for op attrs + +def test_op_attrs(): + x = rx.Var("x", R.Tensor((10,), "float32")) + # Manually create a Call with attributes to test printer support for Op attributes + op = tvm.ir.Op.get("relax.add") + attrs = tvm.ir.make_node("ir.DictAttrs", **{"my_attr": "my_value"}) + call_node = rx.Call(op, [x, x], attrs=attrs) + + call_str = dump_ast(call_node, include_call_attrs=True) + assert_fields( + "Call", + { + "op": 'Op(name="relax.add")', + "attrs": '{"my_attr": "my_value"}', + }, + call_str, + ) def test_call_tir(): From 1adc16989ec296ca241ed02ad4ebb065b95ec7c0 Mon Sep 17 00:00:00 2001 From: "Guan-Ming (Wesley) Chiu" <105915352+guan404ming@users.noreply.github.com> Date: Sat, 27 Dec 2025 13:05:39 +0800 Subject: [PATCH 2/3] Update tests/python/relax/test_ast_printer.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- tests/python/relax/test_ast_printer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/python/relax/test_ast_printer.py b/tests/python/relax/test_ast_printer.py index 541358061b1f..ca356726bcc9 100644 --- a/tests/python/relax/test_ast_printer.py +++ b/tests/python/relax/test_ast_printer.py @@ -419,8 +419,7 @@ def test_op_attrs(): x = rx.Var("x", R.Tensor((10,), "float32")) # Manually create a Call with attributes to test printer support for Op attributes op = tvm.ir.Op.get("relax.add") - attrs = tvm.ir.make_node("ir.DictAttrs", **{"my_attr": "my_value"}) - call_node = rx.Call(op, [x, x], attrs=attrs) + call_node = rx.Call(op, [x, x], attrs={"my_attr": "my_value"}) call_str = dump_ast(call_node, include_call_attrs=True) assert_fields( From f88529fb818ff28140f9c85b0787dc7ae6aeefa7 Mon Sep 17 00:00:00 2001 From: "Guan-Ming (Wesley) Chiu" <105915352+guan404ming@users.noreply.github.com> Date: Sat, 27 Dec 2025 17:15:27 +0800 Subject: [PATCH 3/3] Update test --- tests/python/relax/test_ast_printer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/python/relax/test_ast_printer.py b/tests/python/relax/test_ast_printer.py index ca356726bcc9..96ebbfc2ef32 100644 --- a/tests/python/relax/test_ast_printer.py +++ b/tests/python/relax/test_ast_printer.py @@ -419,7 +419,8 @@ def test_op_attrs(): x = rx.Var("x", R.Tensor((10,), "float32")) # Manually create a Call with attributes to test printer support for Op attributes op = tvm.ir.Op.get("relax.add") - call_node = rx.Call(op, [x, x], attrs={"my_attr": "my_value"}) + attrs = tvm.ir.make_node("ir.DictAttrs", my_attr="my_value") + call_node = rx.Call(op, [x, x], attrs=attrs) call_str = dump_ast(call_node, include_call_attrs=True) assert_fields(