Skip to content

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

[PagedAttention] Add score aggregation inputs (#30174)

Vasily Shamporovef9b07315679
diff --git a/src/bindings/python/src/pyopenvino/core/offline_transformations.cpp b/src/bindings/python/src/pyopenvino/core/offline_transformations.cpp
index 18ae331bb98..8b994708828 100644
--- a/src/bindings/python/src/pyopenvino/core/offline_transformations.cpp
+++ b/src/bindings/python/src/pyopenvino/core/offline_transformations.cpp
@@ -143,17 +143,23 @@ void regmodule_offline_transformations(py::module m) {
m_offline_transformations.def(
"paged_attention_transformation",
- [](py::object& ie_api_model, bool use_block_indices_inputs, bool use_score_outputs, bool allow_cache_rotation) {
+ [](py::object& ie_api_model,
+ bool use_block_indices_inputs,
+ bool use_score_outputs,
+ bool allow_score_aggregation,
+ bool allow_cache_rotation) {
const auto model = Common::utils::convert_to_model(ie_api_model);
ov::pass::Manager manager;
manager.register_pass<ov::pass::SDPAToPagedAttention>(use_block_indices_inputs,
use_score_outputs,
+ allow_score_aggregation,
allow_cache_rotation);
manager.run_passes(model);
},
py::arg("model"),
py::arg("use_block_indices_inputs") = false,
py::arg("use_score_outputs") = false,
+ py::arg("allow_score_aggregation") = false,
py::arg("allow_cache_rotation") = false);
m_offline_transformations.def(
diff --git a/src/common/transformations/include/transformations/sdpa_to_paged_attention/state_management_pattern.hpp b/src/common/transformations/include/transformations/sdpa_to_paged_attention/state_management_pattern.hpp
index 56bad49af0c..0e353ff83a5 100644
--- a/src/common/transformations/include/transformations/sdpa_to_paged_attention/state_management_pattern.hpp
+++ b/src/common/transformations/include/transformations/sdpa_to_paged_attention/state_management_pattern.hpp
@@ -19,7 +19,7 @@ class ov::pass::StateManagementPattern : public ov::pass::MatcherPass {
public:
OPENVINO_MATCHER_PASS_RTTI("StateManagementPattern");
StateManagementPattern(ParameterVector& kv_parameters,
- ParameterVector& model_remaining_params,
+ ParameterVector& model_wide_params,
ParameterVector& parameters_to_remove,
int& layer_index,
ov::Output<Node> max_context_len,
@@ -28,7 +28,9 @@ public:
bool use_per_layer_block_indices_inputs,
bool use_score_outputs,
bool allow_cache_rotation,
+ bool allow_score_aggregation,
ParameterVector& rotated_block_indices_inputs_for_each_layer,
ParameterVector& rotation_deltas_inputs_for_each_layer,
- std::shared_ptr<op::v0::Parameter> model_rotation_trig_lut);
+ std::shared_ptr<op::v0::Parameter> model_rotation_trig_lut,
+ const std::map<std::string, std::shared_ptr<op::v0::Parameter>>& optional_model_wide_params);
};
diff --git a/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp b/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp
index ca900d977c2..ec40732d92c 100644
--- a/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp
+++ b/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp
@@ -35,40 +35,47 @@ ov::pass::ConvertPagedAttnInputs::ConvertPagedAttnInputs(const KVCacheConfig& co
auto sliding_window = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());
auto alibi_slopes = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());
auto max_context_len = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());
+ auto score_aggregation_window = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());
auto rotated_block_indices = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());
auto rotation_deltas = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());
auto rotation_trig_lut = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());
- auto pa_1 = makePattern<op::PagedAttentionExtension>({Q,
- K,
- V,
- key_cache_0,
- value_cache_0,
- past_lens,
- subsequence_begins,
- block_indices,
- block_indices_begins,
- scale,
- sliding_window,
- alibi_slopes,
- max_context_len});
+ auto pa_1 = makePattern<op::PagedAttentionExtension>({
+ Q,
+ K,
+ V,
+ key_cache_0,
+ value_cache_0,
+ past_lens,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ scale,
+ sliding_window,
+ alibi_slopes,
+ max_context_len,
+ score_aggregation_window,
+ });
- auto pa_2 = makePattern<op::PagedAttentionExtension>({Q,
- K,
- V,
- key_cache_0,
- value_cache_0,
- past_lens,
- subsequence_begins,
- block_indices,
- block_indices_begins,
- scale,
- sliding_window,
- alibi_slopes,
- max_context_len,
- rotated_block_indices,
- rotation_deltas,
- rotation_trig_lut});
+ auto pa_2 = makePattern<op::PagedAttentionExtension>({
+ Q,
+ K,
+ V,
+ key_cache_0,
+ value_cache_0,
+ past_lens,
+ subsequence_begins,
+ block_indices,
+ block_indices_begins,
+ scale,
+ sliding_window,
+ alibi_slopes,
+ max_context_len,
+ score_aggregation_window,
+ rotated_block_indices,
+ rotation_deltas,
+ rotation_trig_lut,
+ });
auto result = pa_1 | pa_2;
ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {
const auto pa_op = m.get_match_root();
diff --git a/src/common/transformations/src/transformations/sdpa_to_paged_attention/state_management_pattern.cpp b/src/common/transformations/src/transformations/sdpa_to_paged_attention/state_management_pattern.cpp
index 7a132ae6d20..ae3be3610ce 100644
--- a/src/common/transformations/src/transformations/sdpa_to_paged_attention/state_management_pattern.cpp
+++ b/src/common/transformations/src/transformations/sdpa_to_paged_attention/state_management_pattern.cpp
@@ -229,19 +229,22 @@ static node_tuple kv_read_and_concat(ov::Output<ov::Node> kv_current) {
return node_tuple(kv_past_par, kv_current2, kv_current_reshaped, kv_concat);
}
-ov::pass::StateManagementPattern::StateManagementPattern(ParameterVector& kv_parameters,
- ParameterVector& model_remaining_params,
- ParameterVector& parameters_to_remove,
- int& layer_index,
- Output<Node> max_context_len,
- ParameterVector& block_indices_inputs_for_each_layer,
- ResultVector& score_results,
- bool use_per_layer_block_indices_inputs,
- bool use_score_outputs,
- bool allow_cache_rotation,
- ParameterVector& rotated_block_indices_inputs_for_each_layer,
- ParameterVector& rotation_deltas_inputs_for_each_layer,
- std::shared_ptr<op::v0::Parameter> model_rotation_trig_lut) {
+ov::pass::StateManagementPattern::StateManagementPattern(
+ ParameterVector& kv_parameters,
+ ParameterVector& model_wide_params,
+ ParameterVector& parameters_to_remove,
+ int& layer_index,
+ Output<Node> max_context_len,
+ ParameterVector& block_indices_inputs_for_each_layer,
+ ResultVector& score_results,
+ bool use_per_layer_block_indices_inputs,
+ bool use_score_outputs,
+ bool allow_cache_rotation,
+ bool allow_score_aggregation,
+ ParameterVector& rotated_block_indices_inputs_for_each_layer,
+ ParameterVector& rotation_deltas_inputs_for_each_layer,
+ std::shared_ptr<op::v0::Parameter> model_rotation_trig_lut,
+ const std::map<std::string, std::shared_ptr<op::v0::Parameter>>& optional_model_wide_params) {
MATCHER_SCOPE(StateManagementPattern);
auto k_current = pattern::any_input();
@@ -344,7 +347,7 @@ ov::pass::StateManagementPattern::StateManagementPattern(ParameterVector& kv_par
ov::matcher_pass_callback callback = [=,
&kv_parameters,
- &model_remaining_params,
+ &model_wide_params,
&parameters_to_remove,
&block_indices_inputs_for_each_layer,
&score_results,
@@ -518,7 +521,7 @@ ov::pass::StateManagementPattern::StateManagementPattern(ParameterVector& kv_par
}
OutputVector pa_arguments = {q_reshape, k_reshape, v_reshape, k_parameter, v_parameter};
- pa_arguments.insert(pa_arguments.end(), model_remaining_params.begin(), model_remaining_params.end());
+ pa_arguments.insert(pa_arguments.end(), model_wide_params.begin(), model_wide_params.end());
std::shared_ptr<Node> sliding_window;
if (pattern_map.count(phi3_offset)) {
@@ -544,7 +547,17 @@ ov::pass::StateManagementPattern::StateManagementPattern(ParameterVector& kv_par
block_indices_inputs_for_each_layer.push_back(block_indices);
}
- OPENVINO_ASSERT(pa_arguments.size() == 13);
+ if (allow_score_aggregation) {
+ OPENVINO_ASSERT(
+ optional_model_wide_params.find("score_aggregation_window") != optional_model_wide_params.end(),
+ "No score_aggregation_window input found. For using score aggregation mode, the model have to contain "
+ "an additional input (Parameter) called score_aggregation_window.");
+ pa_arguments.insert(pa_arguments.end(), optional_model_wide_params.at("score_aggregation_window"));
+ } else {
+ pa_arguments.insert(pa_arguments.end(), v0::Constant::create(element::i32, Shape{0}, {}));
+ }
+
+ OPENVINO_ASSERT(pa_arguments.size() == 14);
if (allow_cache_rotation) {
auto rotated_block_indices = setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{-1}),
@@ -552,9 +565,9 @@ ov::pass::StateManagementPattern::StateManagementPattern(ParameterVector& kv_par
auto rotation_deltas = setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{-1, -1}),
"rotation_deltas." + std::to_string(layer_index - 1));
- pa_arguments.insert(pa_arguments.begin() + 13, rotated_block_indices);
- pa_arguments.insert(pa_arguments.begin() + 14, rotation_deltas);
- pa_arguments.insert(pa_arguments.begin() + 15, model_rotation_trig_lut);
+ pa_arguments.insert(pa_arguments.begin() + 14, rotated_block_indices);
+ pa_arguments.insert(pa_arguments.begin() + 15, rotation_deltas);
+ pa_arguments.insert(pa_arguments.begin() + 16, model_rotation_trig_lut);
rotated_block_indices_inputs_for_each_layer.push_back(rotated_block_indices);
rotation_deltas_inputs_for_each_layer.push_back(rotation_deltas);
diff --git a/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp b/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp
index 570fb3c2557..aed4457a8ae 100644
--- a/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp
+++ b/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp
@@ -105,6 +105,7 @@ TEST_P(ConvertPagedAttnInputsTest, checkPrecisionAndShape) {
auto scale = std::make_shared<v0::Constant>(element::f32, Shape{}, 0.5f);
auto sliding_window = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);
auto alibi_slopes = std::make_shared<v0::Constant>(element::f32, Shape{0});
+ auto score_aggregation_window = std::make_shared<v0::Parameter>(ov::element::i32, PartialShape{DYN});
auto pa = std::make_shared<op::PagedAttentionExtension>(OutputVector{Q,
K,
@@ -118,7 +119,8 @@ TEST_P(ConvertPagedAttnInputsTest, checkPrecisionAndShape) {
scale,
sliding_window,
alibi_slopes,
- max_context_len});
+ max_context_len,
+ score_aggregation_window});
pa->get_rt_info()["num_k_heads"] = numKeyHeads;
pa->get_rt_info()["k_head_size"] = keyHeadSize;
pa->get_rt_info()["num_v_heads"] = numValueHeads;
@@ -134,7 +136,8 @@ TEST_P(ConvertPagedAttnInputsTest, checkPrecisionAndShape) {
subsequence_begins,
block_indices,
block_indices_begins,
- max_context_len});
+ max_context_len,
+ score_aggregation_window});
if (isIRKVCacheF16) {
model->set_rt_info("f16", "runtime_options", ov::hint::kv_cache_precision.name());
}
@@ -199,6 +202,7 @@ TEST_P(ConvertPagedAttnInputsTest, checkPrecisionAndShape) {
auto scale = std::make_shared<v0::Constant>(element::f32, Shape{}, 0.5f);
auto sliding_window = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);
auto alibi_slopes = std::make_shared<v0::Constant>(element::f32, Shape{0});
+ auto score_aggregation_window = std::make_shared<v0::Parameter>(ov::element::i32, PartialShape{DYN});
auto pa = std::make_shared<op::PagedAttentionExtension>(OutputVector{Q,
K,
@@ -212,7 +216,8 @@ TEST_P(ConvertPagedAttnInputsTest, checkPrecisionAndShape) {
scale,
sliding_window,
alibi_slopes,
- max_context_len});
+ max_context_len,
+ score_aggregation_window});
pa->get_rt_info()["num_k_heads"] = numKeyHeads;
pa->get_rt_info()["k_head_size"] = keyHeadSize;
pa->get_rt_info()["num_v_heads"] = numValueHeads;
@@ -228,7 +233,8 @@ TEST_P(ConvertPagedAttnInputsTest, checkPrecisionAndShape) {
subsequence_begins,
block_indices,
block_indices_begins,
- max_context_len});
+ max_context_len,
+ score_aggregation_window});
}
ov::pass::ConvertPagedAttnInputs::KVCacheConfig cacheConfig;
cacheConfig.keyCacheBlockSize = blockSize[0];
@@ -292,4 +298,4 @@ INSTANTIATE_TEST_SUITE_P(smoke_ConvertPagedAttnInputsTest,
::testing::Values(true, false)),
ConvertPagedAttnInputsTest::getTestCaseName);
-} // namespace
\ No newline at end of file
+} // namespace
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 d8b6c488850..f00e0ba05de 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
@@ -529,7 +529,9 @@ TEST_P(SDPAToPATest, SDPAToPA_Qwen7bChat_General) {
auto key_cache_0 = makeOP<v0::Parameter>({}, {{"shape", PartialShape{DYN, 32, 128}}, el_type_f32});
auto input_ids = makeOP<v0::Parameter>({}, {{"shape", PartialShape{DYN}}, el_type_i64});
auto position_ids = makeOP<v0::Parameter>({}, {{"shape", PartialShape{DYN}}, el_type_i64});
- auto params = nodes_to_params({max_context_len,
+ auto score_aggregation_window = makeOP<v0::Parameter>({}, {{"shape", PartialShape{DYN}}, el_type_i32});
+ auto params = nodes_to_params({score_aggregation_window,
+ max_context_len,
block_indices_begins,
block_indices,
subsequence_begins,
@@ -575,6 +577,7 @@ TEST_P(SDPAToPATest, SDPAToPA_Qwen7bChat_General) {
auto sliding_window = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);
auto alibi_slopes = std::make_shared<v0::Constant>(element::f32, Shape{0});
auto scale = std::make_shared<v0::Constant>(element::f32, Shape{}, MOCK_VALUE);
+ auto score_aggregation_window_const = std::make_shared<v0::Constant>(element::i32, Shape{0}, 0);
// PagedAttention:
auto pa = std::make_shared<op::PagedAttentionExtension>(OutputVector{Q,
@@ -589,7 +592,8 @@ TEST_P(SDPAToPATest, SDPAToPA_Qwen7bChat_General) {
scale,
sliding_window,
alibi_slopes,
- max_context_len});
+ max_context_len,
+ score_aggregation_window_const});
pa->set_out_type(0, element::i64);
auto pa_aligned = Qwen7bChatPA::align_pa_layout(pa, head_size_2);
auto res = makeOP<v0::Result>({pa_aligned});
@@ -811,6 +815,7 @@ TEST_F(SDPAToPATest, SDPAToPA_Baichuan2_13b_General) {
auto value_cache_0 = make_param(PartialShape{DYN, 40, 128}, element::f32, "value_cache.0");
auto key_cache_0 = make_param(PartialShape{DYN, 40, 128}, element::f32, "key_cache.0");
auto input_ids = make_param(PartialShape{DYN}, element::i64, "input_ids");
+ auto score_aggregation_window = makeConst(element::i32, ov::Shape({0}), MOCK_VALUE);
ParameterVector params = nodes_to_params({max_context_len,
block_indices_begins,
@@ -893,7 +898,8 @@ TEST_F(SDPAToPATest, SDPAToPA_Baichuan2_13b_General) {
c1,
c2,
Reshape166,
- max_context_len});
+ max_context_len,
+ score_aggregation_window});
auto ShapeOf172 = makeOP<opset3::ShapeOf>({Transpose154}, {{"output_type", "i64"}});
auto Gather175 = makeOP<opset8::Gather>({ShapeOf172, -1, 0}, {{"batch_dims", 0}});
auto Unsqueeze177 = makeOP<opset1::Unsqueeze>({Gather175, 0});
@@ -1112,6 +1118,7 @@ TEST_F(SDPAToPATest, SDPAToPA_nanoLLaVA_General) {
auto key_cache_0 = make_param(PartialShape{DYN, 2, 2}, element::f32, "key_cache_0");
auto inputs_embeds = make_param(PartialShape{DYN, DYN}, element::f32, "inputs_embeds");
auto position_ids = make_param(PartialShape{DYN}, element::i64, "position_ids");
+ auto score_aggregation_window = makeConst(element::i32, ov::Shape({0}), MOCK_VALUE);
ParameterVector params = nodes_to_params({max_context_len,
block_indices_begins,
@@ -1240,7 +1247,8 @@ TEST_F(SDPAToPATest, SDPAToPA_nanoLLaVA_General) {
c1,
c2,
c3,
- max_context_len});
+ max_context_len,
+ score_aggregation_window});
auto ShapeOf_51965 = makeOP<opset3::ShapeOf>({Transpose_51955}, {{"output_type", "i64"}});
auto Gather_51966 = makeOP<opset8::Gather>({ShapeOf_51965, -1, 0}, {{"batch_dims", 0}});
auto Unsqueeze_51971 = makeOP<opset1::Unsqueeze>({Gather_51966, 0});
@@ -1433,6 +1441,7 @@ TEST_F(SDPAToPATest, SDPAToPA_Phi3_mini_4k_instruct) {
auto key_cache_0 = make_param(PartialShape{DYN, 32, 96}, element::f32, "key_cache_0");
auto inputs_ids = make_param(PartialShape{DYN}, element::i64, "inputs_ids");
auto position_ids = make_param(PartialShape{DYN}, element::i64, "position_ids");
+ auto score_aggregation_window = makeConst(element::i32, ov::Shape({0}), MOCK_VALUE);
auto params = nodes_to_params({max_context_len,
block_indices_begins,
@@ -1543,7 +1552,8 @@ TEST_F(SDPAToPATest, SDPAToPA_Phi3_mini_4k_instruct) {
scale,
sliding_window,
alibi_slopes,
- max_context_len});
+ max_context_len,
+ score_aggregation_window});
auto ShapeOf1 = makeOP<opset3::ShapeOf>({Transpose6}, {{"output_type", "i64"}});
auto Gather2 = makeOP<opset8::Gather>({ShapeOf1, -1, 0}, {{"batch_dims", 0}});
auto Unsqueeze5 = makeOP<opset1::Unsqueeze>({Gather2, 0});
diff --git a/src/core/include/openvino/pass/sdpa_to_paged_attention.hpp b/src/core/include/openvino/pass/sdpa_to_paged_attention.hpp
index e5e52ef4953..758bfd8492c 100644
--- a/src/core/include/openvino/pass/sdpa_to_paged_attention.hpp
+++ b/src/core/include/openvino/pass/sdpa_to_paged_attention.hpp
@@ -21,12 +21,14 @@ public:
explicit SDPAToPagedAttention(bool use_per_layer_block_indices_inputs = false,
bool use_score_outputs = false,
+ bool allow_score_aggregation = false,
bool allow_cache_rotation = false);
bool run_on_model(const std::shared_ptr<ov::Model>& model) override;
private:
bool m_use_per_layer_block_indices_inputs;
bool m_use_score_outputs;
+ bool m_allow_score_aggregation;
bool m_allow_cache_rotation;
};
} // namespace pass
diff --git a/src/core/src/op/paged_attention.cpp b/src/core/src/op/paged_attention.cpp
index 72821cc3937..ba923c6523d 100644
--- a/src/core/src/op/paged_attention.cpp
+++ b/src/core/src/op/paged_attention.cpp
@@ -79,8 +79,8 @@ void PagedAttentionExtension::validate_and_infer_types() {
OV_OP_SCOPE(PagedAttentionExtension_validate_and_infer_types);
NODE_VALIDATION_CHECK(this,
- get_input_size() == 13 || get_input_size() == 16,
- "PagedAttensionExtension expects 13 or 16 inputs, but it has ",
+ get_input_size() == 14 || get_input_size() == 17,
+ "PagedAttensionExtension expects 14 or 17 inputs, but it has ",
get_input_size());
// format: Node*, input_idx, name, {rank_list}, {type_list}
@@ -97,11 +97,11 @@ void PagedAttentionExtension::validate_and_infer_types() {
input_check(this, 10, "sliding_window", {0}, {element::i32});
input_check(this, 11, "alibi_slopes", {1}, get_real_types());
input_check(this, 12, "max_context_len", {0}, {element::i32});
-
- if (get_input_size() == 16) {
- input_check(this, 13, "rotated_block_indices", {1}, {element::i32});
- input_check(this, 14, "rotation_deltas", {2}, {element::i32});
- input_check(this, 15, "rotation_trig_lut", {2}, {element::f16, element::f32});
+ input_check(this, 13, "score_aggregation_window", {0, 1}, {element::i32});
+ if (get_input_size() == 17) {
+ input_check(this, 14, "rotated_block_indices", {1}, {element::i32});
+ input_check(this, 15, "rotation_deltas", {2}, {element::i32});
+ input_check(this, 16, "rotation_trig_lut", {2}, {element::f16, element::f32});
}
// value head_size may be not same with key
diff --git a/src/core/src/pass/sdpa_to_paged_attention.cpp b/src/core/src/pass/sdpa_to_paged_attention.cpp
index bc5e5c9afb6..94cde87cde1 100644
--- a/src/core/src/pass/sdpa_to_paged_attention.cpp
+++ b/src/core/src/pass/sdpa_to_paged_attention.cpp
@@ -22,9 +22,11 @@ using namespace ov::op;
ov::pass::SDPAToPagedAttention::SDPAToPagedAttention(bool use_per_layer_block_indices_inputs,
bool use_score_outputs,
+ bool allow_score_aggregation,
bool allow_cache_rotation)
: m_use_per_layer_block_indices_inputs(use_per_layer_block_indices_inputs),
m_use_score_outputs(use_score_outputs),
+ m_allow_score_aggregation(use_score_outputs),
m_allow_cache_rotation(allow_cache_rotation) {}
static std::shared_ptr<v0::Parameter> setName(std::shared_ptr<v0::Parameter> node, const char* name) {
@@ -42,15 +44,23 @@ bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr<ov::Mode
"No ScaledDotProductAttention operation observed in the graph, cannot perform "
"the SDPAToPagedAttention transformation.");
+ std::map<std::string, std::shared_ptr<v0::Parameter>> optional_model_wide_params;
+
auto max_context_len = setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{}), "max_context_len");
- ParameterVector model_remaining_params{
+ ParameterVector model_wide_params{
setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{-1}), "past_lens"),
setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{-1}), "subsequence_begins"),
setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{-1}), "block_indices_begins"),
};
if (!m_use_per_layer_block_indices_inputs) {
auto block_indices = setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{-1}), "block_indices");
- model_remaining_params.insert(model_remaining_params.begin() + 2, block_indices);
+ model_wide_params.insert(model_wide_params.begin() + 2, block_indices);
+ }
+
+ if (m_allow_score_aggregation) {
+ auto score_aggregation_window =
+ setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{-1}), "score_aggregation_window");
+ optional_model_wide_params["score_aggregation_window"] = score_aggregation_window;
}
std::shared_ptr<v0::Parameter> model_rotation_trig_lut;
@@ -130,7 +140,7 @@ bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr<ov::Mode
ov::pass::Manager manager("SDPA to PA");
manager.set_per_pass_validation(false);
manager.register_pass<StateManagementPattern>(kv_parameters,
- model_remaining_params,
+ model_wide_params,
parameters_to_remove,
layer_index,
max_context_len->output(0),
@@ -139,9 +149,11 @@ bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr<ov::Mode
m_use_per_layer_block_indices_inputs,
m_use_score_outputs,
m_allow_cache_rotation,
+ m_allow_score_aggregation,
rotated_block_indices_inputs_for_each_layer,
rotation_deltas_inputs_for_each_layer,
- model_rotation_trig_lut);
+ model_rotation_trig_lut,
+ optional_model_wide_params);
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);
@@ -199,6 +211,10 @@ bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr<ov::Mode
model->add_results(score_results);
}
+ if (m_allow_score_aggregation) {
+ model->add_parameters({optional_model_wide_params["score_aggregation_window"]});
+ }
+
if (m_allow_cache_rotation) {
model->add_parameters(rotated_block_indices_inputs_for_each_layer);
model->add_parameters(rotation_deltas_inputs_for_each_layer);
@@ -206,7 +222,7 @@ bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr<ov::Mode
}
model->add_parameters(kv_parameters);
- model->add_parameters(model_remaining_params);
+ model->add_parameters(model_wide_params);
model->add_parameters({std::move(max_context_len)});
model->validate_nodes_and_infer_types();
return true;
diff --git a/src/core/tests/type_prop/paged_attention.cpp b/src/core/tests/type_prop/paged_attention.cpp
index 1f6525dcbc7..92a1e98ca00 100644
--- a/src/core/tests/type_prop/paged_attention.cpp
+++ b/src/core/tests/type_prop/paged_attention.cpp
@@ -11,7 +11,7 @@
namespace ov {
namespace testing {
-TEST(type_prop, paged_attention_static_13_inputs) {
+TEST(type_prop, paged_attention_static_14_inputs) {
const auto query = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4});
const auto key = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4});
const auto value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4});
@@ -25,6 +25,7 @@ TEST(type_prop, paged_attention_static_13_inputs) {
const auto sliding_window = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});
const auto alibi_slopes = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{9});
const auto max_context_len = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});
+ const auto score_aggregation_window = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});
ov::OutputVector args = {query,
key,
@@ -38,13 +39,15 @@ TEST(type_prop, paged_attention_static_13_inputs) {
scale,
sliding_window,
alibi_slopes,
- max_context_len};
+ max_context_len,
+ score_aggregation_window};
+
const auto op = std::make_shared<op::PagedAttentionExtension>(args);
EXPECT_EQ(op->get_output_element_type(0), element::f32);
EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{3, 4}));
}
-TEST(type_prop, paged_attention_static_16_inputs_eviction_per_block) {
+TEST(type_prop, paged_attention_static_17_inputs_eviction_per_block) {
const auto query = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4});
const auto key = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4});
const auto value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4});
@@ -58,6 +61,7 @@ TEST(type_prop, paged_attention_static_16_inputs_eviction_per_block) {
const auto sliding_window = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});
const auto alibi_slopes = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{9});
const auto max_context_len = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});
+ const auto score_aggregation_window = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{5});
const auto rotated_block_indices = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{3});
const auto rotation_deltas = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{12, 1});
@@ -76,6 +80,7 @@ TEST(type_prop, paged_attention_static_16_inputs_eviction_per_block) {
sliding_window,
alibi_slopes,
max_context_len,
+ score_aggregation_window,
rotated_block_indices,
rotation_deltas,
rotation_trig_lut};
@@ -85,7 +90,7 @@ TEST(type_prop, paged_attention_static_16_inputs_eviction_per_block) {
EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{3, 4}));
}
-TEST(type_prop, paged_attention_static_16_inputs_eviction_per_token) {
+TEST(type_prop, paged_attention_static_17_inputs_eviction_per_token) {
const auto query = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4});
const auto key = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4});
const auto value = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{3, 4});
@@ -99,6 +104,7 @@ TEST(type_prop, paged_attention_static_16_inputs_eviction_per_token) {
const auto sliding_window = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});
const auto alibi_slopes = std::make_shared<op::v0::Parameter>(element::f32, PartialShape{9});
const auto max_context_len = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});
+ const auto score_aggregation_window = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{5});
const auto rotated_block_indices = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{3});
const auto rotation_deltas = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{12, 5});
@@ -117,6 +123,7 @@ TEST(type_prop, paged_attention_static_16_inputs_eviction_per_token) {
sliding_window,
alibi_slopes,
max_context_len,
+ score_aggregation_window,
rotated_block_indices,
rotation_deltas,
rotation_trig_lut};
@@ -143,6 +150,7 @@ TEST(type_prop, paged_attention_dynamic_ranks_and_types) {
const auto sliding_window = std::make_shared<v0::Parameter>(element::dynamic, dyn);
const auto alibi_slopes = std::make_shared<v0::Parameter>(element::dynamic, dyn);
const auto max_context_len = std::make_shared<v0::Parameter>(element::dynamic, dyn);
+ const auto score_aggregation_window = std::make_shared<v0::Parameter>(element::dynamic, dyn);
ov::OutputVector args = {query,
key,
@@ -156,7 +164,8 @@ TEST(type_prop, paged_attention_dynamic_ranks_and_types) {
scale,
sliding_window,
alibi_slopes,
- max_context_len};
+ max_context_len,
+ score_aggregation_window};
EXPECT_NO_THROW(std::ignore = std::make_shared<op::PagedAttentionExtension>(args));
}
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/executor_pa.cpp b/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/executor_pa.cpp
index 4a6930766c2..ce6bfc1524e 100644
--- a/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/executor_pa.cpp
+++ b/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/executor_pa.cpp
@@ -3347,7 +3347,8 @@ struct MHA {
const PlainTensor& subsequence_begins,
const PlainTensor& block_indices,
const PlainTensor& block_indices_begins,
- const PlainTensor& alibi_slopes) {
+ const PlainTensor& alibi_slopes,
+ const PlainTensor& score_aggregation_window) {
_workitems.reset(query, past_lens, subsequence_begins, _helper._block_size);
if (output_score) {
_helper.init_score_buffers(past_lens, subsequence_begins);
@@ -3416,6 +3417,7 @@ struct AttentionExecutor : public PagedAttentionExecutor {
size_t& sliding_window,
PlainTensor& alibi_slopes,
size_t& max_context_len,
+ PlainTensor& score_aggregation_window,
PlainTensor& rotated_block_indices,
PlainTensor& rotation_deltas,
PlainTensor& rotation_trig_lut,
@@ -3437,6 +3439,10 @@ struct AttentionExecutor : public PagedAttentionExecutor {
}
max_context_len = static_cast<size_t>(*inputs[ID_MAX_CONTEXT_LEN]->getDataAs<int32_t>());
+ if (!inputs[ID_SCORE_AGGREGATION_WINDOW]->getShape().hasZeroDims()) {
+ score_aggregation_window.reset(inputs[ID_SCORE_AGGREGATION_WINDOW]); // [B_seq]
+ }
+
size_t inputs_size = inputs.size();
if (inputs_size > ID_ROTATED_BLOCK_INDICES) {
OPENVINO_ASSERT(inputs_size >= ID_ROTATION_TRIG_LUT);
@@ -3570,6 +3576,10 @@ struct AttentionExecutor : public PagedAttentionExecutor {
alibi_slopes.assert_dims({H});
}
+ if (score_aggregation_window) {
+ score_aggregation_window.assert_dims({B_seq});
+ }
+
bool init_rotation_coefficient_scratch = false;
if (rotated_block_indices) {
// Only K entries are needed to be rotated, since position is encoded at the Q^T @ (effective_RoPE_matrix) @
@@ -3694,6 +3704,7 @@ struct AttentionExecutor : public PagedAttentionExecutor {
PlainTensor rotated_block_indices;
PlainTensor rotation_deltas;
PlainTensor rotation_trig_lut;
+ PlainTensor score_aggregation_window;
PlainTensor output_emb;
PlainTensor output_score;
@@ -3713,6 +3724,7 @@ struct AttentionExecutor : public PagedAttentionExecutor {
sliding_window,
alibi_slopes,
max_context_len,
+ score_aggregation_window,
rotated_block_indices,
rotation_deltas,
rotation_trig_lut,
@@ -3742,7 +3754,8 @@ struct AttentionExecutor : public PagedAttentionExecutor {
subsequence_begins,
block_indices,
block_indices_begins,
- alibi_slopes);
+ alibi_slopes,
+ score_aggregation_window);
}
};
#endif
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/executor_pa_common.hpp b/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/executor_pa_common.hpp
index 065b7cfe24f..4aa038a3e7c 100644
--- a/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/executor_pa_common.hpp
+++ b/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/executor_pa_common.hpp
@@ -19,22 +19,23 @@ namespace ov::Extensions::Cpu {
struct PagedAttentionExecutor {
// PagedAttention input index
- static const size_t ID_Q = 0; // [B_token, H * S], float
- static const size_t ID_K = 1; // [B_token, Hk * S], float
- static const size_t ID_V = 2; // [B_token, Hk * S], float
- static const size_t ID_KCACHE = 3; // [block_number, H, block_size, S], float
- static const size_t ID_VCACHE = 4; // [block_number, H, block_size, S], float
- static const size_t ID_PAST_LENS = 5; // [B_seq]
- static const size_t ID_SUBSEQUENCE_BEGINS = 6; // [B_seq+1]
- static const size_t ID_BLOCK_INDICES = 7; // [num_blocks]
- static const size_t ID_BLOCK_INDICES_BEGINS = 8; // [B_seq+1]
- static const size_t ID_SCALE = 9; // [], float
- static const size_t ID_SLIDING_WINDOW = 10; // []
- static const size_t ID_ALIBI_SLOPES = 11; // [H|0], float
- static const size_t ID_MAX_CONTEXT_LEN = 12; // []
- static const size_t ID_ROTATED_BLOCK_INDICES = 13; // [num_rotated_blocks || 0], int32
- static const size_t ID_ROTATION_DELTAS = 14; // [num_rotated_blocks * block_size || 0], int32
- static const size_t ID_ROTATION_TRIG_LUT = 15; // [max_context_length * S || 0], f32
+ static const size_t ID_Q = 0; // [B_token, H * S], float
+ static const size_t ID_K = 1; // [B_token, Hk * S], float
+ static const size_t ID_V = 2; // [B_token, Hk * S], float
+ static const size_t ID_KCACHE = 3; // [block_number, H, block_size, S], float
+ static const size_t ID_VCACHE = 4; // [block_number, H, block_size, S], float
+ static const size_t ID_PAST_LENS = 5; // [B_seq]
+ static const size_t ID_SUBSEQUENCE_BEGINS = 6; // [B_seq+1]
+ static const size_t ID_BLOCK_INDICES = 7; // [num_blocks]
+ static const size_t ID_BLOCK_INDICES_BEGINS = 8; // [B_seq+1]
+ static const size_t ID_SCALE = 9; // [], float
+ static const size_t ID_SLIDING_WINDOW = 10; // []
+ static const size_t ID_ALIBI_SLOPES = 11; // [H|0], float
+ static const size_t ID_MAX_CONTEXT_LEN = 12; // []
+ static const size_t ID_SCORE_AGGREGATION_WINDOW = 13; // [B_seq || 0], i32
+ static const size_t ID_ROTATED_BLOCK_INDICES = 14; // [num_rotated_blocks || 0], int32
+ static const size_t ID_ROTATION_DELTAS = 15; // [num_rotated_blocks * block_size || 0], int32
+ static const size_t ID_ROTATION_TRIG_LUT = 16; // [max_context_length * S || 0], f32
virtual void execute(const std::vector<ov::intel_cpu::MemoryPtr>& inputs,
const std::vector<ov::intel_cpu::MemoryPtr> outputs) = 0;
virtual ~PagedAttentionExecutor() = default;
diff --git a/src/plugins/intel_cpu/src/nodes/paged_attn.cpp b/src/plugins/intel_cpu/src/nodes/paged_attn.cpp
index 0f561139ee3..95b100a7275 100644
--- a/src/plugins/intel_cpu/src/nodes/paged_attn.cpp
+++ b/src/plugins/intel_cpu/src/nodes/paged_attn.cpp
@@ -81,8 +81,8 @@ void PagedAttention::initSupportedPrimitiveDescriptors() {
creatorsMap.at(LayoutType::ncsp)
->createSharedDesc(rtPrecision, getInputShapeAtPort(PagedAttentionExecutor::ID_V)));
- CPU_NODE_ASSERT(orgInputNumber == 13 || orgInputNumber == 16,
- "The input number of PagedAttention should be 13 or 16.");
+ CPU_NODE_ASSERT(orgInputNumber == 14 || orgInputNumber == 17,
+ "The input number of PagedAttention should be 14 or 17.");
// kvcache, float, []
auto past_key_input_mem_precision = getOriginalInputPrecisionAtPort(PagedAttentionExecutor::ID_KCACHE);
auto past_value_input_mem_precision = getOriginalInputPrecisionAtPort(PagedAttentionExecutor::ID_VCACHE);
@@ -130,7 +130,13 @@ void PagedAttention::initSupportedPrimitiveDescriptors() {
config.outConfs[1].setMemDesc(
creatorsMap.at(LayoutType::ncsp)->createSharedDesc(ov::element::f32, getOutputShapeAtPort(1)));
- if (orgInputNumber == 16) {
+ // score_aggregation_window, float, [batch_size_in_sequences || 0]
+ config.inConfs[PagedAttentionExecutor::ID_SCORE_AGGREGATION_WINDOW].setMemDesc(
+ creatorsMap.at(LayoutType::ncsp)
+ ->createSharedDesc(ov::element::i32,
+ getInputShapeAtPort(PagedAttentionExecutor::ID_SCORE_AGGREGATION_WINDOW)));
+
+ if (orgInputNumber == 17) {
// rotated_block_indices, int, [num_rotated_blocks || 0]
config.inConfs[PagedAttentionExecutor::ID_ROTATED_BLOCK_INDICES].setMemDesc(
creatorsMap.at(LayoutType::ncsp)
diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_attention.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_attention.hpp
index 5d2377f263a..68754ea5a15 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_attention.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/paged_attention.hpp
@@ -20,7 +20,7 @@ struct paged_attention : public primitive_base<paged_attention> {
paged_attention(const primitive_id& id,
const std::vector<input_info>& inputs)
: primitive_base(id, inputs) {
- OPENVINO_ASSERT((inputs.size() == 13) || (inputs.size() == 16),
+ OPENVINO_ASSERT((inputs.size() == 14) || (inputs.size() == 17),
"[GPU] Unexpected inputs number for PagedAttention primitive: ",
inputs.size());
}
@@ -41,6 +41,7 @@ struct paged_attention : public primitive_base<paged_attention> {
kv_heads_num == rhs_casted.kv_heads_num &&
sliding_window == rhs_casted.sliding_window &&
has_alibi == rhs_casted.has_alibi &&
+ has_score_aggregation == rhs_casted.has_score_aggregation &&
has_rotated_blocks == rhs_casted.has_rotated_blocks &&
scale_val.value_or(1.0f) == rhs_casted.scale_val.value_or(1.0f);
}
@@ -52,6 +53,7 @@ struct paged_attention : public primitive_base<paged_attention> {
ob << heads_num;
ob << kv_heads_num;
ob << has_alibi;
+ ob << has_score_aggregation;
ob << has_rotated_blocks;
ob << sliding_window;
@@ -70,6 +72,7 @@ struct paged_attention : public primitive_base<paged_attention> {
ib >> heads_num;
ib >> kv_heads_num;
ib >> has_alibi;
+ ib >> has_score_aggregation;
ib >> has_rotated_blocks;
ib >> sliding_window;
@@ -91,6 +94,7 @@ struct paged_attention : public primitive_base<paged_attention> {
size_t kv_heads_num = 0;
size_t sliding_window = 0;
bool has_alibi = false;
+ bool has_score_aggregation = false;
bool has_rotated_blocks = false;
};
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl/paged_attention.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl/paged_attention.cpp
index abec0cd9a17..eee7dd6dd68 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl/paged_attention.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl/paged_attention.cpp
@@ -112,6 +112,7 @@ struct paged_attention_impl : multi_stage_primitive<paged_attention> {
void load(BinaryInputBuffer& ib) override {
parent::load(ib);
ib >> make_data(&has_scores_output, sizeof(bool));
+ ib >> make_data(&has_score_aggregation, sizeof(bool));
ib >> make_data(&has_rotated_blocks, sizeof(bool));
ib >> make_data(&use_micro_sdpa, sizeof(bool));
if (is_dynamic()) {
@@ -138,6 +139,7 @@ struct paged_attention_impl : multi_stage_primitive<paged_attention> {
void save(BinaryOutputBuffer& ob) const override {
parent::save(ob);
ob << make_data(&has_scores_output, sizeof(bool));
+ ob << make_data(&has_score_aggregation, sizeof(bool));
ob << make_data(&has_rotated_blocks, sizeof(bool));
ob << make_data(&use_micro_sdpa, sizeof(bool));
}
@@ -657,6 +659,7 @@ struct paged_attention_impl : multi_stage_primitive<paged_attention> {
config.has_const_scale_val = false;
}
+ config.has_score_aggregation = desc->has_score_aggregation;
config.has_rotated_blocks = desc->has_rotated_blocks;
if (desc->heads_num != desc->kv_heads_num) {
@@ -685,9 +688,9 @@ struct paged_attention_impl : multi_stage_primitive<paged_attention> {
auto params = get_default_params<kv_cache_rotate_kernel_params_t>(impl_param, is_dynamic);
const auto& key_cache_tensor = input_tensors[3];
- const auto& rotated_block_indices_tensor = input_tensors[13];
- const auto& rotation_deltas_tensor = input_tensors[14];
- const auto& rotation_trig_lut_tensor = input_tensors[15];
+ const auto& rotated_block_indices_tensor = input_tensors[14];
+ const auto& rotation_deltas_tensor = input_tensors[15];
+ const auto& rotation_trig_lut_tensor = input_tensors[16];
const auto inputs_number = 3;
const auto outputs_number = 1;
@@ -703,9 +706,9 @@ struct paged_attention_impl : multi_stage_primitive<paged_attention> {
const auto& in_offsets_map = impl_param.in_port_to_shape_info_offset;
std::map<size_t, size_t> in_tensor_to_offset_map = {
- {0, in_offsets_map.at(13)},
- {1, in_offsets_map.at(14)},
- {2, in_offsets_map.at(15)},
+ {0, in_offsets_map.at(14)},
+ {1, in_offsets_map.at(15)},
+ {2, in_offsets_map.at(16)},
};
std::map<size_t, size_t> out_tensor_to_offset_map = {
{0, in_offsets_map.at(3)},
@@ -1005,6 +1008,7 @@ struct paged_attention_impl : multi_stage_primitive<paged_attention> {
auto impl = std::make_unique<paged_attention_impl>(kernels_data);
impl->has_scores_output = desc->has_scores_output();
+ impl->has_score_aggregation = desc->has_score_aggregation;
impl->has_rotated_blocks = desc->has_rotated_blocks;
if (!kernels_data[Stage::SDPA].kernels[0].micro_kernels.empty()) {
@@ -1016,6 +1020,7 @@ struct paged_attention_impl : multi_stage_primitive<paged_attention> {
private:
bool has_scores_output = false;
+ bool has_score_aggregation = false;
bool has_rotated_blocks = false;
bool use_micro_sdpa = false;
};
diff --git a/src/plugins/intel_gpu/src/graph/include/paged_attention_inst.h b/src/plugins/intel_gpu/src/graph/include/paged_attention_inst.h
index a8b177c0def..ec86156c1b5 100644
--- a/src/plugins/intel_gpu/src/graph/include/paged_attention_inst.h
+++ b/src/plugins/intel_gpu/src/graph/include/paged_attention_inst.h
@@ -52,9 +52,10 @@ public:
memory::ptr block_indices_memory_ptr() const { return input_memory_ptr(7); }
memory::ptr block_indices_begins_memory_ptr() const { return input_memory_ptr(8); }
memory::ptr alibi_memory_ptr() const { return input_memory_ptr(11); }
- memory::ptr rotated_block_indices_memory_ptr() const { return input_memory_ptr(13); }
- memory::ptr rotation_deltas_memory_ptr() const { return input_memory_ptr(14); }
- memory::ptr rotation_trig_lut_memory_ptr() const { return input_memory_ptr(15); }
+ memory::ptr score_aggregation_window_ptr() const { return input_memory_ptr(13); }
+ memory::ptr rotated_block_indices_memory_ptr() const { return input_memory_ptr(14); }
+ memory::ptr rotation_deltas_memory_ptr() const { return input_memory_ptr(15); }
+ memory::ptr rotation_trig_lut_memory_ptr() const { return input_memory_ptr(16); }
};
using paged_attention_inst = typed_primitive_inst<paged_attention>;
diff --git a/src/plugins/intel_gpu/src/graph/paged_attention.cpp b/src/plugins/intel_gpu/src/graph/paged_attention.cpp
index 9c00dd00234..8963e579d7a 100644
--- a/src/plugins/intel_gpu/src/graph/paged_attention.cpp
+++ b/src/plugins/intel_gpu/src/graph/paged_attention.cpp
@@ -81,6 +81,7 @@ std::string paged_attention_inst::to_string(const paged_attention_node& node) {
paged_attention_info.add("kv_heads_num", desc->kv_heads_num);
paged_attention_info.add("scale", desc->scale_val.value_or(1.0f));
paged_attention_info.add("has_alibi", desc->has_alibi);
+ paged_attention_info.add("has_score_aggregation", desc->has_score_aggregation);
paged_attention_info.add("has_rotated_blocks", desc->has_rotated_blocks);
paged_attention_info.add("key_cache_dt", node.get_input_layout(3).data_type);
paged_attention_info.add("value_cache_dt", node.get_input_layout(4).data_type);
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/sdpa/pa_sdpa_kernel_opt.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/sdpa/pa_sdpa_kernel_opt.cpp
index 531ddd949e4..3cb159a8043 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/sdpa/pa_sdpa_kernel_opt.cpp
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/sdpa/pa_sdpa_kernel_opt.cpp
@@ -298,6 +298,12 @@ JitConstants PagedAttentionSDPAKernelOpt::GetJitConstants(const pa_sdpa_params&
jit.AddConstant(MakeJitConstant("PAGED_ATTENTION_SCORES_OUTPUT", 1));
}
+ const size_t score_aggregation_idx = 13;
+ jit.Merge(MakeTypeJitConstants(params.inputs[score_aggregation_idx].GetDType(), "SCORE_AGGREGATION_INPUT"));
+ if (params.conf.has_score_aggregation) {
+ jit.AddConstant(MakeJitConstant("HAS_SCORE_AGGREGATION", 1));
+ }
+
if (params.conf.has_rotated_blocks)
jit.AddConstant(MakeJitConstant("HAS_ROTATED_BLOCKS", 1));
diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/sdpa/sdpa_kernel_base.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/sdpa/sdpa_kernel_base.h
index 2fafc5cf206..06a486f044a 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/sdpa/sdpa_kernel_base.h
+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/sdpa/sdpa_kernel_base.h
@@ -104,6 +104,7 @@ struct sdpa_configuration {
float scale_val = 0.f;
bool has_const_attn_mask_val = false;
float attn_mask_val = 0.f;
+ bool has_score_aggregation = false;
bool has_rotated_blocks = false;
};
diff --git a/src/plugins/intel_gpu/src/plugin/ops/paged_attention.cpp b/src/plugins/intel_gpu/src/plugin/ops/paged_attention.cpp
index 82b30635373..83efa03fe8b 100644
--- a/src/plugins/intel_gpu/src/plugin/ops/paged_attention.cpp
+++ b/src/plugins/intel_gpu/src/plugin/ops/paged_attention.cpp
@@ -21,7 +21,7 @@ using PagedAttentionExtension = ov::op::PagedAttentionExtension;
namespace ov::intel_gpu {
static void CreatePagedAttentionExtensionOp(ProgramBuilder& p, const std::shared_ptr<ov::op::PagedAttentionExtension>& op) {
- validate_inputs_count(op, {13, 16});
+ validate_inputs_count(op, {14, 17});
auto inputs = p.GetInputInfo(op);
auto prim = cldnn::paged_attention(layer_type_name_ID(op), inputs);
@@ -78,7 +78,19 @@ static void CreatePagedAttentionExtensionOp(ProgramBuilder& p, const std::shared
std::shared_ptr<ov::op::v0::Constant> alibi_const = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(alibi_idx));
OPENVINO_ASSERT(alibi_const != nullptr);
prim.has_alibi = ov::shape_size(alibi_const->get_output_shape(0)) > 0;
- prim.has_rotated_blocks = op->get_input_size() == 16;
+
+
+ const size_t score_aggregation_idx = 13;
+
+ auto score_aggregation_input = ov::as_type_ptr<ov::op::v0::Parameter>(op->get_input_node_shared_ptr(score_aggregation_idx));
+
+ if (!score_aggregation_input) {
+ prim.has_score_aggregation = false;
+ } else {
+ prim.has_score_aggregation = !score_aggregation_input->get_output_partial_shape(0).is_dynamic();
+ }
+
+ prim.has_rotated_blocks = op->get_input_size() == 17;
prim.num_outputs = 1;
diff --git a/src/plugins/intel_gpu/tests/unit/dynamic_execution/update_shape_test.cpp b/src/plugins/intel_gpu/tests/unit/dynamic_execution/update_shape_test.cpp
index 68a99c4d074..3c1e7f78929 100644
--- a/src/plugins/intel_gpu/tests/unit/dynamic_execution/update_shape_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/dynamic_execution/update_shape_test.cpp
@@ -138,6 +138,8 @@ TEST(update_shape_test, max_context_len_shapeof_subgraph) {
auto sliding_window_layout = layout{ov::PartialShape{1}, data_types::i32, format::bfyx};
auto alibi_layout = layout{ov::PartialShape{0}, data_types::f16, format::bfyx};
auto max_context_len_layout = layout{ov::PartialShape{1}, data_types::i32, format::bfyx};
+ auto score_aggregation_window_layout = layout{ov::PartialShape{0}, data_types::i32, format::bfyx};
+ auto score_aggregation_window_mem = engine.allocate_memory(score_aggregation_window_layout);
std::vector<input_info> pa_inputs = {input_info("query"),
input_info("key"),
@@ -151,7 +153,8 @@ TEST(update_shape_test, max_context_len_shapeof_subgraph) {
input_info("scale"),
input_info("sliding_window"),
input_info("alibi"),
- input_info("max_context_len")};
+ input_info("max_context_len"),
+ input_info("score_aggregation_window")};
auto pa_prim = paged_attention("paged_attention", pa_inputs);
pa_prim.k_head_size = 64;
@@ -178,6 +181,7 @@ TEST(update_shape_test, max_context_len_shapeof_subgraph) {
topology.add(input_layout("sliding_window", sliding_window_layout));
topology.add(input_layout("alibi", alibi_layout));
topology.add(input_layout("max_context_len", max_context_len_layout));
+ topology.add(input_layout("score_aggregation_window", score_aggregation_window_layout));
topology.add(data("const_one", const_one_mem));
topology.add(shape_of("shape_of", input_info("input_data"), data_types::i32));
topology.add(gather("gather", input_info("shape_of"), input_info("const_one"), 0, 1, ov::Shape{}));
@@ -202,6 +206,7 @@ TEST(update_shape_test, max_context_len_shapeof_subgraph) {
network.set_input_data("scale", scale_mem);
network.set_input_data("sliding_window", sliding_window_mem);
network.set_input_data("alibi", alibi_mem);
+ network.set_input_data("score_aggregation_window", score_aggregation_window_mem);
// Set original max_context_len value
auto max_context_len_mem_layout = layout{ov::PartialShape{1}, data_types::i32, format::bfyx};
@@ -233,6 +238,7 @@ TEST(update_shape_test, max_context_len_shapeof_subgraph) {
network.set_input_data("scale", scale_mem);
network.set_input_data("sliding_window", sliding_window_mem);
network.set_input_data("alibi", alibi_mem);
+ network.set_input_data("score_aggregation_window", score_aggregation_window_mem);
// Update max_context_len value, which should be taken into account in shape recalculation for broadcast
set_values(max_context_len_mem, {8});
diff --git a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp
index 4ac350e8c4b..e60566dd520 100644
--- a/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/passes/mark_shape_of_subgraphs_test.cpp
@@ -457,6 +457,7 @@ TEST(mark_shape_of_subgraphs, paged_attention_max_context_len_input) {
auto sliding_window_layout = layout{ov::PartialShape{}, data_types::i32, format::bfyx};
auto alibi_layout = layout{ov::PartialShape{}, data_types::f32, format::bfyx};
auto max_context_len_layout = layout{ov::PartialShape{1}, data_types::i32, format::bfyx};;
+ auto score_aggregation_window_layout = dynamic_i32_layout;
std::vector<input_info> pa_inputs = {input_info("query"),
input_info("key"),
@@ -470,7 +471,8 @@ TEST(mark_shape_of_subgraphs, paged_attention_max_context_len_input) {
input_info("scale"),
input_info("sliding_window"),
input_info("alibi"),
- input_info("max_context_len")};
+ input_info("max_context_len"),
+ input_info("score_aggregation_window")};
auto pa_prim = paged_attention("paged_attention", pa_inputs);
pa_prim.k_head_size = 64;
@@ -496,6 +498,7 @@ TEST(mark_shape_of_subgraphs, paged_attention_max_context_len_input) {
topology.add(input_layout("sliding_window", sliding_window_layout));
topology.add(input_layout("alibi", alibi_layout));
topology.add(input_layout("max_context_len", max_context_len_layout));
+ topology.add(input_layout("score_aggregation_window", score_aggregation_window_layout));
topology.add(input_layout("input", input_layout_dynamic));
topology.add(data("target_shape", target_shape));
topology.add(data("subtract_one", subtract_one));
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp
index 9a8d5298ad8..b97f445cd6e 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/paged_attention_gpu_test.cpp
@@ -44,11 +44,12 @@ using namespace ::tests;
* [11]: alibi_slopes, optional
* [12]: max_context_len
* shape: [], type: i32
-* [13]: rotated_block_indices​, optional​
+* [13]: score_aggregation_window​, optional​, shape: [batch_size_in_sequences]
+* [14]: rotated_block_indices​, optional​
* shape: [num_rotated_blocks]​, type: i32
-* [14]: rotation_deltas​, optional​
+* [15]: rotation_deltas​, optional​
* shape: [num_rotated_blocks, BLOCK_SIZE]​ || [num_rotated_blocks, 1]​, type: i32
-* [15]: rotation_trig_lut​, optional​
+* [16]: rotation_trig_lut​, optional​
* shape: [max_num_batched_tokens / BLOCK_SIZE, head_size]​ || [max_num_batched_tokens, head_size], type: f16
*/
@@ -85,6 +86,7 @@ struct PagedAttentionManager {
std::vector<int> block_indices;
std::vector<int> block_indices_begins;
std::vector<int> max_context_len;
+ std::vector<int> score_aggregation_window;
// rotation related inputs
std::vector<int> rotated_block_indices;
@@ -349,6 +351,10 @@ struct PagedAttentionManager {
return get_memory_from_vec(max_context_len);
}
+ memory::ptr get_score_aggregation_window_memory() {
+ return get_memory_from_vec(score_aggregation_window);
+ }
+
memory::ptr get_rotated_block_indices_memory() {
return get_memory_from_vec(rotated_block_indices);
}
@@ -808,6 +814,8 @@ public:
auto alibi_mem = pam.get_alibi_memory();
auto max_context_len_mem = pam.get_max_context_len_memory();
+ auto score_aggregation_window_mem = pam.get_score_aggregation_window_memory();
+
// cache rotation related memory buffers
auto rotated_block_indices_mem = pam.get_rotated_block_indices_memory();
auto rotation_deltas_mem = pam.get_rotation_deltas_memory();
@@ -826,6 +834,7 @@ public:
auto sliding_window_layout = sliding_window_mem->get_layout();
auto alibi_layout = alibi_mem->get_layout();
auto max_context_len_layout = max_context_len_mem->get_layout();
+ auto score_aggregation_window_layout = score_aggregation_window_mem->get_layout();
auto rotated_block_indices_layout = rotated_block_indices_mem->get_layout();
auto rotation_deltas_layout = rotation_deltas_mem->get_layout();
auto rotation_trig_lut_layout = rotation_trig_lut_mem->get_layout();
@@ -888,7 +897,8 @@ public:
input_info("scale"),
input_info("sliding_window"),
input_info("alibi"),
- input_info("max_context_len") };
+ input_info("max_context_len"),
+ input_info("score_aggregation_window") };
if (p.rotation_config.apply_rotation) {
pa_inputs.push_back(input_info("rotated_block_indices"));
@@ -923,6 +933,7 @@ public:
input_layout("sliding_window", sliding_window_layout),
input_layout("alibi", alibi_layout),
input_layout("max_context_len", max_context_len_layout),
+ input_layout("score_aggregation_window", score_aggregation_window_layout),
pa_prim,
reorder("output_data", input_info("paged_attention", 0), format::bfyx, data_types::f16)
);
@@ -960,6 +971,7 @@ public:
network->set_input_data("sliding_window", sliding_window_mem);
network->set_input_data("alibi", alibi_mem);
network->set_input_data("max_context_len", max_context_len_mem);
+ network->set_input_data("score_aggregation_window", score_aggregation_window_mem);
if (p.rotation_config.apply_rotation) {
network->set_input_data("rotated_block_indices", rotated_block_indices_mem);
diff --git a/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py b/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py
index 5a914fd2198..026ed9394aa 100644
--- a/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py
+++ b/tests/model_hub_tests/transformation_tests/generate_ref_diffs.py
@@ -106,7 +106,7 @@ def main():
# wrapping in try/catch block to continue printing models even if one has failed
try:
- paged_attention_transformation(ov_model, use_cache_eviction, use_cache_eviction, use_cache_eviction)
+ paged_attention_transformation(ov_model, use_block_indices_inputs=use_cache_eviction, use_score_outputs=use_cache_eviction, allow_score_aggregation=use_cache_eviction, allow_cache_rotation=use_cache_eviction)
except:
print(f"Couldn't run SDPAToPA transformation on {model_id} and generate diffs.")
continue
diff --git a/tests/model_hub_tests/transformation_tests/sdpa2pa_ref_diff.py b/tests/model_hub_tests/transformation_tests/sdpa2pa_ref_diff.py
index 118ba5bcd39..66f7cab6c6a 100644
--- a/tests/model_hub_tests/transformation_tests/sdpa2pa_ref_diff.py
+++ b/tests/model_hub_tests/transformation_tests/sdpa2pa_ref_diff.py
@@ -339,331 +339,330 @@ ref_diff_map_cache_eviction = {
"hf-internal-testing/tiny-random-LlamaForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-CohereForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-GPTJForCausalLM" : {
"Assign" : -10,
"PagedAttentionExtension" : 5,
- "Parameter" : 28,
+ "Parameter" : 29,
"ReadValue" : -10,
"ScaledDotProductAttention" : -5,
},
+ "hf-internal-testing/tiny-random-GPTNeoForCausalLM" : {
+ "Assign" : -8,
+ "PagedAttentionExtension" : 4,
+ "Parameter" : 24,
+ "ReadValue" : -8,
+ "ScaledDotProductAttention" : -4,
+ },
"hf-internal-testing/tiny-random-GPTNeoXForCausalLM" : {
"Assign" : -10,
"PagedAttentionExtension" : 5,
- "Parameter" : 28,
+ "Parameter" : 29,
"ReadValue" : -10,
"ScaledDotProductAttention" : -5,
},
"hf-internal-testing/tiny-random-MistralForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-CodeGenForCausalLM" : {
"Assign" : -10,
"PagedAttentionExtension" : 5,
- "Parameter" : 28,
+ "Parameter" : 29,
"ReadValue" : -10,
"ScaledDotProductAttention" : -5,
},
"hf-internal-testing/Mixtral-tiny" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-GPTBigCodeForCausalLM" : {
"Assign" : -5,
"PagedAttentionExtension" : 5,
- "Parameter" : 28,
+ "Parameter" : 29,
"ReadValue" : -5,
"ScaledDotProductAttention" : -5,
},
"hf-internal-testing/tiny-random-Starcoder2ForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-BloomForCausalLM" : {
"Assign" : -10,
"PagedAttentionExtension" : 5,
- "Parameter" : 29,
+ "Parameter" : 30,
"ReadValue" : -10,
"ScaledDotProductAttention" : -5,
},
"hf-internal-testing/tiny-random-gpt2" : {
"Assign" : -10,
"PagedAttentionExtension" : 5,
- "Parameter" : 28,
+ "Parameter" : 29,
"ReadValue" : -10,
"ScaledDotProductAttention" : -5,
},
"hf-internal-testing/tiny-random-BlenderbotForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 14,
+ "Parameter" : 15,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-PegasusForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 14,
+ "Parameter" : 15,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-PhiForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-MptForCausalLM" : {
"Assign" : -10,
"PagedAttentionExtension" : 5,
- "Parameter" : 29,
+ "Parameter" : 30,
"ReadValue" : -10,
"ScaledDotProductAttention" : -5,
},
"hf-internal-testing/tiny-random-StableLmForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-PersimmonForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-internal-testing/tiny-random-FalconForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"hf-tiny-model-private/tiny-random-OPTForCausalLM" : {
"Assign" : -10,
"PagedAttentionExtension" : 5,
- "Parameter" : 28,
+ "Parameter" : 29,
"ReadValue" : -10,
"ScaledDotProductAttention" : -5,
},
"katuni4ka/tiny-random-xverse" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-baichuan2-13b" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-qwen" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-aquilachat" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-aquila2" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-qwen1.5-moe" : {
"Assign" : -8,
"PagedAttentionExtension" : 4,
- "Parameter" : 23,
+ "Parameter" : 24,
"ReadValue" : -8,
"ScaledDotProductAttention" : -4,
},
"katuni4ka/tiny-random-codegen2" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-olmo-hf" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-baichuan2" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-jais" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-internlm" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-internlm2" : {
"Assign" : -8,
"PagedAttentionExtension" : 4,
- "Parameter" : 23,
+ "Parameter" : 24,
"ReadValue" : -8,
"ScaledDotProductAttention" : -4,
},
"katuni4ka/tiny-random-minicpm" : {
"Assign" : -8,
"PagedAttentionExtension" : 4,
- "Parameter" : 23,
+ "Parameter" : 24,
"ReadValue" : -8,
"ScaledDotProductAttention" : -4,
},
"katuni4ka/tiny-random-falcon-40b" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-dbrx" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"fxmarty/tiny-random-GemmaForCausalLM" : {
"Assign" : -2,
"PagedAttentionExtension" : 1,
- "Parameter" : 8,
+ "Parameter" : 9,
"ReadValue" : -2,
"ScaledDotProductAttention" : -1,
},
"fxmarty/tiny-dummy-qwen2" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"fxmarty/really-tiny-falcon-testing" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"Xenova/tiny-random-Phi3ForCausalLM" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"facebook/opt-125m" : {
"Assign" : -24,
"PagedAttentionExtension" : 12,
- "Parameter" : 63,
+ "Parameter" : 64,
"ReadValue" : -24,
"ScaledDotProductAttention" : -12,
},
"facebook/opt-350m" : {
"Assign" : -48,
"PagedAttentionExtension" : 24,
- "Parameter" : 123,
+ "Parameter" : 124,
"ReadValue" : -48,
"ScaledDotProductAttention" : -24,
},
"katuni4ka/tiny-random-chatglm2" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-glm4" : {
"Assign" : -12,
"PagedAttentionExtension" : 6,
- "Parameter" : 33,
+ "Parameter" : 34,
"ReadValue" : -12,
"ScaledDotProductAttention" : -6,
},
"katuni4ka/tiny-random-llava-next" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-minicpmv-2_6" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
"katuni4ka/tiny-random-llava" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
- "katuni4ka/tiny-random-nanollava" : {
+ "katuni4ka/tiny-random-nanollava" : {
"Assign" : -4,
"PagedAttentionExtension" : 2,
- "Parameter" : 13,
+ "Parameter" : 14,
"ReadValue" : -4,
"ScaledDotProductAttention" : -2,
},
-
- "hf-internal-testing/tiny-random-GPTNeoForCausalLM" : {
- "ScaledDotProductAttention" : -4,
- "ReadValue" : -8,
- "PagedAttentionExtension" : 4,
- "Parameter" : 23,
- "Assign" : -8,
- }
}
diff --git a/tests/model_hub_tests/transformation_tests/test_pa_transformation.py b/tests/model_hub_tests/transformation_tests/test_pa_transformation.py
index 2951713fe94..c91f3e227fa 100644
--- a/tests/model_hub_tests/transformation_tests/test_pa_transformation.py
+++ b/tests/model_hub_tests/transformation_tests/test_pa_transformation.py
@@ -18,15 +18,15 @@ def apply_transformation_and_compare_diffs(ov_model: ov.Model,
model_id: str,
use_block_indices_inputs: bool,
use_score_outputs: bool,
+ allow_score_aggregation: bool,
allow_cache_rotation: bool,
ie_device: str):
-
before_map = {}
for op in ov_model.get_ordered_ops():
if op.get_type_name() in nodes_to_compare:
before_map[op.get_type_name()] = before_map.get(op.get_type_name(), 0) + 1
- paged_attention_transformation(ov_model, use_block_indices_inputs, use_score_outputs, allow_cache_rotation)
+ paged_attention_transformation(ov_model, use_block_indices_inputs, use_score_outputs, allow_score_aggregation, allow_cache_rotation)
ov.Core().compile_model(ov_model, ie_device)
after_map = {}
@@ -66,6 +66,9 @@ def apply_transformation_and_compare_diffs(ov_model: ov.Model,
if (use_score_outputs):
interesting_output_patterns["scores"] = r'^scores\.[0-9]+'
+ if (allow_score_aggregation):
+ interesting_input_patterns["score_aggregation_window"] = r'score_aggregation_window'
+
if (allow_cache_rotation):
interesting_input_patterns["rotated_block_indices"] = r'^rotated_block_indices\.[0-9]+';
interesting_input_patterns["rotation_deltas"] = r'^rotation_deltas\.[0-9]+';
@@ -88,6 +91,10 @@ def apply_transformation_and_compare_diffs(ov_model: ov.Model,
assert input_counters["rotation_trig_lut"] == 1
input_counters.pop("rotation_trig_lut")
+ if allow_score_aggregation:
+ assert input_counters["score_aggregation_window"] == 1
+ input_counters.pop("score_aggregation_window")
+
for input_id, count in input_counters.items():
assert count == resulting_map["PagedAttentionExtension"], \
f"The number of {input_id} inputs doesn't correspond to the expected value. Expected {resulting_map['PagedAttentionExtension']}, received {count}"
@@ -104,12 +111,13 @@ def run_pa(tmp_path,
cls: Union[Type[OVModelForCausalLM], Type[OVModelForVisualCausalLM]],
use_block_indices_inputs,
use_score_outputs,
+ allow_score_aggregation,
allow_cache_rotation,
ie_device):
model = cls.from_pretrained(model_id, export=True, trust_remote_code=True)
ov_model = model.model if cls is OVModelForCausalLM else model.lm_model
- apply_transformation_and_compare_diffs(ov_model, model_id, use_block_indices_inputs, use_score_outputs, allow_cache_rotation, ie_device)
+ apply_transformation_and_compare_diffs(ov_model, model_id, use_block_indices_inputs, use_score_outputs, allow_score_aggregation, allow_cache_rotation, ie_device)
@pytest.mark.precommit
@pytest.mark.parametrize("model_name, model_link, mark, reason", utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "hf-tiny-random-models-precommit")))
@@ -120,7 +128,7 @@ def test_pa_precommit(tmp_path, model_name, model_link, mark, reason, ie_device)
pytest.skip(reason)
elif mark == 'xfail':
pytest.xfail(reason)
- run_pa(tmp_path, model_name, model_link, OVModelForCausalLM, False, False, False, ie_device)
+ run_pa(tmp_path, model_name, model_link, OVModelForCausalLM, False, False, False, False, ie_device)
@pytest.mark.precommit
@pytest.mark.parametrize("model_name, model_link, mark, reason", utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "hf-tiny-random-models-precommit")))
@@ -131,7 +139,7 @@ def test_pa_precommit_use_cache_eviction(tmp_path, model_name, model_link, mark,
pytest.skip(reason)
elif mark == 'xfail':
pytest.xfail(reason)
- run_pa(tmp_path, model_name, model_link, OVModelForCausalLM, True, True, True, ie_device)
+ run_pa(tmp_path, model_name, model_link, OVModelForCausalLM, True, True, True, True, ie_device)
@pytest.mark.precommit
@pytest.mark.parametrize("model_name, model_link, mark, reason", utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "hf-tiny-random-vl-models-precommit")))
@@ -142,7 +150,7 @@ def test_pa_vlm(tmp_path, model_name, model_link, mark, reason, ie_device):
pytest.skip(reason)
elif mark == 'xfail':
pytest.xfail(reason)
- run_pa(tmp_path, model_name, model_link, OVModelForVisualCausalLM, False, False, False, ie_device)
+ run_pa(tmp_path, model_name, model_link, OVModelForVisualCausalLM, False, False, False, False, ie_device)
@pytest.mark.precommit
@pytest.mark.parametrize("model_name, model_link, mark, reason", utils.get_models_list(os.path.join(os.path.dirname(__file__), "models", "hf-tiny-random-vl-models-precommit")))
@@ -153,4 +161,4 @@ def test_pa_vlm_use_cache_eviction(tmp_path, model_name, model_link, mark, reaso
pytest.skip(reason)
elif mark == 'xfail':
pytest.xfail(reason)
- run_pa(tmp_path, model_name, model_link, OVModelForVisualCausalLM, True, True, True, ie_device)
\ No newline at end of file
+ run_pa(tmp_path, model_name, model_link, OVModelForVisualCausalLM, True, True, True, True, ie_device)