Skip to content
Snippets Groups Projects
Commit c5e2cfc4 authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[Analysis] rename to nodes_topologically_sorted

parent a2a39fd1
No related branches found
No related tags found
No related merge requests found
......@@ -81,10 +81,11 @@ def node_inputs_in_expected_order(model):
return {"node_inputs_in_expected_order": all_OK}
def nodes_in_expected_order(model):
"""Verifies that the graph is topologically sorted.
def nodes_topologically_sorted(model):
"""Verifies that graph.node is topologically sorted. This is required by the
ONNX specification.
Returns {"nodes_in_expected_order": Bool}."""
Returns {"nodes_topologically_sorted": Bool}."""
# get successors of every node and check that
# successor index > current node index
......@@ -100,4 +101,4 @@ def nodes_in_expected_order(model):
if index_n > index_suc:
all_OK = False
return {"nodes_in_expected_order": all_OK}
return {"nodes_topologically_sorted": all_OK}
......@@ -92,45 +92,45 @@ def test_node_inputs_in_expected_order():
assert ret["node_inputs_in_expected_order"] is False
def test_nodes_in_expected_order():
# test analysis pass (nodes_in_expected_order) with different models
def test_nodes_topologically_sorted():
# test analysis pass (nodes_topologically_sorted) with different models
# test with data/onnx/finn-hls-model/tfc_w1_a1_after_conv_to_hls.onnx
raw_m = get_data(
"finn", "data/onnx/finn-hls-model/tfc_w1_a1_after_conv_to_hls.onnx"
)
model = ModelWrapper(raw_m)
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is True
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is True
# remove first node and add it at the end
graph = model.graph
first_node = graph.node[0]
graph.node.remove(first_node)
graph.node.append(first_node)
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is False
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is False
# test with data/onnx/mnist-conv/model.onnx
raw_m = get_data("finn", "data/onnx/mnist-conv/model.onnx")
model = ModelWrapper(raw_m)
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is True
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is True
# remove first node and add it at the end
graph = model.graph
first_node = graph.node[0]
graph.node.remove(first_node)
graph.node.append(first_node)
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is False
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is False
# test with manually created small network
Neg_node = oh.make_node("Neg", inputs=["in1"], outputs=["neg1"],)
Round_node = oh.make_node("Round", inputs=["neg1"], outputs=["round1"],)
Neg_node = oh.make_node("Neg", inputs=["in1"], outputs=["neg1"])
Round_node = oh.make_node("Round", inputs=["neg1"], outputs=["round1"])
Ceil_node = oh.make_node("Ceil", inputs=["neg1"], outputs=["ceil1"],)
Add_node = oh.make_node("Add", inputs=["round1", "ceil1"], outputs=["out1"],)
Ceil_node = oh.make_node("Ceil", inputs=["neg1"], outputs=["ceil1"])
Add_node = oh.make_node("Add", inputs=["round1", "ceil1"], outputs=["out1"])
in1 = oh.make_tensor_value_info("in1", TensorProto.FLOAT, [4, 4])
out1 = oh.make_tensor_value_info("out1", TensorProto.FLOAT, [4, 4])
......@@ -150,8 +150,8 @@ def test_nodes_in_expected_order():
onnx_model = oh.make_model(graph, producer_name="simple-model")
model = ModelWrapper(onnx_model)
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is True
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is True
# create same graph but with "wrong" node order
graph = oh.make_graph(
......@@ -169,22 +169,22 @@ def test_nodes_in_expected_order():
onnx_model = oh.make_model(graph, producer_name="simple-model")
model = ModelWrapper(onnx_model)
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is False
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is False
# test with data/onnx/finn-hls-model/finn-hls-onnx-model.onnx
raw_m = get_data("finn", "data/onnx/finn-hls-model/finn-hls-onnx-model.onnx")
model = ModelWrapper(raw_m)
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is True
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is True
# remove first node and add it at the end
graph = model.graph
first_node = graph.node[0]
graph.node.remove(first_node)
graph.node.append(first_node)
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is False
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is False
# test with cnv_w1a1
build_dir = "/tmp/" + os.environ["FINN_INST_NAME"]
......@@ -193,13 +193,13 @@ def test_nodes_in_expected_order():
cnv, (1, 3, 32, 32), build_dir + "/end2end_cnv_w1a1_export.onnx"
)
model = ModelWrapper(build_dir + "/end2end_cnv_w1a1_export.onnx")
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is True
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is True
# remove first node and add it at the end
graph = model.graph
first_node = graph.node[0]
graph.node.remove(first_node)
graph.node.append(first_node)
ret = model.analysis(ta.nodes_in_expected_order)
assert ret["nodes_in_expected_order"] is False
ret = model.analysis(ta.nodes_topologically_sorted)
assert ret["nodes_topologically_sorted"] is False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment