Skip to content

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

Completely remove makePattern() (#32180)

Andrii Staikovf0e1e64f20ad
diff --git a/src/common/transformations/include/transformations/utils/gen_pattern.hpp b/src/common/transformations/include/transformations/utils/gen_pattern.hpp
index 5fa7de33163..10e8386b351 100644
--- a/src/common/transformations/include/transformations/utils/gen_pattern.hpp
+++ b/src/common/transformations/include/transformations/utils/gen_pattern.hpp
@@ -7,28 +7,14 @@
# pragma warning(disable : 4244)
#endif
-#include <algorithm>
-#include <cassert>
-#include <cfloat>
#include <climits>
-#include <cmath>
-#include <cstdlib>
-#include <fstream>
-#include <iomanip>
-#include <iostream>
-#include <map>
-#include <memory>
#include <sstream>
-#include <string>
-#include <utility>
#include "openvino/core/log_util.hpp"
#include "openvino/core/type/element_type.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/parameter.hpp"
-#include "openvino/op/slice.hpp"
-#include "openvino/op/strided_slice.hpp"
#include "openvino/op/util/variable.hpp"
#include "openvino/opsets/opset1_decl.hpp"
#include "openvino/opsets/opset2_decl.hpp"
@@ -39,7 +25,6 @@
#include "openvino/opsets/opset7_decl.hpp"
#include "openvino/opsets/opset8_decl.hpp"
#include "openvino/pass/pattern/matcher.hpp"
-#include "openvino/pass/pattern/op/label.hpp"
#include "openvino/pass/pattern/op/or.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "openvino/util/log.hpp"
@@ -48,15 +33,6 @@ namespace ov {
namespace gen_pattern {
#ifdef CPU_DEBUG_CAPS
-
-# ifdef __GNUC__
-# define CURRENT_LINE_NO __builtin_LINE()
-# define CURRENT_FILE __builtin_FILE()
-# else
-# define CURRENT_LINE_NO -1
-# define CURRENT_FILE ""
-# endif
-
template <typename... Args>
static inline void _verbose_log(Args&&... args) {
std::stringstream ss;
@@ -75,256 +51,19 @@ static bool matcher_verbose_enabled() {
if (matcher_verbose_enabled()) \
_verbose_log(__VA_ARGS__)
#else
-
-# define CURRENT_LINE_NO -1
-# define CURRENT_FILE ""
-
-static bool matcher_verbose_enabled() {
- return false;
-}
-
# define _VERBOSE_LOG(...)
#endif
namespace detail {
-inline std::vector<std::string> split_string(const std::string& s, const std::string& delimiter) {
- std::vector<std::string> ret;
- size_t pos = 0, pos_next;
- std::string token;
- while ((pos_next = s.find(delimiter, pos)) != std::string::npos) {
- token = s.substr(pos, pos_next - pos);
- ret.push_back(token);
- pos = pos_next + 1;
- }
- // return whole string if no delimiter if found
- token = s.substr(pos, pos_next);
- ret.push_back(token);
- return ret;
-}
-
-template <typename T>
-std::string vec2str(const std::vector<T>& vec, int cnt_limit = 9) {
- std::stringstream ss;
- ss << "{";
- const char* sep = "";
- for (auto& v : vec) {
- cnt_limit--;
- if (cnt_limit == 0) {
- ss << sep << "...";
- break;
- }
- ss << sep << v;
- sep = ",";
- }
- ss << "}";
- return ss.str();
-}
-} // namespace detail
-
-struct values_info {
- values_info(const char* pattern_list = nullptr) {
- if (pattern_list == nullptr || pattern_list[0] == 0) {
- all_type_pshape.clear();
- return;
- }
- auto pattern_vector = detail::split_string(pattern_list, " ");
- for (auto& pattern : pattern_vector) {
- if (pattern[0] == '[') {
- all_type_pshape.emplace_back(ov::element::dynamic, ov::PartialShape(pattern));
- } else {
- auto sep = pattern.find("[");
- if (sep != std::string::npos) {
- // ele_type[p_shape]
- all_type_pshape.emplace_back(ov::element::Type(pattern.substr(0, sep)),
- ov::PartialShape(pattern.substr(sep)));
- } else {
- // ele_type
- all_type_pshape.emplace_back(ov::element::Type(pattern), ov::PartialShape::dynamic());
- }
- }
- }
- }
-
- size_t size() {
- return all_type_pshape.size();
- }
- const std::pair<ov::element::Type, ov::PartialShape>& operator[](int index) {
- return all_type_pshape[index];
- }
-
- //-------------------------------------------------------------
- bool predicate(const ov::Output<ov::Node>& value) const {
- if (all_type_pshape.empty())
- return true;
- auto index = value.get_index();
- if (index >= all_type_pshape.size()) {
- _VERBOSE_LOG("* mismatched vtype : value from output port ",
- index,
- ", but only ",
- all_type_pshape.size(),
- " ports are expected!");
- return false;
- }
- auto& item = all_type_pshape[index];
- if (!item.first.compatible(value.get_element_type()) || !item.second.compatible(value.get_partial_shape())) {
- _VERBOSE_LOG("* mismatched vtype between value & pattern : ",
- value.get_element_type(),
- value.get_partial_shape(),
- "vs",
- item.first,
- item.second);
- return false;
- }
- return true;
- }
-
- std::string to_string() {
- std::stringstream ss;
- const char* sep = "";
- for (auto& t : all_type_pshape) {
- ss << sep << t.first << t.second;
- sep = ";";
- }
- return ss.str();
- }
-
- std::vector<std::pair<ov::element::Type, ov::PartialShape>> all_type_pshape;
-};
-
-// Symbol : a constant that unknown at the pattern's building time
-// but collected and validated after pattern was matched
-// with some sub-graph values.
-class Symbol {
-private:
- struct Entity {
- const char* name = "?";
- char op;
- double literal_const_value;
- std::shared_ptr<Entity> lhs;
- std::shared_ptr<Entity> rhs;
- const char* filename = "";
- int line_no = -1;
- // _,+,-,*,/
- // l : literal const
- // n : named symbol
- double eval(const std::map<const void*, double>& value_map) const {
- switch (op) {
- case 'l':
- return literal_const_value;
- case 'n':
- return value_map.at(this);
- case '+':
- return lhs->eval(value_map) + rhs->eval(value_map);
- case '-':
- return lhs->eval(value_map) - rhs->eval(value_map);
- case '*':
- return lhs->eval(value_map) * rhs->eval(value_map);
- case '/':
- return lhs->eval(value_map) / rhs->eval(value_map);
- case '_':
- return -lhs->eval(value_map);
- case 'r':
- return std::sqrt(lhs->eval(value_map));
- default:
- assert(false);
- return std::numeric_limits<double>::quiet_NaN();
- }
- }
- };
- std::shared_ptr<Entity> entity;
-
-public:
- Symbol() {
- entity = std::make_shared<Entity>();
- entity->op = 'n';
- }
- Symbol(const char* name) {
- entity = std::make_shared<Entity>();
- entity->op = 'n';
- entity->name = name;
- }
- Symbol(const int value, int line_no = CURRENT_LINE_NO, const char* file = CURRENT_FILE) {
- entity = std::make_shared<Entity>();
- entity->op = 'l';
- entity->literal_const_value = value;
- entity->line_no = line_no;
- entity->filename = file;
- }
- Symbol(char op, const Symbol& lhs, const Symbol& rhs) {
- entity = std::make_shared<Entity>();
- entity->op = op;
- entity->lhs = lhs.entity;
- entity->rhs = rhs.entity;
- }
- double eval(const std::map<const void*, double>& value_map) const {
- return entity->eval(value_map);
- }
- bool is_independent_var() const {
- return entity->op == 'n';
- }
- int is_literal_const() const {
- return entity->op == 'l';
- }
- char get_op() const {
- return entity->op;
- }
- void* get_id() const {
- return entity.get();
- }
- std::string get_name() const {
- if (entity->line_no == -1 || is_independent_var())
- return entity->name;
- auto filename = strrchr(entity->filename, '/') ? strrchr(entity->filename, '/') + 1 : entity->filename;
- std::string name(filename); // use filename:lineno instead
- return name + ":" + std::to_string(entity->line_no);
- }
- bool operator<(const Symbol& rhs) const {
- return get_id() < rhs.get_id();
- }
- bool validate = true;
-};
-
-inline Symbol operator-(const Symbol& lhs) {
- return Symbol('_', lhs, lhs);
-}
-inline Symbol operator+(const Symbol& lhs, const Symbol& rhs) {
- return Symbol('+', lhs, rhs);
-}
-inline Symbol operator-(const Symbol& lhs, const Symbol& rhs) {
- return Symbol('-', lhs, rhs);
-}
-inline Symbol operator*(const Symbol& lhs, const Symbol& rhs) {
- return Symbol('*', lhs, rhs);
-}
-inline Symbol operator/(const Symbol& lhs, const Symbol& rhs) {
- return Symbol('/', lhs, rhs);
-}
-inline Symbol sqrt(Symbol lhs) {
- return Symbol('r', lhs, lhs);
-}
-
-namespace detail {
-
-using SymbolObservationVector = std::vector<std::pair<Symbol, double>>;
-
-template <typename T>
-void add_symbol_observed(SymbolObservationVector& sov, const Symbol& sym, const T& value) {
- auto v = static_cast<double>(value);
- OPENVINO_ASSERT(static_cast<T>(v) == value); // ensure there is no precison lost in double
- sov.push_back(std::make_pair(sym, v));
-}
-
// AttrAny is simple wrapper of Any to provide some constructor
// to take advantage of C++ implicit conversion to allow:
// - attribute expressed using initializer_list.
-// - symbol to be used as attributes
struct AttrAny {
ov::Any any;
// empty attribute, means empty vector, and error for scalar
AttrAny() {}
- AttrAny(const Symbol& v) : any(v) {}
AttrAny(const ov::element::Type& v) : any(v) {}
AttrAny(const ov::PartialShape& v) : any(v) {}
AttrAny(const ov::Dimension& v) : any(v) {}
@@ -337,16 +76,8 @@ struct AttrAny {
AttrAny(const char* v) : any(v) {}
AttrAny(const std::string& v) : any(v) {}
- // template <typename T, typename std::enable_if<std::is_arithmetic<T>::value>::type = true>
- // AttrAny(const T& v) : any(v) {}
-
- // template <typename T, typename std::enable_if<std::is_arithmetic<T>::value>::type = true>
- // AttrAny(const std::vector<T>& v) : any(v) {}
-
AttrAny(const std::vector<int64_t>& v) : any(v) {}
- // template <typename T, typename std::enable_if<std::is_arithmetic<T>::value>::type = true>
- // AttrAny(std::initializer_list<T> values) : any(std::vector<T>(values)) {}
AttrAny(std::initializer_list<int> values) : any(std::vector<int>(values)) {}
AttrAny(std::initializer_list<long> values) : any(std::vector<int64_t>(values.begin(), values.end())) {}
AttrAny(std::initializer_list<float> values) : any(std::vector<float>(values)) {}
@@ -517,11 +248,6 @@ public:
return true;
}
- if (m_attr_map[name].any.is<Symbol>()) {
- m_missing_attrs.push_back(name);
- return true;
- }
-
if (m_attr_map[name].any.empty()) {
// input is set to empty, meaning default value is used.
return true;
@@ -614,270 +340,6 @@ public:
}
};
-// for arithmetic data type, Attr matcher will success as long as the actuall attributes
-// is equal to the casted attributes from pattern w/o requiring exact type match.
-class AttrMatcher : public ov::AttributeVisitor {
-public:
- AttrMap& m_attr_map;
- std::vector<std::string> m_missing_attrs;
- SymbolObservationVector* m_psov;
- bool m_all_matched;
-
- AttrMatcher(AttrMap& attrs, SymbolObservationVector* psov = nullptr)
- : m_attr_map(attrs),
- m_psov(psov),
- m_all_matched(true) {}
-
- bool matched() {
- return m_all_matched;
- }
-
- const std::vector<std::string>& get_missing_attrs() {
- return m_missing_attrs;
- }
-
- bool should_skip(const std::string& name, bool allow_symbol = false) {
- if (m_attr_map.count(name) == 0) {
- m_missing_attrs.push_back(name);
- return true;
- }
-
- if (!allow_symbol) {
- OPENVINO_ASSERT(!m_attr_map[name].any.is<Symbol>(), "Symbol is not allowed.");
- }
- return false;
- }
-
- void add_match_result(const std::string& name, bool is_matched) {
- if (!is_matched) {
- _VERBOSE_LOG(" attribute '", name, "' mismatch.");
- }
- m_all_matched = m_all_matched && is_matched;
- }
-
- void on_adapter(const std::string& name, ov::ValueAccessor<std::string>& value) override {
- if (should_skip(name))
- return;
- add_match_result(name, value.get() == m_attr_map[name].as_string());
- }
- void on_adapter(const std::string& name, ov::ValueAccessor<bool>& value) override {
- if (should_skip(name))
- return;
- add_match_result(name, m_attr_map[name].equal_to<bool, int, float>(value.get()));
- }
- void on_adapter(const std::string& name, ov::ValueAccessor<double>& value) override {
- if (should_skip(name))
- return;
- add_match_result(name, m_attr_map[name].equal_to<double, int, float>(value.get()));
- }
- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int32_t>>& value) override {
- if (should_skip(name))
- return;
- add_match_result(name, m_attr_map[name].equal_to<int, int64_t>(value.get()));
- }
-
- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<int64_t>>& value) override {
- if (should_skip(name))
- return;
- add_match_result(name, m_attr_map[name].equal_to<int64_t, int>(value.get()));
- }
-
- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<float>>& value) override {
- if (should_skip(name))
- return;
- add_match_result(name, m_attr_map[name].equal_to<float, int>(value.get()));
- }
-
- void on_adapter(const std::string& name, ov::ValueAccessor<std::vector<std::string>>& value) override {
- if (should_skip(name))
- return;
- add_match_result(name, m_attr_map[name].equal_to<std::string, const char*>(value.get()));
- }
-
- // only integer is allowed to be of symbol type
- void on_adapter(const std::string& name, ov::ValueAccessor<int32_t>& value) override {
- if (should_skip(name, true))
- return;
- auto& any = m_attr_map[name].any;
- if (any.is<Symbol>()) {
- if (m_psov) {
- // collect symbol reference and do comparison later
- add_symbol_observed(*m_psov, any.as<Symbol>(), value.get());
- }
- return;
- }
- add_match_result(name, m_attr_map[name].cast_to<int32_t>() == value.get());
- }
- void on_adapter(const std::string& name, ov::ValueAccessor<int64_t>& value) override {
- if (should_skip(name, true))
- return;
- auto& any = m_attr_map[name].any;
- if (any.is<Symbol>()) {
- if (m_psov) {
- // collect symbol reference and do comparison later
- add_symbol_observed(*m_psov, any.as<Symbol>(), value.get());
- }
- return;
- }
- add_match_result(name, m_attr_map[name].cast_to<int64_t>() == value.get());
- }
-
- void on_adapter(const std::string& name, ov::ValueAccessor<void>& adapter) override {
- if (should_skip(name))
- return;
- OPENVINO_ASSERT(m_attr_map.count(name) > 0);
- auto& any = m_attr_map[name].any;
- bool is_matched = true;
- if (auto a = ov::as_type<ov::AttributeAdapter<ov::element::Type>>(&adapter)) {
- is_matched = (static_cast<ov::element::Type&>(*a) == any.as<ov::element::Type>());
- } else if (auto a = ov::as_type<ov::AttributeAdapter<PartialShape>>(&adapter)) {
- is_matched = (a->get() == any.as<PartialShape>());
- } else if (auto a = ov::as_type<ov::AttributeAdapter<Dimension>>(&adapter)) {
- is_matched = (a->get() == any.as<Dimension>());
- } else if (auto a = ov::as_type<ov::AttributeAdapter<ov::Shape>>(&adapter)) {
- is_matched = m_attr_map[name].equal_to<int64_t, int>(a->get());
- } else if (auto a = ov::as_type<ov::AttributeAdapter<ov::Strides>>(&adapter)) {
- is_matched = m_attr_map[name].equal_to<int64_t, int>(a->get());
- } else if (auto a = ov::as_type<ov::AttributeAdapter<std::vector<size_t>>>(&adapter)) {
-#if defined(__APPLE__) || defined(__EMSCRIPTEN__)
- is_matched = m_attr_map[name].equal_to<size_t, int>(static_cast<std::vector<size_t>&>(*a));
-#else
- is_matched = m_attr_map[name].equal_to<size_t, int>(a->get());
-#endif
- } else if (auto a = ov::as_type<ov::AttributeAdapter<ov::AxisSet>>(&adapter)) {
- is_matched = m_attr_map[name].equal_to<int64_t, int>(a->get());
- } else if (auto a = ov::as_type<ov::AttributeAdapter<ov::op::TopKSortType>>(&adapter)) {
- is_matched = (a->get() == any.as<std::string>());
- } else if (auto a = ov::as_type<ov::AttributeAdapter<ov::op::TopKMode>>(&adapter)) {
- is_matched = (a->get() == any.as<std::string>());
- } else if (auto a = ov::as_type<ov::AttributeAdapter<ov::CoordinateDiff>>(&adapter)) {
- is_matched = m_attr_map[name].equal_to<int64_t, int>(a->get());
- } else {
- OPENVINO_THROW("AttrMatcher met unsupported AttributeAdapter ", name);
- }
- add_match_result(name, is_matched);
- }
-};
-
-// GraphRewrite::apply_matcher_passes() has special logic to make matching faster
-// which relies on pattern::op::Pattern subclassing, thus we have to derive
-// from it. but we didn't use the predicate facility.
-class GenericPattern : public ov::pass::pattern::op::Pattern {
-public:
- OPENVINO_RTTI("GenericPattern");
-
- explicit GenericPattern(const DiscreteTypeInfo& type_info,
- const OutputVector& args,
- const detail::AttrMap& attrs,
- const char* vt,
- const int line_no = -1,
- const char* file = "")
- : ov::pass::pattern::op::Pattern(args),
- m_type_info(type_info),
- m_attrs(attrs),
- m_vt(vt),
- m_signature() {
- static int global_id = 0;
- if (matcher_verbose_enabled()) {
- // generate signature & friendlyname for verbose debugging log
- auto id = global_id++;
- std::stringstream ss;
- ss << "P" << id << "<" << type_info.get_version() << "::" << type_info.name << ">";
- ss << "(";
- const char* sep = "";
- for (auto& i : args) {
- ss << sep << i.get_node()->get_friendly_name();
- sep = ",";
- }
- ss << ")";
- if (line_no != -1) {
- // add the code line no to the log:
- // O P752<opset1::Multiply>(P736,P745)@fuse_rotary_positional_embeddings.cpp:551 vs ...
- auto filename = strrchr(file, '/') ? strrchr(file, '/') + 1 : file;
- ss << "@" << filename << ":" << line_no;
- }
- m_signature = ss.str();
- set_friendly_name(std::string("P") + std::to_string(id));
- }
- // default output for most OP types
- set_output_type(0, element::Type_t::dynamic, PartialShape::dynamic());
- }
-
- std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& /* new_args */) const override {
- OPENVINO_THROW("Uncopyable");
- }
-
- bool match_value(ov::pass::pattern::Matcher* matcher,
- const Output<Node>& pattern_value,
- const Output<Node>& graph_value) override {
- static std::string level;
- // strictly requires pattern & graph value to come from output port with same index,
- // this is absolute necessary when pattern contains split node connections.
- if (pattern_value.get_index() != graph_value.get_index()) {
- _VERBOSE_LOG(level,
- "X output index mismatch:(",
- m_signature,
- "): ",
- pattern_value.get_index(),
- "!=",
- graph_value.get_index());
- OPENVINO_LOG_GENPATTERN1(matcher, pattern_value, graph_value);
- return false;
- }
-
- auto value_node = graph_value.get_node_shared_ptr();
- if (!value_node->get_type_info().is_castable(m_type_info)) {
- _VERBOSE_LOG(level, "X OP type mismatch: ", m_signature, " vs ", graph_value);
- OPENVINO_LOG_GENPATTERN2(matcher, pattern_value, graph_value);
- return false;
- }
-
- if (!m_vt.predicate(graph_value)) {
- _VERBOSE_LOG(level, "X value info mismatch: ", m_signature, " vs ", graph_value);
- OPENVINO_LOG_GENPATTERN3(matcher);
- return false;
- }
-
- if (!m_attrs.empty()) {
- detail::AttrMatcher visitor(m_attrs);
- value_node->visit_attributes(visitor);
- if (!visitor.matched()) {
- _VERBOSE_LOG(level, "X OP attrs mismatch: ", m_signature, " vs ", graph_value);
- OPENVINO_LOG_GENPATTERN4(matcher);
- return false;
- }
- }
-
- auto& pattern_map = matcher->get_pattern_value_map();
- pattern_map[shared_from_this()] = graph_value;
- matcher->add_node(graph_value);
-
- if (get_input_size() == 0)
- return true;
-
- if (matcher_verbose_enabled())
- level.push_back('\t');
- OPENVINO_LOG_GENPATTERN5(matcher);
- bool ret = matcher->match_arguments(pattern_value.get_node(), graph_value.get_node_shared_ptr());
- OPENVINO_LOG_GENPATTERN6(matcher, ret);
- if (matcher_verbose_enabled()) {
- level.pop_back();
- _VERBOSE_LOG(level, ret ? "O" : "X", m_signature, " vs ", graph_value);
- }
- return ret;
- }
-
- const DiscreteTypeInfo& get_wrapped_type() const {
- return m_type_info;
- }
-
-private:
- const DiscreteTypeInfo& m_type_info;
- detail::AttrMap m_attrs;
- values_info m_vt;
- std::string m_signature;
-};
-
// A glue/syntax-sugar type which allows more types to be used as input to makePattern()
struct PatternNode {
std::shared_ptr<Node> node;
@@ -910,145 +372,40 @@ struct PatternNode {
});
}
- PatternNode(values_info vt) {
- node = ov::pass::pattern::any_input([vt](const Output<Node>& value) {
- if (!vt.predicate(value)) {
- _VERBOSE_LOG("*mismatched PatternNode ", value);
- return false;
- }
- _VERBOSE_LOG(" matched PatternNode ", value);
- return true;
- });
- }
PatternNode(const std::shared_ptr<Node>& node) : node(node) {}
PatternNode(const std::shared_ptr<ov::op::v0::Parameter>& node) : node(node) {}
PatternNode(const std::shared_ptr<ov::pass::pattern::op::Or>& pattern)
: node(std::dynamic_pointer_cast<Node>(pattern)) {}
- // 1D-vector & scalar of symbol
- PatternNode(std::initializer_list<Symbol> v) {
- // initializer_list of Symbol ls special, need to be recorded
- // and eval/check in the callback after whole match is complete,
- // where all observed actual constant values are known, first
- // we will go over all symbols and collect actual value for individual
- // symbol(named symbol), and then we go over all derived symbols and
- // evaluate their predicated values and compare against what observed,
- // and check if they all match.
- // node = ConstVector(std::vector<float>(v), nullptr);
- node = ov::pass::pattern::wrap_type<opset1::Constant>();
-
- auto& rt_info = node->get_rt_info();
- rt_info["symbolic_const_value"] = std::vector<Symbol>(v);
- }
- PatternNode(const std::vector<Symbol>& v) {
- node = ov::pass::pattern::wrap_type<opset1::Constant>();
- auto& rt_info = node->get_rt_info();
- rt_info["symbolic_const_value"] = v;
- }
-
- PatternNode(Symbol v) {
- node = ov::pass::pattern::wrap_type<opset1::Constant>();
- auto& rt_info = node->get_rt_info();
- rt_info["symbolic_const_value"] = std::vector<Symbol>({v});
- }
-
// scalar constant (treated as wildcard for single-element-constant with any rank)
PatternNode(int v) : node(std::make_shared<ov::op::v0::Constant>(element::from<int>(), Shape({}), v)) {}
PatternNode(float v) : node(std::make_shared<ov::op::v0::Constant>(element::from<float>(), Shape({}), v)) {}
PatternNode(long long v) : node(std::make_shared<ov::op::v0::Constant>(element::from<int64_t>(), Shape({}), v)) {}
- PatternNode(std::initializer_list<int> v, values_info vi = nullptr) {
- node = ConstVector(std::vector<int>(v), vi);
+ PatternNode(std::initializer_list<int> v) {
+ node = ConstVector(std::vector<int>(v));
}
- PatternNode(std::initializer_list<float> v, values_info vi = nullptr) {
- node = ConstVector(std::vector<float>(v), vi);
+ PatternNode(std::initializer_list<float> v) {
+ node = ConstVector(std::vector<float>(v));
}
- PatternNode(std::initializer_list<long> v, values_info vi = nullptr) {
- node = ConstVector(std::vector<int64_t>(v.begin(), v.end()), vi);
+ PatternNode(std::initializer_list<long> v) {
+ node = ConstVector(std::vector<int64_t>(v.begin(), v.end()));
}
- PatternNode(std::initializer_list<long long> v, values_info vi = nullptr) {
- node = ConstVector(std::vector<int64_t>(v.begin(), v.end()), vi);
+ PatternNode(std::initializer_list<long long> v) {
+ node = ConstVector(std::vector<int64_t>(v.begin(), v.end()));
}
// 1d const tensor or scalar
template <typename T, typename std::enable_if<std::is_arithmetic<T>::value, bool>::type = true>
- static std::shared_ptr<Node> ConstVector(const std::vector<T>& vec, values_info vi = nullptr) {
- if (vi.size() > 0)
- return std::make_shared<ov::op::v0::Constant>(vi[0].first, vi[0].second.to_shape(), vec);
- // initializer_list w/o value_info means to create normal 1D vector
+ static std::shared_ptr<Node> ConstVector(const std::vector<T>& vec) {
return std::make_shared<ov::op::v0::Constant>(element::from<T>(), Shape({vec.size()}), vec);
}
};
-
-/*
-template <typename T>
-static bool vector_equal_to_any(const std::vector<T>& v0, detail::AttrAny& any) {
- auto v1 = any.cast_to_vector<T>();
- if (v0.size() != v1.size())
- return false;
- return std::equal(v0.begin(), v0.end(), v1.begin());
-}
-
-template <typename T>
-static bool scalar_equal_to_any(const T& v0, detail::AttrAny& any) {
- if (any.is<int>()) {
- return v0 == any.as<int>();
- } else if (any.is<float>()) {
- return v0 == any.as<float>();
- }
- return v0 == any.as<T>();
-}
-*/
-
} // namespace detail
//==================================================================================================
-inline std::shared_ptr<Node> GenInput(values_info vt = nullptr) {
- return ov::pass::pattern::any_input([vt](const Output<Node>& value) {
- if (!vt.predicate(value)) {
- _VERBOSE_LOG("*mismatched GenInput ", value);
- return false;
- }
- _VERBOSE_LOG(" matched GenInput ", value);
- return true;
- });
-}
-
-inline std::shared_ptr<Node> makePattern() {
- detail::PatternNode g;
- return g.node;
-}
-
-inline std::shared_ptr<Node> makePattern(ov::Rank rank) {
- detail::PatternNode g(rank);
- return g.node;
-}
-
-inline std::shared_ptr<Node> makePattern(values_info vt) {
- detail::PatternNode g(vt);
- return g.node;
-}
-
// unknown const
-inline std::shared_ptr<Node> makeConst(const ov::element::Type& type,
- const ov::PartialShape& pshape,
- std::function<bool(ov::op::v0::Constant& node)> pred) {
- return ov::pass::pattern::wrap_type<ov::op::v0::Constant>([type, pshape, pred](const Output<Node>& value) {
- auto cnode = ov::as_type_ptr<opset1::Constant>(value.get_node_shared_ptr());
- if (!cnode)
- return false;
-
- if (!type.compatible(value.get_element_type()) || !pshape.compatible(value.get_partial_shape())) {
- return false;
- }
- if (pred && !pred(*cnode)) {
- return false;
- }
- return true;
- });
-}
-
template <typename T>
std::shared_ptr<Node> makeConst(const ov::element::Type& type,
const ov::Shape& shape,
@@ -1056,41 +413,11 @@ std::shared_ptr<Node> makeConst(const ov::element::Type& type,
return std::make_shared<ov::op::v0::Constant>(type, shape, std::vector<T>(values));
}
-inline std::shared_ptr<Node> makeConst(const std::vector<Symbol>& v) {
- auto node = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();
- auto& rt_info = node->get_rt_info();
- rt_info["symbolic_const_value"] = v;
- return node;
-}
-
template <typename T>
std::shared_ptr<Node> makeConst(const ov::element::Type& type, const ov::Shape& shape, const std::vector<T>& values) {
return std::make_shared<ov::op::v0::Constant>(type, shape, values);
}
-template <class T>
-std::shared_ptr<Node> makePattern(const std::vector<detail::PatternNode>& inputs,
- detail::AttrMap attrmap = {},
- const char* vt = nullptr,
- const char* friendly_name = nullptr,
- int line_no = CURRENT_LINE_NO,
- const char* file = CURRENT_FILE) {
- OutputVector args;
- for (auto& in : inputs)
- args.push_back(in.get_output());
-
- // pattern nodes are better for pattern matching because
- // - it can be generic/incomplete, so normal OP node is not working properly
- // - it has predicate to correctly decide which branch to take (in Or pattern)
- auto pattern_node =
- std::make_shared<detail::GenericPattern>(T::get_type_info_static(), args, attrmap, vt, line_no, file);
-
- if (friendly_name)
- pattern_node->set_friendly_name(friendly_name);
-
- return pattern_node;
-}
-
template <class T>
std::shared_ptr<Node> makeOP(const std::vector<detail::PatternNode>& inputs,
detail::AttrMap attrmap = {},
@@ -1107,7 +434,7 @@ std::shared_ptr<Node> makeOP(const std::vector<detail::PatternNode>& inputs,
auto missing_attrs = visitor.get_missing_attrs();
- // when some attribute is missing or is symbol, the returned
+ // when some attribute is missing, the returned
// node is suitable for pattern matching only.
OPENVINO_ASSERT(missing_attrs.size() == 0,
"missing ",
@@ -1122,354 +449,5 @@ std::shared_ptr<Node> makeOP(const std::vector<detail::PatternNode>& inputs,
return node;
}
-template <typename T>
-std::shared_ptr<Node> GenConst_tril(values_info vt) {
- return ov::pass::pattern::wrap_type<opset1::Constant>([vt](const Output<Node>& value) {
- auto s1 = as_type_ptr<opset1::Constant>(value.get_node_shared_ptr());
- if (!s1) {
- _VERBOSE_LOG("*mismatched GenConst_tril op type: opset1::Constant vs", value);
- return false;
- }
-
- if (!vt.predicate(value)) {
- _VERBOSE_LOG("*mismatched GenConst_tril values_info:", value);
- return false;
- }
-
- // ignore higher dimensions, require lowerst 2D to be lower triangular
- auto shape = s1->get_output_shape(0);
- auto rank = shape.size();
- if (rank < 2) {
- _VERBOSE_LOG("*mismatched GenConst_tril rank < 2 (rank=", rank, ")");
- return false;
- }
- if (shape[rank - 1] != shape[rank - 2]) {
- _VERBOSE_LOG("*mismatched GenConst_tril shape[-1] != shape[-2] : ",
- shape[rank - 1],
- " != ",
- shape[rank - 2]);
- return false;
- }
- // NxN const matrix
- auto N = shape[rank - 1];
- std::vector<T> output_vector = s1->cast_vector<T>();
- // check if it's unit lower triangular matrix
- for (size_t i = 0; i < N; i++) {
- for (size_t j = 0; j < N; j++) {
- if (static_cast<bool>(output_vector[i * N + j]) != static_cast<bool>(j <= i))
- return false;
- }
- }
- return true;
- });
-}
-
-inline std::shared_ptr<Node> GenStridedSlice(detail::PatternNode data,
- detail::PatternNode start,
- detail::PatternNode stop,
- detail::PatternNode step,
- size_t axis,
- int line_no = CURRENT_LINE_NO,
- const char* file = CURRENT_FILE) {
- std::vector<int64_t> begin_mask(axis + 1, 1);
- std::vector<int64_t> end_mask(axis + 1, 1);
- std::vector<int64_t> new_axis_mask;
- std::vector<int64_t> shrink_axis_mask;
- std::vector<int64_t> ellipsis_mask;
-
- begin_mask[axis] = 0;
- end_mask[axis] = 0;
-
- auto opt2 = makePattern<opset1::StridedSlice>({data, start, stop, step},
- {{"begin_mask", begin_mask},
- {"end_mask", end_mask},
- {"new_axis_mask", new_axis_mask},
- {"shrink_axis_mask", shrink_axis_mask},
- {"ellipsis_mask", ellipsis_mask}},
- nullptr,
- nullptr,
- line_no,
- file);
- return opt2;
-}
-
-inline std::shared_ptr<Node> GenSlice(detail::PatternNode data,
- Symbol start,
- Symbol stop,
- Symbol step,
- size_t axis,
- int line_no = CURRENT_LINE_NO,
- const char* file = CURRENT_FILE) {
- using namespace ov::pass;
- auto opt1 = makePattern<opset8::Slice>({data, {start}, {stop}, {step}, {static_cast<int>(axis)}},
- {},
- nullptr,
- nullptr,
- line_no,
- file);
-
- std::vector<Symbol> vbegin(axis + 1, Symbol(0));
- std::vector<Symbol> vend(axis + 1, Symbol(0));
- std::vector<Symbol> vstride(axis + 1, Symbol(1));
-
- vbegin[axis] = start;
- vend[axis] = stop;
- vstride[axis] = step;
-
- detail::PatternNode begin(vbegin);
- detail::PatternNode end(vend);
- detail::PatternNode stride(vstride);
-
- std::vector<int64_t> begin_mask(axis + 1, 1);
- std::vector<int64_t> end_mask(axis + 1, 1);
- std::vector<int64_t> new_axis_mask;
- std::vector<int64_t> shrink_axis_mask;
- std::vector<int64_t> ellipsis_mask;
-
- begin_mask[axis] = 0;
- end_mask[axis] = 0;
-
- auto opt2 = makePattern<opset1::StridedSlice>({data, begin, end, stride},
- {{"begin_mask", begin_mask},
- {"end_mask", end_mask},
- {"new_axis_mask", new_axis_mask},
- {"shrink_axis_mask", shrink_axis_mask},
- {"ellipsis_mask", ellipsis_mask}},
- nullptr,
- nullptr,
- line_no,
- file);
- return opt1 | opt2;
-}
-
-//==================================================================================================
-class PatternValidator {
-public:
- PatternValidator(ov::pass::pattern::Matcher& m) {
- m_is_valid = validate(m);
- }
-
- double& operator[](const char* symbol_name) {
- return m_symbol_values[symbol_name];
- }
-
- operator bool() {
- if (!m_is_valid) {
- _VERBOSE_LOG("PatternValidator failed.");
- }
- return m_is_valid;
- }
-
- bool validate(ov::pass::pattern::Matcher& m) {
- detail::SymbolObservationVector sov;
-
- auto& pvmap = m.get_pattern_value_map();
- for (auto& pv : pvmap) {
- auto pnode = pv.first;
- auto value_node = pv.second.get_node_shared_ptr();
- auto& rt_info = pnode->get_rt_info();
-
- if (auto pattern_node = std::dynamic_pointer_cast<ov::pass::pattern::op::Pattern>(pnode)) {
- // pattern_node has no attribute and it has been matched in its predicate
- if (rt_info.count("symbolic_const_value")) {
- // symbolic constant node, a symbol reference is observed
- auto& symbols = rt_info["symbolic_const_value"].as<std::vector<Symbol>>();
- auto constop = ov::as_type_ptr<op::v0::Constant>(value_node);
- if (!constop) {
- _VERBOSE_LOG("symbolic_const_value unexpected OP: ", value_node->get_friendly_name());
- return false;
- }
- auto ele_cnt = shape_size(constop->get_shape());
- auto ele_type = constop->get_element_type();
-
- if (ele_cnt != symbols.size()) {
- _VERBOSE_LOG("symbolic_const_value expect ",
- symbols.size(),
- " but got ",
- ele_cnt,
- " from ",
- value_node->get_friendly_name());
- return false;
- }
-
- if (ele_type == ov::element::i32 || ele_type == ov::element::i64 || ele_type == ov::element::f16 ||
- ele_type == ov::element::f32) {
- auto observed = constop->cast_vector<double>();
- for (size_t i = 0; i < symbols.size(); i++)
- detail::add_symbol_observed(sov, symbols[i], observed[i]);
- } else {
- _VERBOSE_LOG("Unexpect element type ", ele_type, " from ", value_node->get_friendly_name());
- return false;
- }
- }
- continue;
- }
- if (auto pconst_node = ov::as_type_ptr<ov::op::v0::Constant>(pnode)) {
- // const_node needs to match type/shape/value
- auto vconst_node = ov::as_type_ptr<ov::op::v0::Constant>(value_node);
- if (!vconst_node) {
- _VERBOSE_LOG("expecting Constant op, but got ", value_node);
- return false;
- }
-
- // for constant node matched in pattern, a scalar constant is considered to
- // be compatible with any shape with 1 element, like {}, {1,1}, {1,1,...}
- const auto& expected_shape = pconst_node->get_output_shape(0);
- if (expected_shape.size() == 0) {
- if (shape_size(vconst_node->get_output_shape(0)) != 1) {
- _VERBOSE_LOG("expecting a single element const, but got ", vconst_node);
- return false;
- }
- } else {
- if (expected_shape != vconst_node->get_output_shape(0)) {
- _VERBOSE_LOG("expecting Constant of shape ", expected_shape, " but got ", vconst_node);
- return false;
- }
- }
-
- if (pconst_node->get_output_element_type(0) != vconst_node->get_output_element_type(0)) {
- // signed integer compare is relaxed, as long as tey are equal when both up-casted to int64_t
- if (pconst_node->get_output_element_type(0).is_integral() &&
- pconst_node->get_output_element_type(0).is_signed() &&
- vconst_node->get_output_element_type(0).is_integral() &&
- vconst_node->get_output_element_type(0).is_signed()) {
- auto p_values = pconst_node->cast_vector<int64_t>();
- auto v_values = vconst_node->cast_vector<int64_t>();
- if (p_values == v_values) {
- continue;
- }
- }
-
- if (pconst_node->get_output_element_type(0).is_real() &&
- vconst_node->get_output_element_type(0).is_real()) {
- auto p_values = pconst_node->cast_vector<float>();
- auto v_values = vconst_node->cast_vector<float>();
- if (p_values == v_values) {
- continue;
- }
- }
-
- _VERBOSE_LOG("expecting Constant of type ",
- pconst_node->get_output_element_type(0),
- " but got ",
- vconst_node);
- return false;
- }
-
- auto byte_size =
- shape_size(vconst_node->get_output_shape(0)) * vconst_node->get_output_element_type(0).size();
- if (std::memcmp(pconst_node->get_data_ptr(), vconst_node->get_data_ptr(), byte_size) != 0) {
- _VERBOSE_LOG("Constant value mismatch on ", pconst_node, " vs ", vconst_node);
- return false;
- }
- continue;
- }
-
- // compare attributes between them
- // assume that there is no Symbol in the attributes, we need to fetch each attributes
- // from
- if (rt_info.count("__attrs__") == 0) {
- _VERBOSE_LOG(" attr compare failed: __attrs__ not found for ", pnode->get_friendly_name());
- return false;
- }
-
- // attr not specified is treated as not-care and ignored
- // attr with symbol
-
- detail::AttrMap& attr_map = rt_info["__attrs__"].as<detail::AttrMap>();
- detail::AttrMatcher visitor(attr_map, &sov);
- value_node->visit_attributes(visitor);
- if (!visitor.matched()) {
- _VERBOSE_LOG(" attr compare failed: ",
- pnode->get_friendly_name(),
- " vs ",
- value_node->get_friendly_name());
- return false;
- }
- }
-
- // check symbol consistency & return independent symbols
- // assign independent symbols & check literals
- std::map<const void*, double> symbol_value_map;
- for (auto& ref : sov) {
- auto& sym = ref.first;
- auto& value = ref.second;
-
- if (sym.is_independent_var()) {
- auto id = sym.get_id();
- if (symbol_value_map.count(id)) {
- if (sym.validate && symbol_value_map[id] != value) {
- _VERBOSE_LOG(" in-consistency between multiple references of same symbol(",
- sym.get_name(),
- "): ",
- symbol_value_map[id],
- " != ",
- value);
- return false;
- }
- } else {
- symbol_value_map[id] = value;
- m_symbol_values[sym.get_name()] = value;
- _VERBOSE_LOG("Independent Symbol: ", sym.get_name(), " = ", value);
- }
- }
-
- if (sym.is_literal_const()) {
- auto literal = sym.eval(symbol_value_map);
- if (literal != value) {
- _VERBOSE_LOG(" mismatch between literal symbol & value(",
- sym.get_name(),
- "): ",
- literal,
- " != ",
- value);
- return false;
- }
- // no need to put literal into value map to eval them.
- }
- }
-
- // derive/eval dependent symbol's value and check against observed
- for (auto& ref : sov) {
- auto& sym = ref.first;
- if (!sym.is_literal_const() && !sym.is_independent_var()) {
- auto derived = sym.eval(symbol_value_map);
- auto value = ref.second;
- bool is_match;
-
- if (std::trunc(value) == value) {
- // observed integer
- is_match = (derived == value);
- } else {
- auto abs_diff = std::abs(derived - value);
- auto avg = 0.5f * std::abs(derived + value);
- if (avg != 0) {
- is_match = abs_diff < avg * 1e-7; // relative error less than threshold
- } else {
- is_match = (derived == value);
- }
- }
- if (!is_match) {
- _VERBOSE_LOG(" mismatch between derived & value(",
- sym.get_name(),
- "): ",
- std::setprecision(std::numeric_limits<float>::max_digits10),
- derived,
- " != ",
- std::setprecision(std::numeric_limits<float>::max_digits10),
- value);
- return false;
- }
- }
- }
- _VERBOSE_LOG("PatternValidator validate success!");
- return true;
- }
-
-private:
- std::map<std::string, double> m_symbol_values;
- bool m_is_valid;
-};
-
} // namespace gen_pattern
} // namespace ov
diff --git a/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp
index 6acc53d503b..d64a63b3542 100644
--- a/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp
+++ b/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp
@@ -14,6 +14,7 @@
#include "openvino/op/concat.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/matmul.hpp"
+#include "openvino/op/multiply.hpp"
#include "openvino/op/reduce_max.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/scaled_dot_product_attention.hpp"
@@ -29,7 +30,6 @@
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "openvino/util/pp.hpp"
#include "transformations/symbolic_transformations/symbolic_optimizations.hpp"
-#include "transformations/utils/gen_pattern.hpp"
#include "transformations/utils/utils.hpp"
namespace {
@@ -379,19 +379,19 @@ SDPAFusionMatcher::SDPAFusionMatcher() {
ov::OutputVector vec = {q_node, k_node, v_node};
// 3 is the min supported rank according to the SDPA spec
- int64_t supported_rank = std::max(mask_input.get_partial_shape().rank().get_length(), static_cast<int64_t>(3));
+ size_t supported_rank = std::max(mask_input.get_partial_shape().rank().get_length(), static_cast<int64_t>(3));
for (size_t i = 0; i < vec.size(); ++i) {
auto pshape = vec[i].get_partial_shape();
if (pshape.rank().is_dynamic()) {
return false;
}
// align all inputs
- supported_rank = std::max(static_cast<int64_t>(pshape.size()), supported_rank);
+ supported_rank = std::max(pshape.size(), supported_rank);
}
for (size_t i = 0; i < vec.size(); ++i) {
auto pshape = vec[i].get_partial_shape();
- int diff = supported_rank - static_cast<int>(pshape.size());
+ int diff = static_cast<int>(supported_rank - pshape.size());
if (diff > 0) {
std::vector<size_t> axes(diff, 0);
std::iota(axes.begin(), axes.end(), 0);
@@ -564,19 +564,19 @@ SDPAFusionMatcherSinks::SDPAFusionMatcherSinks() {
ov::OutputVector vec = {q_node, k_node, v_node};
// 3 is the min supported rank according to the SDPA spec
- int64_t supported_rank = std::max(mask_input.get_partial_shape().rank().get_length(), static_cast<int64_t>(3));
+ size_t supported_rank = std::max(mask_input.get_partial_shape().rank().get_length(), static_cast<int64_t>(3));
for (size_t i = 0; i < vec.size(); ++i) {
auto pshape = vec[i].get_partial_shape();
if (pshape.rank().is_dynamic()) {
return false;
}
// align all inputs
- supported_rank = std::max(static_cast<int64_t>(pshape.size()), supported_rank);
+ supported_rank = std::max(pshape.size(), supported_rank);
}
for (size_t i = 0; i < vec.size(); ++i) {
auto pshape = vec[i].get_partial_shape();
- int diff = supported_rank - static_cast<int>(pshape.size());
+ int diff = static_cast<int>(supported_rank - pshape.size());
if (diff > 0) {
std::vector<size_t> axes(diff, 0);
std::iota(axes.begin(), axes.end(), 0);
diff --git a/src/common/transformations/src/transformations/fp16_compression/mark_floatpoint_range.cpp b/src/common/transformations/src/transformations/fp16_compression/mark_floatpoint_range.cpp
index 26db5c2313c..8e4e0026cc9 100644
--- a/src/common/transformations/src/transformations/fp16_compression/mark_floatpoint_range.cpp
+++ b/src/common/transformations/src/transformations/fp16_compression/mark_floatpoint_range.cpp
@@ -16,7 +16,6 @@
#include "openvino/op/unsqueeze.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "transformations/rt_info/disable_fp16_compression.hpp"
-#include "transformations/utils/gen_pattern.hpp"
#include "transformations/utils/utils.hpp"
void ov::pass::mark_range_path(const std::shared_ptr<Node>& node) {
@@ -35,7 +34,6 @@ void ov::pass::erase_range_path(const std::shared_ptr<Node>& node) {
ov::pass::MarkFloatingPointRange::MarkFloatingPointRange() {
MATCHER_SCOPE(MarkFloatingPointRange);
using namespace ov::pass::pattern;
- using namespace ov::gen_pattern;
// through these nodes
const auto range_propagating_nodes = pattern::wrap_type<ov::op::v0::Convert,
ov::op::v1::Greater,
diff --git a/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp b/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp
index 0e8da3858fe..0cbc6f8f55f 100644
--- a/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp
+++ b/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp
@@ -16,8 +16,10 @@
#include "openvino/op/reshape.hpp"
#include "openvino/op/scatter_update.hpp"
#include "openvino/op/shape_of.hpp"
+#include "openvino/op/slice.hpp"
#include "openvino/op/split.hpp"
#include "openvino/op/squeeze.hpp"
+#include "openvino/op/strided_slice.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/unsqueeze.hpp"
#include "openvino/op/variadic_split.hpp"
diff --git a/src/common/transformations/tests/op_conversions/einsum_decomposition_test.cpp b/src/common/transformations/tests/op_conversions/einsum_decomposition_test.cpp
index 5bdf0486843..f0c3d2d3b71 100644
--- a/src/common/transformations/tests/op_conversions/einsum_decomposition_test.cpp
+++ b/src/common/transformations/tests/op_conversions/einsum_decomposition_test.cpp
@@ -21,6 +21,7 @@
#include "openvino/op/reshape.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/squeeze.hpp"
+#include "openvino/op/strided_slice.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/unsqueeze.hpp"
diff --git a/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp b/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp
index eafa3e1c462..56fc652de9f 100644
--- a/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp
+++ b/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp
@@ -37,6 +37,7 @@
#include "openvino/op/select.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/sin.hpp"
+#include "openvino/op/slice.hpp"
#include "openvino/op/split.hpp"
#include "openvino/op/sqrt.hpp"
#include "openvino/op/squeeze.hpp"
diff --git a/src/core/dev_api/openvino/core/log_util.hpp b/src/core/dev_api/openvino/core/log_util.hpp
index 3ea8fdb9f24..079452cec13 100644
--- a/src/core/dev_api/openvino/core/log_util.hpp
+++ b/src/core/dev_api/openvino/core/log_util.hpp
@@ -86,69 +86,6 @@ bool is_verbose_logging();
// there's a set of macro for avoiding the additional clutter
// of the matching code.
-// transformations/utils/gen_pattern.hpp
-# define OPENVINO_LOG_GENPATTERN1(matcher, pattern_value, graph_value) \
- do { \
- OPENVINO_LOG_MATCHING(matcher, \
- ov::util::LevelString::get(), \
- OPENVINO_BLOCK_END, \
- OPENVINO_RED, \
- " OUTPUT INDICES DIDN'T MATCH. EXPECTED: ", \
- pattern_value.get_index(), \
- ". OBSERVED: ", \
- graph_value.get_index()); \
- } while (0)
-
-# define OPENVINO_LOG_GENPATTERN2(matcher, pattern_value, graph_value) \
- do { \
- OPENVINO_LOG_MATCHING(matcher, \
- ov::util::LevelString::get(), \
- OPENVINO_BLOCK_END, \
- OPENVINO_RED, \
- " NODES' TYPE DIDN'T MATCH. EXPECTED: ", \
- ov::util::node_version_type_str(*pattern_value.get_node_shared_ptr()), \
- ". OBSERVED: ", \
- ov::util::node_version_type_str(*graph_value.get_node_shared_ptr())); \
- } while (0)
-
-# define OPENVINO_LOG_GENPATTERN3(matcher) \
- do { \
- OPENVINO_LOG_MATCHING(matcher, \
- ov::util::LevelString::get(), \
- OPENVINO_BLOCK_END, \
- OPENVINO_RED, \
- " PREDICATE DIDN'T MATCH."); \
- } while (0)
-
-# define OPENVINO_LOG_GENPATTERN4(matcher) \
- do { \
- OPENVINO_LOG_MATCHING(matcher, \
- ov::util::LevelString::get(), \
- OPENVINO_BLOCK_END, \
- OPENVINO_RED, \
- " ATTRIBUTES DIDN'T MATCH."); \
- } while (0)
-
-# define OPENVINO_LOG_GENPATTERN5(matcher) \
- do { \
- OPENVINO_LOG_MATCHING(matcher, \
- ov::util::LevelString::get(), \
- OPENVINO_BLOCK_BODY_RIGHT, \
- " TYPE MATCHED. CHECKING PATTERN ARGUMENTS"); \
- } while (0)
-
-# define OPENVINO_LOG_GENPATTERN6(matcher, status) \
- do { \
- OPENVINO_LOG_MATCHING(matcher, \
- ov::util::LevelString::get(), \
- OPENVINO_BLOCK_BODY, \
- '\n', \
- ov::util::LevelString::get(), \
- OPENVINO_BLOCK_END, \
- (status ? OPENVINO_GREEN : OPENVINO_RED), \
- (status ? " ALL ARGUMENTS MATCHED" : " ARGUMENTS DIDN'T MATCH")); \
- } while (0)
-
// core/src/node.cpp
# define OPENVINO_LOG_NODE1(matcher, pattern_value, graph_value) \
do { \
@@ -709,25 +646,6 @@ bool is_verbose_logging();
#else // ENABLE_OPENVINO_DEBUG
-# define OPENVINO_LOG_GENPATTERN1(...) \
- do { \
- } while (0)
-# define OPENVINO_LOG_GENPATTERN2(...) \
- do { \
- } while (0)
-# define OPENVINO_LOG_GENPATTERN3(...) \
- do { \
- } while (0)
-# define OPENVINO_LOG_GENPATTERN4(...) \
- do { \
- } while (0)
-# define OPENVINO_LOG_GENPATTERN5(...) \
- do { \
- } while (0)
-# define OPENVINO_LOG_GENPATTERN6(...) \
- do { \
- } while (0)
-
# define OPENVINO_LOG_NODE1(...) \
do { \
} while (0)
diff --git a/src/core/src/log_util.cpp b/src/core/src/log_util.cpp
index b1fb986f445..bd5891c6a2d 100644
--- a/src/core/src/log_util.cpp
+++ b/src/core/src/log_util.cpp
@@ -8,7 +8,6 @@
#include "openvino/pass/pattern/op/true.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "openvino/util/env_util.hpp"
-#include "transformations/utils/gen_pattern.hpp"
namespace ov {
namespace util {
@@ -18,17 +17,6 @@ namespace util {
static const bool verbose = ov::util::getenv_bool("OV_VERBOSE_LOGGING");
// These functions are used for printing nodes in a pretty way for matching logging
-static std::string wrapped_type_str(const ov::gen_pattern::detail::GenericPattern& gp, bool verbose) {
- auto wrapped_type_info = gp.get_wrapped_type();
- auto version = wrapped_type_info.version_id;
- std::string res = "<";
- if (verbose && version)
- res += version + std::string("::");
-
- res += wrapped_type_info.name + std::string(">");
- return res;
-}
-
static std::string wrapped_type_str(const ov::pass::pattern::op::WrapType& wt, bool verbose) {
bool first = true;
std::string res = "<";
@@ -111,11 +99,8 @@ std::string node_version_type_str(const ov::Node& node) {
res += node.get_type_info().name;
- if (auto wrap_type = ov::as_type<const ov::pass::pattern::op::WrapType>(&node)) {
+ if (auto wrap_type = ov::as_type<const ov::pass::pattern::op::WrapType>(&node))
res += wrapped_type_str(*wrap_type, verbose);
- } else if (auto generic_pattern = ov::as_type<const ov::gen_pattern::detail::GenericPattern>(&node)) {
- res += wrapped_type_str(*generic_pattern, verbose);
- }
return res;
}
@@ -133,11 +118,8 @@ std::string node_with_arguments(const ov::Node& node) {
res += node.get_type_info().name;
- if (auto wrap_type = ov::as_type<const ov::pass::pattern::op::WrapType>(&node)) {
+ if (auto wrap_type = ov::as_type<const ov::pass::pattern::op::WrapType>(&node))
res += wrapped_type_str(*wrap_type, verbose);
- } else if (auto generic_pattern = ov::as_type<const ov::gen_pattern::detail::GenericPattern>(&node)) {
- res += wrapped_type_str(*generic_pattern, verbose);
- }
if (verbose)
res += " " + node.get_friendly_name();
diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/causal_mask_preprocess.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/causal_mask_preprocess.cpp
index 69379d8347b..e6be6507652 100644
--- a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/causal_mask_preprocess.cpp
+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/causal_mask_preprocess.cpp
@@ -29,6 +29,7 @@
#include "openvino/op/scatter_nd_update.hpp"
#include "openvino/op/scatter_update.hpp"
#include "openvino/op/select.hpp"
+#include "openvino/op/strided_slice.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/tile.hpp"
#include "openvino/op/unsqueeze.hpp"
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/pre_compute.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/pre_compute.cpp
index 224b21d8ec6..905be2c25b2 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/pre_compute.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/pre_compute.cpp
@@ -15,12 +15,6 @@
namespace opp = ov::pass::pattern;
namespace {
-template <typename T>
-std::shared_ptr<ov::Node> makeConst(const ov::element::Type& type,
- const ov::Shape& shape,
- const std::vector<T>& values) {
- return std::make_shared<ov::op::v0::Constant>(type, shape, values);
-}
// TODO: copied from common tests
static ov::OutputVector makeCosSinCache(const size_t max_position_embeddings,
const std::shared_ptr<ov::Node> inverse_frequencies) {
@@ -48,8 +42,10 @@ static ov::OutputVector makeCosSinCache(const size_t max_position_embeddings,
psin[k + rotary_ndims / 2] = psin[k];
}
}
- auto Cos = makeConst(ov::element::f16, ov::Shape({1, max_position_embeddings, rotary_ndims}), lut_cos);
- auto Sin = makeConst(ov::element::f16, ov::Shape({1, max_position_embeddings, rotary_ndims}), lut_sin);
+ auto Cos =
+ ov::op::v0::Constant::create(ov::element::f16, ov::Shape({1, max_position_embeddings, rotary_ndims}), lut_cos);
+ auto Sin =
+ ov::op::v0::Constant::create(ov::element::f16, ov::Shape({1, max_position_embeddings, rotary_ndims}), lut_sin);
return {Cos, Sin};
}
diff --git a/src/tests/functional/plugin/shared/src/subgraph/rotary_pos_emb.cpp b/src/tests/functional/plugin/shared/src/subgraph/rotary_pos_emb.cpp
index 8cf5ae75cd1..7b5a65ebe7c 100644
--- a/src/tests/functional/plugin/shared/src/subgraph/rotary_pos_emb.cpp
+++ b/src/tests/functional/plugin/shared/src/subgraph/rotary_pos_emb.cpp
@@ -20,6 +20,8 @@
#include "openvino/op/scatter_update.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/split.hpp"
+#include "openvino/op/strided_slice.hpp"
+#include "openvino/op/slice.hpp"
#include "openvino/op/squeeze.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/transpose.hpp"