From cd9e11afea93c1a6b53590d3c334df7f7f72a50c Mon Sep 17 00:00:00 2001 From: Aleksei Kashapov Date: Tue, 5 Mar 2024 12:54:14 +0100 Subject: [PATCH] add test --- nncf/onnx/graph/nncf_graph_builder.py | 1 + .../synthetic/output_with_no_parents_model.dot | 8 ++++++++ tests/onnx/test_nncf_graph_builder.py | 12 ++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 tests/onnx/data/reference_graphs/original_nncf_graph/synthetic/output_with_no_parents_model.dot diff --git a/nncf/onnx/graph/nncf_graph_builder.py b/nncf/onnx/graph/nncf_graph_builder.py index d74a1d7db15..9d8851bb5a4 100644 --- a/nncf/onnx/graph/nncf_graph_builder.py +++ b/nncf/onnx/graph/nncf_graph_builder.py @@ -324,6 +324,7 @@ def _add_nncf_output_nodes( output_port_id=output_port_id, dtype=nncf_dtype, ) + input_port_id += 1 @staticmethod def convert_onnx_dtype_to_nncf_dtype(onnx_dtype: int) -> Dtype: diff --git a/tests/onnx/data/reference_graphs/original_nncf_graph/synthetic/output_with_no_parents_model.dot b/tests/onnx/data/reference_graphs/original_nncf_graph/synthetic/output_with_no_parents_model.dot new file mode 100644 index 00000000000..c1736f8afe3 --- /dev/null +++ b/tests/onnx/data/reference_graphs/original_nncf_graph/synthetic/output_with_no_parents_model.dot @@ -0,0 +1,8 @@ +strict digraph { +"0 Conv1" [id=0, type=Conv]; +"1 nncf_model_input_0" [id=1, type=nncf_model_input]; +"2 nncf_model_output_0" [id=2, type=nncf_model_output]; +"3 nncf_model_output_1" [id=3, type=nncf_model_output]; +"0 Conv1" -> "2 nncf_model_output_0" [label="[]", style=solid]; +"1 nncf_model_input_0" -> "0 Conv1" [label="[1, 3, 10, 10]", style=solid]; +} diff --git a/tests/onnx/test_nncf_graph_builder.py b/tests/onnx/test_nncf_graph_builder.py index 0797197c9c4..576aa55067c 100644 --- a/tests/onnx/test_nncf_graph_builder.py +++ b/tests/onnx/test_nncf_graph_builder.py @@ -16,9 +16,11 @@ import torch from torchvision import models +from nncf.onnx.graph.model_transformer import ONNXModelTransformer from nncf.onnx.graph.nncf_graph_builder import GraphConverter from tests.onnx.conftest import ONNX_TEST_ROOT from tests.onnx.models import ALL_SYNTHETIC_MODELS +from tests.onnx.models import OneConvolutionalModel from tests.onnx.opset_converter import convert_opset_version from tests.onnx.quantization.common import ModelToTest from tests.onnx.weightless_model import load_model_topology_with_zeros_weights @@ -99,3 +101,13 @@ def test_compare_nncf_graph_detection_real_models(tmp_path, model_to_test): nx_graph = nncf_graph.get_graph_for_structure_analysis(extended=True) compare_nx_graph_with_reference(nx_graph, path_to_dot, check_edge_attrs=True) + + +def test_add_output_nodes_with_no_parents_node(): + model_to_test = OneConvolutionalModel().onnx_model + model_outputs = (value_info.name for value_info in model_to_test.graph.output) + model_with_output = ONNXModelTransformer._insert_outputs(model_to_test, (*model_outputs, "Conv1_W")) + nncf_graph = GraphConverter.create_nncf_graph(model_with_output) + nx_graph = nncf_graph.get_graph_for_structure_analysis(extended=True) + path_to_dot = REFERENCE_GRAPHS_DIR / "synthetic" / "output_with_no_parents_model.dot" + compare_nx_graph_with_reference(nx_graph, path_to_dot, check_edge_attrs=True)