Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRANSFORMATIONS][GPU] Add GroupNormalization fusion to common optimizations #28387

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

jhajducz
Copy link
Contributor

@jhajducz jhajducz commented Jan 11, 2025

Details:

  • Added GroupNormalization fusion pass that can handle pattern observed in many customer models that were exported via ONNX in a way that uses InstanceNormalization as a proxy for GroupNormalization. It covers also more traditional cases without additional instance norm related parameters.
  • Per suggestion from @vladimir-paramuzov, for now enabled GroupNormalization fusion only for GPU plugin. Once it will be verified that it doesn't cause regressions in other backends, we can enable it for them as well.

Tickets:

  • 160436

@github-actions github-actions bot added category: Core OpenVINO Core (aka ngraph) category: GPU OpenVINO GPU plugin category: transformations OpenVINO Runtime library - Transformations category: CPP API OpenVINO CPP API bindings labels Jan 11, 2025
@sys-openvino-ci sys-openvino-ci added the ExternalIntelPR External contributor from Intel label Jan 11, 2025
@jhajducz jhajducz force-pushed the private/jhajducz/gpu_gn_fusion branch from 3a67c81 to ba87e35 Compare January 12, 2025 17:37
@jhajducz jhajducz marked this pull request as ready for review January 13, 2025 00:38
@jhajducz jhajducz requested review from a team as code owners January 13, 2025 00:38
@jhajducz jhajducz requested review from itikhono and removed request for a team January 13, 2025 00:38
@mlukasze
Copy link
Contributor

build_jenkins

Copy link
Contributor

@t-jankowski t-jankowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm regarding Core part.

@jhajducz jhajducz force-pushed the private/jhajducz/gpu_gn_fusion branch from ba87e35 to 3bd623d Compare January 13, 2025 10:49
@praasz
Copy link
Contributor

praasz commented Jan 13, 2025

build_jenkins

@jhajducz jhajducz force-pushed the private/jhajducz/gpu_gn_fusion branch from 3bd623d to d69391b Compare January 14, 2025 13:05
@github-actions github-actions bot removed category: Core OpenVINO Core (aka ngraph) category: CPP API OpenVINO CPP API bindings labels Jan 14, 2025
@jhajducz jhajducz requested a review from praasz January 14, 2025 15:39
@jhajducz jhajducz force-pushed the private/jhajducz/gpu_gn_fusion branch from d69391b to b1ac67d Compare January 14, 2025 20:29
auto input = pattern_map.at(input_m);
auto input_ps = input.get_partial_shape();

auto T = input.get_element_type();
Copy link
Contributor

@vladimir-paramuzov vladimir-paramuzov Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the high level approach for matcher passes is that we split what to replace (pattern) and how to replace (callback). So ideally, all applicability checks should be a part of pattern, including this type/shapes/ranks checks. It's not always possible (for instance, when we need to cross-check multiple Ops), but for op attributes or in/out ports checks you can just use predicates mechanism. You can find few examples here: https://github.com/openvinotoolkit/openvino/blob/master/src/plugins/intel_gpu/src/plugin/transformations/transpose_fusion.cpp#L88-L98

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to use predicates for things that don't depend on other nodes, but as you pointed out, I had to still leave some cross-checks between different ops inside callback. Can you check if it looks good to you now?

#include "transformations/init_node_info.hpp"

using namespace testing;
using namespace ov;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider wrap test in namespace

Suggested change
using namespace ov;
namespace ov::test{

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I appreciate your suggestion, I prefer to keep it consistent with other tests for common optimizations.

// we need to be able to cast mvn to MVN layer type
// in order to read actual epsilon value
auto mvn_out = pattern_map.at(mvn_m);
auto mvn = std::dynamic_pointer_cast<ov::op::v6::MVN>(mvn_out.get_node_shared_ptr());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto mvn = std::dynamic_pointer_cast<ov::op::v6::MVN>(mvn_out.get_node_shared_ptr());
auto mvn = ov::as_type_ptr<ov::op::v6::MVN>(mvn_out.get_node_shared_ptr());

Use OV cast,
Or use as_type<op::v6::MVN*>(mvn_out.get_node()) to not create shared pointers as it looks not required for mvn.,

the mvn can be null pointer or is validated before and here is not possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've changed it to OV cast. My understanding is that there is no need for additional check, as it is set in the pattern as node of type "ov::op::v6::MVN" already.

Comment on lines +10 to +11
namespace ov {
namespace pass {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional:

Suggested change
namespace ov {
namespace pass {
namespace ov::pass {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I appreciate your suggestion, I prefer to keep it consistent with header files for other common optimizations.

@jhajducz jhajducz force-pushed the private/jhajducz/gpu_gn_fusion branch 2 times, most recently from 89fe905 to 9cf1017 Compare January 16, 2025 17:32
@jhajducz jhajducz force-pushed the private/jhajducz/gpu_gn_fusion branch from 9cf1017 to 8382572 Compare January 16, 2025 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: GPU OpenVINO GPU plugin category: transformations OpenVINO Runtime library - Transformations ExternalIntelPR External contributor from Intel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants