Skip to content

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

[GPU] SDPA new shape infer (#31124)

Michal Miotk0ceb0bbc9e40
diff --git a/src/plugins/intel_gpu/src/runtime/execution_config.cpp b/src/plugins/intel_gpu/src/runtime/execution_config.cpp
index e28c06ca4ac..3c5e3e5cd62 100644
--- a/src/plugins/intel_gpu/src/runtime/execution_config.cpp
+++ b/src/plugins/intel_gpu/src/runtime/execution_config.cpp
@@ -10,6 +10,9 @@
#include "openvino/op/lstm_sequence.hpp"
#include "openvino/op/gru_sequence.hpp"
#include "openvino/op/paged_attention.hpp"
+#include "openvino/op/scaled_dot_product_attention.hpp"
+#include "intel_gpu/op/sdpa.hpp"
+#include "intel_gpu/op/indirect_sdpa.hpp"
#include "openvino/op/search_sorted.hpp"
#include "openvino/op/stft.hpp"
#include "openvino/op/istft.hpp"
@@ -63,6 +66,31 @@ bool requires_new_shape_infer(const std::shared_ptr<ov::Node>& op) {
if (ov::is_type<ov::op::v5::GRUSequence>(op) || ov::is_type<ov::op::v5::LSTMSequence>(op) || ov::is_type<ov::op::v4::LSTMCell>(op)) {
return true;
}
+
+ if (ov::is_type<ov::op::v13::ScaledDotProductAttention>(op) || ov::is_type<ov::intel_gpu::op::IndirectSDPA>(op) ||
+ ov::is_type<ov::intel_gpu::op::SDPA>(op)) {
+ if (op->get_input_size() > 3) {
+ bool rank_ge_4 = false;
+ bool rank_dynamic = false;
+ for (size_t i = 0; i < op->get_input_size(); i++) {
+ auto input_shape = op->get_input_partial_shape(i);
+ if (input_shape.rank().is_dynamic()) {
+ rank_dynamic = true;
+ break;
+ }
+
+ if (input_shape.size() >= 4) {
+ rank_ge_4 = true;
+ break;
+ }
+ }
+
+ if (!rank_ge_4 && !rank_dynamic) {
+ return true;
+ }
+ }
+ }
+
// When input node has dynamic shape with 4 dimension, this function return false
// because op.is_dynamic() which only checks input shapes return false.
// So, in the case of input data, we need to check output shape.
diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/sdpa.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/sdpa.cpp
index 7835bda7351..aeb65fdffff 100644
--- a/src/plugins/intel_gpu/tests/functional/subgraph_tests/sdpa.cpp
+++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/sdpa.cpp
@@ -219,7 +219,17 @@ TEST_P(SDPAFusion, Inference) {
INSTANTIATE_TEST_SUITE_P(SDPAFusionTests,
SDPAFusion,
- ::testing::Values(std::make_tuple(ov::PartialShape{1, 10, 1024, 64},
+ ::testing::Values(std::make_tuple(ov::PartialShape{10, 1024, 64},
+ ov::Shape{10, 1024, 64},
+ ov::PartialShape{10, 77, 64},
+ ov::Shape{10, 77, 64},
+ ov::PartialShape{10, 77, 64},
+ ov::Shape{10, 77, 64},
+ ov::PartialShape{1024, 77},
+ 1.0f,
+ 0.025f,
+ 0.025f),
+ std::make_tuple(ov::PartialShape{1, 10, 1024, 64},
ov::Shape{10, 1024, 64},
ov::PartialShape{1, 10, 77, 64},
ov::Shape{10, 77, 64},