Skip to content

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

[ONNX FE] Wrong results produced by PRelu operator (#38889)

Szymon Gutajbdcddc0700e9
diff --git a/src/frontends/onnx/docs/supported_ops.md b/src/frontends/onnx/docs/supported_ops.md
index 39569468265..5f701e3381a 100644
--- a/src/frontends/onnx/docs/supported_ops.md
+++ b/src/frontends/onnx/docs/supported_ops.md
@@ -128,7 +128,7 @@ OpenVINO provides support for operations of Default Opset (empty in table below)
| |OptionalGetElement | |18, 15 | |
| |OptionalHasElement | |18, 15 | |
| |Or |1 |7, 1 | |
-| |PRelu |1 |16, 9, 7, 6, 1 | |
+| |PRelu |7, 1 |16, 9, 7, 6, 1 | |
| |Pad |11, 1 |21, 19, 18, 13, 11, 2, 1 | |
| |Pow |1 |15, 13, 12, 7, 1 | |
| |QLinearConv |10 |10 | |
diff --git a/src/frontends/onnx/frontend/src/op/prelu.cpp b/src/frontends/onnx/frontend/src/op/prelu.cpp
index 775f7472679..4d01e793d31 100644
--- a/src/frontends/onnx/frontend/src/op/prelu.cpp
+++ b/src/frontends/onnx/frontend/src/op/prelu.cpp
@@ -5,15 +5,72 @@
#include "openvino/op/prelu.hpp"
#include "core/operator_set.hpp"
+#include "openvino/op/broadcast.hpp"
+#include "openvino/op/concat.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/equal.hpp"
+#include "openvino/op/gather.hpp"
+#include "openvino/op/range.hpp"
+#include "openvino/op/select.hpp"
+#include "openvino/op/shape_of.hpp"
+#include "openvino/op/squeeze.hpp"
+#include "openvino/op/subtract.hpp"
using namespace ov::op;
-namespace ov::frontend::onnx::ai_onnx::opset_1 {
+namespace ov::frontend::onnx::ai_onnx {
+namespace opset_1 {
ov::OutputVector prelu(const ov::frontend::onnx::Node& node) {
ov::OutputVector ov_inputs{node.get_ov_inputs()};
const auto& data = ov_inputs.at(0);
const auto& slope = ov_inputs.at(1);
+
+ // PRelu-1/6 use the legacy (Caffe2-like) broadcasting: a slope of size 1 is shared across channels, i.e. a
+ // rank-1 slope is aligned with the channel axis. OpenVINO's v0::PRelu already implements exactly this behavior,
+ // so the inputs are forwarded without any reshaping.
return {std::make_shared<v0::PRelu>(data, slope)};
}
-ONNX_OP("PRelu", OPSET_SINCE(1), ai_onnx::opset_1::prelu);
-} // namespace ov::frontend::onnx::ai_onnx::opset_1
+ONNX_OP("PRelu", OPSET_RANGE(1, 6), ai_onnx::opset_1::prelu);
+} // namespace opset_1
+
+namespace opset_7 {
+ov::OutputVector prelu(const ov::frontend::onnx::Node& node) {
+ ov::OutputVector ov_inputs{node.get_ov_inputs()};
+ const auto& data = ov_inputs.at(0);
+ const auto& slope = ov_inputs.at(1);
+
+ // v0::PRelu only reinterprets a rank-1 slope as per-channel; any other static rank already broadcasts with
+ // ONNX (NUMPY, trailing-axis) rules, so forward it without the normalization subgraph.
+ const auto& static_slope_rank = slope.get_partial_shape().rank();
+ if (static_slope_rank.is_static() && static_slope_rank.get_length() != 1) {
+ return {std::make_shared<v0::PRelu>(data, slope)};
+ }
+
+ const auto data_shape = std::make_shared<v3::ShapeOf>(data, ov::element::i64);
+ const auto slope_shape = std::make_shared<v3::ShapeOf>(slope, ov::element::i64);
+ const auto data_rank_vector = std::make_shared<v3::ShapeOf>(data_shape, ov::element::i64);
+ const auto slope_rank_vector = std::make_shared<v3::ShapeOf>(slope_shape, ov::element::i64);
+ const auto zero = v0::Constant::create(ov::element::i64, ov::Shape{}, {0});
+ const auto one = v0::Constant::create(ov::element::i64, ov::Shape{}, {1});
+ const auto data_rank = std::make_shared<v0::Squeeze>(data_rank_vector);
+ const auto slope_rank = std::make_shared<v0::Squeeze>(slope_rank_vector);
+ const auto axes_start = std::make_shared<v1::Subtract>(data_rank, slope_rank);
+ const auto trailing_axes = std::make_shared<v4::Range>(axes_start, data_rank, one, ov::element::i64);
+ const auto trailing_shape = std::make_shared<v8::Gather>(data_shape, trailing_axes, zero);
+ const auto singleton_dims = std::make_shared<v1::Equal>(slope_shape, one);
+ const auto compact_target = std::make_shared<v1::Select>(singleton_dims, slope_shape, trailing_shape);
+ const auto leading_ones =
+ std::make_shared<v3::Broadcast>(v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}),
+ std::make_shared<v1::Subtract>(data_rank_vector, slope_rank_vector));
+ const auto normalized_shape = std::make_shared<v0::Concat>(ov::OutputVector{leading_ones, compact_target}, 0);
+
+ // Everything is derived from the current shapes so a post-conversion rank change keeps non-singleton slope
+ // dimensions on the trailing data axes. Broadcasting to this compact target left-pads the slope and rejects
+ // dimensions that are neither 1 nor equal to the data, without materializing an activation-sized slope.
+ const auto normalized_slope = std::make_shared<v3::Broadcast>(slope, normalized_shape, BroadcastType::NUMPY);
+ return {std::make_shared<v0::PRelu>(data, normalized_slope)};
+}
+
+ONNX_OP("PRelu", OPSET_SINCE(7), ai_onnx::opset_7::prelu);
+} // namespace opset_7
+} // namespace ov::frontend::onnx::ai_onnx
diff --git a/src/frontends/onnx/tests/models/prelu_1d_channel_bcast_opset6.prototxt b/src/frontends/onnx/tests/models/prelu_1d_channel_bcast_opset6.prototxt
new file mode 100644
index 00000000000..c67bb403153
--- /dev/null
+++ b/src/frontends/onnx/tests/models/prelu_1d_channel_bcast_opset6.prototxt
@@ -0,0 +1,66 @@
+ir_version: 3
+producer_name: "OpenVINO ONNX Frontend"
+graph {
+ node {
+ input: "X"
+ input: "SLOPE"
+ output: "Y"
+ op_type: "PRelu"
+ }
+ name: "test-model-prelu-1d-channel-bcast-opset6"
+ input {
+ name: "X"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "SLOPE"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "Y"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 6
+}
diff --git a/src/frontends/onnx/tests/models/prelu_1d_last_dim_bcast.prototxt b/src/frontends/onnx/tests/models/prelu_1d_last_dim_bcast.prototxt
new file mode 100644
index 00000000000..4a492011090
--- /dev/null
+++ b/src/frontends/onnx/tests/models/prelu_1d_last_dim_bcast.prototxt
@@ -0,0 +1,72 @@
+ir_version: 7
+producer_name: "OpenVINO ONNX Frontend"
+graph {
+ node {
+ input: "X"
+ input: "SLOPE"
+ output: "Y"
+ op_type: "PRelu"
+ }
+ name: "test-model-prelu-1d-last-dim-bcast"
+ input {
+ name: "X"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "SLOPE"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "Y"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 12
+}
diff --git a/src/frontends/onnx/tests/models/prelu_1d_last_dim_bcast_unknown_data_rank.prototxt b/src/frontends/onnx/tests/models/prelu_1d_last_dim_bcast_unknown_data_rank.prototxt
new file mode 100644
index 00000000000..8ba754c110e
--- /dev/null
+++ b/src/frontends/onnx/tests/models/prelu_1d_last_dim_bcast_unknown_data_rank.prototxt
@@ -0,0 +1,44 @@
+ir_version: 7
+producer_name: "OpenVINO ONNX Frontend"
+graph {
+ node {
+ input: "X"
+ input: "SLOPE"
+ output: "Y"
+ op_type: "PRelu"
+ }
+ name: "test-model-prelu-1d-last-dim-bcast-unknown-data-rank"
+ input {
+ name: "X"
+ type {
+ tensor_type {
+ elem_type: 1
+ }
+ }
+ }
+ input {
+ name: "SLOPE"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "Y"
+ type {
+ tensor_type {
+ elem_type: 1
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 12
+}
diff --git a/src/frontends/onnx/tests/models/prelu_1d_last_dim_bcast_unknown_slope_rank.prototxt b/src/frontends/onnx/tests/models/prelu_1d_last_dim_bcast_unknown_slope_rank.prototxt
new file mode 100644
index 00000000000..d7352632270
--- /dev/null
+++ b/src/frontends/onnx/tests/models/prelu_1d_last_dim_bcast_unknown_slope_rank.prototxt
@@ -0,0 +1,67 @@
+ir_version: 7
+producer_name: "OpenVINO ONNX Frontend"
+graph {
+ node {
+ input: "X"
+ input: "SLOPE"
+ output: "Y"
+ op_type: "PRelu"
+ }
+ name: "test-model-prelu-1d-last-dim-bcast-unknown-slope-rank"
+ input {
+ name: "X"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "SLOPE"
+ type {
+ tensor_type {
+ elem_type: 1
+ }
+ }
+ }
+ output {
+ name: "Y"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+}
+opset_import {
+ domain: ""
+ version: 12
+}
diff --git a/src/frontends/onnx/tests/models/prelu_1d_singleton_constant.prototxt b/src/frontends/onnx/tests/models/prelu_1d_singleton_constant.prototxt
new file mode 100644
index 00000000000..20cbf4702be
--- /dev/null
+++ b/src/frontends/onnx/tests/models/prelu_1d_singleton_constant.prototxt
@@ -0,0 +1,36 @@
+ir_version: 7
+producer_name: "OpenVINO ONNX Frontend"
+graph {
+ name: "prelu-1d-singleton-constant"
+ initializer {
+ name: "SLOPE"
+ data_type: 1
+ dims: 1
+ float_data: 0.5
+ }
+ node {
+ op_type: "PRelu"
+ input: "X"
+ input: "SLOPE"
+ output: "Y"
+ }
+ input {
+ name: "X"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape { dim { dim_value: 24 } }
+ }
+ }
+ }
+ output {
+ name: "Y"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape { dim { dim_value: 24 } }
+ }
+ }
+ }
+}
+opset_import { domain: "" version: 12 }
diff --git a/src/frontends/onnx/tests/models/prelu_compact_channel_constant.prototxt b/src/frontends/onnx/tests/models/prelu_compact_channel_constant.prototxt
new file mode 100644
index 00000000000..ceaf795e4a2
--- /dev/null
+++ b/src/frontends/onnx/tests/models/prelu_compact_channel_constant.prototxt
@@ -0,0 +1,62 @@
+ir_version: 7
+producer_name: "OpenVINO ONNX Frontend"
+graph {
+ name: "prelu-compact-channel-constant"
+ initializer {
+ name: "slope_shape"
+ data_type: 7
+ dims: 3
+ int64_data: 64
+ int64_data: 1
+ int64_data: 1
+ }
+ node {
+ op_type: "ConstantOfShape"
+ input: "slope_shape"
+ output: "SLOPE"
+ attribute {
+ name: "value"
+ type: TENSOR
+ t {
+ data_type: 1
+ dims: 1
+ float_data: 0.5
+ }
+ }
+ }
+ node {
+ op_type: "PRelu"
+ input: "X"
+ input: "SLOPE"
+ output: "Y"
+ }
+ input {
+ name: "X"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_value: 1 }
+ dim { dim_value: 64 }
+ dim { dim_value: 256 }
+ dim { dim_value: 256 }
+ }
+ }
+ }
+ }
+ output {
+ name: "Y"
+ type {
+ tensor_type {
+ elem_type: 1
+ shape {
+ dim { dim_value: 1 }
+ dim { dim_value: 64 }
+ dim { dim_value: 256 }
+ dim { dim_value: 256 }
+ }
+ }
+ }
+ }
+}
+opset_import { domain: "" version: 12 }
diff --git a/src/frontends/onnx/tests/onnx_import.in.cpp b/src/frontends/onnx/tests/onnx_import.in.cpp
index 6dc6756663f..7112010efff 100644
--- a/src/frontends/onnx/tests/onnx_import.in.cpp
+++ b/src/frontends/onnx/tests/onnx_import.in.cpp
@@ -33,9 +33,11 @@
#include "gtest/gtest.h"
#include "onnx_utils.hpp"
#include "openvino/op/constant.hpp"
+#include "openvino/op/prelu.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/scatter_elements_update.hpp"
#include "openvino/op/softmax.hpp"
+#include "openvino/pass/constant_folding.hpp"
using namespace ov;
using namespace ov::frontend::onnx::tests;
@@ -3032,6 +3034,207 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_1d) {
test_case.run();
}
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_1d_last_dim_bcast) {
+ // Regression test for a 1-D slope whose length equals the channel dimension while the channel is not the
+ // last dimension. ONNX uses unidirectional (numpy-style) broadcasting, so the slope must be aligned with the
+ // last data dimension, matching onnxruntime and the ONNX reference evaluator (see GitHub issue #33371).
+ auto model = convert_model("prelu_1d_last_dim_bcast.onnx");
+
+ Inputs inputs;
+ // Shape{1, 3, 2, 3}
+ inputs.emplace_back(
+ std::vector<float>{-1., -2., -3., 4., -5., 6., -7., -8., -9., -1., 2., -3., -4., -5., -6., 7., -8., -9.});
+
+ // Shape{3}
+ inputs.emplace_back(std::vector<float>{1., 2., 3.});
+
+ // Shape{1, 3, 2, 3} - slope broadcast over the last dimension
+ auto expected_output =
+ std::vector<float>{-1., -4., -9., 4., -10., 6., -7., -16., -27., -1., 2., -9., -4., -10., -18., 7., -16., -27.};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_multiple_inputs(inputs);
+ test_case.add_expected_output(expected_output);
+ test_case.run();
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_1d_last_dim_bcast_unknown_data_rank) {
+ auto model = convert_model("prelu_1d_last_dim_bcast_unknown_data_rank.onnx");
+ ASSERT_TRUE(model->get_parameters().at(0)->get_partial_shape().rank().is_dynamic());
+
+ // Specialize only after conversion so the translator sees the unknown rank, but plugins compile static ranks.
+ model->reshape({{"X", PartialShape{1, 3, 2, 3}}});
+ ASSERT_TRUE(model->get_parameters().at(0)->get_partial_shape().rank().is_static());
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 3, 2, 3},
+ {-1., -2., -3., 4., -5., 6., -7., -8., -9., -1., 2., -3., -4., -5., -6., 7., -8., -9.});
+ test_case.add_input<float>(Shape{3}, {1., 2., 3.});
+ // The channel and trailing dimensions are both 3, but the slope must follow the trailing dimension.
+ test_case.add_expected_output<float>(
+ Shape{1, 3, 2, 3},
+ {-1., -4., -9., 4., -10., 6., -7., -16., -27., -1., 2., -9., -4., -10., -18., 7., -16., -27.});
+ test_case.run();
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_1d_last_dim_bcast_unknown_slope_rank) {
+ auto model = convert_model("prelu_1d_last_dim_bcast_unknown_slope_rank.onnx");
+ ASSERT_TRUE(model->get_parameters().at(1)->get_partial_shape().rank().is_dynamic());
+
+ model->reshape({{"SLOPE", PartialShape{3}}});
+ ASSERT_TRUE(model->get_parameters().at(1)->get_partial_shape().rank().is_static());
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 3, 2, 3},
+ {-1., -2., -3., 4., -5., 6., -7., -8., -9., -1., 2., -3., -4., -5., -6., 7., -8., -9.});
+ test_case.add_input<float>(Shape{3}, {1., 2., 3.});
+ test_case.add_expected_output<float>(
+ Shape{1, 3, 2, 3},
+ {-1., -4., -9., 4., -10., 6., -7., -16., -27., -1., 2., -9., -4., -10., -18., 7., -16., -27.});
+ test_case.run();
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_1d_last_dim_bcast_slope_rank_changes_after_conversion) {
+ auto model = convert_model("prelu_1d_last_dim_bcast.onnx");
+ model->reshape({{"SLOPE", PartialShape{3, 1, 1}}});
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(Shape{1, 3, 2, 3},
+ {-1., -2., -3., 4., -5., 6., -7., -8., -9., -1., 2., -3., -4., -5., -6., 7., -8., -9.});
+ test_case.add_input<float>(Shape{3, 1, 1}, {1., 2., 3.});
+ // Preserve [channel, 1, 1] slope axes when padding to the data rank.
+ test_case.add_expected_output<float>(
+ Shape{1, 3, 2, 3},
+ {-1., -2., -3., 4., -5., 6., -14., -16., -18., -2., 2., -6., -12., -15., -18., 7., -24., -27.});
+ test_case.run();
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_reject_incompatible_static_slope) {
+ ov::frontend::FrontEnd::Ptr frontend;
+ auto input_model = load_model("prelu_1d_last_dim_bcast.onnx", &frontend);
+ input_model->set_partial_shape(input_model->get_place_by_tensor_name("X"), PartialShape{1, 3, 2, 1});
+ // Bidirectional broadcasting would expand the last data dimension from 1 to 3, which ONNX forbids.
+ OV_EXPECT_THROW_HAS_SUBSTRING(frontend->convert(input_model), ov::Exception, "cannot be broadcasted");
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_reject_incompatible_specialized_slope) {
+ auto model = convert_model("prelu_1d_last_dim_bcast_unknown_data_rank.onnx");
+ OV_EXPECT_THROW_HAS_SUBSTRING(model->reshape({{"X", PartialShape{1, 3, 2, 1}}}),
+ ov::Exception,
+ "cannot be broadcasted");
+
+ model = convert_model("prelu_1d_last_dim_bcast_unknown_slope_rank.onnx");
+ OV_EXPECT_THROW_HAS_SUBSTRING(model->reshape({{"SLOPE", PartialShape{2}}}), ov::Exception, "cannot be broadcasted");
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_reject_incompatible_runtime_data_shape) {
+ auto model = convert_model("prelu_1d_last_dim_bcast_unknown_data_rank.onnx");
+ const Tensor data(element::f32, Shape{1, 3, 2, 1});
+ const Tensor slope(element::f32, Shape{3});
+ TensorVector outputs{Tensor(element::f32, data.get_shape())};
+ // Evaluate without specializing the unknown rank: Broadcast must reject before PRelu can write its output.
+ OV_EXPECT_THROW_HAS_SUBSTRING(model->evaluate(outputs, TensorVector{data, slope}),
+ ov::Exception,
+ "cannot be broadcasted");
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_reject_incompatible_runtime_slope_shape) {
+ auto model = convert_model("prelu_1d_last_dim_bcast_unknown_slope_rank.onnx");
+ const Tensor data(element::f32, Shape{1, 3, 2, 3});
+ const Tensor slope(element::f32, Shape{2});
+ TensorVector outputs{Tensor(element::f32, data.get_shape())};
+ OV_EXPECT_THROW_HAS_SUBSTRING(model->evaluate(outputs, TensorVector{data, slope}),
+ ov::Exception,
+ "cannot be broadcasted");
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_compact_channel_constant) {
+ auto model = convert_model("prelu_compact_channel_constant.onnx");
+ ov::pass::ConstantFolding().run_on_model(model);
+ const auto prelu = ov::as_type_ptr<op::v0::PRelu>(model->get_results().at(0)->input_value(0).get_node_shared_ptr());
+ ASSERT_NE(prelu, nullptr);
+ const auto constant = ov::as_type_ptr<op::v0::Constant>(prelu->get_input_node_shared_ptr(1));
+ ASSERT_NE(constant, nullptr);
+ EXPECT_EQ(constant->get_shape(), (Shape{64, 1, 1}));
+ EXPECT_EQ(constant->get_byte_size(), 64 * sizeof(float));
+
+ // The large activation shape above must not produce a large folded slope. Infer a smaller equivalent case.
+ model->reshape({{"X", PartialShape{1, 64, 2, 2}}});
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(std::vector<float>(256, -2.f));
+ test_case.add_expected_output<float>(std::vector<float>(256, -1.f));
+ test_case.run();
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_compact_channel_runtime_slope) {
+ ov::frontend::FrontEnd::Ptr frontend;
+ auto input_model = load_model("prelu_1d_last_dim_bcast.onnx", &frontend);
+ input_model->set_partial_shape(input_model->get_place_by_tensor_name("X"), PartialShape{1, 3, 2, 3});
+ input_model->set_partial_shape(input_model->get_place_by_tensor_name("SLOPE"), PartialShape{3, 1, 1});
+ auto model = frontend->convert(input_model);
+ const auto prelu = ov::as_type_ptr<op::v0::PRelu>(model->get_results().at(0)->input_value(0).get_node_shared_ptr());
+ ASSERT_NE(prelu, nullptr);
+ EXPECT_EQ(prelu->get_input_shape(1), (Shape{3, 1, 1}));
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(std::vector<float>(18, -2.f));
+ test_case.add_input<float>(std::vector<float>(3, 0.5f));
+ test_case.add_expected_output<float>(std::vector<float>(18, -1.f));
+ test_case.run();
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_1d_singleton_constant) {
+ // Also instantiated for IE_GPU: its rank-1 lowering requires a single-element Constant slope.
+ auto model = convert_model("prelu_1d_singleton_constant.onnx");
+ ov::pass::ConstantFolding().run_on_model(model);
+ const auto prelu = ov::as_type_ptr<op::v0::PRelu>(model->get_results().at(0)->input_value(0).get_node_shared_ptr());
+ ASSERT_NE(prelu, nullptr);
+ const auto constant = ov::as_type_ptr<op::v0::Constant>(prelu->get_input_node_shared_ptr(1));
+ ASSERT_NE(constant, nullptr);
+ EXPECT_EQ(constant->get_shape(), (Shape{1}));
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_input<float>(std::vector<float>(24, -2.f));
+ test_case.add_expected_output<float>(std::vector<float>(24, -1.f));
+ test_case.run();
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_reject_incompatible_runtime_dimension) {
+ ov::frontend::FrontEnd::Ptr frontend;
+ auto input_model = load_model("prelu_1d_last_dim_bcast.onnx", &frontend);
+ input_model->set_partial_shape(input_model->get_place_by_tensor_name("X"), PartialShape{1, 3, 2, -1});
+ auto model = frontend->convert(input_model);
+ const Tensor data(element::f32, Shape{1, 3, 2, 1});
+ const Tensor slope(element::f32, Shape{3});
+ TensorVector outputs{Tensor(element::f32, data.get_shape())};
+ OV_EXPECT_THROW_HAS_SUBSTRING(model->evaluate(outputs, TensorVector{data, slope}),
+ ov::Exception,
+ "cannot be broadcasted");
+}
+
+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_1d_channel_bcast_opset6) {
+ // Regression test for the legacy PRelu-1/6 broadcasting: a rank-1 slope whose length matches the channel
+ // dimension is shared across channels (aligned with axis 1), which is the behavior of OpenVINO's v0::PRelu.
+ // Unidirectional (numpy-style) broadcasting was only introduced in PRelu-7, so opset <= 6 models must keep the
+ // per-channel semantics (mirrors the ONNX pytorch-converted test_PReLU_*d_multiparam models).
+ auto model = convert_model("prelu_1d_channel_bcast_opset6.onnx");
+
+ Inputs inputs;
+ // Shape{2, 3, 4}
+ inputs.emplace_back(std::vector<float>{-1., -2., -3., -4., 1., 2., 3., 4., -5., -6., -7., -8.,
+ -1., -1., -1., -1., -2., -2., -2., -2., -3., -3., -3., -3.});
+
+ // Shape{3} - slope broadcast over the channel dimension (axis 1)
+ inputs.emplace_back(std::vector<float>{0.5, 1.0, 2.0});
+
+ // Shape{2, 3, 4}
+ auto expected_output = std::vector<float>{-0.5, -1.0, -1.5, -2.0, 1.0, 2.0, 3.0, 4.0, -10., -12., -14., -16.,
+ -0.5, -0.5, -0.5, -0.5, -2.0, -2.0, -2.0, -2.0, -6.0, -6.0, -6.0, -6.0};
+
+ auto test_case = ov::test::TestCase(model, s_device);
+ test_case.add_multiple_inputs(inputs);
+ test_case.add_expected_output(expected_output);
+ test_case.run();
+}
+
OPENVINO_TEST(${BACKEND_NAME}, onnx_model_prelu_C_1_1) {
auto model = convert_model("prelu_c_1_1.onnx");