[TRANSFORMATIONS] Add a check to SDPAToPagedAttention to fail fast (#24841)

[TRANSFORMATIONS] Add a check to SDPAToPagedAttention to fail fast

Add a check to SDPAToPagedAttention to fail fast if no
ScaledDotProductAttention operation present in a graph hence no
transformation will be executed.

### Tickets:
 - CVS-143067

Signed-off-by: Andrii Staikov <andrii.staikov@intel.com>

---------

Signed-off-by: Andrii Staikov <andrii.staikov@intel.com>
Co-authored-by: Ivan Tikhonov <ivan.tikhonov@intel.com>
This commit is contained in:
Andrii Staikov 2024-06-07 10:23:27 +02:00 committed by GitHub
parent 7f1ddd55ac
commit 852878162d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,27 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/pass/sdpa_to_paged_attention.hpp"
#include <gtest/gtest.h>
#include "common_test_utils/test_common.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/scaled_dot_product_attention.hpp"
#include "openvino/pass/manager.hpp"
using namespace ov;
TEST(SDPATOPATest, SDPANotPresent) {
const auto p0 = std::make_shared<op::v0::Parameter>(element::f32, Shape{1, 32, 32});
const auto p1 = std::make_shared<op::v0::Parameter>(element::f32, Shape{1, 32, 32});
const auto add = std::make_shared<op::v1::Add>(p0, p1);
const auto result = std::make_shared<op::v0::Result>(add);
auto model = std::make_shared<Model>(ResultVector{result}, ParameterVector{p0, p1});
ov::pass::Manager manager;
manager.register_pass<pass::SDPAToPagedAttention>();
EXPECT_THROW(manager.run_passes(model), ov::Exception);
}

View File

@ -7,6 +7,7 @@
#include "openvino/cc/pass/itt.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/gather.hpp"
#include "openvino/op/scaled_dot_product_attention.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/unsqueeze.hpp"
#include "openvino/pass/manager.hpp"
@ -29,6 +30,11 @@ static std::shared_ptr<v0::Parameter> setName(std::shared_ptr<v0::Parameter> nod
bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr<ov::Model>& model) {
RUN_ON_MODEL_SCOPE(SDPAToPagedAttention);
OPENVINO_ASSERT(ov::op::util::has_op_with_type<ov::op::v13::ScaledDotProductAttention>(model),
"No ScaledDotProductAttention operation observed in the graph, cannot perform"
"the SDPAToPagedAttention transformation.");
auto max_context_len = setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{}), "max_context_len");
ParameterVector model_remaining_params = {
setName(std::make_shared<v0::Parameter>(element::i32, PartialShape{-1}), "past_lens"),