Skip to content

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

Fix operator tests (#34476)

Surya Siddharth Pemmaraju5884aeb14169
diff --git a/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py b/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py
index bb59e003d23..ea73ee13862 100644
--- a/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py
+++ b/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py
@@ -367,6 +367,11 @@ class TorchFXPythonDecoder (BaseFXDecoder):
strides = list(meta["tensor_meta"].stride)
if strides:
return strides
+ # Fallback for Edge dialect nodes where tensor_meta is absent but val is present
+ if "val" in meta and hasattr(meta["val"], "stride"):
+ strides = list(meta["val"].stride())
+ if strides:
+ return strides
return []
def get_input_type(self, index):
diff --git a/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/backend.py b/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/backend.py
index 827f69a1c96..fba2f3c5055 100644
--- a/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/backend.py
+++ b/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/backend.py
@@ -102,13 +102,13 @@ def fx_openvino(subgraph, example_inputs, options=None):
example_inputs = [example_inputs[ind] for ind in preserved_arg_indices]
model = subgraph
else:
- from torch._subclasses.fake_tensor import FakeTensorMode
-
decompositions = _get_decompositions(options) + get_inf_decomposition_list()
- with FakeTensorMode(allow_non_fake_inputs=True) as fakemode:
- fake_inputs = [fakemode.from_tensor(x) for x in example_inputs]
- model = make_fx(subgraph, decomposition_table=get_decompositions(decompositions))(*fake_inputs)
-
+ model = make_fx(
+ subgraph,
+ decomposition_table=get_decompositions(decompositions),
+ tracing_mode="fake",
+ _allow_non_fake_inputs=True,
+ )(*example_inputs)
with torch.no_grad():
model.eval()
partitioner = Partitioner(options)
diff --git a/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/op_support.py b/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/op_support.py
index 2aa73f415ae..0397cf00a43 100644
--- a/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/op_support.py
+++ b/src/bindings/python/src/openvino/frontend/pytorch/torchdynamo/op_support.py
@@ -208,8 +208,13 @@ class OperatorSupport(OpSupport):
"torch.ops.aten.reciprocal.default": None,
"torch.ops.aten.relu.default": None,
"torch.ops.aten.relu_.default": None,
+ "torch.ops.aten.remainder.default": None,
+ "torch.ops.aten.remainder.Scalar": None,
+ "torch.ops.aten.remainder.Tensor": None,
"torch.ops.aten.repeat.default": None,
"torch.ops.aten.roll.default": None,
+ "torch.ops.aten.round.default": None,
+ "torch.ops.aten.round.out": None,
"torch.ops.aten.rsqrt.default": None,
"torch.ops.aten.rsub.Scalar": None,
"torch.ops.aten.rsub.Tensor": None,
@@ -257,6 +262,11 @@ class OperatorSupport(OpSupport):
"torch.ops.aten.unsqueeze_copy.default": None,
"torch.ops.aten.upsample_nearest2d.default": None,
"torch.ops.aten.upsample_nearest2d.vec": None,
+ "torch.ops.aten.upsample_bicubic2d.default": None,
+ "torch.ops.aten.upsample_bicubic2d.vec": None,
+ "torch.ops.aten.upsample_bilinear2d": None,
+ "torch.ops.aten.upsample_bilinear2d.default": None,
+ "torch.ops.aten.upsample_bilinear2d.vec": None,
"torch.ops.aten.upsample_nearest3d.vec": None,
"torch.ops.aten.var.correction": None,
"torch.ops.aten.var_mean.correction": None,
@@ -272,7 +282,7 @@ class OperatorSupport(OpSupport):
"torch.ops.quantized_decomposed.quantize_per_tensor.default": None,
"torch.ops.quantized_decomposed.quantize_per_channel.default": None,
"torch.ops.quantized_decomposed.dequantize_per_tensor.default": None,
- "torch.ops.quantized_decomposed.dequantize_per_channel.default": None
+ "torch.ops.quantized_decomposed.dequantize_per_channel.default": None,
}
self.enabled_op_names = []
diff --git a/src/frontends/pytorch/src/op/min_max.cpp b/src/frontends/pytorch/src/op/min_max.cpp
index 5a0d1868be1..6ff474bc64d 100644
--- a/src/frontends/pytorch/src/op/min_max.cpp
+++ b/src/frontends/pytorch/src/op/min_max.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "openvino/core/validation_util.hpp"
#include "openvino/frontend/pytorch/node_context.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
@@ -21,6 +22,17 @@ namespace op {
using namespace ov::op;
+// Returns true when the output is an empty list
+static bool is_empty_axes(const Output<Node>& dims_input) {
+ if (is_empty_list(dims_input)) {
+ return true;
+ }
+ if (const auto constant_src = ov::util::get_constant_from_source(dims_input)) {
+ return constant_src->get_shape() == Shape{0};
+ }
+ return false;
+}
+
OutputVector translate_max(const NodeContext& context) {
// torch.max (same for torch.min) actually has two interfaces smashed together:
// torch.max(x, dim, keepdim) and torch.max(x, y)
@@ -175,14 +187,16 @@ OutputVector translate_amin(const NodeContext& context) {
// aten::amin(Tensor self, int[1] dim=[], bool keepdim=False) -> Tensor
// aten::amin.out(Tensor self, int[1] dim=[], bool keepdim=False, *, Tensor(a!) out) -> Tensor(a!)
- num_inputs_check(context, 2, 4);
+ num_inputs_check(context, 1, 4);
auto x = context.get_input(0);
- auto dims = context.get_input(1);
+ // From torch 2.8, amin dim input is optional; an empty list also means reduce all dims
+ auto dim_input = !context.input_is_none(1) ? context.get_input(1) : Output<Node>{};
+ auto dim = (dim_input.get_node() == nullptr || is_empty_axes(dim_input)) ? get_axes_range(context, 0) : dim_input;
bool keep_dims = false;
if (!context.input_is_none(2)) {
keep_dims = context.const_input<bool>(2);
}
- auto res = context.mark_node(std::make_shared<v1::ReduceMin>(x, dims, keep_dims));
+ auto res = context.mark_node(std::make_shared<v1::ReduceMin>(x, dim, keep_dims));
if (!context.input_is_none(3)) {
context.mutate_input(3, res);
}
@@ -193,14 +207,16 @@ OutputVector translate_amax(const NodeContext& context) {
// aten::amax(Tensor self, int[1] dim=[], bool keepdim=False) -> Tensor
// aten::amax.out(Tensor self, int[1] dim=[], bool keepdim=False, *, Tensor(a!) out) -> Tensor(a!)
- num_inputs_check(context, 2, 4);
+ num_inputs_check(context, 1, 4);
auto x = context.get_input(0);
- auto dims = context.get_input(1);
+ // From torch 2.8, amax dim input is optional; an empty list also means reduce all dims
+ auto dim_input = !context.input_is_none(1) ? context.get_input(1) : Output<Node>{};
+ auto dim = (dim_input.get_node() == nullptr || is_empty_axes(dim_input)) ? get_axes_range(context, 0) : dim_input;
bool keep_dims = false;
if (!context.input_is_none(2)) {
keep_dims = context.const_input<bool>(2);
}
- auto res = context.mark_node(std::make_shared<v1::ReduceMax>(x, dims, keep_dims));
+ auto res = context.mark_node(std::make_shared<v1::ReduceMax>(x, dim, keep_dims));
if (!context.input_is_none(3)) {
context.mutate_input(3, res);
}
@@ -213,8 +229,9 @@ OutputVector translate_aminmax(const NodeContext& context) {
auto input = context.get_input(0);
- // check if dim is provided, if not, get the range of axes to compute min and max
- auto dim = !context.input_is_none(1) ? context.get_input(1) : get_axes_range(context, 0);
+ // From torch 2.8, amax dim input is optional; an empty list also means reduce all dims
+ auto dim_input = !context.input_is_none(1) ? context.get_input(1) : Output<Node>{};
+ auto dim = (dim_input.get_node() == nullptr || is_empty_axes(dim_input)) ? get_axes_range(context, 0) : dim_input;
// check if keepdim is provided, if not, set it to false like PyTorch
bool keep_dims = !context.input_is_none(2) ? context.const_input<bool>(2) : false;
diff --git a/src/frontends/pytorch/src/op/upsample.cpp b/src/frontends/pytorch/src/op/upsample.cpp
index 36f0a0aca1e..ce5ec400daa 100644
--- a/src/frontends/pytorch/src/op/upsample.cpp
+++ b/src/frontends/pytorch/src/op/upsample.cpp
@@ -21,7 +21,7 @@ OutputVector base_translate_upsample(const NodeContext& context,
v11::Interpolate::InterpolateMode interpolate_mode,
size_t dims,
bool antialias = false) {
- num_inputs_check(context, 1, 4);
+ num_inputs_check(context, 1, 5);
auto data = context.get_input(0);
std::vector<size_t> pad(dims, 0);
auto size_mode = v11::Interpolate::ShapeCalcMode::SIZES;
diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp
index fbdeec239ef..0f04d775ef9 100644
--- a/src/frontends/pytorch/src/op_table.cpp
+++ b/src/frontends/pytorch/src/op_table.cpp
@@ -1044,7 +1044,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_fx() {
{"aten.one_hot.default", op::translate_one_hot},
{"aten.outer.default", op::translate_outer},
{"aten.permute.default", op::translate_permute},
- {"aten.permute_copy.default", op::translate_1to1_match_2_inputs<opset10::Transpose>},
+ {"aten.permute_copy.default", op::translate_permute},
{"aten.pow.Scalar", op::translate_pow},
{"aten.pow.Tensor_Scalar", op::translate_pow},
{"aten.pow.Tensor_Tensor", op::translate_pow},
@@ -1059,6 +1059,7 @@ 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.remainder.default", op::translate_remainder},
{"aten.remainder.Scalar", op::translate_remainder},
{"aten.remainder.Tensor", op::translate_remainder},
{"aten.repeat.default", op::translate_repeat_fx},
@@ -1068,6 +1069,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_fx() {
{"aten.roll.default", op::translate_roll},
{"aten.rad2deg.default", op::translate_rad2deg},
{"aten.round.default", op::translate_round},
+ {"aten.round.out", op::translate_round},
{"aten.rsqrt.default", op::translate_rsqrt},
{"aten.rsub.Scalar", op::translate_rsub_fx},
{"aten.rsub.Tensor", op::translate_rsub_fx},
@@ -1120,8 +1122,11 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_fx() {
{"aten.unfold.default", op::translate_unfold},
{"aten.unsqueeze.default", common_translators::translate_unsqueeze},
{"aten.unsqueeze_copy.default", op::translate_1to1_match_2_inputs<opset10::Unsqueeze>},
+ {"aten.upsample_bicubic2d.default", op::translate_upsample_bicubic2d},
{"aten.upsample_bicubic2d.vec", op::translate_upsample_bicubic2d},
+ {"aten.upsample_bilinear2d", op::translate_upsample_bilinear2d},
{"aten.upsample_bilinear2d.vec", op::translate_upsample_bilinear2d},
+ {"aten.upsample_bilinear2d.default", op::translate_upsample_bilinear2d},
{"aten.upsample_linear1d.vec", op::translate_upsample_linear1d},
{"aten.upsample_nearest1d.default", op::translate_upsample_nearest1d},
{"aten.upsample_nearest1d.vec", op::translate_upsample_nearest1d},
diff --git a/src/frontends/pytorch/src/transforms/aten_index_put_replacer.cpp b/src/frontends/pytorch/src/transforms/aten_index_put_replacer.cpp
index 86eb5ffc967..be2b5ee286b 100644
--- a/src/frontends/pytorch/src/transforms/aten_index_put_replacer.cpp
+++ b/src/frontends/pytorch/src/transforms/aten_index_put_replacer.cpp
@@ -36,16 +36,6 @@ namespace pass {
using namespace ov::op;
-namespace {
-Output<Node> generate_zeros_with_convertlike(ov::pass::NodeRegistry& rg,
- const Output<Node> sizes,
- const Output<Node> tensor_of_type) {
- auto const_0 = v0::Constant::create(element::i32, Shape{}, {0});
- auto zeros = rg.make<v3::Broadcast>(const_0, sizes);
- return rg.make<v1::ConvertLike>(zeros, tensor_of_type);
-}
-} // namespace
-
AtenIndexPutReplacer::AtenIndexPutReplacer() {
auto index_op = ov::pass::pattern::wrap_type<ov::op::util::FrameworkNode>(
fw_node_predicate({"aten::index_put_", "aten.index_put.default"}));
@@ -254,9 +244,7 @@ AtenIndexPutReplacer::AtenIndexPutReplacer() {
std::shared_ptr<ov::Node> result;
if (accumulate) {
- auto zeros = generate_zeros_with_convertlike(rg, input_shape, input);
- auto scatter = rg.make<v3::ScatterNDUpdate>(zeros, index, values);
- result = rg.make<v1::Add>(input, scatter);
+ result = rg.make<v15::ScatterNDUpdate>(input, index, values, v15::ScatterNDUpdate::Reduction::SUM);
} else {
result = rg.make<v3::ScatterNDUpdate>(input, index, values);
}
diff --git a/tests/layer_tests/pytorch_tests/test_min_max.py b/tests/layer_tests/pytorch_tests/test_min_max.py
index 805975ab453..a6a475efe68 100644
--- a/tests/layer_tests/pytorch_tests/test_min_max.py
+++ b/tests/layer_tests/pytorch_tests/test_min_max.py
@@ -322,9 +322,13 @@ class TestAminAmax(PytorchLayerTest):
self.forward = self.forward_out
def forward_out(self, x, y):
+ if self.axis is None:
+ return self.op(x, out=y), y
return self.op(x, self.axis, self.keep_dims, out=y), y
def forward(self, x):
+ if self.axis is None:
+ return self.op(x)
return self.op(x, self.axis, self.keep_dims)
@@ -333,7 +337,7 @@ class TestAminAmax(PytorchLayerTest):
return model_cls, f"aten::{op_type}"
@pytest.mark.parametrize("op_type", ["amin", "amax"])
- @pytest.mark.parametrize("axis", [0, -1, 1, [1, 2], [-1, -2], [2, 0, -1], [0, 1, 2, 3]])
+ @pytest.mark.parametrize("axis", [None, 0, -1, 1, [1, 2], [-1, -2], [2, 0, -1], [0, 1, 2, 3]])
@pytest.mark.parametrize("keep_dims", [True, False])
@pytest.mark.parametrize("out", [skip_if_export(True), False])
@pytest.mark.parametrize("input_dtype", ['float32', 'int32', 'int64', 'float64'])
diff --git a/tests/layer_tests/pytorch_tests/test_remainder.py b/tests/layer_tests/pytorch_tests/test_remainder.py
index 5d636578510..c592b0ab918 100644
--- a/tests/layer_tests/pytorch_tests/test_remainder.py
+++ b/tests/layer_tests/pytorch_tests/test_remainder.py
@@ -28,6 +28,7 @@ class TestRemainder(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
+ @pytest.mark.precommit_fx_backend
def test_remainder(self, ie_device, precision, ir_version, input_shape_rhs):
self.input_rhs = self.random.randn(*input_shape_rhs)
self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True)
diff --git a/tests/layer_tests/pytorch_tests/test_round.py b/tests/layer_tests/pytorch_tests/test_round.py
index f8f1dc10b03..27fef455775 100644
--- a/tests/layer_tests/pytorch_tests/test_round.py
+++ b/tests/layer_tests/pytorch_tests/test_round.py
@@ -40,6 +40,7 @@ class TestRound(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
+ @pytest.mark.precommit_fx_backend
@pytest.mark.parametrize("out", [skip_if_export(True), False])
@pytest.mark.parametrize("dtype", ["float32", "float64", "int32", "int64"])
def test_round(self, out, dtype, ie_device, precision, ir_version):
@@ -88,4 +89,4 @@ class TestRoundScalar(PytorchLayerTest):
self._prepare_input = self._prepare_input_int
else:
self._prepare_input = self._prepare_input_float
- self._test(*self.create_model(input_type), ie_device, precision, ir_version, trace_model=True)
+ self._test(*self.create_model(input_type), ie_device, precision, ir_version, trace_model=True)
\ No newline at end of file
diff --git a/tests/layer_tests/pytorch_tests/test_upsample.py b/tests/layer_tests/pytorch_tests/test_upsample.py
index 56dbf99e2cc..0fae7acebf9 100644
--- a/tests/layer_tests/pytorch_tests/test_upsample.py
+++ b/tests/layer_tests/pytorch_tests/test_upsample.py
@@ -94,6 +94,7 @@ class TestUpsample2D(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
+ @pytest.mark.precommit_fx_backend
def test_upsample2d(self, mode, size, scale, ie_device, precision, ir_version):
self._test(*self.create_model(size, scale, mode), ie_device,
precision, ir_version, trace_model=True, **{"custom_eps": 1e-3})
@@ -179,7 +180,6 @@ class TestUpsample3D(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
- @pytest.mark.precommit_fx_backend
def test_upsample3d(self, mode, size, scale, ie_device, precision, ir_version):
self._test(*self.create_model(size, scale, mode), ie_device,
precision, ir_version, trace_model=True, **{"custom_eps": 1e-3})
@@ -208,6 +208,7 @@ class TestUpsample2DListSizes(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
+ @pytest.mark.precommit_fx_backend
def test_upsample2d_list_sizes(self, mode, ie_device, precision, ir_version):
self._test(*self.create_model(mode), ie_device,
precision, ir_version, trace_model=True)