Skip to content

Commit

Permalink
[GPU] Remove internal swish fusion pass (openvinotoolkit#22261)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-paramuzov authored Jan 22, 2024
1 parent c39b1f6 commit 639c155
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ using namespace cldnn;
void prepare_primitive_fusing::run(program& p) {
fuse_reorders(p);
remove_redundant_reshape(p);
fuse_sigmoid_mul_to_swish(p);
fuse_bias(p);
fuse_simple_primitives(p);
fuse_constant_transposes(p);
Expand Down Expand Up @@ -124,71 +123,6 @@ void prepare_primitive_fusing::remove_redundant_reshape(program &p) {
}
}

void prepare_primitive_fusing::fuse_sigmoid_mul_to_swish(program &p) {
auto itr = p.get_processing_order().begin();
while (itr != p.get_processing_order().end()) {
auto node_itr = itr++;
auto& node = (*node_itr);

if (node->is_output())
continue;

program_helpers::do_for_types<eltwise>(*node, [&p](eltwise_node& node) {
if (node.get_dependencies().size() != 2)
return;

if (node.get_primitive()->mode != eltwise_mode::prod)
return;

auto& mul = node;
program_node* activation_input = nullptr;
size_t values_id = 1;
if (node.get_dependency(0).is_type<activation>()) {
activation_input = &node.get_dependency(0);
} else if (node.get_dependency(1).is_type<activation>()) {
activation_input = &node.get_dependency(1);
values_id = 0;
}

if (!activation_input)
return;

if (activation_input->as<activation>().get_primitive()->activation_function != activation_func::logistic)
return;

auto& sigmoid = activation_input->as<activation>();

if (sigmoid.is_output() || sigmoid.get_users().size() != 1)
return;

auto& input = node.get_dependency(values_id);

if (&input != &sigmoid.input())
return;

activation_additional_params swish_params = {1.0f, 0.0f};
auto swish_prim = std::make_shared<cldnn::activation>(mul.id() + "_swish", input.id(), activation_func::swish, swish_params);
auto& swish = p.get_or_create(swish_prim);

p.add_optimized_primitive_info(node.id(), {swish.id()});
p.add_optimized_primitive_info(sigmoid.id(), {swish.id()});

p.add_connection(input, swish);
p.replace_all_usages(mul, swish);

p.remove_all_connections(mul);
p.remove_all_connections(sigmoid);

p.remove_if_dangling(mul);
p.remove_if_dangling(sigmoid);

p.get_processing_order().insert_next(&input, &swish);

swish.recalc_output_layout();
});
}
}

void prepare_primitive_fusing::fuse_reorders(program &p) {
// This loop tries fusing several reorders one by one (if present) into one reorder
auto itr = p.get_processing_order().begin();
Expand Down
1 change: 0 additions & 1 deletion src/plugins/intel_gpu/src/graph/include/pass_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ class prepare_primitive_fusing : public base_pass {

private:
void run(program& p) override;
void fuse_sigmoid_mul_to_swish(program &p);
void fuse_bias(program &p);
void fuse_reorders(program& p);
void fuse_simple_primitives(program &p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1488,43 +1488,6 @@ TEST_P(conv_fp32_eltwise_b_fs_zyx_fsv16, vector_ops) {
execute(p);
}

class conv_fp32_swish : public ConvFusingTest {};
TEST_P(conv_fp32_swish, basic) {
auto p = GetParam();
create_topologies(
input_layout("input", get_input_layout(p)),
data("weights", get_mem(get_weights_layout(p))),
data("bias", get_mem(get_per_channel_layout(p))),
convolution("conv_prim", input_info("input"), "weights", "bias", p.groups, p.stride, p.dilation, p.pad, p.pad, format::is_grouped(get_weights_layout(p).format)),
activation("sigmoid", input_info("conv_prim"), activation_func::logistic),
eltwise("mul", { input_info("conv_prim"), input_info("sigmoid") }, eltwise_mode::prod),
reorder("reorder_bfyx", input_info("mul"), p.default_format, data_types::f32)
);

if (engine.get_device_info().supports_immad &&
p.default_type == data_types::f16) {
GTEST_SKIP(); // Issue: 94154
}

tolerance = default_tolerance(p.default_type);
if (p.default_type == data_types::f16) {
tolerance *= 3.f; // Issue: 94154
}
execute(p);
}

INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_swish, ::testing::ValuesIn(std::vector<convolution_test_params>{
// convolution_test_params{ CASE_CONV_FP32_1, 2, 2, 4 },
convolution_test_params{ CASE_CONV_FP32_2, 2, 2, 4 },
convolution_test_params{ CASE_CONV_FP32_3, 2, 2, 4 },
convolution_test_params{ CASE_CONV_FP32_4, 2, 2, 4 },

// convolution_test_params{ CASE_CONV_FP32_1, 2, 2, 4 },
convolution_test_params{ CASE_CONV_FP16_2, 2, 2, 4 },
convolution_test_params{ CASE_CONV_FP16_3, 2, 2, 4 },
convolution_test_params{ CASE_CONV_FP16_4, 2, 2, 4 },
}));

INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_fp32_eltwise_b_fs_zyx_fsv16, ::testing::ValuesIn(std::vector<convolution_test_params>{
convolution_test_params{ CASE_CONV_FP32_6, 2, 2, 3 },
convolution_test_params{ CASE_CONV_FP32_7, 2, 2, 3 },
Expand Down Expand Up @@ -2030,52 +1993,6 @@ INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_int8_eltwise, ::testing::ValuesIn(std
convolution_test_params{ CASE_CONV3D_S8S8_5, 2, 2, 3 },
}));

class conv_int8_scale_shift_swish : public ConvFusingTest {};
TEST_P(conv_int8_scale_shift_swish, basic) {
auto p = GetParam();
create_topologies(
input_layout("input", get_input_layout(p)),
data("weights", get_mem(get_weights_layout(p))),
data("bias", get_mem(get_per_channel_layout(p))),
data("scale_data", get_mem(get_per_channel_layout(p), 1.0f/255.f)),
data("shift_data", get_mem(get_per_channel_layout(p), 1)),
convolution("conv_prim", input_info("input"), "weights", "bias", p.groups, p.stride, p.dilation, p.pad, p.pad, format::is_grouped(get_weights_layout(p).format)),
eltwise("scale0", { input_info("conv_prim"), input_info("scale_data") }, eltwise_mode::prod),
eltwise("scale1", { input_info("conv_prim"), input_info("scale_data") }, eltwise_mode::prod),
eltwise("shift0", { input_info("scale0"), input_info("shift_data") }, eltwise_mode::sum),
eltwise("shift1", { input_info("scale1"), input_info("shift_data") }, eltwise_mode::sum),
activation("sigmoid", input_info("shift0"), activation_func::logistic),
eltwise("mul", { input_info("shift1"), input_info("sigmoid") }, eltwise_mode::prod),
reorder("reorder_bfyx", input_info("mul"), p.default_format, data_types::f32)
);

// high tolerance because many eltwise operations
tolerance = default_tolerance(p.default_type) * 10;
execute(p, -20, 20);
}

INSTANTIATE_TEST_SUITE_P(fusings_gpu, conv_int8_scale_shift_swish, ::testing::ValuesIn(std::vector<convolution_test_params>{
convolution_test_params{ CASE_CONV_U8S8_1, 2, 2, 8 },
convolution_test_params{ CASE_CONV_U8S8_2, 2, 2, 8 },
convolution_test_params{ CASE_CONV_U8S8_3, 2, 2, 8 },
convolution_test_params{ CASE_CONV_U8S8_4, 2, 2, 8 },
convolution_test_params{ CASE_CONV_S8S8_1, 2, 2, 8 },
convolution_test_params{ CASE_CONV_S8S8_2, 2, 2, 8 },
convolution_test_params{ CASE_CONV_S8S8_3, 2, 2, 8 },
convolution_test_params{ CASE_CONV_S8S8_4, 2, 2, 8 },

convolution_test_params{ CASE_CONV3D_U8S8_1, 2, 2, 8 },
convolution_test_params{ CASE_CONV3D_U8S8_2, 2, 2, 8 },
convolution_test_params{ CASE_CONV3D_U8S8_3, 2, 2, 8 },
convolution_test_params{ CASE_CONV3D_U8S8_4, 2, 2, 8 },
convolution_test_params{ CASE_CONV3D_U8S8_5, 2, 2, 8 },
convolution_test_params{ CASE_CONV3D_S8S8_1, 2, 2, 8 },
convolution_test_params{ CASE_CONV3D_S8S8_2, 2, 2, 8 },
convolution_test_params{ CASE_CONV3D_S8S8_3, 2, 2, 8 },
convolution_test_params{ CASE_CONV3D_S8S8_4, 2, 2, 8 },
convolution_test_params{ CASE_CONV3D_S8S8_5, 2, 2, 8 },
}));

class conv_int8_prelu_eltwise : public ConvFusingTest {};
TEST_P(conv_int8_prelu_eltwise, basic) {
auto p = GetParam();
Expand Down

0 comments on commit 639c155

Please sign in to comment.