From 7e51eb723cfea66c5f84a9dd6aa5492ed0cea7f7 Mon Sep 17 00:00:00 2001 From: Josh Pollock Date: Fri, 22 Mar 2019 14:42:43 -0700 Subject: [PATCH 1/4] fix call node printing and add regression test --- src/relay/ir/pretty_printer.cc | 4 +++- tests/python/relay/test_ir_text_printer.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/relay/ir/pretty_printer.cc b/src/relay/ir/pretty_printer.cc index a030a056f7cd..40fcee68edc7 100644 --- a/src/relay/ir/pretty_printer.cc +++ b/src/relay/ir/pretty_printer.cc @@ -416,11 +416,13 @@ class PrettyPrinter : Doc VisitExpr_(const CallNode* op) final { Doc doc; - doc << Print(op->op); + // visit args first so they are lifted before the op + // this places op closer to its call site std::vector args; for (Expr arg : op->args) { args.push_back(Print(arg)); } + doc << Print(op->op); return doc << "(" << PrintVec(args) << PrintAttrs(op->attrs, op->op) << ")"; } diff --git a/tests/python/relay/test_ir_text_printer.py b/tests/python/relay/test_ir_text_printer.py index 626436d9573f..f0f55e39635b 100644 --- a/tests/python/relay/test_ir_text_printer.py +++ b/tests/python/relay/test_ir_text_printer.py @@ -152,6 +152,17 @@ def test_densenet(): net, params = tvm.relay.testing.densenet.get_workload(batch_size=1) net.astext() +def test_call_node_order(): + assert relay.fromtext("v0.0.1\n(fn(%x) { %x })((fn(%y) { %y })(1))").astext(show_meta_data=False) == ("v0.0.1\n" + "%0 = fn (%y) {\n" + " %y\n" + "}\n" + "%1 = %0(1)\n" + "%2 = fn (%x) {\n" + " %x\n" + "}\n" + "%3 = %2(%1)\n" + "%3") if __name__ == "__main__": do_print[0] = True @@ -170,3 +181,4 @@ def test_densenet(): test_call_attrs() test_let_if_scope() test_variable_name() + test_call_node_order() From fa5eba6f2a903a9542859bfc07028e4e70e2f62b Mon Sep 17 00:00:00 2001 From: Josh Pollock Date: Fri, 22 Mar 2019 16:30:11 -0700 Subject: [PATCH 2/4] nit --- tests/python/relay/test_ir_text_printer.py | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/python/relay/test_ir_text_printer.py b/tests/python/relay/test_ir_text_printer.py index f0f55e39635b..f482c85bf3f7 100644 --- a/tests/python/relay/test_ir_text_printer.py +++ b/tests/python/relay/test_ir_text_printer.py @@ -3,9 +3,10 @@ import numpy as np from tvm import relay - do_print = [False] +SEMVER = "v0.0.1\n" + def show(text): if do_print[0]: print("---------------------------") @@ -153,16 +154,17 @@ def test_densenet(): net.astext() def test_call_node_order(): - assert relay.fromtext("v0.0.1\n(fn(%x) { %x })((fn(%y) { %y })(1))").astext(show_meta_data=False) == ("v0.0.1\n" - "%0 = fn (%y) {\n" - " %y\n" - "}\n" - "%1 = %0(1)\n" - "%2 = fn (%x) {\n" - " %x\n" - "}\n" - "%3 = %2(%1)\n" - "%3") + assert relay.fromtext(SEMVER+"(fn(%x) { %x })((fn(%y) { %y })(1))").astext() == SEMVER + \ + ("v0.0.1\n" + "%0 = fn (%y) {\n" + " %y\n" + "}\n" + "%1 = %0(1)\n" + "%2 = fn (%x) {\n" + " %x\n" + "}\n" + "%3 = %2(%1)\n" + "%3") if __name__ == "__main__": do_print[0] = True From 4735aad2e259aa3a3141210be9382d07ee26a722 Mon Sep 17 00:00:00 2001 From: Josh Pollock Date: Fri, 22 Mar 2019 16:48:51 -0700 Subject: [PATCH 3/4] fix test --- tests/python/relay/test_ir_text_printer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/python/relay/test_ir_text_printer.py b/tests/python/relay/test_ir_text_printer.py index f482c85bf3f7..161d08b3299f 100644 --- a/tests/python/relay/test_ir_text_printer.py +++ b/tests/python/relay/test_ir_text_printer.py @@ -155,8 +155,7 @@ def test_densenet(): def test_call_node_order(): assert relay.fromtext(SEMVER+"(fn(%x) { %x })((fn(%y) { %y })(1))").astext() == SEMVER + \ - ("v0.0.1\n" - "%0 = fn (%y) {\n" + ("%0 = fn (%y) {\n" " %y\n" "}\n" "%1 = %0(1)\n" From 38f3bc9c7b5480e84b68dffd891081f6cc6a9bce Mon Sep 17 00:00:00 2001 From: Josh Pollock Date: Fri, 22 Mar 2019 17:01:23 -0700 Subject: [PATCH 4/4] remove parser dependency --- tests/python/relay/test_ir_text_printer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/python/relay/test_ir_text_printer.py b/tests/python/relay/test_ir_text_printer.py index 161d08b3299f..d3e2d005a4e1 100644 --- a/tests/python/relay/test_ir_text_printer.py +++ b/tests/python/relay/test_ir_text_printer.py @@ -154,7 +154,9 @@ def test_densenet(): net.astext() def test_call_node_order(): - assert relay.fromtext(SEMVER+"(fn(%x) { %x })((fn(%y) { %y })(1))").astext() == SEMVER + \ + x = relay.var("x") + y = relay.var("y") + assert relay.Call(relay.Function([x], x), [relay.Call(relay.Function([y], y), [relay.const(1)])]).astext() == SEMVER + \ ("%0 = fn (%y) {\n" " %y\n" "}\n"