Commit 0f2e4328 by Zhi Committed by Tianqi Chen

print ast w/o metadata (#2533)

parent e0af5c20
......@@ -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):
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment