Skip to content

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

Fix AbsSinking transformation to prevent incorrect Abs removal on constants and StatefulSDPAFusion SymbolicOptimizations full_run=true (#31735)

Evgeny Kotovb136b97da23a
diff --git a/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp b/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp
index 2182ae288bd..80f48668423 100644
--- a/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp
+++ b/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp
@@ -164,7 +164,14 @@ pass::AbsSinking::AbsSinking() {
abs_ops.erase(abs_ops.begin());
graph_got_changed = true;
}
+ // We don't handle the case where Abs is applied directly to a constant
+ // This is intentionally left to ConstantFolding pass which is better suited for this task
for (const auto& abs : abs_ops) {
+ // Skip Abs operations applied to constants - let ConstantFolding handle them
+ if (ov::is_type<v0::Constant>(abs->get_input_node_ptr(0))) {
+ continue;
+ }
+
auto bounds = ov::util::evaluate_both_bounds(abs->input_value(0));
if (ov::util::reduce_and(ov::util::greater_equal(bounds.first, 0))) {
replace_output_update_name(abs->output(0), abs->input_value(0));
diff --git a/src/common/transformations/tests/common_optimizations/simplify_shape_of_sub_graph.cpp b/src/common/transformations/tests/common_optimizations/simplify_shape_of_sub_graph.cpp
index efbd5bcd3d3..01bf59c8e23 100644
--- a/src/common/transformations/tests/common_optimizations/simplify_shape_of_sub_graph.cpp
+++ b/src/common/transformations/tests/common_optimizations/simplify_shape_of_sub_graph.cpp
@@ -437,3 +437,36 @@ TEST_F(TransformationTestsF, AbsInTheUnknown) {
manager.register_pass<pass::AbsSinking>();
}
}
+
+// Parameterized test for AbsSinking with constants
+struct AbsSinkingConstantTestParams {
+ std::vector<int64_t> values;
+ std::string test_name;
+};
+
+class AbsSinkingConstantTest : public TransformationTestsF,
+ public ::testing::WithParamInterface<AbsSinkingConstantTestParams> {};
+
+TEST_P(AbsSinkingConstantTest, AbsSinkingSkipsConstants) {
+ // Test that AbsSinking does NOT process constants (leaves them for ConstantFolding)
+ const auto& params = GetParam();
+
+ {
+ auto constant = op::v0::Constant::create(element::i64, {params.values.size()}, params.values);
+ auto abs_op = std::make_shared<op::v0::Abs>(constant);
+
+ model = std::make_shared<Model>(OutputVector{abs_op}, ParameterVector{});
+ manager.register_pass<pass::AbsSinking>();
+ }
+
+ // Reference model should be identical since AbsSinking skips constants
+ model_ref = model->clone();
+}
+
+INSTANTIATE_TEST_SUITE_P(AbsSinkingConstantTests,
+ AbsSinkingConstantTest,
+ ::testing::Values(AbsSinkingConstantTestParams{{-1, -2, 4}, "negative_values"},
+ AbsSinkingConstantTestParams{{1, 2}, "positive_values"}),
+ [](const ::testing::TestParamInfo<AbsSinkingConstantTestParams>& info) {
+ return info.param.test_name;
+ });
diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/stateful_sdpa_fusion.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/stateful_sdpa_fusion.cpp
index 4eb8665df82..6d8f021ae6f 100644
--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/stateful_sdpa_fusion.cpp
+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/stateful_sdpa_fusion.cpp
@@ -297,7 +297,7 @@ StatefulSDPAFusion::StatefulSDPAFusion() {
bool SDPASubgraphFusion::run_on_model(const std::shared_ptr<ov::Model>& f) {
RUN_ON_FUNCTION_SCOPE(SDPASubgraphFusion);
- ov::pass::SymbolicOptimizations symbolic_optimizations(false, get_pass_config());
+ ov::pass::SymbolicOptimizations symbolic_optimizations(true, get_pass_config());
auto& ctx_manager = *symbolic_optimizations.get_manager();
CPU_REGISTER_PASS_COMMON(ctx_manager, ov::pass::SimplifyGatherShapeOf);