Arbitrary indexing in TVM graph_json_str

Hi all.

I’m currently slicing TVM model by modifying graph_json_str and rebuild by graph_executor.create(graph_json_str, lib, dev)

But in some cases, tvm model broke, and I finally figure out that index of TVM’s graph_json_str can be varied.

The number/shape of whole graph is same, but order of occurrence of nodes are not.

My question is that is this situation possible?

I’m currently run in docker 18.04 cuda 11.0, tvm 0.8.0

Thanks in advance.

below is the example of my problem…

The visual graph’s format is [node_name][index][dtype]

You can see that tvmgen_default_fused_nn_conv2d_add_multiply_add…[130] is changed to tvmgen_default_fused_nn_conv2d_add_multiply_add…[113] (left below in pic)

Could I just ask you a question? How did you get the visualized graph?

well, I wrote a code myself for these tvm’s graph json format

below is code snippet for tvm version 0.8.0 and using pygraphviz library

import pygraphviz as pgv
import json

def show_graph(json_data, file_name=None):
    if type(json_data) == str:
        json_data = json.loads(json_data)
    A = pgv.AGraph(directed=True)
    for node_idx, node in enumerate(json_data['nodes']):
        for src in node['inputs']:
            # if args.show_size == 1:
            if 1 == 1:
                src_size = 1
                for i in json_data['attrs']['shape'][1][src[0]]:
                    src_size = src_size * i
                
                dst_size = 1
                for i in json_data['attrs']['shape'][1][node_idx]:
                    dst_size = dst_size * i
                # print(src[0], json_data['nodes'][src[0]]['name'], src_size)

                A.add_edge(json_data['nodes'][src[0]]['name'] + '[{}]'.format(src[0]) + '{}'.format(json_data['attrs']['dltype'][1][src[0]]) + "[{}]".format(src_size), node['name'] + '[{}]'.format(node_idx) + '{}'.format(json_data['attrs']['dltype'][1][node_idx]) + "[{}]".format(dst_size))
            else:
                A.add_edge(json_data['nodes'][src[0]]['name'] + '[{}]'.format(src[0]) + '{}'.format(json_data['attrs']['dltype'][1][src[0]]), node['name'] + '[{}]'.format(node_idx) + '{}'.format(json_data['attrs']['dltype'][1][node_idx]))
    if file_name:
        A.draw(file_name + '.png', format='png', prog='dot')

I heard there is some kind of internal method to plotting graph in tvm 0.9.0, for relay graph, not json graph.

2 Likes

Well, I spend a whole day and figure out that this arbitrary indexing is caused from my mistake.

Specifically, I change the some intermediate nodes to output node in relay by

out = relay.Function(out.params, node_list1 + node_list2 + [out.body]), out.ret_type, out.type_params, out.attrs)

like this.

And to avoid duplicated nodes

out = relay.Function(list(set(out.params, node_list1 + node_list2 + [out.body]))), out.ret_type, out.type_params, out.attrs)

and this cause the problem, because of set identifies each node by some kind of memory address, not its value inside…

Anyway. if someone who might did dumb thing like me, check this… ㅠㅠ