Skip to content

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

[TRANSFORMATIONS] Fix implicit conversion of ov::Node with multiple outputs to ov::Output (#29976)

Andrii Staikov6bbeaedb0d41
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/kv_cache_compression.cpp b/src/plugins/intel_gpu/src/plugin/transformations/kv_cache_compression.cpp
index 8ed571f2ee4..5c71a85d2df 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations/kv_cache_compression.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations/kv_cache_compression.cpp
@@ -77,10 +77,10 @@ std::shared_ptr<ov::intel_gpu::op::ReadValues>
if (past_rv_node->get_input_size() == 0) {
new_past_rv_node = std::make_shared<ov::intel_gpu::op::ReadValues>(past_rv_node->get_variable(), variable_infos);
} else {
- auto initializer_dq = std::make_shared<ov::op::internal::DynamicQuantize>(past_rv_node->get_input_node_shared_ptr(0),
+ auto initializer_dq = std::make_shared<ov::op::internal::DynamicQuantize>(past_rv_node->input_value(0),
quantization_attrs);
- initializer_dq->set_friendly_name(past_rv_node->get_input_node_shared_ptr(0)->get_friendly_name() + "_dyn_quan");
- ov::copy_runtime_info(past_rv_node->get_input_node_shared_ptr(0), initializer_dq);
+ initializer_dq->set_friendly_name(past_rv_node->input_value(0).get_node_shared_ptr()->get_friendly_name() + "_dyn_quan");
+ ov::copy_runtime_info(past_rv_node->input_value(0).get_node_shared_ptr(), initializer_dq);
OutputVector initializer_outputs = { initializer_dq->output(0), initializer_dq->output(1) };
@@ -102,8 +102,8 @@ std::shared_ptr<ov::intel_gpu::op::KVCacheCompressed>
std::shared_ptr<ov::intel_gpu::op::KVCache> kv_cache_node,
const ov::op::internal::DynamicQuantize::Attributes& quantization_attrs) {
OutputVector kv_cache_inputs = { past_rv_node->output(0),
- kv_cache_node->get_input_node_shared_ptr(1),
- kv_cache_node->get_input_node_shared_ptr(2),
+ kv_cache_node->input_value(1),
+ kv_cache_node->input_value(2),
past_rv_node->output(1) };
if (quantization_attrs.quantization_type == ov::op::internal::DynamicQuantize::QuantizationType::Asymmetric &&
@@ -230,7 +230,7 @@ KVCacheCompressionMatcher::KVCacheCompressionMatcher(ov::element::Type compressi
OutputVector sdpa_inputs;
// Add Query, Key, Value, attention_mask, scale inputs
for (size_t i = 0; i < sdpa_node->get_input_size() - 1; i++)
- sdpa_inputs.push_back(sdpa_node->get_input_node_shared_ptr(i));
+ sdpa_inputs.push_back(sdpa_node->input_value(i));
// Replace Key and Value inputs with compressed ones
sdpa_inputs[1] = new_key_cache->output(0);
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/kv_cache_compression.cpp b/src/plugins/intel_gpu/tests/unit/transformations/kv_cache_compression.cpp
index ca101d1b5d2..738295a11f5 100644
--- a/src/plugins/intel_gpu/tests/unit/transformations/kv_cache_compression.cpp
+++ b/src/plugins/intel_gpu/tests/unit/transformations/kv_cache_compression.cpp
@@ -12,6 +12,7 @@
#include "openvino/op/gather.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/unsqueeze.hpp"
+#include "openvino/op/variadic_split.hpp"
#include "intel_gpu/op/read_value.hpp"
#include "intel_gpu/op/read_values.hpp"
@@ -339,6 +340,125 @@ TEST_F(TransformationTestsF, KVCacheCompressionWithInitializers) {
}
}
+TEST_F(TransformationTestsF, NewTestKVCacheCompression) {
+ ov::PartialShape input_shape = ov::PartialShape{-1, 32, -1, 80};
+ std::vector<int64_t> qkv_order = {0, 1, 2, 3};
+ bool causal = false;
+ size_t gather_axis = 0;
+ size_t concat_axis = -2;
+ {
+ auto query = std::make_shared<ov::op::v0::Parameter>(element::f16, input_shape);
+ auto beam_idx = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1});
+
+ auto key_current_data = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 32, -1, 240});
+ auto key_vs_axis = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 1);
+ auto key_vs_split_length = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{3}, std::vector<int>{80, 80, -1});
+ auto key_current_vs = std::make_shared<ov::op::v1::VariadicSplit>(key_current_data, key_vs_axis, key_vs_split_length);
+ auto key_variable_initializer = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, input_shape);
+ auto key_variable = std::make_shared<ov::op::util::Variable>(ov::op::util::VariableInfo{{-1, 32, -1, 80}, ov::element::f16, "v0"});
+ auto key_past = std::make_shared<ov::intel_gpu::op::ReadValue>(key_variable_initializer, key_variable);
+ auto key_cache = std::make_shared<ov::intel_gpu::op::KVCache>(key_past, key_current_vs->output(2), beam_idx, key_variable, concat_axis, gather_axis);
+
+ auto value_current_data = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 32, -1, 240});
+ auto value_vs_axis = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 1);
+ auto value_vs_split_length = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{3}, std::vector<int>{80, 80, -1});
+ auto value_current_vs = std::make_shared<ov::op::v1::VariadicSplit>(value_current_data, value_vs_axis, value_vs_split_length);
+ auto value_variable_initializer = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, input_shape);
+ auto value_variable = std::make_shared<ov::op::util::Variable>(ov::op::util::VariableInfo{{-1, 32, -1, 80}, ov::element::f16, "v1"});
+ auto value_past = std::make_shared<ov::intel_gpu::op::ReadValue>(value_variable_initializer, value_variable);
+ auto value_cache = std::make_shared<ov::intel_gpu::op::KVCache>(value_past, value_current_vs->output(2), beam_idx, value_variable, concat_axis, gather_axis);
+
+ auto attn_mask = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 1, -1, -1});
+ auto scale = std::make_shared<ov::op::v0::Constant>(ov::element::f16, ov::Shape{}, 0.111816f);
+ auto sdpa = std::make_shared<ov::intel_gpu::op::IndirectSDPA>(ov::OutputVector{query, key_cache->output(0), value_cache->output(0), attn_mask, scale},
+ key_cache->output(1),
+ causal,
+ gather_axis,
+ qkv_order,
+ qkv_order,
+ qkv_order,
+ ov::intel_gpu::op::SDPA::default_order(4));
+ auto result = std::make_shared<ov::op::v0::Result>(sdpa);
+
+ auto params = ParameterVector{query, beam_idx, key_variable_initializer, key_current_data, value_variable_initializer, value_current_data, attn_mask};
+ model = std::make_shared<ov::Model>(ResultVector{result}, params);
+ manager.register_pass<KVCacheCompression>(ov::element::i8, false);
+ }
+ {
+ ov::op::internal::DynamicQuantize::Attributes dq_config;
+ dq_config.quantization_type = ov::op::internal::DynamicQuantize::QuantizationType::Asymmetric;
+ dq_config.quantization_dt = ov::element::i8;
+ dq_config.scale_dt = ov::element::f16;
+ dq_config.zp_dt = ov::element::f16;
+ dq_config.group_sizes = { 1, 1, 1, UINT64_MAX };
+ dq_config.scales_zp_output_order = { 0, 1, 2, 3 };
+ dq_config.output_storage_type = ov::op::internal::DynamicQuantize::OutputStorageType::InterleavedScalesZP;
+
+ auto query = std::make_shared<ov::op::v0::Parameter>(element::f16, input_shape);
+ auto beam_idx = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1});
+
+ auto key_past_variable_infos = { ov::op::util::VariableInfo{{-1, 32, -1, 80}, ov::element::i8, "v0"},
+ ov::op::util::VariableInfo{{-1, 32, -1, 2}, ov::element::f16, "v0"} };
+
+ auto key_current_data = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 32, -1, 240});
+ auto key_vs_axis = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 1);
+ auto key_vs_split_length = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{3}, std::vector<int>{80, 80, -1});
+ auto key_current_vs = std::make_shared<ov::op::v1::VariadicSplit>(key_current_data, key_vs_axis, key_vs_split_length);
+ auto key_variable_initializer = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, input_shape);
+ auto key_variable = std::make_shared<ov::op::util::Variable>(ov::op::util::VariableInfo{{-1, 32, -1, 80}, ov::element::f16, "v0"});
+
+ auto key_initializer_dq =
+ std::make_shared<ov::op::internal::DynamicQuantize>(key_variable_initializer, dq_config);
+ auto key_past_initializers = ov::OutputVector{key_initializer_dq->output(0), key_initializer_dq->output(1)};
+ auto key_past_compressed = std::make_shared<ov::intel_gpu::op::ReadValues>(key_past_initializers, key_variable, key_past_variable_infos);
+ auto key_cache_inputs = ov::OutputVector{key_past_compressed->output(0), key_current_vs->output(2), beam_idx, key_past_compressed->output(1)};
+ auto key_cache = std::make_shared<ov::intel_gpu::op::KVCacheCompressed>(key_cache_inputs,
+ key_variable,
+ concat_axis,
+ gather_axis,
+ dq_config);
+
+ auto value_past_variable_infos = {ov::op::util::VariableInfo{{-1, 32, -1, 80}, ov::element::i8, "v1"},
+ ov::op::util::VariableInfo{{-1, 32, -1, 2}, ov::element::f16, "v1"}};
+
+ auto value_current_data = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 32, -1, 240});
+ auto value_vs_axis = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 1);
+ auto value_vs_split_length = std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{3}, std::vector<int>{80, 80, -1});
+ auto value_current_vs = std::make_shared<ov::op::v1::VariadicSplit>(value_current_data, value_vs_axis, value_vs_split_length);
+ auto value_variable_initializer = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, input_shape);
+ auto value_variable = std::make_shared<ov::op::util::Variable>(ov::op::util::VariableInfo{{1, 32, -1, 80}, ov::element::f16, "v1"});
+
+ auto value_initializer_dq =
+ std::make_shared<ov::op::internal::DynamicQuantize>(value_variable_initializer, dq_config);
+ auto value_past_initializers = ov::OutputVector{value_initializer_dq->output(0), value_initializer_dq->output(1)};
+ auto value_past_compressed = std::make_shared<ov::intel_gpu::op::ReadValues>(value_past_initializers, value_variable, value_past_variable_infos);
+ auto value_cache_inputs = ov::OutputVector{value_past_compressed->output(0), value_current_vs->output(2), beam_idx, value_past_compressed->output(1)};
+ auto value_cache = std::make_shared<ov::intel_gpu::op::KVCacheCompressed>(value_cache_inputs,
+ value_variable,
+ concat_axis,
+ gather_axis,
+ dq_config);
+
+ auto attn_mask = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 1, -1, -1});
+ auto scale = std::make_shared<ov::op::v0::Constant>(ov::element::f16, ov::Shape{}, 0.111816f);
+ auto sdpa = std::make_shared<ov::intel_gpu::op::IndirectSDPA>(ov::OutputVector{query, key_cache->output(0), value_cache->output(0),
+ attn_mask, scale,
+ key_cache->output(2), value_cache->output(2)},
+ key_cache->output(1),
+ causal,
+ gather_axis,
+ qkv_order,
+ qkv_order,
+ qkv_order,
+ ov::intel_gpu::op::SDPA::default_order(4),
+ dq_config);
+ auto result = std::make_shared<ov::op::v0::Result>(sdpa);
+
+ auto params = ParameterVector{query, beam_idx, key_variable_initializer, key_current_data, value_variable_initializer, value_current_data, attn_mask};
+ model_ref = std::make_shared<ov::Model>(ResultVector{result}, params);
+ }
+}
+
} // namespace intel_gpu
} // namespace test
} // namespace ov