Traverse Function(Graph) in Relay

For nnvm index graph, we can easily fetch input index, attrs, …, of each node. The way I can figure out for similar task in Relay is to use ir_pass.post_order_visit. I have two questions:

  1. I can create a dictionary to record index information for each nodes. How can I fetch attrs for CallNode?
  2. What is TupleGetItemNode for? In resnet50 expr, all TupleGetItemNodes just pick index 0. If a TupleGetItemNode is an input node of a CallNode, can I replace this TupleGetItemNode with the node selected by it?

Or is there an easier way to do this?

For normal traversals, we can use post order visit. Since relay’s Node is part of TVM’s node system, you can access all the fields, do you can directly do call_node.attrs to get the attribute, and do attrs.field_name to get the corresponding value.

The TupleGetItemNode is made for calls with multiple output, this is one difference between NNVMv1 and relay. NNVMv1 assumes every op have multiple output. Every op in relay has a single output, but that output can be a tuple, then we can use TupleGetItem to get the specific field of the tuple

2 Likes

Thank you! This is very helpful.