Skip to content

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

[PT FE] Improve torch.export tests (#33980)

Maxim Vafin03c304d30c0c
diff --git a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py
index 86f9b4050de..dee83ab47c8 100644
--- a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py
+++ b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py
@@ -54,6 +54,57 @@ class PytorchLayerTest:
return True
return False
+ @staticmethod
+ def _check_fx_op_exist(exported_program, op_name):
+ """Check if an operation exists in the FX graph of an ExportedProgram.
+
+ Args:
+ exported_program: torch.export.ExportedProgram
+ op_name: str - operation name like "aten.add.Tensor" or just "aten.add"
+
+ Returns:
+ bool - True if operation exists in the graph
+ """
+ for node in exported_program.graph.nodes:
+ if node.op == "call_function":
+ target_str = str(node.target)
+ # Support both full name (aten.add.Tensor) and partial match (aten.add)
+ if target_str == op_name or target_str.startswith(op_name + "."):
+ return True
+ return False
+
+ @staticmethod
+ def _derive_fx_kind_from_kind(kind):
+ """Derive FX graph operation name from TorchScript kind.
+
+ Converts TorchScript operation names like "aten::add" to FX names like "aten.add".
+
+ Args:
+ kind: str or tuple of str - TorchScript operation name(s)
+
+ Returns:
+ list of str - FX operation names, or None if conversion not possible
+ """
+ if kind is None:
+ return None
+
+ if isinstance(kind, str):
+ kinds = [kind]
+ else:
+ kinds = list(kind)
+
+ fx_kinds = []
+ for k in kinds:
+ # Convert "aten::op_name" to "aten.op_name"
+ if "::" in k:
+ fx_kind = k.replace("::", ".")
+ fx_kinds.append(fx_kind)
+ else:
+ # Cannot auto-derive, return None to require explicit fx_kind
+ return None
+
+ return fx_kinds if fx_kinds else None
+
@staticmethod
def use_torch_compile_backend():
torch_compile_env = os.getenv("PYTORCH_TRACING_MODE")
@@ -127,6 +178,18 @@ class PytorchLayerTest:
em = export(model, tuple(torch_inputs), dynamic_shapes=dynamic_shapes)
+ # Verify FX graph operations exist
+ # Use explicit fx_kind if provided, otherwise auto-derive from TorchScript kind
+ fx_kind = kwargs.get('fx_kind', None)
+ if fx_kind is None:
+ fx_kind = self._derive_fx_kind_from_kind(kind)
+
+ assert fx_kind is not None, f"fx_kind must be provided explicitly or derivable from kind. Graph:\n{em.graph}"
+ if not isinstance(fx_kind, (tuple, list)):
+ fx_kind = [fx_kind]
+ for op in fx_kind:
+ assert self._check_fx_op_exist(em, op), f"Operation {op} doesn't exist in FX graph. Graph:\n{em.graph}"
+
converted_model = convert_model(
em, example_input=torch_inputs, verbose=True)
self._resolve_input_shape_dtype(
diff --git a/tests/layer_tests/pytorch_tests/test_add.py b/tests/layer_tests/pytorch_tests/test_add.py
index dd9212cdbfc..fa4e1c5945d 100644
--- a/tests/layer_tests/pytorch_tests/test_add.py
+++ b/tests/layer_tests/pytorch_tests/test_add.py
@@ -44,7 +44,8 @@ class TestAdd(PytorchLayerTest):
@pytest.mark.parametrize("op_type", ["add", skip_check("add_")])
def test_add(self, ie_device, precision, ir_version, alpha, input_shape_rhs, op_type):
self.input_rhs = np.random.randn(*input_shape_rhs).astype(np.float32)
- self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version, use_convert_model=True)
+ self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version, use_convert_model=True,
+ fx_kind="aten.add")
class TestAddTypes(PytorchLayerTest):
@@ -135,7 +136,6 @@ class TestAddLists(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
- @pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_add(self, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_aliases.py b/tests/layer_tests/pytorch_tests/test_aliases.py
index 548a4bde9d6..85acf46dc1a 100644
--- a/tests/layer_tests/pytorch_tests/test_aliases.py
+++ b/tests/layer_tests/pytorch_tests/test_aliases.py
@@ -17,8 +17,8 @@ class aten_alias(torch.nn.Module):
class aten_alias_tensor(torch.nn.Module):
def forward(self, x):
y = x.clone()
- n,c,h,w = x.shape
- ones = torch.ones([2,h,w]).to(x.dtype)
+ n, c, h, w = x.shape
+ ones = torch.ones([2, h, w]).to(x.dtype)
y[:, 1:, :, :] = ones
return y
@@ -43,7 +43,8 @@ class TestAliases(PytorchLayerTest):
self._test(aten_alias(), None, ["aten::slice",
"aten::select",
"aten::copy_"],
- ie_device, precision, ir_version)
+ ie_device, precision, ir_version,
+ fx_kind=["aten.clone.default", "aten.select.int", "aten.fill_.Tensor"])
@pytest.mark.nightly
@pytest.mark.precommit
@@ -51,7 +52,8 @@ class TestAliases(PytorchLayerTest):
def test_alias_tensor(self, ie_device, precision, ir_version):
self._test(aten_alias_tensor(), None, ["aten::slice",
"aten::copy_"],
- ie_device, precision, ir_version, freeze_model=False)
+ ie_device, precision, ir_version, freeze_model=False,
+ fx_kind=["aten.slice.Tensor", "aten.copy_.default"])
@pytest.mark.nightly
@pytest.mark.precommit
@@ -61,4 +63,5 @@ class TestAliases(PytorchLayerTest):
"aten::select",
"aten::copy_",
"prim::Loop"],
- ie_device, precision, ir_version, freeze_model=False)
+ ie_device, precision, ir_version, freeze_model=False,
+ fx_kind=["aten.clone.default", "aten.select.int", "aten.fill_.Tensor"])
diff --git a/tests/layer_tests/pytorch_tests/test_as_strided.py b/tests/layer_tests/pytorch_tests/test_as_strided.py
index 9854e7f045f..f27beb7a95a 100644
--- a/tests/layer_tests/pytorch_tests/test_as_strided.py
+++ b/tests/layer_tests/pytorch_tests/test_as_strided.py
@@ -136,7 +136,8 @@ class TestAsStridedListConstruct(PytorchLayerTest):
precision,
ir_version,
kwargs_to_prepare_input=inp_kwargs,
- trace_model=True
+ trace_model=True,
+ fx_kind="aten.as_strided.default",
)
diff --git a/tests/layer_tests/pytorch_tests/test_atan2.py b/tests/layer_tests/pytorch_tests/test_atan2.py
index aa075c28166..9c67ab459b8 100644
--- a/tests/layer_tests/pytorch_tests/test_atan2.py
+++ b/tests/layer_tests/pytorch_tests/test_atan2.py
@@ -35,7 +35,7 @@ class TestAtan2(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_atan2(self, ie_device, precision, ir_version, input_shape_rhs):
self.input_rhs = np.random.randn(*input_shape_rhs).astype(np.float32)
- self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True)
+ self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True, fx_kind="aten.arctan2")
class TestAtan2Types(PytorchLayerTest):
@@ -77,4 +77,4 @@ class TestAtan2Types(PytorchLayerTest):
self.rhs_type = rhs_type
self.rhs_shape = rhs_shape
self._test(*self.create_model(lhs_type, rhs_type),
- ie_device, precision, ir_version, freeze_model=False, trace_model=True)
\ No newline at end of file
+ ie_device, precision, ir_version, freeze_model=False, trace_model=True, fx_kind="aten.arctan2")
\ No newline at end of file
diff --git a/tests/layer_tests/pytorch_tests/test_bitwise_ops.py b/tests/layer_tests/pytorch_tests/test_bitwise_ops.py
index e3049a295d3..eb11ae0be29 100644
--- a/tests/layer_tests/pytorch_tests/test_bitwise_ops.py
+++ b/tests/layer_tests/pytorch_tests/test_bitwise_ops.py
@@ -90,6 +90,7 @@ class TestBitwiseOp(PytorchLayerTest):
},
freeze_model=False,
trace_model=True,
+ fx_kind=f"aten.bitwise_{op_type}",
)
@@ -139,6 +140,7 @@ class TestBitwiseOperators(PytorchLayerTest):
},
trace_model=True,
freeze_model=False,
+ fx_kind=["aten.__and__", "aten.bitwise_not", "aten.__or__", "aten.__xor__"],
)
@@ -187,6 +189,8 @@ class TestBitwiseInplaceOp(PytorchLayerTest):
def test_bitwise_operators(self, op, dtype, lhs_shape, rhs_shape, ie_device, precision, ir_version):
if ie_device == "GPU" and dtype != "bool":
pytest.xfail(reason="bitwise ops are not supported on GPU")
+ # Map op names to fx_kind: __ior__ -> aten.__ior__, __iand__ -> aten.__iand__, __ixor__ -> aten.__ixor__
+ op_to_fx = {"aten::__ior__": "aten.__ior__", "aten::__iand__": "aten.__iand__", "aten::__ixor__": "aten.__ixor__"}
self._test(
*self.create_model(op),
ie_device,
@@ -199,4 +203,5 @@ class TestBitwiseInplaceOp(PytorchLayerTest):
},
trace_model=True,
freeze_model=False,
+ fx_kind=op_to_fx[op],
)
diff --git a/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py b/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py
index 5a118957b3d..c410b645339 100644
--- a/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py
+++ b/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py
@@ -18,29 +18,28 @@ class TestBroadcastTensors(PytorchLayerTest):
import torch
class aten_broadcast_tensors(torch.nn.Module):
- def __init__(self):
- super(aten_broadcast_tensors, self).__init__()
-
def forward(self, x, y, z):
x1, y1, z1 = torch.broadcast_tensors(x, y, z)
return x1, y1, z1
- ref_net = None
-
- return aten_broadcast_tensors(), ref_net, ("prim::ListConstruct", "aten::broadcast_tensors", "prim::ListUnpack")
+ return aten_broadcast_tensors(), None, ("prim::ListConstruct", "aten::broadcast_tensors", "prim::ListUnpack")
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
- @pytest.mark.parametrize("x_shape", [[1, ], [2, 1], [2, 2, 1]])
- @pytest.mark.parametrize("y_shape", [[2, ], [1, 2], [1, 2, 1]])
- @pytest.mark.parametrize("z_shape", [[1, 2], [2, 2], [1, 2, 1, 1]])
- @pytest.mark.parametrize("x_dtype", ["float32", "int32"])
- @pytest.mark.parametrize("y_dtype", ["float32", "int32"])
- @pytest.mark.parametrize("z_dtype", ["float32", "int32"])
+ @pytest.mark.parametrize(("x_shape", "y_shape", "z_shape"), [
+ ([1, ], [2, ], [1, 2]), # 1D broadcasting
+ ([2, 1], [1, 2], [2, 2]), # 2D broadcasting
+ ([2, 2, 1], [1, 2, 1], [1, 2, 1, 1]), # mixed dims broadcasting
+ ])
+ @pytest.mark.parametrize(("x_dtype", "y_dtype", "z_dtype"), [
+ ("float32", "float32", "float32"), # homogeneous float
+ ("int32", "float32", "int32"), # mixed types
+ ])
def test_broadcast_tensors(self, x_shape, y_shape, z_shape, x_dtype, y_dtype, z_dtype, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision, ir_version, kwargs_to_prepare_input={
"x_shape": x_shape, "x_dtype": x_dtype,
"y_shape": y_shape, "y_dtype": y_dtype,
"z_shape": z_shape, "z_dtype": z_dtype,
- })
+ },
+ fx_kind="aten.broadcast_tensors.default")
diff --git a/tests/layer_tests/pytorch_tests/test_clamp.py b/tests/layer_tests/pytorch_tests/test_clamp.py
index 3a8f3566724..b4241101c4a 100644
--- a/tests/layer_tests/pytorch_tests/test_clamp.py
+++ b/tests/layer_tests/pytorch_tests/test_clamp.py
@@ -51,7 +51,7 @@ class TestClamp(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_clamp(self, minimum, maximum, as_tensors, op_type, ie_device, precision, ir_version):
self._test(*self.create_model(minimum, maximum, as_tensors,
- op_type), ie_device, precision, ir_version)
+ op_type), ie_device, precision, ir_version, fx_kind="aten.clamp")
class TestClampMin(PytorchLayerTest):
@@ -124,4 +124,4 @@ class TestClampMax(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_clamp_max(self, maximum, as_tensor, inplace, ie_device, precision, ir_version):
self._test(*self.create_model(maximum, as_tensor, inplace), ie_device,
- precision, ir_version, use_convert_model=True, trace_model=True)
+ precision, ir_version, use_convert_model=True, trace_model=True, fx_kind="aten.clamp_max")
diff --git a/tests/layer_tests/pytorch_tests/test_cond.py b/tests/layer_tests/pytorch_tests/test_cond.py
index c67b0dc1bca..6827b551618 100644
--- a/tests/layer_tests/pytorch_tests/test_cond.py
+++ b/tests/layer_tests/pytorch_tests/test_cond.py
@@ -70,7 +70,7 @@ class TestCondFX(PytorchLayerTest):
self.pred_value = pred_value
self.input_shape = input_shape
self._test(*self.create_simple_cond_model(), ie_device, precision, ir_version,
- use_convert_model=True)
+ use_convert_model=True, fx_kind="cond")
@pytest.mark.parametrize("pred_value", [np.array(True), np.array(False)])
@pytest.mark.parametrize("input_shape", [(1, 4)])
@@ -82,7 +82,7 @@ class TestCondFX(PytorchLayerTest):
self.pred_value = pred_value
self.input_shape = input_shape
self._test(*self.create_multi_output_cond_model(), ie_device, precision, ir_version,
- use_convert_model=True)
+ use_convert_model=True, fx_kind="cond")
@pytest.mark.parametrize("pred_value", [np.array(True), np.array(False)])
@pytest.mark.parametrize("input_shape,hidden_size", [((1, 10, 64), 64)])
@@ -92,4 +92,4 @@ class TestCondFX(PytorchLayerTest):
self.pred_value = pred_value
self.input_shape = input_shape
self._test(*self.create_linear_cond_model(hidden_size), ie_device, precision, ir_version,
- use_convert_model=True)
+ use_convert_model=True, fx_kind="cond")
diff --git a/tests/layer_tests/pytorch_tests/test_convolution.py b/tests/layer_tests/pytorch_tests/test_convolution.py
index 57c873d0f61..39ca5a82f3c 100644
--- a/tests/layer_tests/pytorch_tests/test_convolution.py
+++ b/tests/layer_tests/pytorch_tests/test_convolution.py
@@ -212,9 +212,10 @@ class TestConvolution(PytorchLayerTest):
def test_convolution1d(self, params, bias, underscore, ie_device, precision, ir_version):
if ie_device == "GPU" and params["dilations"] != [1]:
pytest.xfail(reason="Unsupported dilations of Convolution on GPU")
+ fx_op = "aten._convolution" if underscore else "aten.convolution"
self._test(*self.create_model(**params, bias=bias, underscore=underscore),
ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1,
- kwargs_to_prepare_input={'ndim': 3})
+ kwargs_to_prepare_input={'ndim': 3}, fx_kind=fx_op)
@pytest.mark.parametrize("params", d2_params)
@pytest.mark.parametrize("bias", [True, False])
@@ -226,8 +227,10 @@ class TestConvolution(PytorchLayerTest):
def test_convolution2d(self, params, bias, underscore, ie_device, precision, ir_version):
if ie_device == "GPU" and params["dilations"] != [1, 1]:
pytest.xfail(reason="Unsupported dilations of Convolution on GPU")
+ fx_op = "aten._convolution" if underscore else "aten.convolution"
self._test(*self.create_model(**params, bias=bias, underscore=underscore),
- ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1)
+ ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1,
+ fx_kind=fx_op)
@pytest.mark.parametrize("params", d3_params)
@pytest.mark.parametrize("bias", [True, False])
diff --git a/tests/layer_tests/pytorch_tests/test_device.py b/tests/layer_tests/pytorch_tests/test_device.py
index 81aad8911bb..20c196dea04 100644
--- a/tests/layer_tests/pytorch_tests/test_device.py
+++ b/tests/layer_tests/pytorch_tests/test_device.py
@@ -50,7 +50,6 @@ class TestDevice(PytorchLayerTest):
@pytest.mark.parametrize("device_string", ["cpu", "cuda"])
@pytest.mark.nightly
@pytest.mark.precommit
- @pytest.mark.precommit_torch_export
def test_device(self, device_string, ie_device, precision, ir_version):
self._test(
*self.create_model_device(device_string),
@@ -64,7 +63,6 @@ class TestDevice(PytorchLayerTest):
@pytest.mark.parametrize("device_string", ["cpu", "cuda"])
@pytest.mark.nightly
@pytest.mark.precommit
- @pytest.mark.precommit_torch_export
def test_device_type(self, device_string, ie_device, precision, ir_version):
self._test(
*self.create_model_type(device_string),
diff --git a/tests/layer_tests/pytorch_tests/test_expand.py b/tests/layer_tests/pytorch_tests/test_expand.py
index 34dec03ee2f..9502b38c575 100644
--- a/tests/layer_tests/pytorch_tests/test_expand.py
+++ b/tests/layer_tests/pytorch_tests/test_expand.py
@@ -101,7 +101,8 @@ class TestExpandList(PytorchLayerTest):
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_expand(self, dims, op_type, ie_device, precision, ir_version):
- self._test(*self.create_model(op_type), ie_device, precision, ir_version, kwargs_to_prepare_input={"broadcast_shape": dims})
+ self._test(*self.create_model(op_type), ie_device, precision, ir_version,
+ kwargs_to_prepare_input={"broadcast_shape": dims}, fx_kind=f"aten.{op_type}")
class TestExpandAs(PytorchLayerTest):
diff --git a/tests/layer_tests/pytorch_tests/test_eye.py b/tests/layer_tests/pytorch_tests/test_eye.py
index 67a020fb69e..b65b58cde1b 100644
--- a/tests/layer_tests/pytorch_tests/test_eye.py
+++ b/tests/layer_tests/pytorch_tests/test_eye.py
@@ -59,7 +59,7 @@ class TestEye(PytorchLayerTest):
if ie_device == "GPU":
pytest.xfail(reason="eye is not supported on GPU")
self._test(*self.create_model(1, dtype), ie_device, precision,
- ir_version, kwargs_to_prepare_input={"m": m})
+ ir_version, kwargs_to_prepare_input={"m": m}, fx_kind="aten.eye.default")
@pytest.mark.nightly
@pytest.mark.precommit
@@ -72,4 +72,4 @@ class TestEye(PytorchLayerTest):
if ie_device == "GPU":
pytest.xfail(reason="eye is not supported on GPU")
self._test(*self.create_model(2, dtype), ie_device, precision,
- ir_version, kwargs_to_prepare_input={"m": m, "n": n})
+ ir_version, kwargs_to_prepare_input={"m": m, "n": n}, fx_kind="aten.eye.m")
diff --git a/tests/layer_tests/pytorch_tests/test_fake_quantize.py b/tests/layer_tests/pytorch_tests/test_fake_quantize.py
index ae4c264cc4d..8d9d9633606 100644
--- a/tests/layer_tests/pytorch_tests/test_fake_quantize.py
+++ b/tests/layer_tests/pytorch_tests/test_fake_quantize.py
@@ -60,7 +60,8 @@ class TestFakeQuantizePerTensorAffine(PytorchLayerTest):
ie_device,
precision,
ir_version,
- freeze_model=False
+ freeze_model=False,
+ fx_kind="aten.fake_quantize_per_tensor_affine"
)
@@ -115,7 +116,8 @@ class TestFakeQuantizePerTensorAffineCacheMaskTensorQParams(PytorchLayerTest):
ie_device,
precision,
ir_version,
- freeze_model=False
+ freeze_model=False,
+ fx_kind="aten._fake_quantize_per_tensor_affine_cachemask_tensor_qparams"
)
@@ -169,5 +171,6 @@ class TestFakeQuantizePerChannelAffine(PytorchLayerTest):
ie_device,
precision,
ir_version,
- freeze_model=False
+ freeze_model=False,
+ fx_kind="aten.fake_quantize_per_channel_affine"
)
diff --git a/tests/layer_tests/pytorch_tests/test_index_copy_.py b/tests/layer_tests/pytorch_tests/test_index_copy_.py
index e0bf382c1d3..835338ff51d 100644
--- a/tests/layer_tests/pytorch_tests/test_index_copy_.py
+++ b/tests/layer_tests/pytorch_tests/test_index_copy_.py
@@ -6,7 +6,7 @@ import numpy as np
import pytest
import torch
-from pytorch_layer_test_class import PytorchLayerTest
+from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestIndexCopy(PytorchLayerTest):
@@ -82,7 +82,7 @@ class TestIndexCopy(PytorchLayerTest):
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
- @pytest.mark.parametrize('inplace', [True, False])
+ @pytest.mark.parametrize('inplace', [skip_if_export(True), False])
def test_index_copy_single_index(self, inplace, ie_device, precision, ir_version, input_data):
self.input_tensor = np.random.randn(*input_data["input_shape"]).astype(np.float32)
self.values = np.random.randn(*input_data["values_shape"]).astype(np.float32)
diff --git a/tests/layer_tests/pytorch_tests/test_index_tensor.py b/tests/layer_tests/pytorch_tests/test_index_tensor.py
index db104fbcf6b..589b727dae8 100644
--- a/tests/layer_tests/pytorch_tests/test_index_tensor.py
+++ b/tests/layer_tests/pytorch_tests/test_index_tensor.py
@@ -16,7 +16,7 @@ class TestIndexTensor(PytorchLayerTest):
class aten_index_tensor(torch.nn.Module):
def __init__(self, indices_list):
- super(aten_index_tensor, self).__init__()
+ super().__init__()
self.indices_list = indices_list
def forward(self, x):
@@ -24,8 +24,6 @@ class TestIndexTensor(PytorchLayerTest):
return torch.ops.aten.index.Tensor(x, self.indices_list)
return torch.ops.aten._unsafe_index.Tensor(x, self.indices_list)
- ref_net = None
-
adjusted_indices_list = []
for indices in indices_list:
if indices is not None:
@@ -33,7 +31,7 @@ class TestIndexTensor(PytorchLayerTest):
continue
adjusted_indices_list.append(None)
- return aten_index_tensor(adjusted_indices_list), ref_net, None
+ return aten_index_tensor(adjusted_indices_list), None, None
@pytest.mark.nightly
@pytest.mark.precommit_torch_export
@@ -48,5 +46,6 @@ class TestIndexTensor(PytorchLayerTest):
def test_index_tensor(self, safe, input_shape, indices_list, ie_device, precision, ir_version):
if not PytorchLayerTest.use_torch_export():
pytest.skip(reason='aten.index.Tensor test is supported only on torch.export()')
+ kind = "aten.index.Tensor" if safe else "aten._unsafe_index.Tensor"
self._test(*self.create_model(indices_list, safe), ie_device, precision, ir_version,
- kwargs_to_prepare_input={'input_shape': input_shape})
+ kwargs_to_prepare_input={'input_shape': input_shape}, fx_kind=kind)
\ No newline at end of file
diff --git a/tests/layer_tests/pytorch_tests/test_lerp.py b/tests/layer_tests/pytorch_tests/test_lerp.py
index b1787f86196..782b93b82d8 100644
--- a/tests/layer_tests/pytorch_tests/test_lerp.py
+++ b/tests/layer_tests/pytorch_tests/test_lerp.py
@@ -51,10 +51,12 @@ class TestLerp(PytorchLayerTest):
self.input_rhs = np.random.randn(*input_shape_rhs).astype(np.float32)
if isinstance(weight, list):
weight = torch.rand(weight)
+ fx_op = "aten.lerp_" if op_type == "lerp_" else "aten.lerp"
self._test(
*self.create_model(weight, op_type),
ie_device,
precision,
ir_version,
use_convert_model=True,
+ fx_kind=fx_op,
)
diff --git a/tests/layer_tests/pytorch_tests/test_logsumexp.py b/tests/layer_tests/pytorch_tests/test_logsumexp.py
index 0bdf04801e9..4fc2ccf649a 100644
--- a/tests/layer_tests/pytorch_tests/test_logsumexp.py
+++ b/tests/layer_tests/pytorch_tests/test_logsumexp.py
@@ -32,4 +32,4 @@ class TestLogsumexp(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_logsumexp(self, dim, keepdim, ie_device, precision, ir_version):
self._test(aten_logsumexp(dim, keepdim), None, "aten::logsumexp",
- ie_device, precision, ir_version)
+ ie_device, precision, ir_version, fx_kind="aten.logsumexp.default")
diff --git a/tests/layer_tests/pytorch_tests/test_loop.py b/tests/layer_tests/pytorch_tests/test_loop.py
index 05c66f8ec59..53ff0026f52 100644
--- a/tests/layer_tests/pytorch_tests/test_loop.py
+++ b/tests/layer_tests/pytorch_tests/test_loop.py
@@ -76,21 +76,21 @@ class TestWhileLoopFX(PytorchLayerTest):
def test_while_loop_counter(self, num_iterations, ie_device, precision, ir_version):
self.input_shape = (2, 4)
self._test(*self.create_model_simple_counter(num_iterations), ie_device, precision,
- ir_version, trace_model=False, use_torch_export=True)
+ ir_version, trace_model=False, use_torch_export=True, fx_kind="while_loop")
@pytest.mark.nightly
@pytest.mark.precommit_torch_export
def test_while_loop_accumulator(self, ie_device, precision, ir_version):
self.input_shape = (3, 5)
self._test(*self.create_model_accumulator(), ie_device, precision,
- ir_version, trace_model=False, use_torch_export=True)
+ ir_version, trace_model=False, use_torch_export=True, fx_kind="while_loop")
@pytest.mark.nightly
@pytest.mark.precommit_torch_export
def test_while_loop_scalar_only(self, ie_device, precision, ir_version):
self.input_shape = (2, 3)
self._test(*self.create_model_scalar_only(), ie_device, precision,
- ir_version, trace_model=False, use_torch_export=True)
+ ir_version, trace_model=False, use_torch_export=True, fx_kind="while_loop")
class TestLoopWithAlias(PytorchLayerTest):
diff --git a/tests/layer_tests/pytorch_tests/test_masked_fill.py b/tests/layer_tests/pytorch_tests/test_masked_fill.py
index b728d32d1b7..70d690fd7f1 100644
--- a/tests/layer_tests/pytorch_tests/test_masked_fill.py
+++ b/tests/layer_tests/pytorch_tests/test_masked_fill.py
@@ -67,7 +67,7 @@ class TestMaskedFill(PytorchLayerTest):
"mask_fill", ['zeros', 'ones', 'random'])
@pytest.mark.parametrize("input_dtype", [np.float32, np.float64, int, np.int32])
@pytest.mark.parametrize("mask_dtype", [np.uint8, np.int32]) # np.float32 incorrectly casted to bool
- @pytest.mark.parametrize("inplace", [True, False])
+ @pytest.mark.parametrize("inplace", [skip_if_export(True), False])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
diff --git a/tests/layer_tests/pytorch_tests/test_matmul.py b/tests/layer_tests/pytorch_tests/test_matmul.py
index 39edbd8796b..900171806cc 100644
--- a/tests/layer_tests/pytorch_tests/test_matmul.py
+++ b/tests/layer_tests/pytorch_tests/test_matmul.py
@@ -39,5 +39,5 @@ class TestMatMulOperation(PytorchLayerTest):
ie_device,
precision,
ir_version,
- kwargs_to_prepare_input={"matrix": matrix_input, "vector": vector_input}
+ kwargs_to_prepare_input={"matrix": matrix_input, "vector": vector_input},
)
diff --git a/tests/layer_tests/pytorch_tests/test_min_max.py b/tests/layer_tests/pytorch_tests/test_min_max.py
index 218a2bb2309..29148381132 100644
--- a/tests/layer_tests/pytorch_tests/test_min_max.py
+++ b/tests/layer_tests/pytorch_tests/test_min_max.py
@@ -79,7 +79,7 @@ class TestMinMax(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_reduce_min_max(self, axes, keep_dims, op_type, ie_device, precision, ir_version):
self._test(*self.create_model(op_type, axes, keep_dims,
- single_input=True), ie_device, precision, ir_version)
+ single_input=True), ie_device, precision, ir_version, fx_kind=f"aten.{op_type}")
@pytest.mark.parametrize("op_type", ['min', 'max'])
@pytest.mark.parametrize("second_input_dtype", ["float32", "int32", "float64", "int64", "uint8"])
@@ -93,8 +93,8 @@ class TestMinMax(PytorchLayerTest):
pytest.xfail(reason="Cumsum for i8 is unsupported on GPU")
self._test(*self.create_model(op_type, None, None, single_input=False, dtypes=(first_input_dtype, second_input_dtype)),
ie_device, precision, ir_version, kwargs_to_prepare_input=
- {"second_input": True, "input_dtype": first_input_dtype, "second_input_dtype": second_input_dtype}
- )
+ {"second_input": True, "input_dtype": first_input_dtype, "second_input_dtype": second_input_dtype},
+ fx_kind=f"aten.{op_type}")
class TestPrimMax(PytorchLayerTest):
@@ -276,8 +276,8 @@ class TestMinimumMaximum(PytorchLayerTest):
):
self._test(*self.create_model(op_type, dtypes=(first_input_dtype, second_input_dtype), out=False),
ie_device, precision, ir_version, kwargs_to_prepare_input=
- {"input_dtype": first_input_dtype, "second_input_dtype": second_input_dtype, "out": False}
- )
+ {"input_dtype": first_input_dtype, "second_input_dtype": second_input_dtype, "out": False},
+ fx_kind=f"aten.{op_type}")
@pytest.mark.parametrize("op_type", ['minimum', 'maximum'])
@@ -347,4 +347,4 @@ class TestAminAmax(PytorchLayerTest):
self._test(*self.create_model(op_type, axis, keep_dims, out),
ie_device, precision, ir_version, kwargs_to_prepare_input=
{"input_dtype": input_dtype, "out": out, "axes": axis, "keep_dims": keep_dims},
- )
+ fx_kind=f"aten.{op_type}")
diff --git a/tests/layer_tests/pytorch_tests/test_neg.py b/tests/layer_tests/pytorch_tests/test_neg.py
index 631bfa8be1f..1d23735f4c9 100644
--- a/tests/layer_tests/pytorch_tests/test_neg.py
+++ b/tests/layer_tests/pytorch_tests/test_neg.py
@@ -21,8 +21,10 @@ class TestNeg(PytorchLayerTest):
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_neg(self, ie_device, precision, ir_version):
+ # Note: This test uses Python's built-in neg on shape dimension, not torch.neg on tensor
self._test(neg_model(), None, "aten::neg",
ie_device, precision, ir_version,
dynamic_shapes_for_export={
"x": {3: torch.export.Dim("width")}
- })
+ },
+ fx_kind="<built-in function neg>")
diff --git a/tests/layer_tests/pytorch_tests/test_permute.py b/tests/layer_tests/pytorch_tests/test_permute.py
index 86f13edb294..2be5345b96f 100644
--- a/tests/layer_tests/pytorch_tests/test_permute.py
+++ b/tests/layer_tests/pytorch_tests/test_permute.py
@@ -93,4 +93,5 @@ class TestPermuteList(PytorchLayerTest):
def test_permute_list(self, order, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision, ir_version,
kwargs_to_prepare_input={"permute_shape": order},
- dynamic_shapes=ie_device != "GPU")
+ dynamic_shapes=ie_device != "GPU",
+ fx_kind="aten.permute.default")
diff --git a/tests/layer_tests/pytorch_tests/test_repeat.py b/tests/layer_tests/pytorch_tests/test_repeat.py
index ff3e056284f..1e4529eb50f 100644
--- a/tests/layer_tests/pytorch_tests/test_repeat.py
+++ b/tests/layer_tests/pytorch_tests/test_repeat.py
@@ -16,7 +16,7 @@ class TestRepeat(PytorchLayerTest):
class aten_repeat(torch.nn.Module):
def __init__(self, repeats):
- super(aten_repeat, self).__init__()
+ super().__init__()
self.repeats = repeats
def forward(self, x):
@@ -60,7 +60,7 @@ class TestRepeatList(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_repeat(self, repeats, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision, ir_version,
- kwargs_to_prepare_input={"repeats_shape": repeats})
+ kwargs_to_prepare_input={"repeats_shape": repeats}, fx_kind="aten.repeat.default")
class TestRepeatFromFlanT5(PytorchLayerTest):
@@ -80,7 +80,6 @@ class TestRepeatFromFlanT5(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
- @pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_repeat_t5(self, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, use_convert_model=True)
diff --git a/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py b/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py
index c19e7753d8f..5006e726236 100644
--- a/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py
+++ b/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py
@@ -44,7 +44,8 @@ class TestResolveConjNeg(PytorchLayerTest):
@pytest.mark.parametrize("op_type", ["resolve_neg", "resolve_conj"])
@pytest.mark.parametrize("dtype", ["float32", "int32"])
def test_reslove(self, op_type, dtype, ie_device, precision, ir_version):
- self._test(*self.create_model(op_type), ie_device, precision, ir_version, kwargs_to_prepare_input={"dtype": dtype})
+ self._test(*self.create_model(op_type), ie_device, precision, ir_version, kwargs_to_prepare_input={"dtype": dtype},
+ fx_kind=f"aten.{op_type}")
@pytest.mark.nightly
@pytest.mark.precommit
@@ -53,4 +54,5 @@ class TestResolveConjNeg(PytorchLayerTest):
@pytest.mark.xfail(reason="complex dtype is not supported yet")
def test_resolve_complex(self, op_type, ie_device, precision, ir_version):
self._prepare_input = self._prepare_input_complex
- self._test(*self.create_model(op_type), ie_device, precision, ir_version)
+ self._test(*self.create_model(op_type), ie_device, precision, ir_version,
+ fx_kind=f"aten.{op_type}")
diff --git a/tests/layer_tests/pytorch_tests/test_scatter.py b/tests/layer_tests/pytorch_tests/test_scatter.py
index d845751d129..e3c2a0a0ab8 100644
--- a/tests/layer_tests/pytorch_tests/test_scatter.py
+++ b/tests/layer_tests/pytorch_tests/test_scatter.py
@@ -285,4 +285,5 @@ class TestScatterAdd(PytorchLayerTest):
precision,
ir_version,
kwargs_to_prepare_input={"dtype": dtype},
+ fx_kind="aten.scatter_add",
)
diff --git a/tests/layer_tests/pytorch_tests/test_shift_operations.py b/tests/layer_tests/pytorch_tests/test_shift_operations.py
index 62646be6f2d..8f6fe5cdf6d 100644
--- a/tests/layer_tests/pytorch_tests/test_shift_operations.py
+++ b/tests/layer_tests/pytorch_tests/test_shift_operations.py
@@ -53,6 +53,7 @@ class TestShiftOperators(PytorchLayerTest):
},
trace_model=True,
freeze_model=False,
+ fx_kind=["aten.__lshift__", "aten.__rshift__"],
)
@@ -104,4 +105,5 @@ class TestBitwiseShiftFunctions(PytorchLayerTest):
},
trace_model=True,
freeze_model=False,
+ fx_kind="aten.bitwise_left_shift",
)
\ No newline at end of file
diff --git a/tests/layer_tests/pytorch_tests/test_slice.py b/tests/layer_tests/pytorch_tests/test_slice.py
index b09f2fdc8bf..9f85e3880f1 100644
--- a/tests/layer_tests/pytorch_tests/test_slice.py
+++ b/tests/layer_tests/pytorch_tests/test_slice.py
@@ -108,19 +108,15 @@ class TestSliceAndSqueeze(PytorchLayerTest):
def create_model(self):
class aten_slice(torch.nn.Module):
- def __init__(self) -> None:
- super().__init__()
-
def forward(self, x):
a = torch.squeeze(x, 1)
return a[:, None, :]
- ref_net = None
-
- return aten_slice(), ref_net, "aten::slice"
+ return aten_slice(), None, "aten::slice"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_slice_and_squeeze(self, ie_device, precision, ir_version):
- self._test(*self.create_model(), ie_device, precision, ir_version, dynamic_shapes=False)
+ self._test(*self.create_model(), ie_device, precision, ir_version,
+ dynamic_shapes=False, fx_kind="aten.unsqueeze.default")
diff --git a/tests/layer_tests/pytorch_tests/test_split.py b/tests/layer_tests/pytorch_tests/test_split.py
index 7323cef20d1..d18a3692f79 100644
--- a/tests/layer_tests/pytorch_tests/test_split.py
+++ b/tests/layer_tests/pytorch_tests/test_split.py
@@ -5,7 +5,7 @@ import numpy as np
import pytest
import torch
-from pytorch_layer_test_class import PytorchLayerTest
+from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestSplit(PytorchLayerTest):
@@ -15,46 +15,43 @@ class TestSplit(PytorchLayerTest):
def create_model_split_getitem(self):
class aten_split(torch.nn.Module):
def __init__(self, split, axis, getitem):
+ super().__init__()
self.split = split
self.axis = axis
self.getitem = getitem
- super(aten_split, self).__init__()
def forward(self, input):
return torch.split(input, self.split, self.axis)[self.getitem]
- ref_net = None
-
return (
aten_split(self.split_param, self.axis, self.getitem),
- ref_net,
+ None,
"aten::split",
)
def create_model_split_listunpack(self):
class aten_split(torch.nn.Module):
def __init__(self, split, axis):
+ super().__init__()
self.split = split
self.axis = axis
- super(aten_split, self).__init__()
def forward(self, input):
# Hardcode to test with ListUnpack
a, b, c, d, e = torch.split(input, self.split, self.axis)
return b
- ref_net = None
-
- return aten_split(self.split_param, self.axis), ref_net, "aten::split"
+ return aten_split(self.split_param, self.axis), None, "aten::split"
# Test case - (split_param, axis), always split into 5 due to hardcoded number of outputs in ListUnpack test.
test_cases = [
(2, 1),
(45, 2),
(45, -1),
- ([2, 2, 2, 2, 2], 1),
- ([200, 20, 1, 1, 2], 2),
- ([20, 200, 1, 1, 2], -1),
+ # the following test cases produce split_with_sizes for FX
+ skip_if_export(([2, 2, 2, 2, 2], 1)),
+ skip_if_export(([200, 20, 1, 1, 2], 2)),
+ skip_if_export(([20, 200, 1, 1, 2], -1)),
]
@pytest.mark.parametrize("params", test_cases)
@@ -99,7 +96,8 @@ class TestSplitWithSizes(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_split_with_sizes(self, ie_device, precision, ir_version):
self._test(*self.create_model(),
- ie_device, precision, ir_version, trace_model=True)
+ ie_device, precision, ir_version, trace_model=True,
+ fx_kind="aten.split_with_sizes.default")
class TestSplitWithSizesCopy(PytorchLayerTest):
@@ -111,9 +109,6 @@ class TestSplitWithSizesCopy(PytorchLayerTest):
import torch
class aten_split_with_sizes_copy(torch.nn.Module):
- def __init__(self):
- super(aten_split_with_sizes_copy, self).__init__()
-
def forward(self, x, y):
return torch.split_with_sizes_copy(x, [y.shape[0]], dim=0)
@@ -121,10 +116,12 @@ class TestSplitWithSizesCopy(PytorchLayerTest):
return aten_split_with_sizes_copy(), ref_net, ["aten::split_with_sizes", "prim::ListConstruct"]
+ @pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_split_with_sizes_copy(self, ie_device, precision, ir_version):
self._test(*self.create_model(),
- ie_device, precision, ir_version, trace_model=True)
+ ie_device, precision, ir_version, trace_model=True,
+ fx_kind="aten.split_with_sizes_copy.default")
class TestSplitWithSizesComplex(PytorchLayerTest):
@@ -153,4 +150,5 @@ class TestSplitWithSizesComplex(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_split_with_sizes_complex(self, ie_device, precision, ir_version):
self._test(*self.create_model(),
- ie_device, precision, ir_version, trace_model=True)
+ ie_device, precision, ir_version, trace_model=True,
+ fx_kind="aten.split_with_sizes.default")
diff --git a/tests/layer_tests/pytorch_tests/test_strided_const.py b/tests/layer_tests/pytorch_tests/test_strided_const.py
index a15e2f84555..8d4b7e8d123 100644
--- a/tests/layer_tests/pytorch_tests/test_strided_const.py
+++ b/tests/layer_tests/pytorch_tests/test_strided_const.py
@@ -17,16 +17,14 @@ class TestStrides(PytorchLayerTest):
class strided_const(torch.nn.Module):
def __init__(self):
- super(strided_const, self).__init__()
+ super().__init__()
self.const = torch.randint(0, 10, [1, 3, 2, 2], dtype=torch.float32)
self.const = self.const.to(memory_format=torch.channels_last)
def forward(self, x):
return x + self.const
- ref_net = None
-
- return strided_const(), ref_net, None
+ return strided_const(), None, "aten::add"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_unary_ops.py b/tests/layer_tests/pytorch_tests/test_unary_ops.py
index 92316b37463..df235572520 100644
--- a/tests/layer_tests/pytorch_tests/test_unary_ops.py
+++ b/tests/layer_tests/pytorch_tests/test_unary_ops.py
@@ -299,7 +299,7 @@ class TestUnaryOp(PytorchLayerTest):
def test_prim_abs(self, dtype, ie_device, precision, ir_version):
self.dtype = dtype
self._test(prim_abs_net(dtype), None, "prim::abs",
- ie_device, precision, ir_version)
+ ie_device, precision, ir_version, fx_kind="aten.abs")
@pytest.mark.nightly
@pytest.mark.precommit