Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Fixed wrong eltwise handling as bias (#30417)

Taylor Yeonbok Lee67af7c4ed32d
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp
index 62237ac15d6..9061524553a 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/prepare_primitive_fusing.cpp
@@ -253,10 +253,9 @@ void prepare_primitive_fusing::fuse_bias(program &p) {
return node.as<fully_connected>().get_primitive()->input_size == 3;
};
-
+ auto broadcast_type = eltw_node.get_primitive()->broadcast_spec.m_type;
if (node->get_output_layout().is_dynamic()) {
if (eltw_node.get_dependency(non_const_dep_idx).is_type<fully_connected>()) {
- auto broadcast_type = eltw_node.get_primitive()->broadcast_spec.m_type;
if (broadcast_type != ov::op::AutoBroadcastType::NUMPY && broadcast_type != ov::op::AutoBroadcastType::NONE)
continue;
@@ -298,6 +297,9 @@ void prepare_primitive_fusing::fuse_bias(program &p) {
const_dep.get_output_layout().count() != static_cast<size_t>(out_features)) {
continue;
}
+ // Handle eltw as a bias only when eltw's shape is to be broadcasted to parent node
+ if (const_dep.get_output_layout().count() > node->get_dependency(non_const_dep_idx).get_output_layout().count())
+ continue;
}
auto& bias_node = eltw_node.get_dependency(const_dep_idx);
primitive_id bias_name = bias_node.id();
diff --git a/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp b/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp
index 6d10922e2bf..c7d54ba98d4 100644
--- a/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/fusions/convolution_fusion_test.cpp
@@ -466,6 +466,7 @@ public:
#define CASE_CONV_FP16_14 { 1, 32, 55, 1 }, { 1, 32, 55, 1 }, { 32, 1, 1, 3, 1 }, { 1, 1 }, { 1, 1 }, { 1, 1 }, 32, data_types::f16, format::b_fs_yx_fsv16, data_types::f16, format::gs_oiyx_gsv16, data_types::f16, format::bfyx
#define CASE_CONV_FP16_15 { 1, 39, 55, 1 }, { 1, 39, 55, 1 }, { 39, 1, 1, 3, 1 }, { 1, 1 }, { 1, 1 }, { 1, 1 }, 39, data_types::f16, format::b_fs_yx_fsv16, data_types::f16, format::gs_oiyx_gsv16, data_types::f16, format::bfyx
#define CASE_CONV_FP16_16 { 1, 3, 112, 112, 8 }, { 1, 32, 56, 56, 8 }, { 32, 3, 3, 3, 1 }, { 2, 2, 1 }, { 1, 1, 0 }, { 1, 1, 1 }, 1, data_types::f16, format::bfzyx, data_types::f16, format::bfzyx, data_types::f16, format::bfzyx
+#define CASE_CONV_FP16_17 { 1, 512, 1, 1}, { 1, 1, 1, 1}, { 1, 512, 1, 1 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, 1, data_types::f16, format::bfyx, data_types::f16, format::bfyx, data_types::f16, format::bfyx
#define CASE_CONV_U8S8_1 { 1, 15, 4, 5 }, { 1, 30, 2, 3 }, { 30, 15, 3, 3 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, 1, data_types::u8, format::bfyx, data_types::i8, format::bfyx, data_types::f32, format::bfyx
#define CASE_CONV_U8S8_2 { 1, 15, 5, 5 }, { 1, 30, 3, 3 }, { 30, 15, 3, 3 }, { 1, 1 }, { 0, 0 }, { 1, 1 }, 1, data_types::u8, format::bfyx, data_types::i8, format::bfyx, data_types::f32, format::bfyx
@@ -790,6 +791,32 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_wrong_bias, ::testing::ValuesIn(
convolution_test_params{ CASE_CONV_FP32_15, 3, 3, 3 },
}));
+class conv_fp16_wrong_bias : public ConvFusingTest {};
+TEST_P(conv_fp16_wrong_bias, basic) {
+ // Check case when eltwise add dependency has shape [1, 1, X, Y] and X*Y == CONV_OUT_FEATURES
+ auto p = GetParam();
+ ov::PartialShape eltw_data_shape = get_input_layout(p).get_partial_shape();
+ eltw_data_shape[1] *= 128;
+
+ auto eltw_data_layout = layout{eltw_data_shape, p.default_type, format::bfyx};
+
+ create_topologies(
+ input_layout("input", get_input_layout(p)),
+ data("weights", get_mem(get_weights_layout(p))),
+ data("non-bias", get_mem(eltw_data_layout)),
+ convolution("conv_prim", input_info("input"), "weights", "", p.groups, p.stride, p.dilation, p.pad, p.pad, format::is_grouped(get_weights_layout(p).format)),
+ eltwise("add", { input_info("conv_prim"), input_info("non-bias") }, eltwise_mode::sum),
+ reorder("reorder_bfyx", input_info("add"), p.default_format, data_types::f32)
+ );
+
+ tolerance = default_tolerance(p.default_type);
+ execute(p);
+}
+
+INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp16_wrong_bias, ::testing::ValuesIn(std::vector<convolution_test_params>{
+ convolution_test_params{ CASE_CONV_FP16_17, 3, 3, 3 },
+}));
+
class conv_fp32_add_per_element_planar_const : public ConvFusingTest {};
TEST_P(conv_fp32_add_per_element_planar_const, basic) {
auto p = GetParam();