Skip to content

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

[TRANSFORMATIONS] SDPAToPA: Add PositionIDsReplacerCodeGen2 (#31117)

Andrii Staikov436133cba957
diff --git a/src/common/transformations/include/transformations/sdpa_to_paged_attention/position_ids_replacer.hpp b/src/common/transformations/include/transformations/sdpa_to_paged_attention/position_ids_replacer.hpp
index acdbc91a7e0..153e90f0316 100644
--- a/src/common/transformations/include/transformations/sdpa_to_paged_attention/position_ids_replacer.hpp
+++ b/src/common/transformations/include/transformations/sdpa_to_paged_attention/position_ids_replacer.hpp
@@ -6,6 +6,7 @@
#include "openvino/op/add.hpp"
#include "openvino/op/parameter.hpp"
+#include "openvino/op/unsqueeze.hpp"
#include "openvino/pass/matcher_pass.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "transformations/utils/utils.hpp"
@@ -16,6 +17,7 @@ namespace pass {
class TRANSFORMATIONS_API PositionIDsReplacer;
class TRANSFORMATIONS_API PositionIDsReplacerQwen;
+class TRANSFORMATIONS_API PositionIDsReplacerCodeGen2;
} // namespace pass
} // namespace ov
@@ -44,3 +46,46 @@ public:
OPENVINO_MATCHER_PASS_RTTI("PositionIDsReplacerQwen");
explicit PositionIDsReplacerQwen(const Output<Node>& position_ids);
};
+
+/**
+ * @brief Codegen2 model doesn't use the position_ids input explicitly.
+ * Instead, the model infers them from the max_context_len value by generating
+ * a range from 0 to max_context_len, applying RoPE and only then Slicing the
+ * last token which is not correct in case of 0th iteration (prompt iteration)
+ * when values for the entire sequence need to be sliced.
+ *
+ * We change from this:
+ *
+ * ┌─────┐
+ * │Range│
+ * └──┬──┘
+ * │
+ * ┌──┴──┐ ┌─────────┐ ┌─────────┐
+ * │RoPE │ │ Start │ │ End │
+ * │Block│ │(prev.seq| │(cur.seq │
+ * └──┬──┘ │ len) │ │ len) │
+ * │ └────┬────┘ └────┬────┘
+ * ┌──┴──┐──────────┘ │
+ * |Slice├─────────────────────────┘
+ * └─────┘
+ *
+ * To this to Gather by position_ids
+ *
+ * ┌─────┐
+ * │Range│
+ * └──┬──┘
+ * │
+ * ┌──┴──┐
+ * │RoPE │
+ * │Block│ ┌──────────────┐
+ * └──┬──┘ │ position_ids │
+ * │ └──────┬───────┘
+ * ┌──┴───┐ │
+ * │Gather├──────────┘
+ * └──────┘
+ */
+class ov::pass::PositionIDsReplacerCodeGen2 : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("PositionIDsReplacerCodeGen2");
+ explicit PositionIDsReplacerCodeGen2(const std::shared_ptr<ov::op::v0::Parameter>& position_ids);
+};
diff --git a/src/common/transformations/include/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.hpp b/src/common/transformations/include/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.hpp
index 3b34410cfca..05a3a770cdb 100644
--- a/src/common/transformations/include/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.hpp
+++ b/src/common/transformations/include/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.hpp
@@ -16,6 +16,7 @@ namespace pass {
class TRANSFORMATIONS_API TotalSequenceLengthPattern;
class TRANSFORMATIONS_API TotalSequenceLengthPatternQwen;
+class TRANSFORMATIONS_API TotalSequenceLengthPatternCodeGen2;
} // namespace pass
} // namespace ov
@@ -44,3 +45,16 @@ public:
OPENVINO_MATCHER_PASS_RTTI("TotalSequenceLengthPattern", "0");
explicit TotalSequenceLengthPatternQwen(const std::shared_ptr<ov::op::v0::Parameter>& max_context_len);
};
+
+/**
+ * @brief Codegen2 model has a specific pattern for TotalSequenceLen place detection.
+ *
+ * Similarly to Qwen, the PrevSeqLen is already detected in PrevSequenceLengthPattern:
+ * PrevSeqLen: Subtract (in: Parameter(name: max_context_len), in: CurrentSeqLen)
+ *
+ **/
+class ov::pass::TotalSequenceLengthPatternCodeGen2 : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("TotalSequenceLengthPatternCodeGen2", "0");
+ explicit TotalSequenceLengthPatternCodeGen2(const std::shared_ptr<ov::op::v0::Parameter>& max_context_len);
+};
\ No newline at end of file
diff --git a/src/common/transformations/src/transformations/sdpa_to_paged_attention/position_ids_replacer.cpp b/src/common/transformations/src/transformations/sdpa_to_paged_attention/position_ids_replacer.cpp
index 76d70e8f542..ac718c8951f 100644
--- a/src/common/transformations/src/transformations/sdpa_to_paged_attention/position_ids_replacer.cpp
+++ b/src/common/transformations/src/transformations/sdpa_to_paged_attention/position_ids_replacer.cpp
@@ -6,13 +6,21 @@
#include "openvino/cc/pass/itt.hpp"
#include "openvino/core/graph_util.hpp"
+#include "openvino/op/cos.hpp"
+#include "openvino/op/einsum.hpp"
#include "openvino/op/gather.hpp"
#include "openvino/op/matmul.hpp"
#include "openvino/op/multiply.hpp"
+#include "openvino/op/power.hpp"
+#include "openvino/op/range.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/shape_of.hpp"
+#include "openvino/op/sin.hpp"
#include "openvino/op/slice.hpp"
#include "openvino/op/squeeze.hpp"
+#include "openvino/op/subtract.hpp"
+#include "openvino/op/tile.hpp"
+#include "openvino/op/transpose.hpp"
#include "openvino/op/unsqueeze.hpp"
#include "openvino/pass/pattern/op/optional.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
@@ -53,10 +61,6 @@ ov::pass::PositionIDsReplacer::PositionIDsReplacer(const Output<Node>& position_
ov::pass::PositionIDsReplacerQwen::PositionIDsReplacerQwen(const Output<Node>& position_ids) {
MATCHER_SCOPE(PositionIDsReplacerQwen);
- auto _const = []() {
- return wrap_type<v0::Constant>();
- };
-
// total seq len:
auto p_max_context_len = wrap_type<v0::Parameter>();
auto p_opt_convert = optional<v0::Convert>(p_max_context_len);
@@ -69,7 +73,7 @@ ov::pass::PositionIDsReplacerQwen::PositionIDsReplacerQwen(const Output<Node>& p
// Probably we can use the symbols to re-use one of these ways.
// Currently, "any_input" is used to detect the both places.
auto p_shape_of = wrap_type<v3::ShapeOf>({any_input()});
- auto p_current_len = wrap_type<v8::Gather>({p_shape_of, _const(), _const()});
+ auto p_current_len = wrap_type<v8::Gather>({p_shape_of, wrap_const(), wrap_const()});
auto p_neg_const = wrap_type<v0::Constant>();
auto p_neg_const_convert = optional<v0::Convert>(p_neg_const);
@@ -84,8 +88,9 @@ ov::pass::PositionIDsReplacerQwen::PositionIDsReplacerQwen(const Output<Node>& p
// dequantizing subgraph, so it's going to be any_input() here.
auto p_rotary_emb_sincos = pattern::any_input();
// the rotary_emb_cos/rotary_emb_sin are sliced by the total length [1,..4096,1,128]
- auto p_slice_1 = wrap_type<v8::Slice>({p_rotary_emb_sincos, _const(), p_opt_reshape, _const(), _const()});
- auto p_slice_2 = wrap_type<v8::Slice>({p_slice_1, p_neg_mul, _const(), _const(), _const()});
+ auto p_slice_1 =
+ wrap_type<v8::Slice>({p_rotary_emb_sincos, wrap_const(), p_opt_reshape, wrap_const(), wrap_const()});
+ auto p_slice_2 = wrap_type<v8::Slice>({p_slice_1, p_neg_mul, wrap_const(), wrap_const(), wrap_const()});
ov::matcher_pass_callback callback = [=](Matcher& m) {
const auto& pattern_map = m.get_pattern_value_map();
@@ -123,3 +128,42 @@ ov::pass::PositionIDsReplacerQwen::PositionIDsReplacerQwen(const Output<Node>& p
auto m = std::make_shared<Matcher>(p_slice_2, matcher_name);
register_matcher(m, callback);
}
+
+ov::pass::PositionIDsReplacerCodeGen2::PositionIDsReplacerCodeGen2(const std::shared_ptr<v0::Parameter>& position_ids) {
+ MATCHER_SCOPE(PositionIDsReplacerCodeGen2);
+
+ auto p_range = wrap_type<v4::Range>();
+ auto p_power = wrap_type<v1::Power>();
+ auto p_einsum = wrap_type<v7::Einsum>({p_range, p_power});
+ auto p_sin_cos = wrap_type<v0::Sin, v0::Cos>({p_einsum});
+ auto p_reshape = wrap_type<v1::Reshape>({p_sin_cos, any_input()});
+ auto p_tile = wrap_type<v0::Tile>({p_reshape, any_input()});
+ auto p_opt_reshape = optional<v1::Reshape>({p_tile, any_input()});
+ auto p_opt_unsq = optional<v0::Unsqueeze>({p_opt_reshape, any_input()});
+
+ auto p_reshape_1in = wrap_type<v1::Reshape>({any_input(), any_input()});
+ auto p_add_2in = wrap_type<v1::Add>({any_input(), any_input()});
+ auto p_slice = wrap_type<v8::Slice>({p_opt_unsq, p_reshape_1in, p_add_2in, wrap_const(), wrap_const()});
+
+ auto p_add = wrap_type<v1::Add>();
+ matcher_pass_callback callback = [=, &position_ids](Matcher& m) {
+ auto pvm = m.get_pattern_value_map();
+ auto slice = pvm.at(p_slice).get_node_shared_ptr();
+
+ auto gather = std::make_shared<v8::Gather>(slice->input_value(0),
+ position_ids,
+ v0::Constant::create(element::i64, Shape{}, {1}));
+ if (gather->output(0).get_partial_shape().rank() != 3) {
+ return false;
+ }
+
+ auto transpose =
+ std::make_shared<v1::Transpose>(gather, v0::Constant::create(element::i64, Shape{3}, {1, 0, 2}));
+
+ replace_node(slice, transpose);
+ return true;
+ };
+
+ auto m = std::make_shared<Matcher>(p_slice, matcher_name);
+ register_matcher(m, callback);
+}
\ No newline at end of file
diff --git a/src/common/transformations/src/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.cpp b/src/common/transformations/src/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.cpp
index fa429d45e49..8efed4b772d 100644
--- a/src/common/transformations/src/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.cpp
+++ b/src/common/transformations/src/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.cpp
@@ -14,6 +14,7 @@
#include "openvino/op/shape_of.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/unsqueeze.hpp"
+#include "openvino/op/variadic_split.hpp"
#include "openvino/pass/pattern/op/optional.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "transformations/utils/utils.hpp"
@@ -147,3 +148,33 @@ ov::pass::TotalSequenceLengthPatternQwen::TotalSequenceLengthPatternQwen(
auto m = std::make_shared<Matcher>(p_total_seq, matcher_name);
register_matcher(m, callback);
}
+
+ov::pass::TotalSequenceLengthPatternCodeGen2::TotalSequenceLengthPatternCodeGen2(
+ const std::shared_ptr<ov::op::v0::Parameter>& max_context_len) {
+ MATCHER_SCOPE(TotalSequenceLengthPatternCodeGen2);
+
+ auto p_max_context_len = wrap_type<v0::Parameter>();
+ auto p_sub = wrap_type<v1::Subtract>({p_max_context_len, any_input()});
+ auto p_conv = wrap_type<v0::Convert>({p_sub});
+
+ auto p_var_split = wrap_type<v1::VariadicSplit>({any_input(), any_input(), any_input()});
+ auto p_kv_shape_current = wrap_type<v3::ShapeOf>({p_var_split});
+ auto p_gather = wrap_type<v8::Gather>({p_kv_shape_current, any_input(), any_input()});
+ auto p_total_seq = wrap_type<v1::Add>({p_gather, p_conv});
+
+ matcher_pass_callback callback = [=, &max_context_len](Matcher& m) {
+ const auto& pattern_map = m.get_pattern_value_map();
+ auto total_seq = pattern_map.at(p_total_seq).get_node_shared_ptr();
+ std::shared_ptr<Node> replacement = max_context_len;
+
+ auto target_type = total_seq->get_output_element_type(0);
+ auto required_shape = total_seq->get_output_partial_shape(0);
+ align_replacement(replacement, required_shape, target_type);
+
+ replace_node(total_seq, replacement);
+ return true;
+ };
+
+ auto m = std::make_shared<Matcher>(p_total_seq, matcher_name);
+ register_matcher(m, callback);
+}
\ No newline at end of file
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 53f9c2f2004..320fdb222fa 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
@@ -15,6 +15,7 @@
#include "openvino/op/constant.hpp"
#include "openvino/op/cos.hpp"
#include "openvino/op/divide.hpp"
+#include "openvino/op/einsum.hpp"
#include "openvino/op/equal.hpp"
#include "openvino/op/gather.hpp"
#include "openvino/op/greater.hpp"
@@ -23,7 +24,10 @@
#include "openvino/op/less_eq.hpp"
#include "openvino/op/logical_and.hpp"
#include "openvino/op/matmul.hpp"
+#include "openvino/op/maximum.hpp"
+#include "openvino/op/minimum.hpp"
#include "openvino/op/multiply.hpp"
+#include "openvino/op/mvn.hpp"
#include "openvino/op/paged_attention.hpp"
#include "openvino/op/power.hpp"
#include "openvino/op/range.hpp"
@@ -37,6 +41,7 @@
#include "openvino/op/sqrt.hpp"
#include "openvino/op/squeeze.hpp"
#include "openvino/op/subtract.hpp"
+#include "openvino/op/tile.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/unsqueeze.hpp"
#include "openvino/op/variadic_split.hpp"
@@ -1633,6 +1638,331 @@ TEST_F(SDPAToPATest, SDPAToPA_Phi3_mini_4k_instruct) {
}
}
+TEST_F(SDPAToPATest, SDPAToPA_Codegen2) {
+ {
+ auto beam_idx = make_param(PartialShape{DYN}, element::i32, "beam_idx");
+ auto position_ids = make_param(PartialShape{DYN, DYN}, element::i64, "position_ids");
+ auto attention_mask = make_param(PartialShape{DYN, DYN}, element::i64, "attention_mask");
+ auto input_ids = make_param(PartialShape{DYN, DYN}, element::i64, "input_ids");
+ auto params = nodes_to_params({beam_idx, position_ids, attention_mask, input_ids});
+
+ auto Constant0 = makeConst(element::f16, ov::Shape({}), {0});
+ auto Convert0 = makeOP<opset1::Convert>({Constant0}, {{"destination_type", "f32"}});
+ auto ShapeOf0 = makeOP<opset3::ShapeOf>({input_ids}, {{"output_type", "i64"}});
+ auto Gather0 = makeOP<opset8::Gather>({ShapeOf0, {0}, 0}, {{"batch_dims", 0}});
+ auto Concat0 = makeOP<opset1::Concat>({Gather0, {16l}, {0l}, {256l}}, {{"axis", 0}});
+ auto Broadcast0 = makeOP<opset3::Broadcast>({Convert0, Concat0}, {{"mode", "numpy"}});
+ auto ReadValue0 = makeOP<opset6::ReadValue>(
+ {Broadcast0},
+ {{"variable_id", "var1"}, {"variable_type", "f32"}, {"variable_shape", PartialShape{DYN, 16, DYN, 256}}});
+ auto Gather1 = makeOP<opset8::Gather>({ReadValue0, beam_idx, 0}, {{"batch_dims", 0}});
+ auto Constant1 = makeConst(element::f16, ov::Shape({51200, 4096}), MOCK_VALUE);
+ auto Convert1 = makeOP<opset1::Convert>({Constant1}, {{"destination_type", "f32"}});
+ auto Reshape0 = makeOP<opset1::Reshape>({input_ids, {-1, 0}}, {{"special_zero", true}});
+ auto Convert2 = makeOP<opset1::Convert>({Reshape0}, {{"destination_type", "i32"}});
+ auto Gather2 = makeOP<opset8::Gather>({Convert1, Convert2, 0}, {{"batch_dims", 0}});
+ auto MVN0 = makeOP<opset6::MVN>({Gather2, {-1}},
+ {{"eps", 0.000010}, {"normalize_variance", true}, {"eps_mode", "INSIDE_SQRT"}});
+ auto Constant2 = makeConst(element::f16, ov::Shape({1, 1, 4096}), MOCK_VALUE);
+ auto Convert3 = makeOP<opset1::Convert>({Constant2}, {{"destination_type", "f32"}});
+ auto Multiply0 = makeOP<opset1::Multiply>({MVN0, Convert3}, {{"auto_broadcast", "numpy"}});
+ auto Constant3 = makeConst(element::f16, ov::Shape({1, 1, 4096}), MOCK_VALUE);
+ auto Convert4 = makeOP<opset1::Convert>({Constant3}, {{"destination_type", "f32"}});
+ auto Add0 = makeOP<opset1::Add>({Multiply0, Convert4}, {{"auto_broadcast", "numpy"}});
+ auto Constant4 = makeConst(element::f16, ov::Shape({12288, 4096}), MOCK_VALUE);
+ auto Convert5 = makeOP<opset1::Convert>({Constant4}, {{"destination_type", "f32"}});
+ auto MatMul0 = makeOP<opset1::MatMul>({Add0, Convert5}, {{"transpose_a", false}, {"transpose_b", true}});
+ auto Reshape1 = makeOP<opset1::Reshape>({MatMul0, {0, 0, 4, -1}}, {{"special_zero", true}});
+ auto VariadicSplit0 = makeOP<opset1::VariadicSplit>({Reshape1, -1, {1024, 1024, -1}});
+ auto Reshape2 =
+ makeOP<opset1::Reshape>({VariadicSplit0->output(0), {0, 0, 0, 4, 256}}, {{"special_zero", true}});
+ auto Reshape3 = makeOP<opset1::Reshape>({Reshape2, {0, 0, 16, 256}}, {{"special_zero", true}});
+ auto Slice0 = makeOP<opset8::Slice>({Reshape3, {0}, {64}, {1}, {3}});
+ auto ShapeOf1 = makeOP<opset3::ShapeOf>({VariadicSplit0->output(0)}, {{"output_type", "i64"}});
+ auto Gather3 = makeOP<opset8::Gather>({ShapeOf1, 1, 0}, {{"batch_dims", 0}});
+ auto Constant5 = makeConst(element::f16, ov::Shape({}), {0});
+ auto Convert6 = makeOP<opset1::Convert>({Constant5}, {{"destination_type", "f32"}});
+ auto Concat1 = makeOP<opset1::Concat>({Gather0, {16l}, {0l}, {256l}}, {{"axis", 0}});
+ auto Broadcast1 = makeOP<opset3::Broadcast>({Convert6, Concat1}, {{"mode", "numpy"}});
+ auto ReadValue1 = makeOP<opset6::ReadValue>(
+ {Broadcast1},
+ {{"variable_id", "var1"}, {"variable_type", "f32"}, {"variable_shape", PartialShape{DYN, 16, DYN, 256}}});
+ auto Gather4 = makeOP<opset8::Gather>({ReadValue1, beam_idx, 0}, {{"batch_dims", 0}});
+ auto ShapeOf2 = makeOP<opset3::ShapeOf>({Gather4}, {{"output_type", "i64"}});
+ auto Gather5 = makeOP<opset8::Gather>({ShapeOf2, 2, 0}, {{"batch_dims", 0}});
+ auto Add1 = makeOP<opset1::Add>({Gather3, Gather5}, {{"auto_broadcast", "numpy"}});
+ auto Range0 = makeOP<opset4::Range>({0, Add1, 1}, {{"output_type", "f32"}});
+ auto Constant6 = makeConst(element::f16, ov::Shape({1}), {10000});
+ auto Convert7 = makeOP<opset1::Convert>({Constant6}, {{"destination_type", "f32"}});
+ auto Reshape4 =
+ makeOP<opset1::Reshape>({VariadicSplit0->output(2), {0, 0, 0, 4, 256}}, {{"special_zero", true}});
+ auto Reshape5 = makeOP<opset1::Reshape>({Reshape4, {0, 0, 16, 256}}, {{"special_zero", true}});
+ auto Slice1 = makeOP<opset8::Slice>({Reshape5, {0}, {64}, {1}, {3}});
+ auto ShapeOf3 = makeOP<opset3::ShapeOf>({Slice1}, {{"output_type", "i64"}});
+ auto Gather6 = makeOP<opset8::Gather>({ShapeOf3, 3, 0}, {{"batch_dims", 0}});
+ auto Range1 = makeOP<opset4::Range>({0, Gather6, 2}, {{"output_type", "f32"}});
+ auto Convert8 = makeOP<opset1::Convert>({Gather6}, {{"destination_type", "f32"}});
+ auto Divide0 = makeOP<opset1::Divide>({Range1, Convert8}, {{"auto_broadcast", "numpy"}, {"m_pythondiv", true}});
+ auto Power0 = makeOP<opset1::Power>({Convert7, Divide0}, {{"auto_broadcast", "numpy"}});
+ auto Constant7 = makeConst(element::f16, ov::Shape({1}), {-1});
+ auto Convert9 = makeOP<opset1::Convert>({Constant7}, {{"destination_type", "f32"}});
+ auto Power1 = makeOP<opset1::Power>({Power0, Convert9}, {{"auto_broadcast", "numpy"}});
+ auto Einsum0 = makeOP<opset7::Einsum>({Range0, Power1}, {{"equation", "i,j->ij"}});
+ auto Cos0 = makeOP<opset1::Cos>({Einsum0});
+ auto Reshape6 = makeOP<opset1::Reshape>({Cos0, {-1, 1}}, {{"special_zero", false}});
+ auto Tile0 = makeOP<opset1::Tile>({Reshape6, {1, 2}});
+ auto ShapeOf4 = makeOP<opset3::ShapeOf>({Cos0}, {{"output_type", "i64"}});
+ auto Gather7 = makeOP<opset8::Gather>({ShapeOf4, {0}, 0}, {{"batch_dims", 0}});
+ auto Concat2 = makeOP<opset1::Concat>({Gather7, {-1l}}, {{"axis", 0}});
+ auto Reshape7 = makeOP<opset1::Reshape>({Tile0, Concat2}, {{"special_zero", false}});
+ auto Unsqueeze0 = makeOP<opset1::Unsqueeze>({Reshape7, 0});
+ auto Reshape8 = makeOP<opset1::Reshape>({Gather5, {1}}, {{"special_zero", false}});
+ auto Reshape9 = makeOP<opset1::Reshape>({Gather3, {1}}, {{"special_zero", false}});
+ auto Add2 = makeOP<opset1::Add>({Reshape9, Reshape8}, {{"auto_broadcast", "numpy"}});
+ auto Slice2 = makeOP<opset8::Slice>({Unsqueeze0, Reshape8, Add2, {1}, {1}});
+ auto Unsqueeze1 = makeOP<opset1::Unsqueeze>({Slice2, 2});
+ auto Multiply1 = makeOP<opset1::Multiply>({Slice0, Unsqueeze1}, {{"auto_broadcast", "numpy"}});
+ auto Slice3 = makeOP<opset8::Slice>({Slice0, {1}, {LLONG_MAX}, {2}, {3}});
+ auto Convert10 = makeOP<opset1::Convert>({-1}, {{"destination_type", "f32"}});
+ auto Multiply2 = makeOP<opset1::Multiply>({Slice3, Convert10}, {{"auto_broadcast", "numpy"}});
+ auto Unsqueeze2 = makeOP<opset1::Unsqueeze>({Multiply2, -1});
+ auto Slice4 = makeOP<opset8::Slice>({Slice0, {0}, {LLONG_MAX}, {2}, {3}});
+ auto Unsqueeze3 = makeOP<opset1::Unsqueeze>({Slice4, -1});
+ auto Concat3 = makeOP<opset1::Concat>({Unsqueeze2, Unsqueeze3}, {{"axis", -1}});
+ auto Reshape10 = makeOP<opset1::Reshape>({Concat3, {0, 0, 16, 64}}, {{"special_zero", true}});
+ auto Sin0 = makeOP<opset1::Sin>({Einsum0});
+ auto Reshape11 = makeOP<opset1::Reshape>({Sin0, {-1, 1}}, {{"special_zero", false}});
+ auto Tile1 = makeOP<opset1::Tile>({Reshape11, {1, 2}});
+ auto Reshape12 = makeOP<opset1::Reshape>({Tile1, Concat2}, {{"special_zero", false}});
+ auto Unsqueeze4 = makeOP<opset1::Unsqueeze>({Reshape12, 0});
+ auto Slice5 = makeOP<opset8::Slice>({Unsqueeze4, Reshape8, Add2, {1}, {1}});
+ auto Unsqueeze5 = makeOP<opset1::Unsqueeze>({Slice5, 2});
+ auto Multiply3 = makeOP<opset1::Multiply>({Reshape10, Unsqueeze5}, {{"auto_broadcast", "numpy"}});
+ auto Add3 = makeOP<opset1::Add>({Multiply1, Multiply3}, {{"auto_broadcast", "numpy"}});
+ auto Slice6 = makeOP<opset8::Slice>({Reshape3, {64}, {LLONG_MAX}, {1}, {3}});
+ auto Concat4 = makeOP<opset1::Concat>({Add3, Slice6}, {{"axis", -1}});
+ auto Transpose0 = makeOP<opset1::Transpose>({Concat4, {0, 2, 1, 3}});
+ auto Multiply4 = makeOP<opset1::Multiply>({Slice1, Unsqueeze1}, {{"auto_broadcast", "numpy"}});
+ auto Slice7 = makeOP<opset8::Slice>({Slice1, {1}, {LLONG_MAX}, {2}, {3}});
+ auto Convert11 = makeOP<opset1::Convert>({-1}, {{"destination_type", "f32"}});
+ auto Multiply5 = makeOP<opset1::Multiply>({Slice7, Convert11}, {{"auto_broadcast", "numpy"}});
+ auto Unsqueeze6 = makeOP<opset1::Unsqueeze>({Multiply5, -1});
+ auto Slice8 = makeOP<opset8::Slice>({Slice1, {0}, {LLONG_MAX}, {2}, {3}});
+ auto Unsqueeze7 = makeOP<opset1::Unsqueeze>({Slice8, -1});
+ auto Concat5 = makeOP<opset1::Concat>({Unsqueeze6, Unsqueeze7}, {{"axis", -1}});
+ auto Reshape13 = makeOP<opset1::Reshape>({Concat5, {0, 0, 16, 64}}, {{"special_zero", true}});
+ auto Multiply6 = makeOP<opset1::Multiply>({Reshape13, Unsqueeze5}, {{"auto_broadcast", "numpy"}});
+ auto Add4 = makeOP<opset1::Add>({Multiply4, Multiply6}, {{"auto_broadcast", "numpy"}});
+ auto Slice9 = makeOP<opset8::Slice>({Reshape5, {64}, {LLONG_MAX}, {1}, {3}});
+ auto Concat6 = makeOP<opset1::Concat>({Add4, Slice9}, {{"axis", -1}});
+ auto Transpose1 = makeOP<opset1::Transpose>({Concat6, {0, 2, 1, 3}});
+ auto Concat7 = makeOP<opset1::Concat>({Gather4, Transpose1}, {{"axis", -2}});
+ auto Constant8_compressed = makeConst(element::f16, ov::Shape({}), {0});
+ auto Convert12 = makeOP<opset1::Convert>({Constant8_compressed}, {{"destination_type", "f32"}});
+ auto Concat8 = makeOP<opset1::Concat>({Gather0, {16l}, {0l}, {256l}}, {{"axis", 0}});
+ auto Broadcast2 = makeOP<opset3::Broadcast>({Convert12, Concat8}, {{"mode", "numpy"}});
+ auto ReadValue2 = makeOP<opset6::ReadValue>(
+ {Broadcast2},
+ {{"variable_id", "var2"}, {"variable_type", "f32"}, {"variable_shape", PartialShape{DYN, 16, DYN, 256}}});
+ auto Gather8 = makeOP<opset8::Gather>({ReadValue2, beam_idx, 0}, {{"batch_dims", 0}});
+ auto Reshape14 =
+ makeOP<opset1::Reshape>({VariadicSplit0->output(1), {0, 0, 0, 4, 256}}, {{"special_zero", true}});
+ auto Reshape15 = makeOP<opset1::Reshape>({Reshape14, {0, 0, 16, 256}}, {{"special_zero", true}});
+ auto Transpose2 = makeOP<opset1::Transpose>({Reshape15, {0, 2, 1, 3}});
+ auto Concat9 = makeOP<opset1::Concat>({Gather8, Transpose2}, {{"axis", -2}});
+ auto Constant9 = makeConst(element::u8, ov::Shape({1, 1, 2048, 2048}), MOCK_VALUE);
+ auto Add5 = makeOP<opset1::Add>({Reshape8, Reshape9}, {{"auto_broadcast", "numpy"}});
+ auto Subtract0 = makeOP<opset1::Subtract>({Add5, Reshape9}, {{"auto_broadcast", "numpy"}});
+ auto Concat10 = makeOP<opset1::Concat>({Subtract0, {0l}}, {{"axis", 0}});
+ auto Broadcast3 = makeOP<opset3::Broadcast>({Add5, {2}}, {{"mode", "numpy"}});
+ auto Slice10 = makeOP<opset8::Slice>({Constant9, Concat10, Broadcast3, {1, 1}, {2, 3}});
+ auto Convert13 = makeOP<opset1::Convert>({Slice10}, {{"destination_type", "boolean"}});
+ auto Constant10 = makeConst(element::f16, ov::Shape({}), {0});
+ auto Convert14 = makeOP<opset1::Convert>({Constant10}, {{"destination_type", "f32"}});
+ auto Select0 = makeOP<opset1::Select>({Convert13, Convert14, -FLT_MAX}, {{"auto_broadcast", "numpy"}});
+ auto Constant11 = makeConst(element::f16, ov::Shape({1, 1, 1, 1}), {1});
+ auto Convert15 = makeOP<opset1::Convert>({Constant11}, {{"destination_type", "f32"}});
+ auto Reshape16 = makeOP<opset1::Reshape>({attention_mask, {0, 0}}, {{"special_zero", true}});
+ auto Unsqueeze8 = makeOP<opset1::Unsqueeze>({Reshape16, 1});
+ auto Unsqueeze9 = makeOP<opset1::Unsqueeze>({Unsqueeze8, 2});
+ auto Convert16 = makeOP<opset1::Convert>({Unsqueeze9}, {{"destination_type", "f32"}});
+ auto Constant12 = makeConst(element::f16, ov::Shape({1, 1, 1, 1}), {1});
+ auto Convert17 = makeOP<opset1::Convert>({Constant12}, {{"destination_type", "f32"}});
+ auto Multiply7 = makeOP<opset1::Multiply>({Convert16, Convert17}, {{"auto_broadcast", "numpy"}});
+ auto Subtract1 = makeOP<opset1::Subtract>({Convert15, Multiply7}, {{"auto_broadcast", "numpy"}});
+ auto Constant13 = makeConst(element::f32, ov::Shape({1, 1, 1, 1}), {-FLT_MAX});
+ auto Multiply8 = makeOP<opset1::Multiply>({Subtract1, Constant13}, {{"auto_broadcast", "numpy"}});
+ auto Minimum0 = makeOP<opset1::Minimum>({Select0, Multiply8}, {{"auto_broadcast", "numpy"}});
+ auto ShapeOf5 = makeOP<opset3::ShapeOf>({Minimum0}, {{"output_type", "i64"}});
+ auto Gather9 = makeOP<opset8::Gather>({ShapeOf1, {0}, 0}, {{"batch_dims", 0}});
+ auto Concat11 = makeOP<opset1::Concat>({Gather9, {1l}, {1l}, {1l}}, {{"axis", 0}});
+ auto Maximum0 = makeOP<opset1::Maximum>({ShapeOf5, Concat11}, {{"auto_broadcast", "numpy"}});
+ auto Broadcast4 = makeOP<opset3::Broadcast>({Minimum0, Maximum0}, {{"mode", "numpy"}});
+ auto ScaledDotProductAttention =
+ makeOP<v13::ScaledDotProductAttention>({Transpose0, Concat7, Concat9, Broadcast4}, {{"causal", false}});
+
+ auto res = make_shared<v0::Result>(ScaledDotProductAttention);
+
+ model = std::make_shared<ov::Model>(OutputVector{res}, params);
+
+ manager.register_pass<ov::pass::SDPAToPagedAttention>();
+ }
+ {
+ auto max_context_len = make_param(PartialShape{}, element::i32, "max_context_len");
+ auto block_indices_begins = make_param(PartialShape{DYN}, element::i32, "block_indices_begins");
+ auto block_indices = make_param(PartialShape{DYN}, element::i32, "block_indices");
+ auto subsequence_begins = make_param(PartialShape{DYN}, element::i32, "subsequence_begins");
+ auto past_lens = make_param(PartialShape{DYN}, element::i32, "past_lens");
+ auto value_cache_0 = make_param(PartialShape{DYN, 16, 256}, element::f32, "value_cache_0");
+ auto key_cache_0 = make_param(PartialShape{DYN, 16, 256}, element::f32, "key_cache_0");
+ auto input_ids = make_param(PartialShape{DYN}, element::i64, "inputs_ids");
+ auto position_ids = make_param(PartialShape{DYN}, element::i64, "position_ids");
+ auto Constant0 = makeConst(element::i32, ov::Shape({0}), MOCK_VALUE);
+
+ auto params = nodes_to_params({max_context_len,
+ block_indices_begins,
+ block_indices,
+ subsequence_begins,
+ past_lens,
+ value_cache_0,
+ key_cache_0,
+ input_ids,
+ position_ids});
+
+ auto Constant1 = makeConst(element::f16, ov::Shape({51200, 4096}), MOCK_VALUE);
+ auto Convert0 = makeOP<opset1::Convert>({Constant1}, {{"destination_type", "f32"}});
+ auto Unsqueeze0 = makeOP<opset1::Unsqueeze>({input_ids, 1});
+ auto Reshape0 = makeOP<opset1::Reshape>({Unsqueeze0, {-1, 0}}, {{"special_zero", true}});
+ auto Convert1 = makeOP<opset1::Convert>({Reshape0}, {{"destination_type", "i32"}});
+ auto Gather0 = makeOP<opset8::Gather>({Convert0, Convert1, 0}, {{"batch_dims", 0}});
+ auto MVN0 = makeOP<opset6::MVN>({Gather0, {-1}},
+ {{"eps", 0.000010}, {"normalize_variance", true}, {"eps_mode", "INSIDE_SQRT"}});
+ auto Constant2 = makeConst(element::f16, ov::Shape({1, 1, 4096}), MOCK_VALUE);
+ auto Convert2 = makeOP<opset1::Convert>({Constant2}, {{"destination_type", "f32"}});
+ auto Multiply0 = makeOP<opset1::Multiply>({MVN0, Convert2}, {{"auto_broadcast", "numpy"}});
+ auto Constant3 = makeConst(element::f16, ov::Shape({1, 1, 4096}), MOCK_VALUE);
+ auto Convert3 = makeOP<opset1::Convert>({Constant3}, {{"destination_type", "f32"}});
+ auto Add0 = makeOP<opset1::Add>({Multiply0, Convert3}, {{"auto_broadcast", "numpy"}});
+ auto Constant4 = makeConst(element::f16, ov::Shape({12288, 4096}), MOCK_VALUE);
+ auto Convert4 = makeOP<opset1::Convert>({Constant4}, {{"destination_type", "f32"}});
+ auto MatMul0 = makeOP<opset1::MatMul>({Add0, Convert4}, {{"transpose_a", false}, {"transpose_b", true}});
+ auto Reshape1 = makeOP<opset1::Reshape>({MatMul0, {0, 0, 4, -1}}, {{"special_zero", true}});
+ auto VariadicSplit0 = makeOP<opset1::VariadicSplit>({Reshape1, -1, {1024, 1024, -1}});
+ auto Reshape2 =
+ makeOP<opset1::Reshape>({VariadicSplit0->output(0), {0, 0, 0, 4, 256}}, {{"special_zero", true}});
+ auto Reshape3 = makeOP<opset1::Reshape>({Reshape2, {0, 0, 16, 256}}, {{"special_zero", true}});
+ auto Slice0 = makeOP<opset8::Slice>({Reshape3, {0}, {64}, {1}, {3}});
+ auto Convert5 = makeOP<opset1::Convert>({max_context_len}, {{"destination_type", "i64"}});
+ auto Range0 = makeOP<opset4::Range>({0, Convert5, 1}, {{"output_type", "f32"}});
+ auto Constant5 = makeConst(element::f16, ov::Shape({1}), {10000});
+ auto Convert6 = makeOP<opset1::Convert>({Constant5}, {{"destination_type", "f32"}});
+ auto Reshape4 =
+ makeOP<opset1::Reshape>({VariadicSplit0->output(2), {0, 0, 0, 4, 256}}, {{"special_zero", true}});
+ auto Reshape5 = makeOP<opset1::Reshape>({Reshape4, {0, 0, 16, 256}}, {{"special_zero", true}});
+ auto Slice1 = makeOP<opset8::Slice>({Reshape5, {0}, {64}, {1}, {3}});
+ auto ShapeOf0 = makeOP<opset3::ShapeOf>({Slice1}, {{"output_type", "i64"}});
+ auto Gather1 = makeOP<opset8::Gather>({ShapeOf0, 3, 0}, {{"batch_dims", 0}});
+ auto Range1 = makeOP<opset4::Range>({0, Gather1, 2}, {{"output_type", "f32"}});
+ auto Convert7 = makeOP<opset1::Convert>({Gather1}, {{"destination_type", "f32"}});
+ auto Divide0 = makeOP<opset1::Divide>({Range1, Convert7}, {{"auto_broadcast", "numpy"}, {"m_pythondiv", true}});
+ auto Power0 = makeOP<opset1::Power>({Convert6, Divide0}, {{"auto_broadcast", "numpy"}});
+ auto Constant6 = makeConst(element::f16, ov::Shape({1}), {-1});
+ auto Convert8 = makeOP<opset1::Convert>({Constant6}, {{"destination_type", "f32"}});
+ auto Power1 = makeOP<opset1::Power>({Power0, Convert8}, {{"auto_broadcast", "numpy"}});
+ auto Einsum0 = makeOP<opset7::Einsum>({Range0, Power1}, {{"equation", "i,j->ij"}});
+ auto Cos0 = makeOP<opset1::Cos>({Einsum0});
+ auto Reshape6 = makeOP<opset1::Reshape>({Cos0, {-1, 1}}, {{"special_zero", false}});
+ auto Tile0 = makeOP<opset1::Tile>({Reshape6, {1, 2}});
+ auto ShapeOf1 = makeOP<opset3::ShapeOf>({Cos0}, {{"output_type", "i64"}});
+ auto Gather2 = makeOP<opset8::Gather>({ShapeOf1, {0}, 0}, {{"batch_dims", 0}});
+ auto Concat0 = makeOP<opset1::Concat>({Gather2, {-1l}}, {{"axis", 0}});
+ auto Reshape7 = makeOP<opset1::Reshape>({Tile0, Concat0}, {{"special_zero", false}});
+ auto Unsqueeze1 = makeOP<opset1::Unsqueeze>({Reshape7, 0});
+ auto Gather3 = makeOP<opset8::Gather>({Unsqueeze1, position_ids, 1}, {{"batch_dims", 0}});
+ auto Transpose0 = makeOP<opset1::Transpose>({Gather3, {1, 0, 2}});
+ auto Unsqueeze2 = makeOP<opset1::Unsqueeze>({Transpose0, 2});
+ auto Multiply1 = makeOP<opset1::Multiply>({Slice0, Unsqueeze2}, {{"auto_broadcast", "numpy"}});
+ auto Slice2 = makeOP<opset8::Slice>({Slice0, {1}, {LLONG_MAX}, {2}, {3}});
+ auto Convert9 = makeOP<opset1::Convert>({-1}, {{"destination_type", "f32"}});
+ auto Multiply2 = makeOP<opset1::Multiply>({Slice2, Convert9}, {{"auto_broadcast", "numpy"}});
+ auto Unsqueeze3 = makeOP<opset1::Unsqueeze>({Multiply2, -1});
+ auto Slice3 = makeOP<opset8::Slice>({Slice0, {0}, {LLONG_MAX}, {2}, {3}});
+ auto Unsqueeze4 = makeOP<opset1::Unsqueeze>({Slice3, -1});
+ auto Concat1 = makeOP<opset1::Concat>({Unsqueeze3, Unsqueeze4}, {{"axis", -1}});
+ auto Reshape8 = makeOP<opset1::Reshape>({Concat1, {0, 0, 16, 64}}, {{"special_zero", true}});
+ auto Sin0 = makeOP<opset1::Sin>({Einsum0});
+ auto Reshape9 = makeOP<opset1::Reshape>({Sin0, {-1, 1}}, {{"special_zero", false}});
+ auto Tile1 = makeOP<opset1::Tile>({Reshape9, {1, 2}});
+ auto Reshape10 = makeOP<opset1::Reshape>({Tile1, Concat0}, {{"special_zero", false}});
+ auto Unsqueeze5 = makeOP<opset1::Unsqueeze>({Reshape10, 0});
+ auto Gather4 = makeOP<opset8::Gather>({Unsqueeze5, position_ids, 1}, {{"batch_dims", 0}});
+ auto Transpose1 = makeOP<opset1::Transpose>({Gather4, {1, 0, 2}});
+ auto Unsqueeze6 = makeOP<opset1::Unsqueeze>({Transpose1, 2});
+ auto Multiply3 = makeOP<opset1::Multiply>({Reshape8, Unsqueeze6}, {{"auto_broadcast", "numpy"}});
+ auto Add1 = makeOP<opset1::Add>({Multiply1, Multiply3}, {{"auto_broadcast", "numpy"}});
+ auto Slice4 = makeOP<opset8::Slice>({Reshape3, {64}, {LLONG_MAX}, {1}, {3}});
+ auto Concat2 = makeOP<opset1::Concat>({Add1, Slice4}, {{"axis", -1}});
+ auto Transpose2 = makeOP<opset1::Transpose>({Concat2, {0, 2, 1, 3}});
+ auto Transpose3 = makeOP<opset1::Transpose>({Transpose2, {0, 2, 1, 3}});
+ auto Reshape11 = makeOP<opset1::Reshape>({Transpose3, {0, -1}}, {{"special_zero", true}});
+ auto Multiply4 = makeOP<opset1::Multiply>({Slice1, Unsqueeze2}, {{"auto_broadcast", "numpy"}});
+ auto Slice5 = makeOP<opset8::Slice>({Slice1, {1}, {LLONG_MAX}, {2}, {3}});
+ auto Convert10 = makeOP<opset1::Convert>({-1}, {{"destination_type", "f32"}});
+ auto Multiply5 = makeOP<opset1::Multiply>({Slice5, Convert10}, {{"auto_broadcast", "numpy"}});
+ auto Unsqueeze7 = makeOP<opset1::Unsqueeze>({Multiply5, -1});
+ auto Slice6 = makeOP<opset8::Slice>({Slice1, {0}, {LLONG_MAX}, {2}, {3}});
+ auto Unsqueeze8 = makeOP<opset1::Unsqueeze>({Slice6, -1});
+ auto Concat3 = makeOP<opset1::Concat>({Unsqueeze7, Unsqueeze8}, {{"axis", -1}});
+ auto Reshape12 = makeOP<opset1::Reshape>({Concat3, {0, 0, 16, 64}}, {{"special_zero", true}});
+ auto Multiply6 = makeOP<opset1::Multiply>({Reshape12, Unsqueeze6}, {{"auto_broadcast", "numpy"}});
+ auto Add2 = makeOP<opset1::Add>({Multiply4, Multiply6}, {{"auto_broadcast", "numpy"}});
+ auto Slice7 = makeOP<opset8::Slice>({Reshape5, {64}, {LLONG_MAX}, {1}, {3}});
+ auto Concat4 = makeOP<opset1::Concat>({Add2, Slice7}, {{"axis", -1}});
+ auto Transpose4 = makeOP<opset1::Transpose>({Concat4, {0, 2, 1, 3}});
+ auto Transpose5 = makeOP<opset1::Transpose>({Transpose4, {0, 2, 1, 3}});
+ auto Reshape13 = makeOP<opset1::Reshape>({Transpose5, {0, -1}}, {{"special_zero", true}});
+ auto Reshape14 =
+ makeOP<opset1::Reshape>({VariadicSplit0->output(1), {0, 0, 0, 4, 256}}, {{"special_zero", true}});
+ auto Reshape15 = makeOP<opset1::Reshape>({Reshape14, {0, 0, 16, 256}}, {{"special_zero", true}});
+ auto Transpose6 = makeOP<opset1::Transpose>({Reshape15, {0, 2, 1, 3}});
+ auto Transpose7 = makeOP<opset1::Transpose>({Transpose6, {0, 2, 1, 3}});
+ auto Reshape16 = makeOP<opset1::Reshape>({Transpose7, {0, -1}}, {{"special_zero", true}});
+
+ auto sliding_window = v0::Constant::create(element::i32, {}, {0});
+ auto scale = v0::Constant::create(element::f32, {}, {0.062500f});
+ auto alibi_slopes_stub = v0::Constant::create(element::f32, Shape{0}, {});
+ auto PagedAttentionExtension =
+ std::make_shared<ov::op::PagedAttentionExtension>(OutputVector{Reshape11,
+ Reshape13,
+ Reshape16,
+ key_cache_0,
+ value_cache_0,
+ past_lens,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ scale,
+ sliding_window,
+ alibi_slopes_stub,
+ max_context_len,
+ Constant0});
+ auto ShapeOf2 = makeOP<opset3::ShapeOf>({Transpose7}, {{"output_type", "i64"}});
+ auto Gather5 = makeOP<opset8::Gather>({ShapeOf2, -1, 0}, {{"batch_dims", 0}});
+ auto Unsqueeze9 = makeOP<opset1::Unsqueeze>({Gather5, 0});
+ auto Concat5 = makeOP<opset1::Concat>({{0l}, {1l}, {-1l}, Unsqueeze9}, {{"axis", 0}});
+ auto Reshape17 =
+ makeOP<opset1::Reshape>({PagedAttentionExtension->output(0), Concat5}, {{"special_zero", true}});
+ auto Transpose8 = makeOP<opset1::Transpose>({Reshape17, {0, 2, 1, 3}});
+ auto res = makeOP<opset1::Result>({Transpose8});
+
+ model_ref = std::make_shared<ov::Model>(res, params);
+
+ comparator.disable(FunctionsComparator::PRECISIONS);
+ disable_result_friendly_names_check();
+ disable_rt_info_check();
+ }
+}
+
/*
As there's often a need to cover specific model's architecutres in these
tests, please, make sure you name the tests in the following manner:
diff --git a/src/core/include/openvino/pass/pattern/op/wrap_type.hpp b/src/core/include/openvino/pass/pattern/op/wrap_type.hpp
index eb6917afabd..01467f56ca0 100644
--- a/src/core/include/openvino/pass/pattern/op/wrap_type.hpp
+++ b/src/core/include/openvino/pass/pattern/op/wrap_type.hpp
@@ -93,4 +93,6 @@ template <class... Args>
std::shared_ptr<Node> wrap_type(std::initializer_list<std::pair<const std::string, ov::Any>>&& attrs) {
return wrap_type<Args...>(PatternOps{}, Attributes(attrs));
}
+
+std::shared_ptr<Node> wrap_const();
} // namespace ov::pass::pattern
diff --git a/src/core/src/pass/sdpa_to_paged_attention.cpp b/src/core/src/pass/sdpa_to_paged_attention.cpp
index b5d6c3dd70a..5a563dd52b6 100644
--- a/src/core/src/pass/sdpa_to_paged_attention.cpp
+++ b/src/core/src/pass/sdpa_to_paged_attention.cpp
@@ -156,8 +156,10 @@ bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr<ov::Mode
manager.register_pass<PrevSequenceLengthPattern>(processed_input_ids, max_context_len, position_ids);
manager.register_pass<TotalSequenceLengthPattern>(max_context_len);
manager.register_pass<TotalSequenceLengthPatternQwen>(max_context_len);
+ manager.register_pass<TotalSequenceLengthPatternCodeGen2>(max_context_len);
manager.register_pass<PositionIDsReplacer>(unsqueezed_position_ids);
manager.register_pass<PositionIDsReplacerQwen>(unsqueezed_position_ids);
+ manager.register_pass<PositionIDsReplacerCodeGen2>(position_ids);
manager.run_passes(model);
{
diff --git a/src/core/src/pattern/op/wrap_type.cpp b/src/core/src/pattern/op/wrap_type.cpp
index 5f48922f363..d35af84f238 100644
--- a/src/core/src/pattern/op/wrap_type.cpp
+++ b/src/core/src/pattern/op/wrap_type.cpp
@@ -59,4 +59,8 @@ std::ostream& ov::pass::pattern::op::WrapType::write_type_description(std::ostre
}
out << (m_wrapped_types.size() > 1 ? ">" : "");
return out;
+}
+
+std::shared_ptr<ov::Node> ov::pass::pattern::wrap_const() {
+ return ov::pass::pattern::wrap_type<ov::op::v0::Constant>();
}
\ No newline at end of file
diff --git a/src/core/tests/type_prop/read_value.cpp b/src/core/tests/type_prop/read_value.cpp
index 3a9d6bafea6..d245e40a443 100644
--- a/src/core/tests/type_prop/read_value.cpp
+++ b/src/core/tests/type_prop/read_value.cpp
@@ -125,4 +125,4 @@ TEST(type_prop, DISABLED_read_value_symbols_propagation_from_init_subgraph) {
auto variable = std::make_shared<op::util::Variable>(variable_info);
std::shared_ptr<ov::op::v6::ReadValue> read_value = std::make_shared<ov::op::v6::ReadValue>(input, variable);
EXPECT_THAT(get_shape_symbols(read_value->get_output_partial_shape(0)), symbols);
-}
+}
\ No newline at end of file