OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU] applying activations scaling if decompressed_to_f32 is present (#33964)
Eddy Kim74d5eac01e94
diff --git a/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp b/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cppindex 72bd0f02e5c..c4805044a85 100644--- a/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp@@ -100,13 +100,13 @@ activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(float scale_factif (transformation_callback(scaled_op))return false;- // in the case of decompressed_to_f32 nodes, no need to apply activations scaling+ // If a decompressed_to_f32 Convert node is present, we need to add scale_up layer after it.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<v0::Convert>(child_node) &&ov::fp16_compression_is_disabled(child_node->shared_from_this()) &&constant_folding_is_disabled(child_node->shared_from_this())) {- return false;+ output_of_scaled_op = child_node->shared_from_this();}const std::vector<float> scale_up_value = {scale_factor};diff --git a/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp b/src/common/transformations/tests/common_optimizations/activations_scaling_test.cppindex 4bf9f2d2a79..9ea6fe7204d 100644--- a/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp+++ b/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp@@ -15,6 +15,7 @@#include "openvino/op/constant.hpp"#include "openvino/op/convolution.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/parameter.hpp"@@ -22,6 +23,8 @@#include "openvino/op/shape_of.hpp"#include "openvino/op/variadic_split.hpp"#include "openvino/pass/manager.hpp"+#include "transformations/common_optimizations/lin_op_sequence_fusion.hpp"+#include "transformations/common_optimizations/nop_elimination.hpp"#include "transformations/utils/utils.hpp"using namespace ov;@@ -73,6 +76,43 @@ TEST_F(TransformationTestsF, ScaleDownSingleLayerTest) {}}+TEST_F(TransformationTestsF, ScaleDownSingleLayerTest_f32) {+ float scale_factor = 128.f;+ {+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{1, 16});+ auto weights_const0 = v0::Constant::create(ov::element::f16, ov::Shape{16, 8}, {1});+ auto matmul0 = std::make_shared<v0::MatMul>(input, weights_const0);+ auto weights_const1 = v0::Constant::create(ov::element::f16, ov::Shape{8, 16}, {1});+ auto matmul1 = std::make_shared<v0::MatMul>(matmul0, weights_const1);+ auto convert = std::make_shared<v0::Convert>(matmul1, ov::element::f32);+ disable_fp16_compression(convert);+ disable_constant_folding(convert);+ auto convert_f16 = std::make_shared<v0::Convert>(convert, ov::element::f16);+ auto result = std::make_shared<v0::Result>(convert_f16);++ 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);+ manager.register_pass<ov::pass::MultiplyMultiplyFusion>();+ manager.register_pass<ov::pass::EliminateEltwise>();+ }+ {+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{1, 16});+ auto weights_const0 = v0::Constant::create(ov::element::f16, ov::Shape{16, 8}, {1});+ auto scale_down_const = v0::Constant::create(ov::element::f16, ov::Shape{}, {1.f / scale_factor});+ auto scale_down = std::make_shared<v1::Multiply>(input, scale_down_const);+ auto matmul0 = std::make_shared<v0::MatMul>(scale_down, weights_const0);+ auto weights_const1 = v0::Constant::create(ov::element::f16, ov::Shape{8, 16}, {1});+ auto matmul1 = std::make_shared<v0::MatMul>(matmul0, weights_const1);+ auto convert = std::make_shared<v0::Convert>(matmul1, ov::element::f32);+ auto scale_up_const = v0::Constant::create(ov::element::f32, ov::Shape{}, {scale_factor});+ auto scale_up = std::make_shared<v1::Multiply>(convert, scale_up_const);+ auto convert_f16 = std::make_shared<v0::Convert>(scale_up, ov::element::f16);+ auto result = std::make_shared<v0::Result>(convert_f16);++ model_ref = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});+ }+}+TEST_F(TransformationTestsF, EliminateScalarMulTest) {double epsilon = 1.f;float scale_factor = 8.f;