Skip to content

Commit

Permalink
Fix graph_tuner ancestor duplication (apache#7704)
Browse files Browse the repository at this point in the history
A diamond dependency currently generates a duplication of ancestors:
  A
 / \
B   C
 \ /
  D
under some conditions, this scenario leads to the following dictionnary
entry: "D":[A, A] instead of "D":[A].

This results in failures when subsequently trying to transpose node
states based on this data.

Change-Id: I72f9b19286bbab0581b851c228b9d0e79ead400f
  • Loading branch information
ambroise-arm authored Mar 22, 2021
1 parent e4b3e90 commit 43ec869
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/tvm/autotvm/graph_tuner/utils/traverse_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ def get_direct_ancestor(node_list, visited_dict, target_ops, node_idx, input_nam
else:
tmp = get_direct_ancestor(node_list, visited_dict, target_ops, item_idx[0], input_names)
for tmp_item in tmp:
node_direct_ancestor.append(tmp_item)
if tmp_item not in node_direct_ancestor:
node_direct_ancestor.append(tmp_item)
visited_dict[node_idx] = node_direct_ancestor
return node_direct_ancestor

Expand Down
10 changes: 10 additions & 0 deletions tests/python/unittest/test_autotvm_graph_tuner_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ def test_get_direct_ancestor():
out = get_direct_ancestor(node_list, visited_dict, target_ops, 5, input_names)
assert out == [0], "Output mismatch: expecting [0] but got %s." % str(out)

# non-regression test
out = relay.add(relay.log(data), relay.sqrt(data))
net = relay.Function(relay.analysis.free_vars(out), out)
net = bind_inputs(net, {"data": (1, 16, 224, 224)})
node_list = []
node_dict = {}
expr2graph(net, target_ops, node_dict, node_list)
out = get_direct_ancestor(node_list, visited_dict, target_ops, 3, input_names)
assert out == [0], "Output mismatch: expecting [0] but got %s." % str(out)


def test_get_in_nodes():
data = relay.var("data")
Expand Down

0 comments on commit 43ec869

Please sign in to comment.