Skip to content

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

[PT FE] Add support for aten::rrelu operation (#35717)

Tanisha Vermabbb6398c2396
diff --git a/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/export_decompositions.py b/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/export_decompositions.py
index b0623edf88d..a1a353342bb 100644
--- a/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/export_decompositions.py
+++ b/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/export_decompositions.py
@@ -207,6 +207,7 @@ def ops_to_not_decompose() -> list:
torch.ops.aten.leaky_relu_.default,
torch.ops.aten.log_sigmoid_forward.default,
torch.ops.aten.mish.default,
+ torch.ops.aten.rrelu.default,
torch.ops.aten.silu.default,
torch.ops.aten.silu_.default,
# Normalization
diff --git a/src/frontends/pytorch/src/op/rrelu.cpp b/src/frontends/pytorch/src/op/rrelu.cpp
new file mode 100644
index 00000000000..06103ca4afb
--- /dev/null
+++ b/src/frontends/pytorch/src/op/rrelu.cpp
@@ -0,0 +1,43 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/frontend/pytorch/node_context.hpp"
+#include "openvino/op/prelu.hpp"
+#include "utils.hpp"
+
+namespace ov {
+namespace frontend {
+namespace pytorch {
+namespace op {
+
+using namespace ov::op;
+
+OutputVector translate_rrelu(const NodeContext& context) {
+ // aten::rrelu(Tensor self, Scalar lower=0.125, Scalar upper=0.3333, bool training=False,
+ // Generator? generator=None) -> Tensor
+ // In inference mode the negative slope is a fixed value: (lower + upper) / 2.
+ num_inputs_check(context, 1, 5);
+ auto x = context.get_input(0);
+
+ float lower = 1.0f / 8;
+ float upper = 1.0f / 3;
+
+ if (context.get_input_size() > 1 && !context.input_is_none(1)) {
+ lower = context.const_input<float>(1);
+ }
+ if (context.get_input_size() > 2 && !context.input_is_none(2)) {
+ upper = context.const_input<float>(2);
+ }
+
+ const float slope = (lower + upper) / 2.0f;
+ Output<Node> negative_slope = ov::op::v0::Constant::create(element::f32, Shape{1}, {slope});
+ negative_slope = context.mark_node(std::make_shared<v1::ConvertLike>(negative_slope, x));
+
+ return {context.mark_node(std::make_shared<v0::PRelu>(x, negative_slope))};
+}
+
+} // namespace op
+} // namespace pytorch
+} // namespace frontend
+} // namespace ov
diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp
index 008d7d0d1f7..648ac575e5d 100644
--- a/src/frontends/pytorch/src/op_table.cpp
+++ b/src/frontends/pytorch/src/op_table.cpp
@@ -229,6 +229,7 @@ OP_CONVERTER(translate_randn_like);
OP_CONVERTER(translate_reciprocal);
OP_CONVERTER(translate_reflection_pad_nd);
OP_CONVERTER(translate_relu6);
+OP_CONVERTER(translate_rrelu);
OP_CONVERTER(translate_remainder);
OP_CONVERTER(translate_repeat_interleave);
OP_CONVERTER(translate_replication_pad_nd);
@@ -699,6 +700,8 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() {
{"aten::relu", op::optional_out<op::translate_1to1_match_1_inputs<opset10::Relu>, 1>},
{"aten::relu_", op::inplace_op<op::translate_1to1_match_1_inputs<opset10::Relu>>},
{"aten::relu6", op::translate_relu6},
+ {"aten::rrelu", op::translate_rrelu},
+ {"aten::rrelu_", op::inplace_op<op::translate_rrelu>},
{"aten::remainder", op::translate_remainder},
{"aten::repeat", op::translate_1to1_match_2_inputs<opset10::Tile>},
{"aten::repeat_interleave", op::translate_repeat_interleave},
@@ -1084,6 +1087,8 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_fx() {
{"aten.reflection_pad3d.default", op::translate_reflection_pad_nd},
{"aten.relu.default", op::translate_1to1_match_1_inputs<opset10::Relu>},
{"aten.relu_.default", op::inplace_op<op::translate_1to1_match_1_inputs<opset10::Relu>>},
+ {"aten.rrelu.default", op::translate_rrelu},
+ {"aten.rrelu_.default", op::inplace_op<op::translate_rrelu>},
{"aten.remainder.default", op::translate_remainder},
{"aten.remainder.Scalar", op::translate_remainder},
{"aten.remainder.Tensor", op::translate_remainder},
diff --git a/tests/layer_tests/pytorch_tests/test_rrelu.py b/tests/layer_tests/pytorch_tests/test_rrelu.py
new file mode 100644
index 00000000000..d52c1d52fca
--- /dev/null
+++ b/tests/layer_tests/pytorch_tests/test_rrelu.py
@@ -0,0 +1,49 @@
+# Copyright (C) 2018-2026 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+import pytest
+import torch
+import torch.nn.functional as F
+
+from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
+
+
+class aten_rrelu(torch.nn.Module):
+ def __init__(self, lower, upper, dtype, inplace):
+ super().__init__()
+ self.lower = lower
+ self.upper = upper
+ self.dtype = dtype
+ self.inplace = inplace
+
+ def forward(self, x):
+ x = x.to(self.dtype)
+ return F.rrelu(x, lower=self.lower, upper=self.upper, training=False, inplace=self.inplace), x
+
+
+class TestRRelu(PytorchLayerTest):
+ def _prepare_input(self):
+ return (self.random.randn(2, 3, 4),)
+
+ @pytest.mark.nightly
+ @pytest.mark.precommit
+ @pytest.mark.precommit_torch_export
+ @pytest.mark.parametrize("lower,upper", [
+ (1 / 8, 1 / 3), # PyTorch defaults
+ (0.1, 0.5),
+ (0.0, 1.0),
+ ])
+ @pytest.mark.parametrize("dtype", [torch.float16, torch.float32, torch.float64])
+ @pytest.mark.parametrize("inplace", [skip_if_export(True), False])
+ def test_rrelu(self, lower, upper, dtype, inplace, ie_device, precision, ir_version):
+ kwargs = {}
+ if dtype == torch.float16:
+ kwargs["custom_eps"] = 1e-2
+ self._test(
+ aten_rrelu(lower, upper, dtype, inplace),
+ "aten::rrelu_" if inplace else "aten::rrelu",
+ ie_device,
+ precision,
+ ir_version,
+ **kwargs,
+ )