Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "openvino/op/multiply.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/divide.hpp"
#include "openvino/op/select.hpp"
#include "openvino/core/rt_info.hpp"
#include "openvino/pass/pattern/op/pattern.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
Expand All @@ -38,10 +39,12 @@ ClampFP16OutputSoftmaxMatcher::ClampFP16OutputSoftmaxMatcher() {
auto in1 = any_input(class_other_than<v0::Constant>());
auto matmul_m = wrap_type<v0::MatMul>({in0, in1}, type_matches(ov::element::f16) && consumers_count(1));
auto reshape_m = wrap_type<v1::Reshape>({matmul_m, any_input()}, type_matches(ov::element::f16) && consumers_count(1));
auto add_m = wrap_type<v1::Add>({matmul_m, any_input()}, type_matches(ov::element::f16) && consumers_count(1));
auto eltwise_m = wrap_type<v1::Divide, v1::Add, v1::Multiply, v1::Subtract>({matmul_m, any_input()},
type_matches(ov::element::f16) && consumers_count(1));
auto softmax_input_m = std::make_shared<Or>(ov::OutputVector{eltwise_m, reshape_m, matmul_m});
auto input_m = std::make_shared<Or>(ov::OutputVector{matmul_m, eltwise_m, reshape_m});
auto select_then_m = wrap_type<v1::Select>({any_input(), input_m, any_input()}, type_matches(ov::element::f16) && consumers_count(1));
auto select_else_m = wrap_type<v1::Select>({any_input(), any_input(), input_m}, type_matches(ov::element::f16) && consumers_count(1));
auto softmax_input_m = std::make_shared<Or>(ov::OutputVector{select_then_m, select_else_m, input_m});
auto softmax_m = wrap_type<v8::Softmax>({softmax_input_m}, type_matches(ov::element::f16));

ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "openvino/op/maximum.hpp"
#include "openvino/op/matmul.hpp"
#include "openvino/op/softmax.hpp"
#include "openvino/op/select.hpp"
#include <plugin/transformations/clamp_fp16_output.hpp>
#include <transformations/init_node_info.hpp>
#include <transformations/utils/utils.hpp>
Expand Down Expand Up @@ -159,6 +160,36 @@ TEST_F(TransformationTestsF, ClampFp16OutputTest6) {
comparator.enable(FunctionsComparator::CmpValues::ATTRIBUTES);
}

TEST_F(TransformationTestsF, ClampFp16OutputTest7) {
{
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 cond = std::make_shared<ov::op::v0::Parameter>(ov::element::boolean, ov::Shape{ 3, 2, 2 });
auto select = std::make_shared<ov::op::v1::Select>(cond, data, matmul);
auto softmax = std::make_shared<ov::op::v8::Softmax>(select, 1);

model = std::make_shared<ov::Model>(ov::OutputVector{softmax}, ov::ParameterVector{input1, input2, data, cond});
manager.register_pass<ClampFP16Output>();
}
{
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 cond = std::make_shared<ov::op::v0::Parameter>(ov::element::boolean, ov::Shape{ 3, 2, 2 });
auto select = std::make_shared<ov::op::v1::Select>(cond, data, matmul);
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>(select, min, max);
auto softmax = std::make_shared<ov::op::v8::Softmax>(clamp, 1);

model_ref = std::make_shared<ov::Model>(ov::OutputVector{softmax}, ov::ParameterVector{input1, input2, data, cond});
}
comparator.enable(FunctionsComparator::CmpValues::ATTRIBUTES);
}

TEST_F(TransformationTestsF, ClampFp16OutputRMS) {
{
auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{ -1, -1, 2560 });
Expand Down
Loading