diff --git a/src/common/transformations/tests/sdpa_to_paged_attention_test.cpp b/src/common/transformations/tests/sdpa_to_paged_attention_test.cpp new file mode 100644 index 00000000000..0443e7b82de --- /dev/null +++ b/src/common/transformations/tests/sdpa_to_paged_attention_test.cpp @@ -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 + +#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(element::f32, Shape{1, 32, 32}); + const auto p1 = std::make_shared(element::f32, Shape{1, 32, 32}); + const auto add = std::make_shared(p0, p1); + const auto result = std::make_shared(add); + + auto model = std::make_shared(ResultVector{result}, ParameterVector{p0, p1}); + + ov::pass::Manager manager; + manager.register_pass(); + EXPECT_THROW(manager.run_passes(model), ov::Exception); +} \ No newline at end of file diff --git a/src/core/src/pass/sdpa_to_paged_attention.cpp b/src/core/src/pass/sdpa_to_paged_attention.cpp index 1eaf15c928d..0d71c6a4b0d 100644 --- a/src/core/src/pass/sdpa_to_paged_attention.cpp +++ b/src/core/src/pass/sdpa_to_paged_attention.cpp @@ -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 setName(std::shared_ptr nod bool ov::pass::SDPAToPagedAttention::run_on_model(const std::shared_ptr& model) { RUN_ON_MODEL_SCOPE(SDPAToPagedAttention); + + OPENVINO_ASSERT(ov::op::util::has_op_with_type(model), + "No ScaledDotProductAttention operation observed in the graph, cannot perform" + "the SDPAToPagedAttention transformation."); + auto max_context_len = setName(std::make_shared(element::i32, PartialShape{}), "max_context_len"); ParameterVector model_remaining_params = { setName(std::make_shared(element::i32, PartialShape{-1}), "past_lens"),