From 1a35726f519ff31e6bc10931d2ee7eeedbc6be78 Mon Sep 17 00:00:00 2001 From: Georgy Krivoruchko Date: Sat, 29 Oct 2022 01:51:13 +0400 Subject: [PATCH] Changed behavior of SubgraphDumper in case of Constans (#13678) --- .../subgraphs_dumper/src/op_cloner.cpp | 58 +++++++++++++------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/op_cloner.cpp b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/op_cloner.cpp index 852cff27b33..5c6075c456d 100644 --- a/src/tests/functional/plugin/conformance/subgraphs_dumper/src/op_cloner.cpp +++ b/src/tests/functional/plugin/conformance/subgraphs_dumper/src/op_cloner.cpp @@ -73,39 +73,61 @@ void get_port_range(const std::shared_ptr &constant_input, std::shared_ptr clone(const std::shared_ptr &node, LayerTestsUtils::OPInfo &meta) { ov::OutputVector op_inputs; bool has_parameters = false; - for (size_t i = 0; i < node->get_input_size(); ++i) { - const auto input = node->input(i).get_source_output(); + + auto add_input_func = [&](size_t index) { + const auto input = node->input(index).get_source_output(); auto port_info = LayerTestsUtils::PortInfo(); const auto constant = ov::get_constant_from_source(input); + std::shared_ptr input_node; if (constant) { get_port_range(constant, port_info); float weights_size = - static_cast(ov::shape_size(constant->get_shape()) * - constant->get_element_type().size()) / (1024 * 1024); - if (weights_size > ClonersMap::constant_size_threshold_mb) { - std::cout << "Constant with size " << weights_size << " detected on port " << i << " of OP " << node + static_cast(ov::shape_size(constant->get_shape()) * constant->get_element_type().size()) / + (1024 * 1024); + // Here we check for a big (by memory consuption) size constant, or case when Constant-only input + // has been covered and we need to add first Constant as a Parameter + if (weights_size > ClonersMap::constant_size_threshold_mb || (!has_parameters && index == 0)) { + std::cout << "Constant with size " << weights_size << " detected on port " << index << " of OP " << node << std::endl << "The constant will be replaced with parameter and initial data ranges meta info" << std::endl; - auto param = std::make_shared(constant->get_element_type(), - constant->get_shape()); - op_inputs.push_back(param); + input_node = + std::make_shared(constant->get_element_type(), constant->get_shape()); + + if (!has_parameters && index == 0) { + // Resets port info to defaults + port_info.convert_to_const = false; + port_info.min = std::numeric_limits::min(); + port_info.max = std::numeric_limits::max(); + } has_parameters = true; - } else { - const auto clone = std::make_shared(constant->get_element_type(), - constant->get_shape(), - constant->get_data_ptr()); - op_inputs.push_back(clone); + input_node = std::make_shared(constant->get_element_type(), + constant->get_shape(), + constant->get_data_ptr()); } } else { + input_node = std::make_shared(input.get_element_type(), input.get_partial_shape()); + has_parameters = true; - auto param = std::make_shared(input.get_element_type(), - input.get_partial_shape()); - op_inputs.push_back(param); } - meta.ports_info[i] = port_info; + + if (index > 0) + op_inputs.push_back(input_node); + else + op_inputs.insert(op_inputs.begin(), input_node); + + meta.ports_info[index] = port_info; + }; + // Try to add all inputs, except first + for (size_t i = 1; i < node->get_input_size(); ++i) { + add_input_func(i); + } + if (node->get_input_size() > 0) { + // In case of first input, if we haven't found a Parameter yet (means Constants-only input) + // we will add a first constant as a Parameter input explicitly + add_input_func(0); } if (!has_parameters) { return nullptr;