Skip to content

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

[GPU] activations scaling to resolve accuracy issues for infer precision of f16 (#27265)

Eddy Kimcc67ad1e9c22
diff --git a/src/common/low_precision_transformations/include/low_precision/layer_transformation.hpp b/src/common/low_precision_transformations/include/low_precision/layer_transformation.hpp
index 16d98201e0b..c675ade19b5 100644
--- a/src/common/low_precision_transformations/include/low_precision/layer_transformation.hpp
+++ b/src/common/low_precision_transformations/include/low_precision/layer_transformation.hpp
@@ -252,11 +252,13 @@ public:
element::Type deqPrecision = element::f32,
const std::vector<ov::element::Type> defaultPrecisions =
{ ov::element::u8, ov::element::i8 },
- const bool reshapeIgnorePerTensorQuantizationCheck = false) :
+ const bool reshapeIgnorePerTensorQuantizationCheck = false,
+ const bool scalingMode = false) :
updatePrecisions(updatePrecisions),
deqPrecision(deqPrecision),
defaultPrecisions(defaultPrecisions),
- reshapeIgnorePerTensorQuantizationCheck(reshapeIgnorePerTensorQuantizationCheck) {}
+ reshapeIgnorePerTensorQuantizationCheck(reshapeIgnorePerTensorQuantizationCheck),
+ scalingMode(scalingMode) {}
Params& setUpdatePrecisions(const bool updatePrecisions) {
this->updatePrecisions = updatePrecisions;
@@ -281,6 +283,8 @@ public:
std::vector<ov::element::Type> defaultPrecisions;
// to support GPU workarround to keep Reshape and MatMul in FP32
bool reshapeIgnorePerTensorQuantizationCheck;
+ // to support Activations Scaling
+ bool scalingMode;
};
class PrecisionDetails {
@@ -352,6 +356,7 @@ protected:
element::Type deqPrecision;
std::vector<ov::element::Type> defaultPrecisions;
bool reshapeIgnorePerTensorQuantizationCheck;
+ bool scalingMode;
static constexpr char originalLayerPostfix[] = "_original";
TransformationContext* context;
diff --git a/src/common/low_precision_transformations/src/add.cpp b/src/common/low_precision_transformations/src/add.cpp
index 656831b1b75..b895d332537 100644
--- a/src/common/low_precision_transformations/src/add.cpp
+++ b/src/common/low_precision_transformations/src/add.cpp
@@ -214,14 +214,15 @@ bool AddTransformation::transform(TransformationContext& context, ov::pass::patt
newSubtractFullPathValues),
newMultiplyFullPathValues);
+ auto output_type = scalingMode ? add->get_output_element_type(0) : element::f32;
newAddOrSubtract = std::make_shared<ov::op::TypeRelaxed<ov::opset1::Add>>(
- std::vector<element::Type>{element::f32, element::f32}, std::vector<element::Type>{ element::f32 },
- ov::op::TemporaryReplaceOutputType(inputs[0], element::f32).get(),
- ov::op::TemporaryReplaceOutputType(inputs[1], element::f32).get());
+ std::vector<element::Type>{output_type, output_type}, std::vector<element::Type>{output_type},
+ ov::op::TemporaryReplaceOutputType(inputs[0], output_type).get(),
+ ov::op::TemporaryReplaceOutputType(inputs[1], output_type).get());
newMultiply = std::make_shared<ov::op::TypeRelaxed<ov::opset1::Multiply>>(
- std::vector<element::Type>{element::f32, element::f32}, std::vector<element::Type>{ add->get_output_element_type(0) },
- ov::op::TemporaryReplaceOutputType(newAddOrSubtract, element::f32).get(),
- ov::op::TemporaryReplaceOutputType(multiplyEmptyPathValues, element::f32).get());
+ std::vector<element::Type>{output_type, output_type}, std::vector<element::Type>{add->get_output_element_type(0)},
+ ov::op::TemporaryReplaceOutputType(newAddOrSubtract, output_type).get(),
+ ov::op::TemporaryReplaceOutputType(multiplyEmptyPathValues, output_type).get());
NetworkHelper::insertDequantizationAfter(add, newMultiply, newAddOrSubtract);
NetworkHelper::copyInfo(add, newAddOrSubtract);
diff --git a/src/common/low_precision_transformations/src/layer_transformation.cpp b/src/common/low_precision_transformations/src/layer_transformation.cpp
index 9b222948f58..fa014a078a2 100644
--- a/src/common/low_precision_transformations/src/layer_transformation.cpp
+++ b/src/common/low_precision_transformations/src/layer_transformation.cpp
@@ -45,6 +45,7 @@ LayerTransformation::LayerTransformation(const Params& params) :
deqPrecision(params.deqPrecision),
defaultPrecisions(params.defaultPrecisions),
reshapeIgnorePerTensorQuantizationCheck(params.reshapeIgnorePerTensorQuantizationCheck),
+ scalingMode(params.scalingMode),
context(nullptr) {}
void LayerTransformation::setContext(TransformationContext* context) noexcept {
diff --git a/src/common/low_precision_transformations/src/multiply_partial.cpp b/src/common/low_precision_transformations/src/multiply_partial.cpp
index 16cfb80a68e..aea1bf49b8f 100644
--- a/src/common/low_precision_transformations/src/multiply_partial.cpp
+++ b/src/common/low_precision_transformations/src/multiply_partial.cpp
@@ -79,16 +79,17 @@ bool MultiplyPartialTransformation::transform(TransformationContext& context, ov
auto constParent = multiply->input_value(multiplyBranch.first == 0 ? 1 : 0);
auto multiplyParentParent = multiplyParent.get_node_shared_ptr()->input_value(multiplyBranch.second);
auto multiplyParentConst = multiplyParent.get_node_shared_ptr()->input_value(multiplyBranch.second == 0 ? 1 : 0);
+ auto inputDataType = scalingMode ? multiply->get_output_element_type(0) : element::f32;
newMultiply = std::make_shared<ov::op::TypeRelaxed<ov::opset1::Multiply>>(
- std::vector<ov::element::Type>{ element::f32, element::f32 },
+ std::vector<ov::element::Type>{ inputDataType, inputDataType },
std::vector<ov::element::Type>{ multiply->get_output_element_type(0) },
- ov::op::TemporaryReplaceOutputType(multiplyParentParent, element::f32).get(),
+ ov::op::TemporaryReplaceOutputType(multiplyParentParent, inputDataType).get(),
ov::op::TemporaryReplaceOutputType(
fold<ov::opset1::Multiply>(
- foldConvert(multiplyParentConst, element::f32),
- foldConvert(constParent, element::f32)),
- element::f32).get());
+ foldConvert(multiplyParentConst, inputDataType),
+ foldConvert(constParent, inputDataType)),
+ inputDataType).get());
NetworkHelper::copyInfo(multiplyParent.get_node_shared_ptr(), newMultiply);
NetworkHelper::copyInfo(multiply, newMultiply);
@@ -133,24 +134,30 @@ bool MultiplyPartialTransformation::transform(TransformationContext& context, ov
// before: Y = (SC1 * (X1 - SH1)) * (SC2 * X2)
- // after : Y = (SC1' * (X1 - SH1)) * (X2) , where :
- // SC1' = SC1 * SC2
+ // if scalingMode == false
+ // after : Y = (SC1' * (X1 - SH1)) * (X2) , where :
+ // SC1' = SC1 * SC2
+ // else
+ // after : Y = ((X1 - SH1) * X2) * SC1' , where :
+ // SC1' = SC1 * SC2
auto newMultiplyValuesFullPath = fold<ov::opset1::Multiply>(multiplyValuesEmptyPath, multiplyValuesFullPath);
OutputVector inputs{ {}, {} };
- inputs[emptyPathIndex] = dequantizationEmptyPath.data;
+ inputs[emptyPathIndex] = scalingMode ? newMultiplyValuesFullPath : dequantizationEmptyPath.data;
+ auto input_for_fullPath = scalingMode ? dequantizationEmptyPath.data.get_node_shared_ptr() :
+ newMultiplyValuesFullPath;
ov::Output<ov::Node> parent0 = dequantizationFullPath.subtract == nullptr ?
(dequantizationFullPath.convert == nullptr ? dequantizationFullPath.data : dequantizationFullPath.convert) :
dequantizationFullPath.subtract;
inputs[fullPathIndex] =
- parent0.get_node()->get_output_element_type(0) == newMultiplyValuesFullPath->get_output_element_type(0) ?
- std::make_shared<ov::opset1::Multiply>(parent0, newMultiplyValuesFullPath) :
+ parent0.get_node()->get_output_element_type(0) == input_for_fullPath->get_output_element_type(0) ?
+ std::make_shared<ov::opset1::Multiply>(parent0, input_for_fullPath) :
std::make_shared<ov::op::TypeRelaxed<ov::opset1::Multiply>>(
std::vector<element::Type>{element::f32, element::f32},
std::vector<element::Type>{element::f32},
ov::op::TemporaryReplaceOutputType(parent0, element::f32).get(),
- ov::op::TemporaryReplaceOutputType(newMultiplyValuesFullPath, element::f32).get());
+ ov::op::TemporaryReplaceOutputType(input_for_fullPath, element::f32).get());
newMultiply = std::make_shared<ov::op::TypeRelaxed<ov::opset1::Multiply>>(
std::vector<element::Type>{element::f32, element::f32},
diff --git a/src/common/low_precision_transformations/src/network_helper.cpp b/src/common/low_precision_transformations/src/network_helper.cpp
index c42ae304869..e57fdcfb1b8 100644
--- a/src/common/low_precision_transformations/src/network_helper.cpp
+++ b/src/common/low_precision_transformations/src/network_helper.cpp
@@ -218,7 +218,6 @@ std::shared_ptr<Node> NetworkHelper::swapMultiplyAndAdd(std::shared_ptr<ov::opse
if (multiplyConst == nullptr)
return addAfterMultiply;
- const auto x = multiply->input_value(multiplyInputBranch);
auto a = as_type_ptr<ov::opset1::Constant>(multiply->get_input_node_shared_ptr(multiplyInputBranch == 0 ? 1 : 0));
auto b = as_type_ptr<ov::opset1::Constant>(addAfterMultiply->get_input_node_shared_ptr(multiplyBranch == 0 ? 1 : 0));
std::shared_ptr<ov::opset1::Constant> bDivA;
@@ -263,15 +262,15 @@ std::shared_ptr<Node> NetworkHelper::swapMultiplyAndAdd(std::shared_ptr<ov::opse
bDivA = as_type_ptr<ov::opset1::Constant>(foldConvert(bDivA->output(0), a->get_element_type()));
}
- OutputVector inputs{ {}, {} };
- inputs[0] = x;
- inputs[1] = bDivA->output(0);
-
+ const auto& add_input = multiply->input_value(multiplyInputBranch);
+ // Note: precision is copied to a separate variable intentionally,
+ // since TemporaryReplaceOutputType replaces add_input's precision, whereas we need to set the original precision on newAdd's output
+ const auto add_output_precision = add_input.get_element_type();
std::shared_ptr<ov::opset1::Add> newAdd = std::make_shared<ov::op::TypeRelaxed<ov::opset1::Add>>(
std::vector<element::Type>{element::f32, element::f32},
- std::vector<element::Type>{ x.get_element_type() },
- ov::op::TemporaryReplaceOutputType(inputs[0], element::f32).get(),
- ov::op::TemporaryReplaceOutputType(inputs[1], element::f32).get());
+ std::vector<element::Type>{ add_output_precision },
+ ov::op::TemporaryReplaceOutputType(add_input, element::f32).get(),
+ ov::op::TemporaryReplaceOutputType(bDivA, element::f32).get());
copyInfo(addAfterMultiply, newAdd);
auto newMultiply = std::make_shared<ov::op::TypeRelaxed<ov::opset1::Multiply>>(
diff --git a/src/common/transformations/include/transformations/common_optimizations/activations_scaling.hpp b/src/common/transformations/include/transformations/common_optimizations/activations_scaling.hpp
new file mode 100644
index 00000000000..d8c96a1df54
--- /dev/null
+++ b/src/common/transformations/include/transformations/common_optimizations/activations_scaling.hpp
@@ -0,0 +1,104 @@
+// Copyright (C) 2024 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <memory>
+
+#include "openvino/pass/matcher_pass.hpp"
+#include "transformations_visibility.hpp"
+
+namespace ov {
+namespace pass {
+
+class TRANSFORMATIONS_API ActivationsScaling;
+
+namespace activations_scaling {
+
+class TRANSFORMATIONS_API ScaleDownSingleLayer;
+class TRANSFORMATIONS_API EliminateScalarMul;
+class TRANSFORMATIONS_API MulConcatTransformation;
+class TRANSFORMATIONS_API MulShareTransformation;
+class TRANSFORMATIONS_API MoveDownScalarMul;
+
+} // namespace activations_scaling
+} // namespace pass
+} // namespace ov
+
+// ActivationsScaling makes activation values smaller to prevent overflow due to the limited range of FP16
+// This feature is controlled by ov::hint::activations_scale_factor.
+// For example, when this property is set as 16, activations are divided by 16.
+// If ov::hint::activations_scale_factor is less than or equal to zero, it is disabled.
+
+// Add scale_down and scale_up layers around Convolution and MatMul nodes
+// Conv/MatMul
+// ==>
+// Multiply(scale_down by scale_factor) --> Conv/MatMul --> Multiply(scale_up by scale_factor)
+class ov::pass::activations_scaling::ScaleDownSingleLayer : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("ScaleDownSingleLayer", "0");
+ ScaleDownSingleLayer(float scale_factor, ov::element::Type scaled_prec);
+};
+
+// Normalization and ShapeOf have the following property.
+//
+// Norm(input * const_a) = Norm(input)
+//
+// So, we can skip Multiply that is connected to Normalization and ShapeOf.
+//
+// input --> Multiply --> Normalization/ShapeOf
+// ==>
+// input --> Normalization/ShapeOf
+class ov::pass::activations_scaling::EliminateScalarMul : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("EliminateScalarMul", "0");
+ EliminateScalarMul();
+};
+
+// input_a const_a input_b const_b input_c const_c
+// \ / \ / \ /
+// Multiply_a Multiply_b Multiply_c
+// \ | /
+// \ | /
+// ---------- Concat ------------
+// ==>
+// (const_a (const_b (const_c
+// input_a /const_c) input_b /const_c) input_c /const_c)
+// \ / \ / \ /
+// Multiply_a Multiply_b Multiply_c
+// \ | /
+// \ | /
+// ---------- Concat ------------
+// | const_c
+// | /
+// Multiply
+class ov::pass::activations_scaling::MulConcatTransformation : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("MulConcatTransformation", "0");
+ MulConcatTransformation();
+};
+
+// input input
+// / \ |
+// Norm Mul ==> Mul (expect to be fused into the input layer)
+// | | / \_
+// op_a op_b Norm op_b
+// |
+// op_a
+class ov::pass::activations_scaling::MulShareTransformation : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("MulShareTransformation", "0");
+ MulShareTransformation();
+};
+
+// input_b scalar input_a input_b
+// \ / \ /
+// input_a Mul_b ==> Mul_a' scalar
+// \ / \ /
+// Mul_a Mul_b' (expect to be merged with Mul_a')
+class ov::pass::activations_scaling::MoveDownScalarMul : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("MoveDownScalarMul", "0");
+ MoveDownScalarMul();
+};
diff --git a/src/common/transformations/include/transformations/rt_info/dequantization_node.hpp b/src/common/transformations/include/transformations/rt_info/dequantization_node.hpp
index cc1015c83db..50be44aba3d 100644
--- a/src/common/transformations/include/transformations/rt_info/dequantization_node.hpp
+++ b/src/common/transformations/include/transformations/rt_info/dequantization_node.hpp
@@ -12,7 +12,7 @@ namespace ov {
TRANSFORMATIONS_API void mark_as_dequantization_node(const std::shared_ptr<Node>& node);
-TRANSFORMATIONS_API bool is_dequantization_node(const std::shared_ptr<Node>& node);
+TRANSFORMATIONS_API bool is_dequantization_node(const std::shared_ptr<const Node>& node);
/**
* @ingroup ov_runtime_attr_api
diff --git a/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp b/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp
new file mode 100644
index 00000000000..7fd1a5a237f
--- /dev/null
+++ b/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp
@@ -0,0 +1,392 @@
+// Copyright (C) 2024 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "transformations/common_optimizations/activations_scaling.hpp"
+
+#include <memory>
+
+#include "itt.hpp"
+#include "low_precision/network_helper.hpp"
+#include "openvino/core/rt_info.hpp"
+#include "openvino/op/add.hpp"
+#include "openvino/op/concat.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/convolution.hpp"
+#include "openvino/op/divide.hpp"
+#include "openvino/op/group_normalization.hpp"
+#include "openvino/op/matmul.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/mvn.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/unsqueeze.hpp"
+#include "openvino/op/variadic_split.hpp"
+#include "openvino/pass/constant_folding.hpp"
+#include "openvino/pass/manager.hpp"
+#include "openvino/pass/pattern/op/optional.hpp"
+#include "openvino/pass/pattern/op/or.hpp"
+#include "openvino/pass/pattern/op/wrap_type.hpp"
+#include "ov_ops/rms.hpp"
+#include "transformations/common_optimizations/lin_op_sequence_fusion.hpp"
+#include "transformations/utils/utils.hpp"
+
+namespace {
+const auto is_scalar_node = [](const ov::Output<ov::Node>& output) -> bool {
+ const auto shape = output.get_partial_shape();
+ if (shape.is_dynamic())
+ return false;
+ return ov::shape_size(shape.to_shape()) == 1;
+};
+
+const auto is_non_const_node = [](const ov::Output<ov::Node>& output) -> bool {
+ return !ov::is_type<ov::op::v0::Constant>(output.get_node());
+};
+} // namespace
+
+using namespace ov::pass::activations_scaling;
+using namespace ov::pass::pattern;
+using ov::pass::pattern::op::Or;
+
+ov::pass::activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(float scale_factor,
+ ov::element::Type scaled_prec) {
+ MATCHER_SCOPE(ScaleDownSingleLayer);
+
+ auto activation_m = any_input();
+ auto weights_m = any_input();
+ auto convolution_m = wrap_type<ov::op::v1::Convolution>({activation_m, weights_m});
+ auto matmul_m = wrap_type<ov::op::v0::MatMul>({activation_m, weights_m});
+ auto scaled_op_m = std::make_shared<Or>(OutputVector{convolution_m, matmul_m});
+
+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {
+ const auto& pattern_map = m.get_pattern_value_map();
+
+ OPENVINO_ASSERT(pattern_map.count(convolution_m) || pattern_map.count(matmul_m),
+ "Not found any Convolution or MatMul layer");
+
+ auto insert_scale_down_layer = [&scale_factor, &scaled_prec](std::shared_ptr<ov::Node>& node,
+ const size_t input_idx,
+ const bool keep_precision) {
+ const std::vector<float> scale_down_value = {1.f / scale_factor};
+
+ auto scale_down_layer = std::make_shared<ov::op::v1::Multiply>(
+ node->input(input_idx).get_source_output(),
+ std::make_shared<ov::op::v0::Constant>(node->input(input_idx).get_element_type(),
+ ov::Shape(),
+ scale_down_value));
+ scale_down_layer->set_friendly_name(node->get_friendly_name() + "_scale_down");
+ ov::copy_runtime_info(node, scale_down_layer);
+
+ if (scale_down_layer->output(0).get_element_type() != scaled_prec && !keep_precision) {
+ auto convert_prec = std::make_shared<ov::op::v0::Convert>(scale_down_layer->output(0), scaled_prec);
+ node->input(input_idx).replace_source_output(convert_prec->output(0));
+ } else {
+ node->input(input_idx).replace_source_output(scale_down_layer->output(0));
+ }
+ };
+
+ // scale_down and scale_up layers will be added around scaled_op
+ std::shared_ptr<ov::Node> scaled_op = nullptr;
+
+ if (pattern_map.count(convolution_m))
+ scaled_op = pattern_map.at(convolution_m).get_node_shared_ptr();
+
+ if (pattern_map.count(matmul_m))
+ scaled_op = pattern_map.at(matmul_m).get_node_shared_ptr();
+
+ if (transformation_callback(scaled_op))
+ return false;
+
+ // in the case of decompressed_to_f32 nodes, scale_up layer will be added after Convert node.
+ bool keep_precision = false;
+ std::shared_ptr<ov::Node> output_of_scaled_op = scaled_op;
+ auto child_node = scaled_op->get_output_target_inputs(0).begin()->get_node();
+ if (scaled_op->get_output_target_inputs(0).size() == 1 && ov::is_type<ov::op::v0::Convert>(child_node) &&
+ ov::fp16_compression_is_disabled(child_node->shared_from_this()) &&
+ ov::pass::constant_folding_is_disabled(child_node->shared_from_this())) {
+ output_of_scaled_op = child_node->shared_from_this();
+ child_node = output_of_scaled_op->get_output_target_inputs(0).begin()->get_node();
+ keep_precision = true;
+ }
+
+ const std::vector<float> scale_up_value = {scale_factor};
+ auto output_prec = output_of_scaled_op->output(0).get_element_type();
+
+ // adding a scale_down layer before the target node
+ insert_scale_down_layer(scaled_op, 0, keep_precision);
+ if (scaled_op->input(1).get_element_type() != scaled_prec && !keep_precision) {
+ auto convert_prec1 =
+ std::make_shared<ov::op::v0::Convert>(scaled_op->input(1).get_source_output(), scaled_prec);
+ scaled_op->input(1).replace_source_output(convert_prec1->output(0));
+ }
+
+ scaled_op->revalidate_and_infer_types();
+
+ std::set<ov::Input<ov::Node>> target_inputs;
+
+ // If the target node has a bias layer, scale_up layer will be added after the bias layer.
+ // So, we need to scale_down the bias layer too.
+ bool has_bias = false;
+ size_t bias_index = 1;
+ {
+ if (scaled_op->get_output_target_inputs(0).size() == 1 && ov::is_type<ov::op::v1::Add>(child_node)) {
+ bias_index = (child_node->get_input_node_shared_ptr(0) == scaled_op) ? 1 : 0;
+ const auto& bias_pshape = child_node->get_input_partial_shape(bias_index);
+ if (bias_pshape.is_static()) {
+ const auto& bias_shape = bias_pshape.get_shape();
+ const bool per_channel = std::count_if(bias_shape.begin(), bias_shape.end(), [](size_t x) {
+ return x > 1;
+ }) == 1;
+ if (ov::shape_size(bias_shape) == 1 || per_channel) {
+ has_bias = true;
+ }
+ }
+ }
+ }
+
+ if (has_bias) {
+ auto add = child_node->shared_from_this();
+ target_inputs = add->get_output_target_inputs(0);
+ insert_scale_down_layer(add, bias_index, keep_precision);
+ add->revalidate_and_infer_types();
+ if (add->output(0).get_element_type() != output_prec && !keep_precision) {
+ output_of_scaled_op = std::make_shared<ov::op::v0::Convert>(add->output(0), output_prec);
+ } else {
+ output_of_scaled_op = add;
+ }
+ } else {
+ target_inputs = output_of_scaled_op->get_output_target_inputs(0);
+ if (output_of_scaled_op->output(0).get_element_type() != output_prec && !keep_precision) {
+ output_of_scaled_op =
+ std::make_shared<ov::op::v0::Convert>(output_of_scaled_op->output(0), output_prec);
+ }
+ }
+
+ auto scale_up = register_new_node<ov::op::v1::Multiply>(
+ output_of_scaled_op->output(0),
+ std::make_shared<ov::op::v0::Constant>(output_of_scaled_op->output(0).get_element_type(),
+ ov::Shape(),
+ scale_up_value));
+ scale_up->set_friendly_name(scaled_op->get_friendly_name() + "_scale_up");
+ ov::copy_runtime_info(scaled_op, scale_up);
+ for (auto& in : target_inputs) {
+ in.replace_source_output(scale_up);
+ }
+
+ return true;
+ };
+
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(scaled_op_m, "ScaleDownSingleLayer");
+ this->register_matcher(m, callback);
+}
+
+ov::pass::activations_scaling::EliminateScalarMul::EliminateScalarMul() {
+ MATCHER_SCOPE(EliminateScalarMul);
+
+ auto activation_m = any_input(is_non_const_node);
+ auto convert_m = ov::pass::pattern::optional<ov::op::v0::Convert>(activation_m);
+ auto scale_const_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(is_scalar_node);
+ auto mul_m = wrap_type<ov::op::v1::Multiply>({convert_m, scale_const_m});
+ auto mvn_m = wrap_type<ov::op::v6::MVN>({mul_m, any_input()});
+ auto rms_m = wrap_type<ov::op::internal::RMS>({mul_m, any_input()});
+ auto group_norm_m = wrap_type<ov::op::v12::GroupNormalization>({mul_m, any_input(), any_input()});
+ auto shape_of_m = wrap_type<ov::op::v3::ShapeOf>({mul_m});
+ auto norm_m = std::make_shared<Or>(OutputVector{mvn_m, rms_m, group_norm_m, shape_of_m});
+
+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {
+ const auto& pattern_map = m.get_pattern_value_map();
+
+ if (transformation_callback(m.get_match_root())) {
+ return false;
+ }
+
+ auto activation = pattern_map.at(activation_m);
+ auto norm = pattern_map.at(norm_m).get_node_shared_ptr();
+
+ norm->input(0).replace_source_output(activation);
+
+ return true;
+ };
+
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(norm_m, "EliminateScalarMul");
+ this->register_matcher(m, callback);
+}
+
+ov::pass::activations_scaling::MulConcatTransformation::MulConcatTransformation() {
+ MATCHER_SCOPE(MulConcatTransformation);
+
+ auto concat_m = wrap_type<ov::op::v0::Concat>();
+
+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {
+ const auto& pattern_map = m.get_pattern_value_map();
+
+ OPENVINO_ASSERT(pattern_map.count(concat_m), "Not found any Concat layer");
+
+ auto concat = pattern_map.at(concat_m).get_node_shared_ptr();
+
+ if (transformation_callback(concat)) {
+ return false;
+ }
+
+ // check if all inputs are Multiply with scalar operand
+ ov::Output<ov::Node> last_dep_const = {};
+ ov::element::Type last_dep_const_type = ov::element::undefined;
+ for (auto& input : concat->inputs()) {
+ auto dep_node = ov::as_type_ptr<ov::op::v1::Multiply>(input.get_source_output().get_node_shared_ptr());
+ if (!dep_node) {
+ return false;
+ }
+ auto dep_const0 =
+ ov::as_type_ptr<ov::op::v0::Constant>(dep_node->input(0).get_source_output().get_node_shared_ptr());
+ auto dep_const1 =
+ ov::as_type_ptr<ov::op::v0::Constant>(dep_node->input(1).get_source_output().get_node_shared_ptr());
+ if (!dep_const0 && !dep_const1) {
+ return false;
+ }
+ last_dep_const =
+ dep_const0 ? dep_node->input(0).get_source_output() : dep_node->input(1).get_source_output();
+ if (!is_scalar_node(last_dep_const))
+ return false;
+ if (last_dep_const_type != ov::element::undefined &&
+ last_dep_const_type != last_dep_const.get_element_type())
+ return false;
+ last_dep_const_type = last_dep_const.get_element_type();
+ }
+
+ auto target_inputs = concat->get_output_target_inputs(0);
+
+ for (auto& input : concat->inputs()) {
+ auto dep_node = input.get_source_output().get_node_shared_ptr();
+ auto dep_input0 = dep_node->input(0).get_source_output().get_node();
+ size_t const_index = ov::is_type<ov::op::v0::Constant>(dep_input0) ? 0 : 1;
+ size_t activation_index = ov::is_type<ov::op::v0::Constant>(dep_input0) ? 1 : 0;
+
+ auto dep_type = dep_node->get_output_element_type(0);
+ auto new_mul = std::make_shared<ov::op::TypeRelaxed<ov::op::v1::Multiply>>(
+ std::vector<element::Type>{dep_type, dep_type},
+ std::vector<element::Type>{dep_type},
+ ov::op::TemporaryReplaceOutputType(dep_node->input(activation_index).get_source_output(), dep_type)
+ .get(),
+ ov::op::TemporaryReplaceOutputType(
+ ov::op::util::eltwise_fold<ov::op::v1::Divide>(dep_node->input(const_index).get_source_output(),
+ last_dep_const),
+ dep_type)
+ .get());
+ new_mul->set_friendly_name(dep_node->get_friendly_name() + "_c");
+ ov::copy_runtime_info(dep_node, new_mul);
+
+ input.replace_source_output(new_mul);
+ }
+
+ auto concat_type = concat->get_output_element_type(0);
+ auto new_mul = std::make_shared<ov::op::TypeRelaxed<ov::op::v1::Multiply>>(
+ std::vector<element::Type>{concat_type, concat_type},
+ std::vector<element::Type>{concat_type},
+ ov::op::TemporaryReplaceOutputType(concat->output(0), concat_type).get(),
+ ov::op::TemporaryReplaceOutputType(last_dep_const, concat_type).get());
+ new_mul->set_friendly_name(concat->get_friendly_name() + "_c");
+ ov::copy_runtime_info(concat, new_mul);
+
+ for (auto& in : target_inputs) {
+ in.replace_source_output(new_mul);
+ }
+
+ return true;
+ };
+
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(concat_m, "MulConcatTransformation");
+ this->register_matcher(m, callback);
+}
+
+ov::pass::activations_scaling::MulShareTransformation::MulShareTransformation() {
+ MATCHER_SCOPE(MulShareTransformation);
+
+ auto mvn_m = wrap_type<ov::op::v6::MVN>({any_input(), any_input()});
+ auto rms_m = wrap_type<ov::op::internal::RMS>({any_input(), any_input()});
+ auto group_norm_m = wrap_type<ov::op::v12::GroupNormalization>({any_input(), any_input(), any_input()});
+ auto shape_of_m = wrap_type<ov::op::v3::ShapeOf>({any_input()});
+ auto norm_m = std::make_shared<Or>(OutputVector{mvn_m, rms_m, group_norm_m, shape_of_m});
+
+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {
+ const auto& pattern_map = m.get_pattern_value_map();
+
+ if (transformation_callback(m.get_match_root())) {
+ return false;
+ }
+
+ auto norm = pattern_map.at(norm_m).get_node_shared_ptr();
+
+ auto parent_output = norm->get_input_source_output(0);
+ if (parent_output.get_target_inputs().size() == 1)
+ return false;
+
+ for (auto& child : parent_output.get_target_inputs()) {
+ if (child == norm->input(0))
+ continue;
+
+ if (ov::is_type<ov::op::v1::Multiply>(child.get_node())) {
+ ov::Output<ov::Node> const_input;
+ for (auto input : child.get_node()->input_values()) {
+ if (input == parent_output)
+ continue;
+ const_input = input;
+ }
+
+ if (is_scalar_node(const_input) && !is_non_const_node(const_input)) {
+ norm->input(0).replace_source_output(child.get_node()->output(0));
+ return true;
+ }
+ }
+ }
+
+ return false;
+ };
+
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(norm_m, "ScalarMulShareTransformation");
+ this->register_matcher(m, callback);
+}
+
+ov::pass::activations_scaling::MoveDownScalarMul::MoveDownScalarMul() {
+ MATCHER_SCOPE(MoveDownScalarMul);
+
+ auto activation_b_m = any_input(is_non_const_node);
+ auto mul_const_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(is_scalar_node);
+ auto mul_b_m = wrap_type<ov::op::v1::Multiply>({activation_b_m, mul_const_m});
+ auto activation_a_m = any_input(is_non_const_node);
+ auto mul_a_m = wrap_type<ov::op::v1::Multiply>({activation_a_m, mul_b_m});
+
+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {
+ const auto& pattern_map = m.get_pattern_value_map();
+
+ if (transformation_callback(m.get_match_root())) {
+ return false;
+ }
+
+ auto mul_a = pattern_map.at(mul_a_m).get_node_shared_ptr();
+ auto mul_b = pattern_map.at(mul_b_m).get_node_shared_ptr();
+ auto output_type = mul_a->get_output_element_type(0);
+
+ auto new_mul_a = std::make_shared<ov::op::TypeRelaxed<ov::op::v1::Multiply>>(
+ std::vector<element::Type>{output_type, output_type},
+ std::vector<element::Type>{output_type},
+ ov::op::TemporaryReplaceOutputType(pattern_map.at(activation_a_m), output_type).get(),
+ ov::op::TemporaryReplaceOutputType(pattern_map.at(activation_b_m), output_type).get());
+ new_mul_a->set_friendly_name(mul_a->get_friendly_name() + "_mm");
+ ov::copy_runtime_info(mul_a, new_mul_a);
+
+ auto new_mul_b = std::make_shared<ov::op::TypeRelaxed<ov::op::v1::Multiply>>(
+ std::vector<element::Type>{output_type, output_type},
+ std::vector<element::Type>{output_type},
+ ov::op::TemporaryReplaceOutputType(new_mul_a->output(0), output_type).get(),
+ ov::op::TemporaryReplaceOutputType(pattern_map.at(mul_const_m), output_type).get());
+ new_mul_b->set_friendly_name(mul_b->get_friendly_name() + "_mm");
+ ov::copy_runtime_info(mul_b, new_mul_b);
+
+ ov::replace_node(mul_a, new_mul_b);
+
+ return true;
+ };
+
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_a_m, "MoveDownScalarMul");
+ this->register_matcher(m, callback);
+}
diff --git a/src/common/transformations/src/transformations/rt_info/dequantization_node.cpp b/src/common/transformations/src/transformations/rt_info/dequantization_node.cpp
index 4694de56ae6..91ebe224fcc 100644
--- a/src/common/transformations/src/transformations/rt_info/dequantization_node.cpp
+++ b/src/common/transformations/src/transformations/rt_info/dequantization_node.cpp
@@ -9,7 +9,7 @@ void ov::mark_as_dequantization_node(const std::shared_ptr<Node>& node) {
rt_info[DequantizationNode::get_type_info_static()] = DequantizationNode();
}
-bool ov::is_dequantization_node(const std::shared_ptr<Node>& node) {
+bool ov::is_dequantization_node(const std::shared_ptr<const Node>& node) {
const auto& rt_info = node->get_rt_info();
return rt_info.find(DequantizationNode::get_type_info_static()) != rt_info.end();
}
diff --git a/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp b/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp
new file mode 100644
index 00000000000..a8797b588c3
--- /dev/null
+++ b/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp
@@ -0,0 +1,185 @@
+// Copyright (C) 2024 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "transformations/common_optimizations/activations_scaling.hpp"
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <string>
+
+#include "common_test_utils/graph_comparator.hpp"
+#include "common_test_utils/ov_test_utils.hpp"
+#include "openvino/op/add.hpp"
+#include "openvino/op/concat.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convolution.hpp"
+#include "openvino/op/group_normalization.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/mvn.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/shape_of.hpp"
+#include "openvino/op/variadic_split.hpp"
+#include "openvino/pass/manager.hpp"
+#include "transformations/utils/utils.hpp"
+
+using namespace ov;
+using namespace testing;
+
+TEST_F(TransformationTestsF, ScaleDownSingleLayerTest) {
+ float scale_factor = 128.f;
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 16, 16});
+ auto weights_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3, 3, 3, 3}, {1});
+ auto conv = std::make_shared<ov::op::v1::Convolution>(input,
+ weights_const,
+ Strides{},
+ CoordinateDiff{},
+ CoordinateDiff{},
+ Strides{});
+ auto bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 3, 1, 1}, {2.3f});
+ auto add = std::make_shared<ov::op::v1::Add>(conv, bias_const);
+ auto convert = std::make_shared<ov::op::v0::Convert>(add, ov::element::f32);
+ auto result = std::make_shared<ov::op::v0::Result>(convert);
+
+ model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});
+ manager.register_pass<ov::pass::activations_scaling::ScaleDownSingleLayer>(scale_factor, ov::element::f16);
+ }
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 16, 16});
+ auto weights_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3, 3, 3, 3}, {1});
+ auto scale_down_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{}, {1.f / scale_factor});
+ auto scale_down = std::make_shared<ov::op::v1::Multiply>(input, scale_down_const);
+ auto conv = std::make_shared<ov::op::v1::Convolution>(scale_down,
+ weights_const,
+ Strides{},
+ CoordinateDiff{},
+ CoordinateDiff{},
+ Strides{});
+ auto bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 3, 1, 1}, {2.3f});
+ auto scale_down_bias = std::make_shared<ov::op::v1::Multiply>(bias_const, scale_down_const);
+ auto add = std::make_shared<ov::op::v1::Add>(conv, scale_down_bias);
+ auto scale_up_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{}, {scale_factor});
+ auto scale_up = std::make_shared<ov::op::v1::Multiply>(add, scale_up_const);
+ auto convert = std::make_shared<ov::op::v0::Convert>(scale_up, ov::element::f32);
+ auto result = std::make_shared<ov::op::v0::Result>(convert);
+
+ model_ref = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});
+ }
+}
+
+TEST_F(TransformationTestsF, EliminateScalarMulTest) {
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 16, 16});
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});
+ auto mul = std::make_shared<ov::op::v1::Multiply>(input, scale_const);
+ auto norm_scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});
+ auto norm_bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});
+ auto group_norm =
+ std::make_shared<ov::op::v12::GroupNormalization>(mul, norm_scale_const, norm_bias_const, 1, 0.01f);
+ auto convert = std::make_shared<ov::op::v0::Convert>(group_norm, ov::element::f32);
+ auto result = std::make_shared<ov::op::v0::Result>(convert);
+
+ model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});
+ manager.register_pass<ov::pass::activations_scaling::EliminateScalarMul>();
+ }
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 16, 16});
+ auto norm_scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});
+ auto norm_bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});
+ auto group_norm =
+ std::make_shared<ov::op::v12::GroupNormalization>(input, norm_scale_const, norm_bias_const, 1, 0.01f);
+ auto convert = std::make_shared<ov::op::v0::Convert>(group_norm, ov::element::f32);
+ auto result = std::make_shared<ov::op::v0::Result>(convert);
+
+ model_ref = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});
+ }
+}
+
+TEST_F(TransformationTestsF, ConcatTransformationTest) {
+ {
+ auto input0 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto scale_const0 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});
+ auto mul0 = std::make_shared<ov::op::v1::Multiply>(input0, scale_const0);
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto scale_const1 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});
+ auto mul1 = std::make_shared<ov::op::v1::Multiply>(input1, scale_const1);
+ auto concat = std::make_shared<ov::op::v0::Concat>(OutputVector{mul0, mul1}, 0);
+ auto convert = std::make_shared<ov::op::v0::Convert>(concat, ov::element::f32);
+ auto result = std::make_shared<ov::op::v0::Result>(convert);
+
+ model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input0, input1});
+ manager.register_pass<ov::pass::activations_scaling::MulConcatTransformation>();
+ }
+ {
+ auto input0 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto scale_const0 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {1});
+ auto mul0 = std::make_shared<ov::op::v1::Multiply>(input0, scale_const0);
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto scale_const1 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {1});
+ auto mul1 = std::make_shared<ov::op::v1::Multiply>(input1, scale_const1);
+ auto concat = std::make_shared<ov::op::v0::Concat>(OutputVector{mul0, mul1}, 0);
+ auto new_scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});
+ auto new_mul = std::make_shared<ov::op::v1::Multiply>(concat, new_scale_const);
+ auto convert = std::make_shared<ov::op::v0::Convert>(new_mul, ov::element::f32);
+ auto result = std::make_shared<ov::op::v0::Result>(convert);
+
+ model_ref = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input0, input1});
+ }
+}
+
+TEST_F(TransformationTestsF, MoveDownScalarMulTest) {
+ {
+ auto input0 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto scale_const0 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});
+ auto mul0 = std::make_shared<ov::op::v1::Multiply>(input0, scale_const0);
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto mul1 = std::make_shared<ov::op::v1::Multiply>(input1, mul0);
+ auto convert = std::make_shared<ov::op::v0::Convert>(mul1, ov::element::f32);
+ auto result = std::make_shared<ov::op::v0::Result>(convert);
+
+ model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input0, input1});
+ manager.register_pass<ov::pass::activations_scaling::MoveDownScalarMul>();
+ }
+ {
+ auto input0 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto mul0 = std::make_shared<ov::op::v1::Multiply>(input0, input1);
+ auto scale_const0 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});
+ auto mul1 = std::make_shared<ov::op::v1::Multiply>(mul0, scale_const0);
+ auto convert = std::make_shared<ov::op::v0::Convert>(mul1, ov::element::f32);
+ auto result = std::make_shared<ov::op::v0::Result>(convert);
+
+ model_ref = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input0, input1});
+ }
+}
+
+TEST_F(TransformationTestsF, MulShareTransformationTest) {
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto shape_of = std::make_shared<ov::op::v3::ShapeOf>(input);
+ auto convert0 = std::make_shared<ov::op::v0::Convert>(shape_of, ov::element::f32);
+ auto result0 = std::make_shared<ov::op::v0::Result>(convert0);
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});
+ auto mul = std::make_shared<ov::op::v1::Multiply>(input, scale_const);
+ auto convert1 = std::make_shared<ov::op::v0::Convert>(mul, ov::element::f32);
+ auto result1 = std::make_shared<ov::op::v0::Result>(convert1);
+
+ model = std::make_shared<ov::Model>(ov::ResultVector{result0, result1}, ov::ParameterVector{input});
+ manager.register_pass<ov::pass::activations_scaling::MulShareTransformation>();
+ }
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});
+ auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});
+ auto mul = std::make_shared<ov::op::v1::Multiply>(input, scale_const);
+ auto shape_of = std::make_shared<ov::op::v3::ShapeOf>(mul);
+ auto convert0 = std::make_shared<ov::op::v0::Convert>(shape_of, ov::element::f32);
+ auto result0 = std::make_shared<ov::op::v0::Result>(convert0);
+ auto convert1 = std::make_shared<ov::op::v0::Convert>(mul, ov::element::f32);
+ auto result1 = std::make_shared<ov::op::v0::Result>(convert1);
+
+ model_ref = std::make_shared<ov::Model>(ov::ResultVector{result0, result1}, ov::ParameterVector{input});
+ }
+}
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/permute_f_y_axes.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/permute_f_y_axes.cl
index 3aafc2c727b..9f74654bd45 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/permute_f_y_axes.cl
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/permute_f_y_axes.cl
@@ -40,7 +40,7 @@ KERNEL (permute_f_y_axes)(
OUT_VEC_TYPE result;
IN_VEC_TYPE res = READ_VEC(0, &input[INPUT0_GET_INDEX(b_idx, f_idx, y_idx, x_idx)]);
FUSED_OPS_VEC;
- result = FUSED_OPS_RESULT_VEC;
+ result = TO_OUT_VEC_TYPE(FUSED_OPS_RESULT_VEC);
#else
IN_VEC_TYPE res = READ_VEC(0, &input[INPUT0_GET_INDEX(b_idx, f_idx, y_idx, x_idx)]);
OUT_VEC_TYPE result = TO_OUT_VEC_TYPE(ACTIVATION(res, ACTIVATION_PARAMS));
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/clamp_fp16_output.cpp b/src/plugins/intel_gpu/src/plugin/transformations/clamp_fp16_output.cpp
index b8af1558664..e5395d92384 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations/clamp_fp16_output.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations/clamp_fp16_output.cpp
@@ -47,17 +47,14 @@ ClampFP16Output::ClampFP16Output() {
}
auto matmul = pattern_map.at(matmul_m).get_node_shared_ptr();
- auto target_inputs = matmul->get_output_target_inputs(0);
auto min = static_cast<double>(std::numeric_limits<ov::float16>::lowest());
auto max = static_cast<double>(std::numeric_limits<ov::float16>::max());
- auto clamp = std::make_shared<v0::Clamp>(matmul, min, max);
+ auto clamp = std::make_shared<v0::Clamp>(softmax->get_input_source_output(0), min, max);
clamp->set_friendly_name(matmul->get_friendly_name() + "/ClampFP16Output");
ov::copy_runtime_info({matmul, softmax}, clamp);
- for (auto& in : target_inputs) {
- in.replace_source_output(clamp);
- }
+ softmax->input(0).replace_source_output(clamp);
return true;
};
diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
index 9ec31bcca46..62dcfcb6ad7 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
@@ -16,6 +16,7 @@
#include "intel_gpu/runtime/debug_configuration.hpp"
#include "intel_gpu/runtime/itt.hpp"
#include "low_precision/add.hpp"
+#include "low_precision/concat.hpp"
#include "low_precision/convolution.hpp"
#include "low_precision/convolution_backprop_data.hpp"
#include "low_precision/fold_convert.hpp"
@@ -24,6 +25,7 @@
#include "low_precision/low_precision.hpp"
#include "low_precision/mat_mul.hpp"
#include "low_precision/multiply_to_group_convolution.hpp"
+#include "low_precision/mvn.hpp"
#include "low_precision/network_helper.hpp"
#include "low_precision/pull_reshape_through_dequantization.hpp"
#include "low_precision/pull_transpose_through_dequantization.hpp"
@@ -94,8 +96,10 @@
#include "transformations/common_optimizations/move_eltwise_up_data_movement.hpp"
#include "transformations/common_optimizations/mvn_fusion.hpp"
#include "transformations/common_optimizations/sdpa_scale_fusion.hpp"
+#include "transformations/common_optimizations/activations_scaling.hpp"
#include "transformations/common_optimizations/softmax_fusion.hpp"
#include "transformations/common_optimizations/glu_fusion.hpp"
+#include "transformations/common_optimizations/shared_ops_optimization.hpp"
#include "transformations/common_optimizations/transpose_sinking.hpp"
#include "transformations/common_optimizations/weights_dequantize_to_fake_quantize.hpp"
#include "transformations/common_optimizations/wrap_interpolate_into_transposes.hpp"
@@ -162,6 +166,7 @@
#include "transformations/opset_conversions/convert_opset2_to_opset1.hpp"
#include "transformations/opset_conversions/convert_opset3_to_opset2.hpp"
#include "transformations/resolve_names_collisions.hpp"
+#include "transformations/rt_info/dequantization_node.hpp"
#include "transformations/rt_info/fused_names_attribute.hpp"
#include "transformations/rt_info/keep_const_precision.hpp"
#include "transformations/smart_reshape/matmul_sr.hpp"
@@ -284,6 +289,7 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
const auto& defaultPrecisions = ov::pass::low_precision::precision_set::get_int8_support();
const ov::element::TypeVector supported_woq_types = {ov::element::u8, ov::element::i8, ov::element::u4, ov::element::i4};
bool enableInt8;
+ ov::element::Type infer_precision = ov::element::undefined;
bool unroll_loop = config.get_property(ov::intel_gpu::enable_loop_unrolling);
{
ov::pass::Manager manager("Plugin:GPU");
@@ -330,7 +336,7 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
};
// Add conversion from FP data types to infer precision if it's specified
- auto infer_precision = config.get_property(ov::hint::inference_precision);
+ infer_precision = config.get_property(ov::hint::inference_precision);
if (infer_precision != ov::element::undefined) {
if (!fp_precision_supported(infer_precision))
infer_precision = fallback_precision;
@@ -893,8 +899,10 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
}
{
- ov::pass::Manager manager("GPU:PostLPT");
+ OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "TransformationsPipeline::apply::activations_scaling");
+ ov::pass::Manager manager("GPU:ActivationsScaling");
manager.set_per_pass_validation(false);
+ auto pass_config = manager.get_pass_config();
// Other ops support eltwise fusions
const std::vector<DiscreteTypeInfo> allowed_data_movement_ops = {
@@ -914,6 +922,68 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
// not working properly.
manager.register_pass<ov::pass::Validate>();
+ manager.register_pass<ov::pass::RoPEFusion>(true);
+ pass_config->disable<ov::pass::RoPEFusionGPTJ>();
+ pass_config->disable<ov::pass::RoPEFusionIOSlicing>();
+ pass_config->disable<ov::pass::RoPEShareCosSin>();
+
+ float activations_scale_factor = config.get_property(ov::hint::activations_scale_factor);
+
+ if (activations_scale_factor > 0.f && infer_precision == ov::element::f16 && !enableInt8) {
+ using namespace ov::pass::low_precision;
+
+ auto supportedPrecisions = std::vector<PrecisionsRestriction>({});
+ auto perTensorQuantization = std::vector<QuantizationGranularityRestriction>({});
+
+ pass_config->disable<ov::pass::AddMultiplyFusion>();
+ pass_config->disable<RecurrentCellTransformation>();
+ pass_config->disable<MultiplyToGroupConvolutionTransformation>();
+ pass_config->disable<ConvolutionTransformation>();
+ pass_config->disable<ConvolutionBackpropDataTransformation>();
+ pass_config->disable<GroupConvolutionTransformation>();
+ pass_config->disable<MatMulTransformation>();
+ pass_config->disable<MVNTransformation>();
+ pass_config->disable<ConcatTransformation>();
+
+ pass_config->set_callback<FoldConvertTransformation>(
+ [](const std::shared_ptr<const ov::Node> &node) -> bool {
+ return ov::is_dequantization_node(node);
+ });
+
+ pass_config->set_callback<FuseConvertTransformation>(
+ [](const std::shared_ptr<const ov::Node> &node) -> bool {
+ return (ov::is_dequantization_node(node) || ov::is_type<ov::opset1::FakeQuantize>(node));
+ });
+
+ manager.register_pass<ov::pass::activations_scaling::ScaleDownSingleLayer>(activations_scale_factor, infer_precision);
+ manager.register_pass<ov::pass::SharedOpOptimization>();
+
+ // Move down scalar-multiply layers as much as possible
+ auto params = LayerTransformation::Params(false, infer_precision, {infer_precision}, true, true);
+ auto lpt_pass = manager.register_pass<LowPrecision>(supportedPrecisions, perTensorQuantization, params);
+ lpt_pass->add_main<ov::pass::activations_scaling::EliminateScalarMul>();
+ lpt_pass->add_main<ov::pass::activations_scaling::MulConcatTransformation>();
+ lpt_pass->add_main<ov::pass::activations_scaling::MoveDownScalarMul>();
+
+ // Move up remained scalar-multiply layers
+ manager.register_pass<ov::pass::EliminateEltwise>();
+ manager.register_pass<ov::pass::activations_scaling::MulShareTransformation>();
+
+ const std::vector<DiscreteTypeInfo> allowed_data_movement_ops = {
+ ov::op::v1::Reshape::get_type_info_static(),
+ ov::op::v1::Transpose::get_type_info_static(),
+ };
+ manager.register_pass<ov::pass::MoveEltwiseUpThroughDataMovScalar>(allowed_data_movement_ops);
+ manager.register_pass<ov::pass::Validate>();
+ }
+
+ manager.run_passes(func);
+ }
+
+ {
+ ov::pass::Manager manager("GPU:PostLPT");
+ manager.set_per_pass_validation(false);
+
manager.register_pass<ov::intel_gpu::ClampFP16Output>();
manager.register_pass<ov::intel_gpu::ConvertMatMulToFullyConnected>();
manager.register_pass<ov::intel_gpu::MoveFCReshapeToWeights>();
@@ -954,7 +1024,6 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
manager.register_pass<ov::intel_gpu::KVCacheFusion>();
manager.register_pass<ov::intel_gpu::FullyConnectedConvertFusion>();
manager.register_pass<ov::intel_gpu::TransposeFusion>(device_info.supports_immad);
- manager.register_pass<ov::intel_gpu::FullyConnectedPerLayerScaling>(config.get_property(ov::hint::activations_scale_factor));
if (!device_info.supports_immad) {
manager.register_pass<ov::intel_gpu::UnsqueezeBroadcastReshapeMatmulFusion>();
@@ -977,11 +1046,6 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
const size_t zp_pad_size = device_info.supports_immad ? 16 : 32;
manager.register_pass<ov::intel_gpu::BroadcastAndPadZeroPointBuffers>(zp_pad_size, device_info.supports_immad);
- manager.register_pass<ov::pass::RoPEFusion>(true);
- pass_config->disable<ov::pass::RoPEFusionGPTJ>();
- pass_config->disable<ov::pass::RoPEFusionIOSlicing>();
- pass_config->disable<ov::pass::RoPEShareCosSin>();
-
manager.register_pass<ov::intel_gpu::OptimizeSubsequentReshapes>();
manager.register_pass<ov::intel_gpu::IncreasePositionIdsPrecision>();
diff --git a/src/plugins/intel_gpu/src/runtime/execution_config.cpp b/src/plugins/intel_gpu/src/runtime/execution_config.cpp
index 3b1376d19b4..0372050657f 100644
--- a/src/plugins/intel_gpu/src/runtime/execution_config.cpp
+++ b/src/plugins/intel_gpu/src/runtime/execution_config.cpp
@@ -61,7 +61,7 @@ void ExecutionConfig::set_default() {
std::make_tuple(ov::hint::kv_cache_precision, ov::element::undefined),
std::make_tuple(ov::intel_gpu::hint::enable_kernels_reuse, false),
std::make_tuple(ov::weights_path, ""),
- std::make_tuple(ov::hint::activations_scale_factor, 0.f),
+ std::make_tuple(ov::hint::activations_scale_factor, -1.f),
// Legacy API properties
std::make_tuple(ov::intel_gpu::nv12_two_inputs, false),
diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/activations_scaling.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/activations_scaling.cpp
new file mode 100644
index 00000000000..0b315dc088a
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/activations_scaling.cpp
@@ -0,0 +1,228 @@
+// Copyright (C) 2023 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "common_test_utils/file_utils.hpp"
+#include "shared_test_classes/base/ov_subgraph.hpp"
+
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/result.hpp"
+#include "openvino/op/concat.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/add.hpp"
+#include "openvino/op/sqrt.hpp"
+#include "openvino/op/divide.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/power.hpp"
+#include "openvino/op/reduce_mean.hpp"
+
+namespace {
+using ov::test::InputShape;
+
+struct ShapeParams {
+ ShapeParams() = default;
+ ShapeParams(std::vector<InputShape> input_shape, std::vector<ov::Shape> weights_shapes)
+ : input_shape(std::move(input_shape)),
+ weights_shapes(std::move(weights_shapes)) {}
+
+ std::vector<InputShape> input_shape;
+ std::vector<ov::Shape> weights_shapes;
+};
+
+using ActivationsScalingParams = std::tuple<ShapeParams, // input shapes
+ ov::element::Type>; // input precision
+
+class ActivationsScaling : public testing::WithParamInterface<ActivationsScalingParams>,
+ virtual public ov::test::SubgraphBaseTest {
+public:
+ static std::string getTestCaseName(testing::TestParamInfo<ActivationsScalingParams> obj) {
+ ShapeParams shape_params;
+ ov::element::Type input_precision;
+
+ std::tie(shape_params, input_precision) = obj.param;
+
+ std::ostringstream result;
+ result << "IS=(";
+ for (const auto& shape : shape_params.input_shape) {
+ result << ov::test::utils::partialShape2str({shape.first}) << "_";
+ }
+ result << ")_TS=";
+ for (const auto& shape : shape_params.input_shape) {
+ result << "(";
+ if (!shape.second.empty()) {
+ auto itr = shape.second.begin();
+ do {
+ result << ov::test::utils::vec2str(*itr);
+ } while (++itr != shape.second.end() && result << "_");
+ }
+ result << ")_";
+ }
+ result << "input_precision=" << input_precision;
+ return result.str();
+ }
+
+protected:
+ // input
+ // / \_
+ // MatMul MutMul
+ // | |
+ // Add Add
+ // | |
+ // Variadic Reshape
+ // Split |
+ // / \ Transpose
+ // Add \ |
+ // / \ |
+ // Reshape Reshape |
+ // | | |
+ // Transpose Transpose /
+ // | \ / /
+ // | Add /
+ // | / \ /
+ // Concat Concat
+ // \ /
+ // Add
+ // |
+ // Output
+ std::shared_ptr<ov::Model> init_subgraph(const std::vector<ov::PartialShape>& input_shapes,
+ const std::vector<ov::Shape>& weights_shapes,
+ const ov::element::Type input_precision) {
+ ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(input_precision, input_shapes[0])};
+
+ const auto weights_tensor0 = ov::test::utils::create_and_fill_tensor(
+ input_precision, weights_shapes[0], ov::test::utils::InputGenerateData(-1, 2, 1357, 1));
+ auto weight0 = std::make_shared<ov::op::v0::Constant>(weights_tensor0);
+
+ const auto weights_tensor1 = ov::test::utils::create_and_fill_tensor(
+ input_precision, weights_shapes[1], ov::test::utils::InputGenerateData(-1, 2, 1357, 1));
+ auto weight1 = std::make_shared<ov::op::v0::Constant>(weights_tensor1);
+
+ auto matmul0 = std::make_shared<ov::op::v0::MatMul>(params[0], weight0, false, false);
+ auto matmul1 = std::make_shared<ov::op::v0::MatMul>(params[0], weight1, false, false);
+
+ std::vector<ov::Shape> bias_shape = {{weights_shapes[0][1]}, {weights_shapes[1][1]}};
+ const auto bias_tensor0 = ov::test::utils::create_and_fill_tensor(
+ input_precision, bias_shape[0], ov::test::utils::InputGenerateData(-1, 2, 1357, 1));
+ const auto bias_tensor1 = ov::test::utils::create_and_fill_tensor(
+ input_precision, bias_shape[1], ov::test::utils::InputGenerateData(-1, 2, 1357, 1));
+
+ auto bias0 = std::make_shared<ov::op::v0::Constant>(bias_tensor0);
+ auto bias1 = std::make_shared<ov::op::v0::Constant>(bias_tensor1);
+
+ auto add0 = std::make_shared<ov::op::v1::Add>(matmul0, bias0);
+ auto add1 = std::make_shared<ov::op::v1::Add>(matmul1, bias1);
+
+ int32_t last_size0 = static_cast<int32_t>(weights_shapes[0][1]);
+ auto axis0 = ov::op::v0::Constant::create(ov::element::i32, {1}, {2});
+ auto split_lengths0 = ov::op::v0::Constant::create(ov::element::i32, {2}, {last_size0/2, last_size0/2});
+ auto variadic_split0 = std::make_shared<ov::op::v1::VariadicSplit>(add0, axis0, split_lengths0);
+
+ ov::Shape bias_shape00 = {weights_shapes[0][1]/2};
+ const auto bias_tensor00 = ov::test::utils::create_and_fill_tensor(
+ input_precision, bias_shape00, ov::test::utils::InputGenerateData(-1, 2, 1357, 1));
+ auto bias00 = std::make_shared<ov::op::v0::Constant>(bias_tensor00);
+ auto add00 = std::make_shared<ov::op::v1::Add>(variadic_split0->output(0), bias00);
+
+ const std::vector<int32_t> reshape_target_shape = {0, -1, 16, (last_size0/32)};
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32,
+ {reshape_target_shape.size()},
+ reshape_target_shape);
+
+ auto reshape0 = std::make_shared<ov::op::v1::Reshape>(add00, reshape_const, true);
+ auto reshape1 = std::make_shared<ov::op::v1::Reshape>(variadic_split0->output(1), reshape_const, true);
+ auto reshape2 = std::make_shared<ov::op::v1::Reshape>(add1, reshape_const, true);
+
+ const std::vector<int32_t> transpose_order = {0, 2, 1, 3};
+ auto transpose_const = ov::op::v0::Constant::create(ov::element::i32,
+ {transpose_order.size()},
+ transpose_order);
+
+ auto transpose0 = std::make_shared<ov::op::v1::Transpose>(reshape0, transpose_const);
+ auto transpose1 = std::make_shared<ov::op::v1::Transpose>(reshape1, transpose_const);
+ auto transpose2 = std::make_shared<ov::op::v1::Transpose>(reshape2, transpose_const);
+
+ auto add12 = std::make_shared<ov::op::v1::Add>(transpose1, transpose2);
+
+ auto concat0 = std::make_shared<ov::op::v0::Concat>(ov::NodeVector{transpose0, add12}, 0);
+
+ auto concat1 = std::make_shared<ov::op::v0::Concat>(ov::NodeVector{add12, transpose2}, 0);
+
+ auto add = std::make_shared<ov::op::v1::Add>(concat0, concat1);
+
+ return std::make_shared<ov::Model>(ov::NodeVector{add}, params, "ActivationsScaling");
+ }
+
+ void SetUp() override {
+ targetDevice = ov::test::utils::DEVICE_GPU;
+
+ ShapeParams shape_params;
+ ov::element::Type input_precision;
+
+ std::tie(shape_params, input_precision) = GetParam();
+
+ init_input_shapes(shape_params.input_shape);
+
+ inType = outType = input_precision;
+
+ if (input_precision == ov::element::f16) {
+ abs_threshold = 1.0f;
+ } else {
+ abs_threshold = 1e-4f;
+ }
+
+ function = init_subgraph(inputDynamicShapes, shape_params.weights_shapes, input_precision);
+ }
+
+ void validate() override {
+ ov::test::SubgraphBaseTest::validate();
+
+ ov::element::Type input_precision = function->input(0).get_element_type();
+ auto runtime_model = compiledModel.get_runtime_model();
+
+ for (auto& op : runtime_model->get_ordered_ops()) {
+ ASSERT_EQ(op->output(0).get_element_type(), input_precision)
+ << "expected output precision is " << input_precision << " , while actual is " << op->output(0).get_element_type();
+ }
+ }
+};
+
+TEST_P(ActivationsScaling, Inference) {
+ core->set_property(targetDevice, ov::hint::activations_scale_factor(4.3));
+ run();
+}
+
+TEST_P(ActivationsScaling, Inference_cached) {
+ std::stringstream ss;
+ ss << "gpu_model_cache_" << std::hash<std::string>{}(
+ std::string(::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name()) +
+ std::string(::testing::UnitTest::GetInstance()->current_test_info()->name()));
+ std::string cacheDirName = ss.str();
+ {
+ ov::test::utils::removeFilesWithExt(cacheDirName, "blob");
+ ov::test::utils::removeFilesWithExt(cacheDirName, "cl_cache");
+ ov::test::utils::removeDir(cacheDirName);
+ core->set_property(ov::cache_dir(cacheDirName));
+ compile_model();
+ }
+ {
+ run();
+ ov::test::utils::removeFilesWithExt(cacheDirName, "blob");
+ ov::test::utils::removeFilesWithExt(cacheDirName, "cl_cache");
+ ov::test::utils::removeDir(cacheDirName);
+ }
+}
+
+const std::vector<ov::element::Type> input_precisions = {ov::element::f16};
+
+const std::vector<ShapeParams> input_shapes = {
+ {{{{-1, 32, 128}, {{1, 32, 128}}}}, {{128, 128}, {128, 64}}},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_ActivationsScaling_basic,
+ ActivationsScaling,
+ ::testing::Combine(::testing::ValuesIn(input_shapes),
+ ::testing::ValuesIn(input_precisions)),
+ ActivationsScaling::getTestCaseName);
+} // namespace
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/clamp_fp16_output_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/clamp_fp16_output_test.cpp
index b5cb1671c45..380f2ee9550 100644
--- a/src/plugins/intel_gpu/tests/unit/transformations/clamp_fp16_output_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/transformations/clamp_fp16_output_test.cpp
@@ -68,12 +68,12 @@ TEST_F(TransformationTestsF, ClampFp16OutputTest2) {
auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{ 3, 2, 2 });
auto input2 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{ 1, 2, 2 });
auto matmul = std::make_shared<ov::op::v0::MatMul>(input1, input2, true, false);
+ auto target_shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{ 2 }, { 3, 4 });
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(matmul, target_shape, false);
auto min = static_cast<double>(std::numeric_limits<ov::float16>::lowest());
auto max = static_cast<double>(std::numeric_limits<ov::float16>::max());
- auto clamp = std::make_shared<ov::op::v0::Clamp>(matmul, min, max);
- auto target_shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{ 2 }, { 3, 4 });
- auto reshape = std::make_shared<ov::op::v1::Reshape>(clamp, target_shape, false);
- auto softmax = std::make_shared<ov::op::v8::Softmax>(reshape, 1);
+ auto clamp = std::make_shared<ov::op::v0::Clamp>(reshape, min, max);
+ auto softmax = std::make_shared<ov::op::v8::Softmax>(clamp, 1);
model_ref = std::make_shared<ov::Model>(ov::NodeVector{ softmax }, ov::ParameterVector{ input1, input2 });
}
@@ -128,12 +128,12 @@ TEST_F(TransformationTestsF, ClampFp16OutputTest5) {
auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{ 3, 2, 2 });
auto input2 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{ 1, 2, 2 });
auto matmul = std::make_shared<ov::op::v0::MatMul>(input1, input2, true, false);
+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{ 3, 2, 2 });
+ auto add = std::make_shared<ov::op::v1::Add>(matmul, data);
auto min = static_cast<double>(std::numeric_limits<ov::float16>::lowest());
auto max = static_cast<double>(std::numeric_limits<ov::float16>::max());
- auto clamp = std::make_shared<ov::op::v0::Clamp>(matmul, min, max);
- auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{ 3, 2, 2 });
- auto add = std::make_shared<ov::op::v1::Add>(clamp, data);
- auto softmax = std::make_shared<ov::op::v8::Softmax>(add, 1);
+ auto clamp = std::make_shared<ov::op::v0::Clamp>(add, min, max);
+ auto softmax = std::make_shared<ov::op::v8::Softmax>(clamp, 1);
model_ref = std::make_shared<ov::Model>(ov::NodeVector{ softmax }, ov::ParameterVector{ input1, input2, data });
}