From 19d048e0c3b3b05f1a435838a0a515349bc9de4d Mon Sep 17 00:00:00 2001 From: "yuan.xiong" Date: Mon, 9 Dec 2024 12:51:13 +0800 Subject: [PATCH] Check dependencies of reorder node all the way to input_layout node for quantized model Signed-off-by: yuan.xiong --- .../mark_shape_of_subgraphs.cpp | 99 ++++++++++++++++--- 1 file changed, 88 insertions(+), 11 deletions(-) diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp index a28ddb3d1b619a..d8e4f2288ada85 100644 --- a/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp +++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/mark_shape_of_subgraphs.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // +#include "broadcast_inst.h" #include "shape_of_inst.h" #include "read_value_inst.h" #include "reshape_inst.h" @@ -16,26 +17,102 @@ using namespace cldnn; namespace { - bool conv_reorder_with_fake_quantize(program_node& node) { - if (!node.is_type()) { - return false; + bool has_input_layout_dep(const std::vector>& shape_of_deps) { + for (auto& shape_of_dep : shape_of_deps) { + // input_layout node + if (shape_of_dep.first->is_type()) { + return true; + } } + return false; + } - std::string dequantize_name = "DequantizationMultiply"; - for (auto& dependency : node.get_dependencies()) { - if (dependency.first->is_type()) { - auto& conv_deps = dependency.first->get_dependencies(); + bool has_shape_of_dep(const std::vector>& broadcast_deps) { + for (auto& broadcast_dep : broadcast_deps) { + // shape_of node + if (broadcast_dep.first->is_type()) { + auto& shape_of_deps = broadcast_dep.first->get_dependencies(); + return has_input_layout_dep(shape_of_deps); + } + } + return false; + } + + bool has_broadcast_dep(const std::vector>& reorder_deps) { + for (auto& reorder_dep : reorder_deps) { + // broadcast node + if (reorder_dep.first->is_type()) { + auto& broadcast_deps = reorder_dep.first->get_dependencies(); + return has_shape_of_dep(broadcast_deps); + } + } + return false; + } - for (auto& conv_dep : conv_deps) { - if (conv_dep.first->id().find(dequantize_name) != std::string::npos) { - return true; + bool has_reorder_reoder_dep(const std::vector>& eltwise_deps) { + for (auto& eltwise_dep : eltwise_deps) { + // reorder node (reorder -> eltwise) + if (eltwise_dep.first->is_type()) { + auto& eltwise_dep_reorder_deps = eltwise_dep.first->get_dependencies(); + + for (auto& eltwise_dep_reorder_dep : eltwise_dep_reorder_deps) { + // reorder node (broadcast -> reorder) + if (eltwise_dep_reorder_dep.first->is_type()) { + auto& reorder_dep_reorder_deps = eltwise_dep_reorder_dep.first->get_dependencies(); + return has_broadcast_dep(reorder_dep_reorder_deps); } } } } + return false; + } + + bool has_eltwise_dep(const std::vector>& reorder_deps) { + for (auto& reorder_dep : reorder_deps) { + // eltwise node + if (reorder_dep.first->is_type()) { + auto& eltwise_deps = reorder_dep.first->get_dependencies(); + return has_reorder_reoder_dep(eltwise_deps); + } + } + return false; + } + + bool has_reorder_dep(const std::vector>& conv_deps) { + for (auto& conv_dep : conv_deps) { + //if (conv_dep.first->id().find(dequantize_name) != std::string::npos) { + + // reorder node ( reorder -> convolution) + if (conv_dep.first->is_type()) { + auto& reorder_deps = conv_dep.first->get_dependencies(); + return has_eltwise_dep(reorder_deps); + } + } + return false; + } + bool has_convolution_dep(const std::vector>& dependencies) { + for (auto& dependency : dependencies) { + // convolution node + if (dependency.first->is_type()) { + auto& conv_deps = dependency.first->get_dependencies(); + return has_reorder_dep(conv_deps); + } + } return false; } + + // check dependencies for reorder node added for convolution in quantized model + bool skip_quantization_conv_reorder(const program_node& node) { + // reorder -> convolution -> reorder -> eltwise -> reorder -> reorder -> broadcast -> shape_of -> input_layout + if (!node.is_type()) { + return false; + } + + auto& dependencies = node.get_dependencies(); + return has_convolution_dep(dependencies); + } + } // namespace void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { @@ -45,7 +122,7 @@ void mark_shape_of_subgraphs::look_for_shape_of_subgraph(program_node& node) { } // skip mark_node for reorder node (after convolution node) for quantized model - if (conv_reorder_with_fake_quantize(node)) { + if (skip_quantization_conv_reorder(node)) { return; }