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
[def/transformations]: Fix for failing roblox model at ConvertPrecision transformation (#27298)
Piotr Kowalczyk9235543beb6f
diff --git a/src/common/transformations/src/transformations/convert_precision.cpp b/src/common/transformations/src/transformations/convert_precision.cppindex c34e91f8353..3ab2c694be4 100644--- a/src/common/transformations/src/transformations/convert_precision.cpp+++ b/src/common/transformations/src/transformations/convert_precision.cpp@@ -62,6 +62,8 @@ bool fuse_type_to_ctc_greedy_decoder_seq_len(const std::shared_ptr<ov::Node>& nobool fuse_type_to_random_uniform_v8(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions);+bool fuse_type_to_search_sorted_v15(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions);+bool extend_select_type(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions);bool extend_reverse_type(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions);@@ -468,7 +470,8 @@ bool ov::pass::ConvertPrecision::run_on_model(const std::shared_ptr<ov::Model>&{ov::op::v13::Multinomial::get_type_info_static(), fuse_type_to_multinomial_v13},{ov::op::v0::PriorBox::get_type_info_static(), fuse_type_to_prior_box<ov::op::v0::PriorBox>},{ov::op::v8::PriorBox::get_type_info_static(), fuse_type_to_prior_box<ov::op::v8::PriorBox>},- {ov::op::v0::PriorBoxClustered::get_type_info_static(), fuse_type_to_prior_box<ov::op::v0::PriorBoxClustered>}};+ {ov::op::v0::PriorBoxClustered::get_type_info_static(), fuse_type_to_prior_box<ov::op::v0::PriorBoxClustered>},+ {ov::op::v15::SearchSorted::get_type_info_static(), fuse_type_to_search_sorted_v15}};for (const auto& it : m_additional_type_to_fuse_map) {type_to_fuse[it.first] = it.second;@@ -553,6 +556,18 @@ bool fuse_type_to_unique_v10(const std::shared_ptr<Node>& node, const precisionsreturn res;}+bool fuse_type_to_search_sorted_v15(const std::shared_ptr<Node>& node, const precisions_map& precisions) {+ bool res = false;+ if (auto op = ov::as_type_ptr<ov::op::v15::SearchSorted>(node)) {+ auto it = precisions.find(node->get_output_element_type(0));+ if (it != precisions.end()) {+ op->set_output_type_attr(it->second);+ res = true;+ }+ }+ return res;+}+bool fuse_type_to_range_v4(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {auto it = precisions.find(node->get_output_element_type(0));if (it == precisions.end())diff --git a/src/common/transformations/tests/utils/convert_precision.cpp b/src/common/transformations/tests/utils/convert_precision.cppindex 9554cf09162..2aa4d4d2fac 100644--- a/src/common/transformations/tests/utils/convert_precision.cpp+++ b/src/common/transformations/tests/utils/convert_precision.cpp@@ -15,6 +15,7 @@#include "openvino/core/model.hpp"#include "openvino/opsets/opset1.hpp"#include "openvino/opsets/opset10.hpp"+#include "openvino/opsets/opset15.hpp"#include "openvino/opsets/opset3.hpp"#include "openvino/opsets/opset4.hpp"#include "openvino/opsets/opset5.hpp"@@ -1036,6 +1037,28 @@ TEST(TransformationTests, ConvertPrecision_TypeRelaxed) {}}+TEST(TransformationTests, ConvertPrecision_SearchSorted) {+ std::shared_ptr<Model> f(nullptr);+ {+ auto search_sorted_input = opset15::Constant::create(ov::element::i64, {5}, {1, 2, 3, 4, 5});+ auto indices = std::make_shared<opset15::Parameter>(ov::element::i64, Shape{3});+ auto search_sorted = std::make_shared<opset15::SearchSorted>(search_sorted_input, indices);++ auto less_input = opset15::Constant::create(ov::element::i64, {3}, {4, 5, 6});+ auto less = std::make_shared<opset15::Less>(search_sorted, less_input);++ f = std::make_shared<Model>(OutputVector{less}, ParameterVector{indices});++ pass::Manager manager;+ manager.register_pass<pass::InitNodeInfo>();+ manager.register_pass<pass::ConvertPrecision>(precisions_map{{element::i64, element::i32}});+ manager.run_passes(f);+ }+ OV_ASSERT_NO_THROW(check_rt_info(f));+ ASSERT_FALSE(has_type<element::Type_t::i64>(f));+ ASSERT_TRUE(has_type<element::Type_t::i32>(f));+}+TEST(TransformationTests, ConvertPrecision_Variables) {std::shared_ptr<Model> f(nullptr);{diff --git a/src/core/include/openvino/op/search_sorted.hpp b/src/core/include/openvino/op/search_sorted.hppindex c370ba46b2f..efb1f8491e0 100644--- a/src/core/include/openvino/op/search_sorted.hpp+++ b/src/core/include/openvino/op/search_sorted.hpp@@ -22,7 +22,15 @@ public:/// \param values Values to search indexs for./// \param right_mode If False, return the first suitable index that is found for given value. If True, return/// the last such index.- SearchSorted(const Output<Node>& sorted_sequence, const Output<Node>& values, bool right_mode = false);+ /// \param output_type The element type of the output tensor. This is purely an implementation flag, which+ /// is used to convert the output type for CPU plugin in ConvertPrecision transformation (and potentially other+ /// plugins as well). Setting this flag to element::i32 will result in the output tensor of i32 element type.+ /// Setting this flag to element::i64 will generally not give any effect, since it will be converted to i32 anyway,+ /// at least for CPU plugin.+ SearchSorted(const Output<Node>& sorted_sequence,+ const Output<Node>& values,+ bool right_mode = false,+ const element::Type& output_type = element::i64);void validate_and_infer_types() override;bool visit_attributes(AttributeVisitor& visitor) override;@@ -36,8 +44,17 @@ public:m_right_mode = right_mode;}+ void set_output_type_attr(const element::Type& output_type) {+ m_output_type = output_type;+ }++ element::Type get_output_type_attr() const {+ return m_output_type;+ }+private:bool m_right_mode{};+ element::Type m_output_type = element::i64;};} // namespace v15} // namespace opdiff --git a/src/core/src/op/search_sorted.cpp b/src/core/src/op/search_sorted.cppindex 8b9bb012b27..65b5ff31861 100644--- a/src/core/src/op/search_sorted.cpp+++ b/src/core/src/op/search_sorted.cpp@@ -12,9 +12,13 @@ namespace ov {namespace op {namespace v15 {-SearchSorted::SearchSorted(const Output<Node>& sorted_sequence, const Output<Node>& values, bool right_mode)+SearchSorted::SearchSorted(const Output<Node>& sorted_sequence,+ const Output<Node>& values,+ bool right_mode,+ const element::Type& output_type): Op({sorted_sequence, values}),- m_right_mode(right_mode) {+ m_right_mode(right_mode),+ m_output_type(output_type) {constructor_validate_and_infer_types();}@@ -23,20 +27,25 @@ void SearchSorted::validate_and_infer_types() {NODE_VALIDATION_CHECK(this,get_input_element_type(0).compatible(get_input_element_type(1)),"Sorted sequence and values must have the same element type.");+ NODE_VALIDATION_CHECK(this,+ m_output_type == element::i32 || m_output_type == element::i64,+ "The element type of the last output can only be set to i32 or i64.");+const auto& output_shapes = shape_infer(this, ov::util::get_node_input_partial_shapes(*this));- set_output_type(0, ov::element::i64, output_shapes[0]);+ set_output_type(0, m_output_type, output_shapes[0]);}bool SearchSorted::visit_attributes(AttributeVisitor& visitor) {OV_OP_SCOPE(v15_SearchSorted_visit_attributes);visitor.on_attribute("right_mode", m_right_mode);+ visitor.on_attribute("output_type", m_output_type);return true;}std::shared_ptr<Node> SearchSorted::clone_with_new_inputs(const OutputVector& new_args) const {OV_OP_SCOPE(v15_SearchSorted_clone_with_new_inputs);check_new_args_count(this, new_args);- return std::make_shared<SearchSorted>(new_args.at(0), new_args.at(1), get_right_mode());+ return std::make_shared<SearchSorted>(new_args.at(0), new_args.at(1), get_right_mode(), get_output_type_attr());}} // namespace v15} // namespace opdiff --git a/src/core/tests/visitors/op/sorted_search.cpp b/src/core/tests/visitors/op/sorted_search.cppindex 860c9528d0e..10d544527f3 100644--- a/src/core/tests/visitors/op/sorted_search.cpp+++ b/src/core/tests/visitors/op/sorted_search.cpp@@ -22,7 +22,7 @@ TEST(attributes, search_sorted_op) {auto g_op = ov::as_type_ptr<TOp>(builder.create());// attribute count- const auto expected_attr_count = 1;+ const auto expected_attr_count = 2;EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);// space_to_depth attributes