print ast w/o metadata (#2533)
authorZhi <5145158+zhiics@users.noreply.github.com>
Sun, 3 Feb 2019 17:46:00 +0000 (09:46 -0800)
committerTianqi Chen <tqchen@users.noreply.github.com>
Sun, 3 Feb 2019 17:46:00 +0000 (09:46 -0800)
python/tvm/relay/base.py
tests/python/relay/test_ir_text_printer.py

index 780d52863079bdffd0f337b4c001dddd0334eed8..e0491d62f552125730dff6953a3df56393c31785 100644 (file)
@@ -54,7 +54,7 @@ class RelayNode(NodeBase):
         Note
         ----
         The metadata section is necessary to fully parse the text format.
-        However, it can contain dumps that are big (e.g constant weights)a,
+        However, it can contain dumps that are big (e.g constant weights),
         so it can be helpful to skip printing the meta data section.
 
         Returns
@@ -67,6 +67,9 @@ class RelayNode(NodeBase):
     def set_span(self, span):
         _base.set_span(self, span)
 
+    def __str__(self):
+        return self.astext(show_meta_data=False)
+
 
 @register_relay_node
 class Span(RelayNode):
index 07d2ad2af447393b3c06de2cf161b5ab31c93ada..21bd85a3eb37c676a66c111b6597be8d3bc6d774 100644 (file)
@@ -32,7 +32,9 @@ def test_env():
     env["myf"] = f
     text = env.astext()
     assert "def @myf" in text
+    assert "def @myf" in str(env)
     assert "%1 = add(%0, %0) # ty=float32" in text
+    assert "%1 = add(%0, %0) # ty=float32" in str(env)
     show(env.astext(annotate=lambda x: str(x.checked_type.dtype)))
     show(text)
 
@@ -47,9 +49,15 @@ def test_meta_data():
                         channels=2)
     f = relay.Function([x, w], z)
     text = f.astext()
+    text_no_meta = str(f)
     assert "channels=2" in text
+    assert "channels=2" in text_no_meta
     assert "meta[Variable][0]" in text
+    assert "meta[Variable][0]" in text_no_meta
+    assert "type_key" in text
+    assert "type_key" not in text_no_meta
     show(text)
+    show(f)
 
     text = relay.const([1,2,3]).astext()
     assert "meta[relay.Constant][0]" in text