Skip to content

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

[PT FE] Make all pytorch layer tests use static seed for random numbers (#34030)

Maxim Vafin2ea24b1a7c99
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 0a241fa52e3..976d7e89251 100644
--- a/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py
+++ b/src/bindings/python/src/openvino/frontend/pytorch/fx_decoder.py
@@ -75,8 +75,9 @@ class BaseFXDecoder(Decoder):
elif isinstance(arg, float):
return make_constant(OVType.f32, Shape([]), [arg])
elif isinstance(arg, str):
- u8_tensor = torch.frombuffer(str.encode(arg), dtype=torch.uint8)
- return torch_tensor_to_ov_const(u8_tensor, shared_memory=True)
+ buf = bytearray(arg, "utf-8")
+ u8_tensor = torch.frombuffer(buf, dtype=torch.uint8)
+ return torch_tensor_to_ov_const(u8_tensor, shared_memory=False)
return None
@staticmethod
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 dee83ab47c8..a35c75c76fb 100644
--- a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py
+++ b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py
@@ -19,6 +19,121 @@ import openvino.properties.hint as hints
logging.basicConfig(level=logging.DEBUG)
+class SeededRandom:
+ """
+ A seeded random number generator for reproducible test data generation.
+
+ Each test gets a deterministic seed based on its class name, allowing
+ tests to be run in any order or in parallel while maintaining reproducibility.
+ """
+
+ def __init__(self, seed: int = 0):
+ """Initialize with a seed value."""
+ self._seed = seed
+ self._rng = np.random.RandomState(seed)
+
+ @staticmethod
+ def _to_numpy_dtype(dtype):
+ if dtype is None:
+ return None
+ if isinstance(dtype, torch.dtype):
+ dtype_map = {
+ torch.float32: np.float32,
+ torch.float64: np.float64,
+ torch.float16: np.float16,
+ torch.int8: np.int8,
+ torch.int16: np.int16,
+ torch.int32: np.int32,
+ torch.int64: np.int64,
+ torch.uint8: np.uint8,
+ torch.bool: np.bool_,
+ }
+ return dtype_map.get(dtype, np.float32)
+ return dtype
+
+ def randn(self, *shape, dtype=None) -> np.ndarray:
+ """Generate random samples from standard normal distribution."""
+ np_dtype = self._to_numpy_dtype(dtype) if dtype is not None else np.float32
+ return np.asarray(self._rng.randn(*shape)).astype(np_dtype)
+
+ def rand(self, *shape, dtype=None) -> np.ndarray:
+ """Generate random samples from uniform distribution [0, 1)."""
+ np_dtype = self._to_numpy_dtype(dtype) if dtype is not None else np.float32
+ return np.asarray(self._rng.rand(*shape)).astype(np_dtype)
+
+ def randint(self, low, high=None, size=None, dtype=np.int64):
+ """Generate random integers from low (inclusive) to high (exclusive).
+
+ Returns a scalar if size is None, otherwise returns an array.
+ """
+ result = self._rng.randint(low, high, size=size)
+ np_dtype = self._to_numpy_dtype(dtype)
+ if size is None:
+ # Return scalar with appropriate type
+ return np_dtype(result) if np_dtype is not None else result
+ return result.astype(np_dtype) if np_dtype is not None else result
+
+ def uniform(self, low=0.0, high=1.0, size=None, dtype=np.float32):
+ """Generate random samples from uniform distribution [low, high).
+
+ Returns a scalar if size is None, otherwise returns an array.
+ """
+ result = self._rng.uniform(low, high, size=size)
+ np_dtype = self._to_numpy_dtype(dtype)
+ if size is None:
+ return np_dtype(result) if np_dtype is not None else result
+ return result.astype(np_dtype) if np_dtype is not None else result
+
+ def choice(self, a, size=None, replace=True, p=None):
+ """Generate a random sample from a given 1-D array."""
+ return self._rng.choice(a, size=size, replace=replace, p=p)
+
+ def random_bool(self, *shape) -> np.ndarray:
+ """Generate random boolean array."""
+ return self._rng.randint(0, 2, size=shape).astype(bool)
+
+ def shuffle(self, x):
+ """Shuffle array in place."""
+ self._rng.shuffle(x)
+
+ def torch_randn(self, *shape, dtype=torch.float32):
+ """Generate random normal samples as a torch tensor."""
+ if len(shape) == 1 and isinstance(shape[0], (list, tuple)):
+ shape = tuple(shape[0])
+ np_result = self.randn(*shape, dtype=np.float32)
+ t = torch.from_numpy(np_result)
+ if dtype != torch.float32:
+ t = t.to(dtype)
+ return t
+
+ def torch_rand(self, *shape, dtype=torch.float32):
+ """Generate random uniform [0, 1) samples as a torch tensor."""
+ if len(shape) == 1 and isinstance(shape[0], (list, tuple)):
+ shape = tuple(shape[0])
+ np_result = self.rand(*shape, dtype=np.float32)
+ t = torch.from_numpy(np_result)
+ if dtype != torch.float32:
+ t = t.to(dtype)
+ return t
+
+ def torch_randint(self, low, high, size, dtype=torch.int64):
+ """Generate random integers as a torch tensor."""
+ np_result = self._rng.randint(low, high, size=size).astype(np.int64)
+ t = torch.from_numpy(np_result)
+ if dtype != torch.int64:
+ t = t.to(dtype)
+ return t
+
+ @property
+ def rng(self) -> np.random.RandomState:
+ """Access the underlying random state for advanced operations."""
+ return self._rng
+
+ def reset(self):
+ """Reset the random state to the initial seed."""
+ self._rng = np.random.RandomState(self._seed)
+
+
def skip_check(*param, reason="Unsupported"):
return skip_if_export(*param, reason=reason) if PytorchLayerTest.use_torch_export() else skip_if_fx(*param, reason=reason)
@@ -43,6 +158,37 @@ class PytorchLayerTest:
"uint8": Type.u8,
"float16": Type.f16
}
+
+ # Class-level cache for SeededRandom instances
+ _random_instances = {}
+
+ @property
+ def random(self) -> SeededRandom:
+ """
+ Get a seeded random number generator for this test class.
+
+ The seed is derived from the test class name, ensuring reproducibility
+ regardless of test execution order or parallelization.
+
+ Note: The random state is reset at the start of each _test() call,
+ not on every access. This ensures that within a test, multiple calls
+ to self.random.randn() produce different values, while the same test
+ always produces the same sequence.
+
+ Usage in _prepare_input():
+ return (self.random.randn(2, 3, 4),)
+ """
+ class_name = self.__class__.__name__
+ if class_name not in PytorchLayerTest._random_instances:
+ self._reset_random_state()
+ return PytorchLayerTest._random_instances[class_name]
+
+ def _reset_random_state(self):
+ """Reset the random state for this test class. Called at the start of each test."""
+ class_name = self.__class__.__name__
+ if class_name not in PytorchLayerTest._random_instances:
+ PytorchLayerTest._random_instances[class_name] = SeededRandom(42)
+ PytorchLayerTest._random_instances[class_name].reset()
@staticmethod
def _check_kind_exist(graph, kind):
@@ -120,14 +266,17 @@ class PytorchLayerTest:
return False
- def _test(self, model, ref_net, kind, ie_device, precision, ir_version, infer_timeout=60, dynamic_shapes=True,
+ def _test(self, model, kind, ie_device, precision, ir_version, infer_timeout=60, dynamic_shapes=True,
**kwargs):
+ # Reset random state at the start of each test for reproducibility
+ self._reset_random_state()
+
retries = 0
max_retries = 3
last_e = None
while retries < max_retries:
try:
- return self._test_impl(model, ref_net, kind, ie_device, precision, ir_version, infer_timeout, dynamic_shapes, **kwargs)
+ return self._test_impl(model, kind, ie_device, precision, ir_version, infer_timeout, dynamic_shapes, **kwargs)
except RuntimeError as e:
# This is a potentially sporadic issue
print(f"An error occurred: {e}. Retrying...")
@@ -137,7 +286,7 @@ class PytorchLayerTest:
raise RuntimeError("Max retries reached. Function execution failed.") from last_e
- def _test_impl(self, model, ref_net, kind, ie_device, precision, ir_version, infer_timeout=60, dynamic_shapes=True,
+ def _test_impl(self, model, kind, ie_device, precision, ir_version, infer_timeout=60, dynamic_shapes=True,
**kwargs):
"""
:param enabled_transforms/disabled_transforms: string with idxs of transforms that should be enabled/disabled.
diff --git a/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py b/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py
index 179ba618e2f..ff83501915c 100644
--- a/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py
+++ b/tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -25,9 +24,8 @@ class TestAdaptiveAvgPool3D(PytorchLayerTest):
def forward(self, input_tensor):
return torch.nn.functional.adaptive_avg_pool3d(input_tensor, self.output_size)
- ref_net = None
- return aten_adaptive_avg_pool3d(output_size), ref_net, "aten::adaptive_avg_pool3d"
+ return aten_adaptive_avg_pool3d(output_size), "aten::adaptive_avg_pool3d"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -36,7 +34,7 @@ class TestAdaptiveAvgPool3D(PytorchLayerTest):
def test_adaptive_avg_pool3d(self, ie_device, precision, ir_version, input_tensor, output_size):
if ie_device == "GPU" and len(input_tensor) < 5:
pytest.xfail(reason="Unsupported shape for adaptive pool on GPU")
- self.input_tensor = np.random.randn(*input_tensor).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_tensor)
self._test(*self.create_model(output_size), ie_device, precision, ir_version)
@@ -57,16 +55,15 @@ class TestAdaptiveAvgPool2D(PytorchLayerTest):
def forward(self, input_tensor):
return torch.nn.functional.adaptive_avg_pool2d(input_tensor, self.output_size)
- ref_net = None
- return aten_adaptive_avg_pool2d(output_size), ref_net, "aten::adaptive_avg_pool2d"
+ return aten_adaptive_avg_pool2d(output_size), "aten::adaptive_avg_pool2d"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_adaptive_avg_pool2d(self, ie_device, precision, ir_version, input_shape, output_size):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model(output_size), ie_device, precision, ir_version)
@@ -87,14 +84,13 @@ class TestAdaptiveAvgPool1D(PytorchLayerTest):
def forward(self, input_tensor):
return torch.nn.functional.adaptive_avg_pool1d(input_tensor, self.output_size)
- ref_net = None
- return aten_adaptive_avg_pool1d(output_size), ref_net, "aten::adaptive_avg_pool1d"
+ return aten_adaptive_avg_pool1d(output_size), "aten::adaptive_avg_pool1d"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_adaptive_avg_pool1d(self, ie_device, precision, ir_version, input_shape, output_size):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model(output_size), ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py b/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py
index e20201dd9dc..085b6dd1e7c 100644
--- a/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py
+++ b/tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py
@@ -3,7 +3,6 @@
import platform
-import numpy as np
import pytest
import torch
import torch.nn.functional as F
@@ -30,9 +29,8 @@ class TestAdaptiveMaxPool3D(PytorchLayerTest):
return output, indices
return F.adaptive_max_pool3d(input_tensor, self.output_size, False), input_tensor.to(torch.int64)
- ref_net = None
- return aten_adaptive_max_pool3d(output_size, return_indices), ref_net, "aten::adaptive_max_pool3d"
+ return aten_adaptive_max_pool3d(output_size, return_indices), "aten::adaptive_max_pool3d"
@pytest.mark.parametrize('input_shape', [[2, 1, 1, 4, 4],
[4, 1, 3, 32, 32],
@@ -54,7 +52,7 @@ class TestAdaptiveMaxPool3D(PytorchLayerTest):
def test_adaptive_max_pool3d(self, ie_device, precision, ir_version, input_shape, output_size, return_indices):
if ie_device == "GPU" and len(input_shape) < 5:
pytest.xfail(reason="Unsupported shape for adaptive pool on GPU")
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version)
@@ -77,9 +75,8 @@ class TestAdaptiveMaxPool2D(PytorchLayerTest):
return output, indices
return F.adaptive_max_pool2d(input_tensor, self.output_size, False), input_tensor.to(torch.int64)
- ref_net = None
- return aten_adaptive_max_pool2d(output_size, return_indices), ref_net, "aten::adaptive_max_pool2d"
+ return aten_adaptive_max_pool2d(output_size, return_indices), "aten::adaptive_max_pool2d"
@pytest.mark.parametrize('input_shape', [[2, 1, 4, 4],
[1, 3, 32, 32],
@@ -99,7 +96,7 @@ class TestAdaptiveMaxPool2D(PytorchLayerTest):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
def test_adaptive_max_pool2d(self, ie_device, precision, ir_version, input_shape, output_size, return_indices):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version)
@@ -122,9 +119,8 @@ class TestAdaptiveMaxPool1D(PytorchLayerTest):
return output, indices
return F.adaptive_max_pool1d(input_tensor, self.output_size, False), input_tensor.to(torch.int64)
- ref_net = None
- return aten_adaptive_max_pool1d(output_size, return_indices), ref_net, "aten::adaptive_max_pool1d"
+ return aten_adaptive_max_pool1d(output_size, return_indices), "aten::adaptive_max_pool1d"
@pytest.mark.parametrize('input_shape', [
[1, 4, 4],
@@ -146,5 +142,5 @@ class TestAdaptiveMaxPool1D(PytorchLayerTest):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
def test_adaptive_max_pool1d(self, ie_device, precision, ir_version, input_shape, output_size, return_indices):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_add.py b/tests/layer_tests/pytorch_tests/test_add.py
index fa4e1c5945d..bbaff3451df 100644
--- a/tests/layer_tests/pytorch_tests/test_add.py
+++ b/tests/layer_tests/pytorch_tests/test_add.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -17,7 +16,7 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_check
class TestAdd(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 5, 3, 4).astype(np.float32), self.input_rhs)
+ return (self.random.randn(2, 5, 3, 4), self.input_rhs)
def create_model(self, alpha, op_type):
class aten_add(torch.nn.Module):
@@ -33,9 +32,8 @@ class TestAdd(PytorchLayerTest):
def forward2(self, lhs, rhs):
return lhs.add_(rhs, alpha=self.alpha)
- ref_net = None
- return aten_add(alpha, op_type), ref_net, f"aten::{op_type}"
+ return aten_add(alpha, op_type), f"aten::{op_type}"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -43,7 +41,7 @@ class TestAdd(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
@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.input_rhs = self.random.randn(*input_shape_rhs)
self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version, use_convert_model=True,
fx_kind="aten.add")
@@ -52,11 +50,11 @@ class TestAddTypes(PytorchLayerTest):
def _prepare_input(self):
if len(self.lhs_shape) == 0:
- return (torch.randint(0, 10, self.rhs_shape).to(self.rhs_type).numpy(),)
+ return (self.random.randint(0, 10, size=self.rhs_shape, dtype=self.rhs_type),)
elif len(self.rhs_shape) == 0:
- return (torch.randint(0, 10, self.lhs_shape).to(self.lhs_type).numpy(),)
- return (torch.randint(0, 10, self.lhs_shape).to(self.lhs_type).numpy(),
- torch.randint(0, 10, self.rhs_shape).to(self.rhs_type).numpy())
+ return (self.random.randint(0, 10, size=self.lhs_shape, dtype=self.lhs_type),)
+ return (self.random.randint(0, 10, size=self.lhs_shape, dtype=self.lhs_type),
+ self.random.randint(0, 10, size=self.rhs_shape, dtype=self.rhs_type))
def create_model(self, lhs_type, lhs_shape, rhs_type, rhs_shape):
@@ -81,9 +79,8 @@ class TestAddTypes(PytorchLayerTest):
def forward3(self, lhs, rhs):
return torch.add(lhs.to(self.lhs_type), rhs.to(self.rhs_type), alpha=2)
- ref_net = None
- return aten_add(lhs_type, lhs_shape, rhs_type, rhs_shape), ref_net, "aten::add"
+ return aten_add(lhs_type, lhs_shape, rhs_type, rhs_shape), "aten::add"
@pytest.mark.parametrize(("lhs_type", "rhs_type"),
[[torch.bool, torch.uint8],
@@ -125,14 +122,14 @@ class TestAddTypes(PytorchLayerTest):
class TestAddLists(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 5, 3, 4).astype(np.float32),)
+ return (self.random.randn(2, 5, 3, 4),)
def create_model(self):
class aten_add(torch.nn.Module):
def forward(self, x):
return x.reshape(x.shape[:-1] + (-1,))
- return aten_add(), None, "aten::add"
+ return aten_add(), "aten::add"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -144,23 +141,22 @@ class TestAddLists(PytorchLayerTest):
class TestAddBool(PytorchLayerTest):
def _prepare_input(self):
- input2 = np.random.randint(0, 2, (1, 3, 20, 24)).astype(bool)
- input1 = np.random.randint(0, 2, (1, 3, 20, 24)).astype(bool)
+ input2 = self.random.randint(0, 2, (1, 3, 20, 24), dtype=bool)
+ input1 = self.random.randint(0, 2, (1, 3, 20, 24), dtype=bool)
return (input1, input2)
def create_model(self, lhs_type=torch.bool, rhs_type=torch.bool):
class aten_add(torch.nn.Module):
def __init__(self):
- super(aten_add, self).__init__()
+ super().__init__()
self.lhs_type = lhs_type
self.rhs_type = rhs_type
def forward(self, x1, x2):
return torch.add(x1.to(self.rhs_type), x2.to(self.lhs_type))
- ref_net = None
- return aten_add(), ref_net, "aten::add"
+ return aten_add(), "aten::add"
@pytest.mark.parametrize(("lhs_type", "rhs_type"), [
(torch.bool, torch.bool),
@@ -179,8 +175,8 @@ class TestAddWithLhsComplex(PytorchLayerTest):
def _prepare_input(self):
rhs_input_shape = [3, 4, 5]
lhs_input_shape = rhs_input_shape + [2]
- return [torch.randint(0, 10, lhs_input_shape).to(self.lhs_type).numpy(),
- torch.randint(0, 10, rhs_input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(0, 10, size=lhs_input_shape, dtype=self.lhs_type),
+ self.random.randint(0, 10, size=rhs_input_shape, dtype=self.rhs_type)]
def create_model(self, alpha, op_type):
class aten_add(torch.nn.Module):
@@ -200,9 +196,8 @@ class TestAddWithLhsComplex(PytorchLayerTest):
res = lhs.add_(rhs, alpha=self.alpha)
return torch.view_as_real(res + lhs)
- ref_net = None
- return aten_add(alpha, op_type), ref_net, f"aten::{op_type}"
+ return aten_add(alpha, op_type), f"aten::{op_type}"
@pytest.mark.parametrize('alpha', (0, 0.5))
@pytest.mark.parametrize("lhs_type",
@@ -229,8 +224,8 @@ class TestAddWithRhsComplex(PytorchLayerTest):
def _prepare_input(self):
lhs_input_shape = [3, 4, 5]
rhs_input_shape = lhs_input_shape + [2]
- return [torch.randint(0, 10, lhs_input_shape).to(self.lhs_type).numpy(),
- torch.randint(0, 10, rhs_input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(0, 10, size=lhs_input_shape, dtype=self.lhs_type),
+ self.random.randint(0, 10, size=rhs_input_shape, dtype=self.rhs_type)]
def create_model(self, alpha):
class aten_add(torch.nn.Module):
@@ -244,9 +239,8 @@ class TestAddWithRhsComplex(PytorchLayerTest):
res = torch.add(lhs, rhs, alpha=self.alpha)
return torch.view_as_real(res)
- ref_net = None
- return aten_add(alpha), ref_net, f"aten::add"
+ return aten_add(alpha), f"aten::add"
@pytest.mark.parametrize('alpha', (0, 0.5))
@pytest.mark.parametrize("rhs_type",
@@ -272,8 +266,8 @@ class TestAddWithBothComplex(PytorchLayerTest):
def _prepare_input(self):
input_shape = [3, 4, 5]
input_shape = input_shape + [2]
- return [torch.randint(0, 10, input_shape).to(self.lhs_type).numpy(),
- torch.randint(0, 10, input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(0, 10, size=input_shape, dtype=self.lhs_type),
+ self.random.randint(0, 10, size=input_shape, dtype=self.rhs_type)]
def create_model(self, alpha, op_type):
class aten_add(torch.nn.Module):
@@ -295,9 +289,8 @@ class TestAddWithBothComplex(PytorchLayerTest):
res = lhs.add_(rhs, alpha=self.alpha)
return torch.view_as_real(res + lhs)
- ref_net = None
- return aten_add(alpha, op_type), ref_net, f"aten::{op_type}"
+ return aten_add(alpha, op_type), f"aten::{op_type}"
@pytest.mark.parametrize('alpha', (0, 0.5))
@pytest.mark.parametrize("lhs_type",
diff --git a/tests/layer_tests/pytorch_tests/test_addcmul.py b/tests/layer_tests/pytorch_tests/test_addcmul.py
index bb59e450d1c..c79f4ea2628 100644
--- a/tests/layer_tests/pytorch_tests/test_addcmul.py
+++ b/tests/layer_tests/pytorch_tests/test_addcmul.py
@@ -9,16 +9,16 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestAddCMul(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.uniform(0, 50, 3).astype(self.input_type),
- np.random.uniform(0, 50, 3).astype(self.input_type),
- np.random.uniform(0, 50, 3).astype(self.input_type))
+ return (self.random.uniform(0, 50, 3, dtype=self.input_type),
+ self.random.uniform(0, 50, 3, dtype=self.input_type),
+ self.random.uniform(0, 50, 3, dtype=self.input_type))
def create_model(self, value=None):
import torch
class aten_addcmul(torch.nn.Module):
def __init__(self, value=None):
- super(aten_addcmul, self).__init__()
+ super().__init__()
self.value = value
def forward(self, x, y, z):
@@ -26,9 +26,8 @@ class TestAddCMul(PytorchLayerTest):
return torch.addcmul(x, y, z, value=self.value)
return torch.addcmul(x, y, z)
- ref_net = None
- return aten_addcmul(value), ref_net, "aten::addcmul"
+ return aten_addcmul(value), "aten::addcmul"
@pytest.mark.parametrize(("input_type", "value"), [
[np.int32, None],
diff --git a/tests/layer_tests/pytorch_tests/test_addmm.py b/tests/layer_tests/pytorch_tests/test_addmm.py
index 424b129ce0b..aaaf0769d1c 100644
--- a/tests/layer_tests/pytorch_tests/test_addmm.py
+++ b/tests/layer_tests/pytorch_tests/test_addmm.py
@@ -8,11 +8,10 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestAddMM(PytorchLayerTest):
def _prepare_input(self, input_shape=(2, 2), matrix1_shape=(2, 2), matrix2_shape=(2, 2)):
- import numpy as np
return (
- np.random.randn(*input_shape).astype(np.float32),
- np.random.randn(*matrix1_shape).astype(np.float32),
- np.random.randn(*matrix2_shape).astype(np.float32)
+ self.random.randn(*input_shape),
+ self.random.randn(*matrix1_shape),
+ self.random.randn(*matrix2_shape)
)
def create_model(self, alpha, beta):
@@ -20,16 +19,15 @@ class TestAddMM(PytorchLayerTest):
class aten_addmm(torch.nn.Module):
def __init__(self, alpha, beta):
- super(aten_addmm, self).__init__()
+ super().__init__()
self.alpha = alpha
self.beta = beta
def forward(self, m0, m1, m2):
return torch.addmm(m0, m1, m2, alpha=self.alpha, beta=self.beta)
- ref_net = None
- return aten_addmm(alpha, beta), ref_net, 'aten::addmm'
+ return aten_addmm(alpha, beta), 'aten::addmm'
@pytest.mark.parametrize("kwargs_to_prepare_input", [
{"input_shape": (3, 3), 'matrix1_shape': (3, 3), 'matrix2_shape': (3, 3)},
@@ -52,11 +50,10 @@ class TestAddMM(PytorchLayerTest):
class TestBAddBMM(PytorchLayerTest):
def _prepare_input(self, input_shape=(2, 2), matrix1_shape=(2, 2), matrix2_shape=(2, 2)):
- import numpy as np
return (
- np.random.randn(*input_shape).astype(np.float32),
- np.random.randn(*matrix1_shape).astype(np.float32),
- np.random.randn(*matrix2_shape).astype(np.float32)
+ self.random.randn(*input_shape),
+ self.random.randn(*matrix1_shape),
+ self.random.randn(*matrix2_shape)
)
def create_model(self, alpha, beta):
@@ -64,16 +61,15 @@ class TestBAddBMM(PytorchLayerTest):
class aten_addmm(torch.nn.Module):
def __init__(self, alpha, beta):
- super(aten_addmm, self).__init__()
+ super().__init__()
self.alpha = alpha
self.beta = beta
def forward(self, m0, m1, m2):
return torch.baddbmm(m0, m1, m2, alpha=self.alpha, beta=self.beta)
- ref_net = None
- return aten_addmm(alpha, beta), ref_net, 'aten::baddbmm'
+ return aten_addmm(alpha, beta), 'aten::baddbmm'
@pytest.mark.parametrize("kwargs_to_prepare_input", [
{"input_shape": (2, 3, 3), 'matrix1_shape': (2, 3, 3), 'matrix2_shape': (2, 3, 3)},
diff --git a/tests/layer_tests/pytorch_tests/test_aliases.py b/tests/layer_tests/pytorch_tests/test_aliases.py
index 85acf46dc1a..dc71eb33c77 100644
--- a/tests/layer_tests/pytorch_tests/test_aliases.py
+++ b/tests/layer_tests/pytorch_tests/test_aliases.py
@@ -33,16 +33,15 @@ class aten_loop_alias(torch.nn.Module):
class TestAliases(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_alias(self, ie_device, precision, ir_version):
- self._test(aten_alias(), None, ["aten::slice",
- "aten::select",
- "aten::copy_"],
+ self._test(aten_alias(), ["aten::slice",
+ "aten::select",
+ "aten::copy_"],
ie_device, precision, ir_version,
fx_kind=["aten.clone.default", "aten.select.int", "aten.fill_.Tensor"])
@@ -50,8 +49,8 @@ class TestAliases(PytorchLayerTest):
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_alias_tensor(self, ie_device, precision, ir_version):
- self._test(aten_alias_tensor(), None, ["aten::slice",
- "aten::copy_"],
+ self._test(aten_alias_tensor(), ["aten::slice",
+ "aten::copy_"],
ie_device, precision, ir_version, freeze_model=False,
fx_kind=["aten.slice.Tensor", "aten.copy_.default"])
@@ -59,9 +58,9 @@ class TestAliases(PytorchLayerTest):
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_loop_alias(self, ie_device, precision, ir_version):
- self._test(aten_loop_alias(), None, ["aten::slice",
- "aten::select",
- "aten::copy_",
- "prim::Loop"],
+ self._test(aten_loop_alias(), ["aten::slice",
+ "aten::select",
+ "aten::copy_",
+ "prim::Loop"],
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_all.py b/tests/layer_tests/pytorch_tests/test_all.py
index bf722e54852..82fdcb08999 100644
--- a/tests/layer_tests/pytorch_tests/test_all.py
+++ b/tests/layer_tests/pytorch_tests/test_all.py
@@ -81,10 +81,10 @@ class TestAll(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_all_noparams(self, input_shape, d_type, out, ie_device, precision, ir_version):
if type(input_shape) is list:
- self.input_tensor = np.random.randint(0, 2, input_shape, dtype=d_type)
+ self.input_tensor = self.random.randint(0, 2, input_shape, dtype=d_type)
else:
self.input_tensor = input_shape
- self._test(aten_all_noparam() if not out else aten_all_noparam_out(), None, "aten::all",
+ self._test(aten_all_noparam() if not out else aten_all_noparam_out(), "aten::all",
ie_device, precision, ir_version, trace_model=True, freeze_model=False, kwargs_to_prepare_input={"out": out})
@pytest.mark.parametrize("input_shape, d_type", [
@@ -114,9 +114,9 @@ class TestAll(PytorchLayerTest):
reason='Ticket - 122715')
def test_all(self, input_shape, d_type, keepdim, out, ie_device, precision, ir_version):
if type(input_shape) is list:
- self.input_tensor = np.random.randint(0, 2, input_shape, dtype=d_type)
+ self.input_tensor = self.random.randint(0, 2, input_shape, dtype=d_type)
else:
self.input_tensor = input_shape
for dim in range(len(self.input_tensor.shape)):
- self._test(aten_all(dim, keepdim) if not out else aten_all_out(dim, keepdim), None, "aten::all",
+ self._test(aten_all(dim, keepdim) if not out else aten_all_out(dim, keepdim), "aten::all",
ie_device, precision, ir_version, trace_model=True, freeze_model=False, kwargs_to_prepare_input={"out": out})
diff --git a/tests/layer_tests/pytorch_tests/test_aminmax.py b/tests/layer_tests/pytorch_tests/test_aminmax.py
index c363f149819..48723b94ae1 100644
--- a/tests/layer_tests/pytorch_tests/test_aminmax.py
+++ b/tests/layer_tests/pytorch_tests/test_aminmax.py
@@ -33,9 +33,8 @@ class TestAminMax(PytorchLayerTest):
model_class = aten_aminmax(dtype, dim, keepdim)
- ref_net = None
- return model_class, ref_net, "aten::aminmax"
+ return model_class, "aten::aminmax"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_and.py b/tests/layer_tests/pytorch_tests/test_and.py
index 067f430b51c..101d139568b 100644
--- a/tests/layer_tests/pytorch_tests/test_and.py
+++ b/tests/layer_tests/pytorch_tests/test_and.py
@@ -20,9 +20,8 @@ class TestAnd(PytorchLayerTest):
def forward(self, tensor_a, tensor_b):
return tensor_a & tensor_b
- ref_net = None
- return aten_and_tensor(), ref_net, "aten::__and__"
+ return aten_and_tensor(), "aten::__and__"
def create_model_bool_input(self):
class aten_and_bool(torch.nn.Module):
@@ -32,9 +31,8 @@ class TestAnd(PytorchLayerTest):
def forward(self, bool_a: bool, bool_b: bool):
return bool_a & bool_b
- ref_net = None
- return aten_and_bool(), ref_net, "aten::__and__"
+ return aten_and_bool(), "aten::__and__"
def create_model_int_input(self):
class aten_and_int(torch.nn.Module):
@@ -44,9 +42,8 @@ class TestAnd(PytorchLayerTest):
def forward(self, int_a: int, int_b: int):
return int_a & int_b
- ref_net = None
- return aten_and_int(), ref_net, "aten::__and__"
+ return aten_and_int(), "aten::__and__"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_angle.py b/tests/layer_tests/pytorch_tests/test_angle.py
index 359b15e77a4..26f0d11054c 100644
--- a/tests/layer_tests/pytorch_tests/test_angle.py
+++ b/tests/layer_tests/pytorch_tests/test_angle.py
@@ -12,7 +12,7 @@ class TestAngle(PytorchLayerTest):
shape = (5, 6, 7)
if complex_type:
shape += (2,)
- return [np.random.uniform(-10, 10, shape).astype(np.float32)]
+ return [self.random.uniform(-10, 10, shape, dtype=np.float32)]
def create_model(self, complex_type):
import torch
@@ -28,7 +28,7 @@ class TestAngle(PytorchLayerTest):
res = torch.angle(x)
return res
- return aten_angle(complex_type), None, "aten::angle"
+ return aten_angle(complex_type), "aten::angle"
@pytest.mark.parametrize("complex_type", [True, False])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_any.py b/tests/layer_tests/pytorch_tests/test_any.py
index 793af890752..d80a55e8e70 100644
--- a/tests/layer_tests/pytorch_tests/test_any.py
+++ b/tests/layer_tests/pytorch_tests/test_any.py
@@ -81,10 +81,10 @@ class TestAny(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_any_noparams(self, input_shape, d_type, out, ie_device, precision, ir_version):
if type(input_shape) is list:
- self.input_tensor = np.random.randint(0, 2, input_shape, dtype=d_type)
+ self.input_tensor = self.random.randint(0, 2, input_shape, dtype=d_type)
else:
self.input_tensor = input_shape
- self._test(aten_any_noparam() if not out else aten_any_noparam_out(), None, "aten::any",
+ self._test(aten_any_noparam() if not out else aten_any_noparam_out(), "aten::any",
ie_device, precision, ir_version, trace_model=True, freeze_model=False, kwargs_to_prepare_input={"out": out})
@pytest.mark.parametrize("input_shape, d_type", [
@@ -114,9 +114,9 @@ class TestAny(PytorchLayerTest):
reason='Ticket - 122715')
def test_any(self, input_shape, d_type, keepdim, out, ie_device, precision, ir_version):
if type(input_shape) is list:
- self.input_tensor = np.random.randint(0, 2, input_shape, dtype=d_type)
+ self.input_tensor = self.random.randint(0, 2, input_shape, dtype=d_type)
else:
self.input_tensor = input_shape
for dim in range(len(self.input_tensor.shape)):
- self._test(aten_any(dim, keepdim) if not out else aten_any_out(dim, keepdim), None, "aten::any",
+ self._test(aten_any(dim, keepdim) if not out else aten_any_out(dim, keepdim), "aten::any",
ie_device, precision, ir_version, trace_model=True, freeze_model=False, kwargs_to_prepare_input={"out": out})
diff --git a/tests/layer_tests/pytorch_tests/test_arange.py b/tests/layer_tests/pytorch_tests/test_arange.py
index c099ee36ba6..eefb4c32817 100644
--- a/tests/layer_tests/pytorch_tests/test_arange.py
+++ b/tests/layer_tests/pytorch_tests/test_arange.py
@@ -22,7 +22,7 @@ class TestArange(PytorchLayerTest):
def forward(self, end):
return torch.arange(end)
- self._test(aten_arange_end(), None, "aten::arange",
+ self._test(aten_arange_end(), "aten::arange",
ie_device, precision, ir_version, trace_model=True,
kwargs_to_prepare_input={"end": end})
@@ -40,7 +40,7 @@ class TestArange(PytorchLayerTest):
def forward(self, end):
return torch.arange(end, dtype=self.dtype)
- self._test(aten_arange_end_dtype(dtype), None, "aten::arange",
+ self._test(aten_arange_end_dtype(dtype), "aten::arange",
ie_device, precision, ir_version, trace_model=True,
kwargs_to_prepare_input={"end": end})
@@ -54,7 +54,7 @@ class TestArange(PytorchLayerTest):
def forward(self, end, ref):
return torch.arange(end, dtype=ref.dtype)
- self._test(aten_arange_end_prim_dtype(), None, ["aten::arange", "prim::dtype"],
+ self._test(aten_arange_end_prim_dtype(), ["aten::arange", "prim::dtype"],
ie_device, precision, ir_version,
kwargs_to_prepare_input={"end": end,
"ref_value": torch.tensor(1, dtype=dtype).numpy()})
@@ -70,7 +70,7 @@ class TestArange(PytorchLayerTest):
def forward(self, start, end):
return torch.arange(start, end)
- self._test(aten_arange_start_end(), None, "aten::arange",
+ self._test(aten_arange_start_end(), "aten::arange",
ie_device, precision, ir_version, trace_model=True,
kwargs_to_prepare_input={"start": start, "end": end})
@@ -94,7 +94,7 @@ class TestArange(PytorchLayerTest):
def forward(self, start, end):
return torch.arange(start, end, dtype=self.dtype)
- self._test(aten_arange_start_end_dtype(dtype), None, "aten::arange",
+ self._test(aten_arange_start_end_dtype(dtype), "aten::arange",
ie_device, precision, ir_version, trace_model=True,
kwargs_to_prepare_input={"start": start, "end": end})
@@ -115,7 +115,7 @@ class TestArange(PytorchLayerTest):
def forward(self, start, end, ref):
return torch.arange(start, end, dtype=ref.dtype)
- self._test(aten_arange_start_end_prim_dtype(), None, ["aten::arange", "prim::dtype"],
+ self._test(aten_arange_start_end_prim_dtype(), ["aten::arange", "prim::dtype"],
ie_device, precision, ir_version,
kwargs_to_prepare_input={"start": start, "end": end,
"ref_value": torch.tensor(1, dtype=dtype).numpy()})
@@ -134,7 +134,7 @@ class TestArange(PytorchLayerTest):
def forward(self, start, end, step):
return torch.arange(start, end, step)
- self._test(aten_arange_start_end_step(), None, "aten::arange",
+ self._test(aten_arange_start_end_step(), "aten::arange",
ie_device, precision, ir_version, trace_model=True,
kwargs_to_prepare_input={"start": start, "end": end, "step": step})
@@ -162,7 +162,7 @@ class TestArange(PytorchLayerTest):
def forward(self, start, end, step):
return torch.arange(start, end, step, dtype=self.dtype)
- self._test(aten_arange_start_end_step_dtype(dtype), None, "aten::arange",
+ self._test(aten_arange_start_end_step_dtype(dtype), "aten::arange",
ie_device, precision, ir_version, trace_model=True,
kwargs_to_prepare_input={"start": start, "end": end, "step": step})
@@ -188,7 +188,7 @@ class TestArange(PytorchLayerTest):
ref = ref.to(self.dtype)
return torch.arange(start, end, step, dtype=ref.dtype)
- self._test(aten_arange_start_end_step_prim_dtype(dtype), None, ["aten::arange", "prim::dtype"],
+ self._test(aten_arange_start_end_step_prim_dtype(dtype), ["aten::arange", "prim::dtype"],
ie_device, precision, ir_version,
kwargs_to_prepare_input={"start": start, "end": end, "step": step,
"ref_value": torch.tensor(1, dtype=dtype).numpy()})
@@ -217,7 +217,7 @@ class TestArangeLegacy(PytorchLayerTest):
class aten_arange_end_dtype(torch.nn.Module):
def __init__(self, dtype) -> None:
- super(aten_arange_end_dtype, self).__init__()
+ super().__init__()
self.dtype = dtype
def forward(self, x):
@@ -225,7 +225,7 @@ class TestArangeLegacy(PytorchLayerTest):
class aten_arange_start_end_dtype(torch.nn.Module):
def __init__(self, dtype) -> None:
- super(aten_arange_start_end_dtype, self).__init__()
+ super().__init__()
self.dtype = dtype
def forward(self, x, y):
@@ -233,7 +233,7 @@ class TestArangeLegacy(PytorchLayerTest):
class aten_arange_start_end_step_dtype(torch.nn.Module):
def __init__(self, dtype) -> None:
- super(aten_arange_start_end_step_dtype, self).__init__()
+ super().__init__()
self.dtype = dtype
def forward(self, x, y, z):
@@ -241,7 +241,7 @@ class TestArangeLegacy(PytorchLayerTest):
class aten_arange_end_out(torch.nn.Module):
def __init__(self, dtype) -> None:
- super(aten_arange_end_out, self).__init__()
+ super().__init__()
self.dtype = dtype
def forward(self, x):
@@ -249,7 +249,7 @@ class TestArangeLegacy(PytorchLayerTest):
class aten_arange_start_end_out(torch.nn.Module):
def __init__(self, out) -> None:
- super(aten_arange_start_end_out, self).__init__()
+ super().__init__()
self.out = out
def forward(self, x, y):
@@ -257,7 +257,7 @@ class TestArangeLegacy(PytorchLayerTest):
class aten_arange_start_end_step_out(torch.nn.Module):
def __init__(self, out) -> None:
- super(aten_arange_start_end_step_out, self).__init__()
+ super().__init__()
self.out = out
def forward(self, x, y, z):
@@ -291,9 +291,8 @@ class TestArangeLegacy(PytorchLayerTest):
else:
model_class = model_classes[num_inputs][1](dtype)
- ref_net = None
- return model_class, ref_net, "aten::arange"
+ return model_class, "aten::arange"
@pytest.mark.nightly
@pytest.mark.precommit_torch_export
diff --git a/tests/layer_tests/pytorch_tests/test_argmax_argmin.py b/tests/layer_tests/pytorch_tests/test_argmax_argmin.py
index b886fe5eaed..b39ed02ba6e 100644
--- a/tests/layer_tests/pytorch_tests/test_argmax_argmin.py
+++ b/tests/layer_tests/pytorch_tests/test_argmax_argmin.py
@@ -10,8 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestArgMinArgMax(PytorchLayerTest):
def _prepare_input(self, dtype="float32"):
- import numpy as np
- a = np.random.randn(1, 3, 10, 10).astype(dtype)
+ a = self.random.randn(1, 3, 10, 10, dtype=dtype)
return (a.repeat(2).reshape(1, 3, 20, 10),)
@@ -27,7 +26,7 @@ class TestArgMinArgMax(PytorchLayerTest):
class aten_argmin_argmax(torch.nn.Module):
def __init__(self, op):
- super(aten_argmin_argmax, self).__init__()
+ super().__init__()
self.op = op
def forward(self, x):
@@ -43,13 +42,12 @@ class TestArgMinArgMax(PytorchLayerTest):
def forward(self, x):
return self.op(x, self.axes, self.keep_dims)
- ref_net = None
if axes is None and keep_dims is None:
model_cls = aten_argmin_argmax(op)
else:
model_cls = aten_argmin_argmax_3arg(op, axes, keep_dims)
- return model_cls, ref_net, f"aten::arg{op_type}"
+ return model_cls, f"aten::arg{op_type}"
@pytest.mark.parametrize("axes,keep_dims", [
(None, None),
diff --git a/tests/layer_tests/pytorch_tests/test_argsort.py b/tests/layer_tests/pytorch_tests/test_argsort.py
index 352ff9dd02c..febab899651 100644
--- a/tests/layer_tests/pytorch_tests/test_argsort.py
+++ b/tests/layer_tests/pytorch_tests/test_argsort.py
@@ -32,9 +32,8 @@ class TestArgSort(PytorchLayerTest):
dim = self.dim,
descending = self.descending
)
- ref_net = None
- return aten_argsort(dim, descending, stable), ref_net, "aten::argsort"
+ return aten_argsort(dim, descending, stable), "aten::argsort"
@pytest.mark.parametrize("tensor_stable_pair", [
([1, 4], False),
@@ -74,7 +73,7 @@ class TestArgSort(PytorchLayerTest):
def test_argsort(self, tensor_stable_pair, descending, ie_device, precision, ir_version):
input_shape, stable = tensor_stable_pair
if type(input_shape) is list:
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
else:
self.input_tensor = input_shape
dims = len(self.input_tensor.shape)
diff --git a/tests/layer_tests/pytorch_tests/test_as_strided.py b/tests/layer_tests/pytorch_tests/test_as_strided.py
index f27beb7a95a..685eb883929 100644
--- a/tests/layer_tests/pytorch_tests/test_as_strided.py
+++ b/tests/layer_tests/pytorch_tests/test_as_strided.py
@@ -10,7 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestAsStrided(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(8, 8).astype(np.float32),)
+ return (self.random.randn(8, 8),)
def create_model(self, size, stride, offset):
class aten_as_strided(torch.nn.Module):
@@ -23,9 +23,8 @@ class TestAsStrided(PytorchLayerTest):
def forward(self, x):
return torch.as_strided(x, self.size, self.stride, self.offset)
- ref_net = None
- return aten_as_strided(size, stride, offset), ref_net, "aten::as_strided"
+ return aten_as_strided(size, stride, offset), "aten::as_strided"
@pytest.mark.parametrize(
"size,stride",
@@ -47,7 +46,7 @@ class TestAsStrided(PytorchLayerTest):
class TestAsStridedCopy(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(8, 8).astype(np.float32),)
+ return (self.random.randn(8, 8),)
def create_model(self, size, stride, offset):
class aten_as_strided_copy(torch.nn.Module):
@@ -60,9 +59,8 @@ class TestAsStridedCopy(PytorchLayerTest):
def forward(self, x):
return torch.as_strided_copy(x, self.size, self.stride, self.offset)
- ref_net = None
- return aten_as_strided_copy(size, stride, offset), ref_net, "aten::as_strided_copy"
+ return aten_as_strided_copy(size, stride, offset), "aten::as_strided_copy"
@pytest.mark.parametrize(
"size,stride",
@@ -83,7 +81,7 @@ class TestAsStridedCopy(PytorchLayerTest):
class TestAsStridedListConstruct(PytorchLayerTest):
def _prepare_input(self, size_shape_tensor=[1], stride_shape_tensor=[1]):
return (
- np.random.randn(8, 8).astype(np.float32),
+ self.random.randn(8, 8),
np.ones(size_shape_tensor),
np.ones(stride_shape_tensor),
)
@@ -117,9 +115,8 @@ class TestAsStridedListConstruct(PytorchLayerTest):
st1, st2, st3 = stride_shape_tensor.shape
return torch.as_strided(x, self.size, [st1, st2, st3], self.offset)
- ref_net = None
- return aten_as_strided(size, stride, offset, mode), ref_net, ["aten::as_strided", "prim::ListConstruct"]
+ return aten_as_strided(size, stride, offset, mode), ["aten::as_strided", "prim::ListConstruct"]
@pytest.mark.parametrize("size,stride", [([5, 4, 3], [1, 3, 7]), ([5, 5, 5], [5, 0, 5])])
@pytest.mark.parametrize("offset", [None, 7])
@@ -143,7 +140,7 @@ class TestAsStridedListConstruct(PytorchLayerTest):
class TestAsStridedLongformer(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(1, 10, 20, 40).astype(np.float32).transpose([0, 2, 3, 1]),)
+ return (self.random.randn(1, 10, 20, 40).transpose([0, 2, 3, 1]),)
def create_model(self):
class aten_as_strided_lf(torch.nn.Module):
@@ -154,9 +151,8 @@ class TestAsStridedLongformer(PytorchLayerTest):
chunk_stride[1] = chunk_stride[1] // 2
return x.as_strided(size=chunk_size, stride=chunk_stride)
- ref_net = None
- return aten_as_strided_lf(), ref_net, "aten::as_strided"
+ return aten_as_strided_lf(), "aten::as_strided"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_atan2.py b/tests/layer_tests/pytorch_tests/test_atan2.py
index 9c67ab459b8..4863c1daa6a 100644
--- a/tests/layer_tests/pytorch_tests/test_atan2.py
+++ b/tests/layer_tests/pytorch_tests/test_atan2.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -15,48 +14,46 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestAtan2(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 5, 3, 4).astype(np.float32), self.input_rhs)
+ return (self.random.randn(2, 5, 3, 4), self.input_rhs)
def create_model(self):
class aten_atan2(torch.nn.Module):
def __init__(self):
- super(aten_atan2, self).__init__()
+ super().__init__()
def forward(self, lhs, rhs):
return torch.arctan2(lhs, rhs)
- ref_net = None
- return aten_atan2(), ref_net, "aten::atan2"
+ return aten_atan2(), "aten::atan2"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@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.input_rhs = self.random.randn(*input_shape_rhs)
self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True, fx_kind="aten.arctan2")
class TestAtan2Types(PytorchLayerTest):
def _prepare_input(self):
- return (torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),
- torch.randn(self.rhs_shape).to(self.rhs_type).numpy())
+ return (self.random.randn(*self.lhs_shape, dtype=self.lhs_type),
+ self.random.randn(*self.rhs_shape, dtype=self.rhs_type))
def create_model(self, lhs_type, rhs_type):
class aten_atan2(torch.nn.Module):
def __init__(self, lhs_type, rhs_type):
- super(aten_atan2, self).__init__()
+ super().__init__()
self.lhs_type = lhs_type
self.rhs_type = rhs_type
def forward(self, lhs, rhs):
return torch.arctan2(lhs.to(self.lhs_type), rhs.to(self.rhs_type))
- ref_net = None
- return aten_atan2(lhs_type, rhs_type), ref_net, "aten::atan2"
+ return aten_atan2(lhs_type, rhs_type), "aten::atan2"
@pytest.mark.parametrize(("lhs_type", "rhs_type"),
[[torch.int, torch.float32],
diff --git a/tests/layer_tests/pytorch_tests/test_batch_norm.py b/tests/layer_tests/pytorch_tests/test_batch_norm.py
index 20a6ae7427e..efb8955cefe 100644
--- a/tests/layer_tests/pytorch_tests/test_batch_norm.py
+++ b/tests/layer_tests/pytorch_tests/test_batch_norm.py
@@ -7,10 +7,9 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestBatchNorm(PytorchLayerTest):
def _prepare_input(self, ndim=4):
- import numpy as np
shape5d = [20, 6, 10, 10, 10]
shape = shape5d[:ndim]
- return (np.random.randn(*shape).astype(np.float32),)
+ return (self.random.randn(*shape),)
def create_model(self, weights, bias, eps, train, running_stats):
@@ -18,32 +17,31 @@ class TestBatchNorm(PytorchLayerTest):
import torch.nn.functional as F
class aten_batch_norm_inference(torch.nn.Module):
- def __init__(self, weights=True, bias=True, eps=1e-05):
- super(aten_batch_norm_inference, self).__init__()
- self.weight = torch.randn(6) if weights else None
- self.bias = torch.randn(6) if bias else None
- self.running_mean = torch.randn(6)
- self.running_var = torch.randn(6)
+ def __init__(self, rng, weights=True, bias=True, eps=1e-05):
+ super().__init__()
+ self.weight = rng.torch_randn(6) if weights else None
+ self.bias = rng.torch_randn(6) if bias else None
+ self.running_mean = rng.torch_randn(6)
+ self.running_var = rng.torch_randn(6)
self.eps = eps
def forward(self, x):
return F.batch_norm(x, self.running_mean, self.running_var, self.weight, self.bias, eps=self.eps, training=False)
class aten_batch_norm_train(torch.nn.Module):
- def __init__(self, weights=True, bias=True, eps=1e-05, running_stats=False):
- super(aten_batch_norm_train, self).__init__()
- self.weight = torch.randn(6) if weights else None
- self.bias = torch.randn(6) if bias else None
- self.running_mean = torch.randn(6) if running_stats else None
- self.running_var = torch.randn(6) if running_stats else None
+ def __init__(self, rng, weights=True, bias=True, eps=1e-05, running_stats=False):
+ super().__init__()
+ self.weight = rng.torch_randn(6) if weights else None
+ self.bias = rng.torch_randn(6) if bias else None
+ self.running_mean = rng.torch_randn(6) if running_stats else None
+ self.running_var = rng.torch_randn(6) if running_stats else None
self.eps = eps
def forward(self, x):
return F.batch_norm(x, self.running_mean, self.running_var, self.weight, self.bias, eps=self.eps, training=True)
- ref_net = None
- return aten_batch_norm_inference(weights, bias, eps) if not train else aten_batch_norm_train(weights, bias, eps, running_stats), ref_net, "aten::batch_norm"
+ return aten_batch_norm_inference(self.random, weights, bias, eps) if not train else aten_batch_norm_train(self.random, weights, bias, eps, running_stats), "aten::batch_norm"
@pytest.mark.parametrize("weights", [True, False])
@pytest.mark.parametrize("bias", [True, False])
diff --git a/tests/layer_tests/pytorch_tests/test_bernoulli.py b/tests/layer_tests/pytorch_tests/test_bernoulli.py
index f69e6412450..bc88c88dc61 100644
--- a/tests/layer_tests/pytorch_tests/test_bernoulli.py
+++ b/tests/layer_tests/pytorch_tests/test_bernoulli.py
@@ -39,9 +39,8 @@ class TestBernoulli(PytorchLayerTest):
bernoulli_res = torch.bernoulli(input, generator=self.gen, out=out)
return bernoulli_res
- ref_net = None
- return aten_bernoulli(out, seed), ref_net, "aten::bernoulli"
+ return aten_bernoulli(out, seed), "aten::bernoulli"
@pytest.mark.parametrize("input", [
np.array([[0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0]]),
@@ -86,9 +85,8 @@ class TestBernoulliWithP(PytorchLayerTest):
bernoulli_res = torch.bernoulli(input, self.p, generator=self.gen)
return bernoulli_res
- ref_net = None
- return aten_bernoulli(p, seed), ref_net, "aten::bernoulli"
+ return aten_bernoulli(p, seed), "aten::bernoulli"
@pytest.mark.parametrize("input", [
np.array([[0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0]]),
diff --git a/tests/layer_tests/pytorch_tests/test_bitwise_ops.py b/tests/layer_tests/pytorch_tests/test_bitwise_ops.py
index eb11ae0be29..f0773a7f36e 100644
--- a/tests/layer_tests/pytorch_tests/test_bitwise_ops.py
+++ b/tests/layer_tests/pytorch_tests/test_bitwise_ops.py
@@ -12,10 +12,10 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestBitwiseOp(PytorchLayerTest):
def _prepare_input(self, out, unary, lhs_dtype, rhs_dtype, lhs_shape, rhs_shape):
choices = np.array([0, 1, 255, 7])
- x = np.random.choice(choices, lhs_shape).astype(lhs_dtype)
+ x = self.random.choice(choices, lhs_shape).astype(lhs_dtype)
if unary:
return (x,) if not out else (x, np.zeros_like(x).astype(lhs_dtype))
- y = np.random.choice(choices, rhs_shape).astype(rhs_dtype)
+ y = self.random.choice(choices, rhs_shape).astype(rhs_dtype)
if not out:
return x, y
return x, y, np.zeros_like(x).astype(lhs_dtype) + np.zeros_like(y).astype(rhs_dtype)
@@ -50,9 +50,8 @@ class TestBitwiseOp(PytorchLayerTest):
def forward_not_out(self, tensor_a, out):
return self.op(tensor_a, out=out), out
- ref_net = None
- return aten_bitwise(op, out), ref_net, f"aten::bitwise_{op_name}"
+ return aten_bitwise(op, out), f"aten::bitwise_{op_name}"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -97,8 +96,8 @@ class TestBitwiseOp(PytorchLayerTest):
class TestBitwiseOperators(PytorchLayerTest):
def _prepare_input(self, lhs_dtype, rhs_dtype, lhs_shape, rhs_shape):
choices = np.array([0, 1, 255, 7])
- x = np.random.choice(choices, lhs_shape).astype(lhs_dtype)
- y = np.random.choice(choices, rhs_shape).astype(rhs_dtype)
+ x = self.random.choice(choices, lhs_shape).astype(lhs_dtype)
+ y = self.random.choice(choices, rhs_shape).astype(rhs_dtype)
return x, y
def create_model(self):
@@ -106,9 +105,8 @@ class TestBitwiseOperators(PytorchLayerTest):
def forward(self, lhs, rhs):
return lhs & rhs, ~lhs, lhs | rhs, lhs ^ rhs
- ref_net = None
- return aten_bitwise(), ref_net, ("aten::__and__", "aten::bitwise_not", "aten::__or__", "aten::__xor__")
+ return aten_bitwise(), ("aten::__and__", "aten::bitwise_not", "aten::__or__", "aten::__xor__")
@pytest.mark.nightly
@pytest.mark.precommit
@@ -147,8 +145,8 @@ class TestBitwiseOperators(PytorchLayerTest):
class TestBitwiseInplaceOp(PytorchLayerTest):
def _prepare_input(self, lhs_shape, rhs_shape, dtype):
choices = np.array([0, 1, 255, 7])
- x = np.random.choice(choices, lhs_shape).astype(dtype)
- y = np.random.choice(choices, rhs_shape).astype(dtype)
+ x = self.random.choice(choices, lhs_shape).astype(dtype)
+ y = self.random.choice(choices, rhs_shape).astype(dtype)
return x, y
def create_model(self, op):
@@ -171,7 +169,7 @@ class TestBitwiseInplaceOp(PytorchLayerTest):
def forward_xor(self, lhs, rhs):
return lhs.__ixor__(rhs)
- return aten_bitwise(op), None, op
+ return aten_bitwise(op), op
@pytest.mark.skipif(PytorchLayerTest.use_torch_export() and parse_version(torch.__version__) < parse_version("2.6.0"), reason="unsupported on pytorch before 2.6 with torch.export")
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_bool.py b/tests/layer_tests/pytorch_tests/test_bool.py
index 440bc9e7063..6ae310ebcf9 100644
--- a/tests/layer_tests/pytorch_tests/test_bool.py
+++ b/tests/layer_tests/pytorch_tests/test_bool.py
@@ -9,14 +9,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestBool(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
- return (np.random.randint(0, 10, 1).astype(np.int32),)
+ return (self.random.randint(0, 10, 1, dtype=np.int32),)
def create_model(self, input_type):
import torch
class prim_bool(torch.nn.Module):
def __init__(self, input_type):
- super(prim_bool, self).__init__()
+ super().__init__()
self.forward = self.forward_tensor if input_type != "scalar" else self.forward_scalar
def forward_tensor(self, x):
@@ -25,9 +25,8 @@ class TestBool(PytorchLayerTest):
def forward_scalar(self, x:int):
return bool(x)
- ref_net = None
- return prim_bool(input_type), ref_net, "aten::Bool"
+ return prim_bool(input_type), "aten::Bool"
@pytest.mark.parametrize("input_type", ["tensor", "scalar"])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py b/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py
index c410b645339..6a5908927c6 100644
--- a/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py
+++ b/tests/layer_tests/pytorch_tests/test_broadcast_tensors.py
@@ -8,11 +8,10 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestBroadcastTensors(PytorchLayerTest):
def _prepare_input(self, x_shape, y_shape, z_shape, x_dtype, y_dtype, z_dtype):
- import numpy as np
return (
- np.random.randn(*x_shape).astype(x_dtype),
- np.random.randn(*y_shape).astype(y_dtype),
- np.random.randn(*z_shape).astype(z_dtype))
+ self.random.randn(*x_shape, dtype=x_dtype),
+ self.random.randn(*y_shape, dtype=y_dtype),
+ self.random.randn(*z_shape, dtype=z_dtype))
def create_model(self):
import torch
@@ -22,7 +21,7 @@ class TestBroadcastTensors(PytorchLayerTest):
x1, y1, z1 = torch.broadcast_tensors(x, y, z)
return x1, y1, z1
- return aten_broadcast_tensors(), None, ("prim::ListConstruct", "aten::broadcast_tensors", "prim::ListUnpack")
+ return aten_broadcast_tensors(), ("prim::ListConstruct", "aten::broadcast_tensors", "prim::ListUnpack")
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_bucketize.py b/tests/layer_tests/pytorch_tests/test_bucketize.py
index cc6b070f278..f4465b17690 100644
--- a/tests/layer_tests/pytorch_tests/test_bucketize.py
+++ b/tests/layer_tests/pytorch_tests/test_bucketize.py
@@ -12,7 +12,7 @@ class TestBucketize(PytorchLayerTest):
def _prepare_input(self, input_shape, boundaries_range, input_dtype, boundaries_dtype):
return (
- np.random.randn(*input_shape).astype(input_dtype),
+ self.random.randn(*input_shape, dtype=input_dtype),
np.arange(*boundaries_range).astype(boundaries_dtype))
def create_model(self, out_int32, right, is_out):
@@ -33,9 +33,8 @@ class TestBucketize(PytorchLayerTest):
else:
return torch.bucketize(input, boundaries, out_int32=self.out_int32, right=self.right)
- ref_net = None
- return aten_bucketize(out_int32, right, is_out), ref_net, "aten::bucketize"
+ return aten_bucketize(out_int32, right, is_out), "aten::bucketize"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_cat.py b/tests/layer_tests/pytorch_tests/test_cat.py
index 252ed58474f..c427147aa84 100644
--- a/tests/layer_tests/pytorch_tests/test_cat.py
+++ b/tests/layer_tests/pytorch_tests/test_cat.py
@@ -86,8 +86,7 @@ class aten_cat_single_complex(aten_cat_complex):
class TestCat(PytorchLayerTest):
def _prepare_input(self, out=False, num_repeats=2):
- import numpy as np
- data = np.random.randn(3, 1, 2)
+ data = self.random.randn(3, 1, 2)
if not out:
return (data, )
concat = [data for _ in range(num_repeats)]
@@ -100,7 +99,7 @@ class TestCat(PytorchLayerTest):
@pytest.mark.parametrize("out", [False, True])
def test_cat(self, out, ie_device, precision, ir_version):
model = aten_cat() if not out else aten_cat_out()
- self._test(model, None, ["aten::cat", "prim::ListConstruct"],
+ self._test(model, ["aten::cat", "prim::ListConstruct"],
ie_device, precision, ir_version,
kwargs_to_prepare_input={"out": out, "num_repeats": 2})
@@ -108,7 +107,7 @@ class TestCat(PytorchLayerTest):
@pytest.mark.precommit
def test_single_cat(self, ie_device, precision, ir_version):
model = aten_single_cat()
- self._test(model, None, ["aten::cat", "prim::ListConstruct"],
+ self._test(model, ["aten::cat", "prim::ListConstruct"],
ie_device, precision, ir_version)
@@ -117,7 +116,7 @@ class TestCat(PytorchLayerTest):
@pytest.mark.parametrize("out", [False, True])
def test_append_cat(self, out, ie_device, precision, ir_version):
model = aten_append_cat() if not out else aten_append_cat_out()
- self._test(model, None, ["aten::cat", "aten::append", "prim::ListConstruct"],
+ self._test(model, ["aten::cat", "aten::append", "prim::ListConstruct"],
ie_device, precision, ir_version,
kwargs_to_prepare_input={"out": out, "num_repeats": 2})
@@ -126,7 +125,7 @@ class TestCat(PytorchLayerTest):
@pytest.mark.parametrize("out", [False, pytest.param(True, marks=pytest.mark.xfail(reason="out case is not supported"))])
def test_loop_append_cat(self, out, ie_device, precision, ir_version):
model = aten_loop_append_cat() if not out else aten_loop_append_cat_out()
- self._test(model, None, ["aten::cat", "aten::append", "prim::ListConstruct", "prim::Loop"],
+ self._test(model, ["aten::cat", "aten::append", "prim::ListConstruct", "prim::Loop"],
ie_device, precision, ir_version, freeze_model=False,
kwargs_to_prepare_input={"out": out, "num_repeats": 3})
@@ -135,7 +134,7 @@ class TestCat(PytorchLayerTest):
@pytest.mark.parametrize("out", [False, True])
def test_add_cat(self, out, ie_device, precision, ir_version):
model = aten_add_cat() if not out else aten_add_cat_out()
- self._test(model, None, ["aten::cat", "aten::add", "prim::ListConstruct"],
+ self._test(model, ["aten::cat", "aten::add", "prim::ListConstruct"],
ie_device, precision, ir_version, freeze_model=False,
kwargs_to_prepare_input={"out": out, "num_repeats": 4})
@@ -143,14 +142,14 @@ class TestCat(PytorchLayerTest):
@pytest.mark.precommit
def test_cat_complex(self, ie_device, precision, ir_version):
model = aten_cat_complex()
- self._test(model, None, ["aten::cat", "prim::ListConstruct"],
+ self._test(model, ["aten::cat", "prim::ListConstruct"],
ie_device, precision, ir_version, freeze_model=False)
@pytest.mark.nightly
@pytest.mark.precommit
def test_cat_single_complex(self, ie_device, precision, ir_version):
model = aten_cat_single_complex()
- self._test(model, None, ["aten::cat", "prim::ListConstruct"],
+ self._test(model, ["aten::cat", "prim::ListConstruct"],
ie_device, precision, ir_version, freeze_model=False)
@@ -158,7 +157,7 @@ class TestCatAlignTypes(PytorchLayerTest):
def _prepare_input(self, in_types):
in_vals = []
for dtype in in_types:
- in_vals.append(np.random.randn(2, 1, 3).astype(dtype))
+ in_vals.append(self.random.randn(2, 1, 3, dtype=dtype))
return in_vals
def create_model(self, in_count):
@@ -201,21 +200,21 @@ class TestCatAlignTypes(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_align_types_cat(self, ie_device, precision, ir_version, in_types, trace_model):
- self._test(self.create_model(len(in_types)), None, ["aten::cat", "prim::ListConstruct"],
+ self._test(self.create_model(len(in_types)), ["aten::cat", "prim::ListConstruct"],
ie_device, precision, ir_version,
kwargs_to_prepare_input={"in_types": in_types}, trace_model=trace_model)
class TestCatAlignTypesPT(PytorchLayerTest):
def _prepare_input(self, in_types):
- in_vals = [np.random.randn(2, 2, 3).astype(in_types[0])]
+ in_vals = [self.random.randn(2, 2, 3, dtype=in_types[0])]
return in_vals
def create_model_param_first(self, in_types):
class aten_align_types_cat_two_args(torch.nn.Module):
- def __init__(self):
- super(aten_align_types_cat_two_args, self).__init__()
- self.y = torch.randn(2, 1, 3).to(in_types[1])
+ def __init__(self, rng):
+ super().__init__()
+ self.y = rng.torch_randn(2, 1, 3).to(in_types[1])
def forward(self, x):
x_ = torch.split(x, 1, 1)[1]
@@ -223,10 +222,10 @@ class TestCatAlignTypesPT(PytorchLayerTest):
return torch.cat(ins, 1)
class aten_align_types_cat_three_args(torch.nn.Module):
- def __init__(self):
- super(aten_align_types_cat_three_args, self).__init__()
- self.y = torch.randn(2, 1, 3).to(in_types[1])
- self.z = torch.randn(2, 1, 3).to(in_types[2])
+ def __init__(self, rng):
+ super().__init__()
+ self.y = rng.torch_randn(2, 1, 3).to(in_types[1])
+ self.z = rng.torch_randn(2, 1, 3).to(in_types[2])
def forward(self, x):
x_ = torch.split(x, 1, 1)[1]
@@ -235,36 +234,36 @@ class TestCatAlignTypesPT(PytorchLayerTest):
in_count = len(in_types)
if in_count == 2:
- return aten_align_types_cat_two_args()
+ return aten_align_types_cat_two_args(self.random)
if in_count == 3:
- return aten_align_types_cat_three_args()
+ return aten_align_types_cat_three_args(self.random)
def create_model_param_mid(self, in_types):
class aten_align_types_cat_three_args(torch.nn.Module):
- def __init__(self):
- super(aten_align_types_cat_three_args, self).__init__()
- self.x = torch.randn(2, 1, 3).to(in_types[1])
- self.z = torch.randn(2, 1, 3).to(in_types[2])
+ def __init__(self, rng):
+ super().__init__()
+ self.x = rng.torch_randn(2, 1, 3).to(in_types[1])
+ self.z = rng.torch_randn(2, 1, 3).to(in_types[2])
def forward(self, y):
y_ = torch.split(y, 1, 1)[1]
ins = [self.x, y_, self.z]
return torch.cat(ins, 1)
- return aten_align_types_cat_three_args()
+ return aten_align_types_cat_three_args(self.random)
def create_model_param_last(self, in_types):
class aten_align_types_cat_three_args(torch.nn.Module):
- def __init__(self):
- super(aten_align_types_cat_three_args, self).__init__()
- self.x = torch.randn(2, 1, 3).to(in_types[1])
- self.y = torch.randn(2, 1, 3).to(in_types[2])
+ def __init__(self, rng):
+ super().__init__()
+ self.x = rng.torch_randn(2, 1, 3).to(in_types[1])
+ self.y = rng.torch_randn(2, 1, 3).to(in_types[2])
def forward(self, z):
z_ = torch.split(z, 1, 1)[1]
ins = [self.x, self.y, z_]
return torch.cat(ins, 1)
- return aten_align_types_cat_three_args()
+ return aten_align_types_cat_three_args(self.random)
@pytest.mark.parametrize(("in_types"), [
# Two inputs (param, const)
@@ -293,7 +292,7 @@ class TestCatAlignTypesPT(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_align_types_cat(self, ie_device, precision, ir_version, in_types, trace_model):
- self._test(self.create_model_param_first(in_types), None, ["aten::cat", "prim::ListConstruct"],
+ self._test(self.create_model_param_first(in_types), ["aten::cat", "prim::ListConstruct"],
ie_device, precision, ir_version,
kwargs_to_prepare_input={"in_types": in_types}, trace_model=trace_model)
@@ -309,7 +308,7 @@ class TestCatAlignTypesPT(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_align_types_cat_param_mid(self, ie_device, precision, ir_version, in_types, trace_model):
- self._test(self.create_model_param_mid(in_types), None, ["aten::cat", "prim::ListConstruct"],
+ self._test(self.create_model_param_mid(in_types), ["aten::cat", "prim::ListConstruct"],
ie_device, precision, ir_version,
kwargs_to_prepare_input={"in_types": in_types}, trace_model=trace_model)
@@ -325,6 +324,6 @@ class TestCatAlignTypesPT(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_align_types_cat_param_last(self, ie_device, precision, ir_version, in_types, trace_model):
- self._test(self.create_model_param_last(in_types), None, ["aten::cat", "prim::ListConstruct"],
+ self._test(self.create_model_param_last(in_types), ["aten::cat", "prim::ListConstruct"],
ie_device, precision, ir_version,
kwargs_to_prepare_input={"in_types": in_types}, trace_model=trace_model)
diff --git a/tests/layer_tests/pytorch_tests/test_celu.py b/tests/layer_tests/pytorch_tests/test_celu.py
index a12576a2546..c98d6c5b83b 100644
--- a/tests/layer_tests/pytorch_tests/test_celu.py
+++ b/tests/layer_tests/pytorch_tests/test_celu.py
@@ -10,7 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class aten_celu(torch.nn.Module):
def __init__(self, alpha, dtype, inplace):
- super(aten_celu, self).__init__()
+ super().__init__()
self.alpha = alpha
self.dtype = dtype
self.inplace = inplace
@@ -28,8 +28,7 @@ class aten_celu(torch.nn.Module):
class TestCelu(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 4, 224, 224).astype(np.float32),)
+ return (self.random.randn(2, 4, 224, 224),)
@pytest.mark.nightly
@pytest.mark.precommit
@@ -41,5 +40,5 @@ class TestCelu(PytorchLayerTest):
kwargs = {}
if dtype == torch.float16:
kwargs["custom_eps"] = 1e-2
- self._test(aten_celu(alpha, dtype, inplace), None,
+ self._test(aten_celu(alpha, dtype, inplace),
"aten::celu_" if inplace else "aten::celu", ie_device, precision, ir_version, **kwargs)
diff --git a/tests/layer_tests/pytorch_tests/test_chunk.py b/tests/layer_tests/pytorch_tests/test_chunk.py
index 9f18c30da6c..dd3d8af46c9 100644
--- a/tests/layer_tests/pytorch_tests/test_chunk.py
+++ b/tests/layer_tests/pytorch_tests/test_chunk.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -75,7 +74,7 @@ class aten_chunk_getitem(torch.nn.Module):
class TestChunk(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.rand(*self.input_shape),)
+ return (self.random.rand(*self.input_shape),)
@pytest.mark.parametrize("input_shape", [
(4, 4),
@@ -111,7 +110,7 @@ class TestChunk(PytorchLayerTest):
elif output_chunks == 4:
cls = aten_chunk_4
- self._test(cls(dim, unsafe), None,
+ self._test(cls(dim, unsafe),
"aten::unsafe_chunk" if unsafe else "aten::chunk",
ie_device, precision, ir_version, dynamic_shapes=False,
freeze_model=True, trace_model=True)
@@ -141,7 +140,7 @@ class TestChunk(PytorchLayerTest):
output_chunks += 1 if dim_shape % chunk_size > 0 else 0
for idx in [0, 1, output_chunks - 1]:
- self._test(aten_chunk_getitem(chunks, dim, idx, unsafe), None,
+ self._test(aten_chunk_getitem(chunks, dim, idx, unsafe),
"aten::unsafe_chunk" if unsafe else "aten::chunk",
ie_device, precision, ir_version)
@@ -165,7 +164,7 @@ class aten_chunk_loop_getitem(torch.nn.Module):
class TestChunkLoopGetitem(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.rand(*self.input_shape),)
+ return (self.random.rand(*self.input_shape),)
@pytest.mark.parametrize("input_shape", [
(4, 4),
@@ -185,6 +184,6 @@ class TestChunkLoopGetitem(PytorchLayerTest):
self.input_shape = input_shape
chunk_op = "aten::unsafe_chunk" if unsafe else "aten::chunk"
- self._test(aten_chunk_loop_getitem(chunks, unsafe), None,
+ self._test(aten_chunk_loop_getitem(chunks, unsafe),
[chunk_op, "prim::Loop", "aten::__getitem__"],
ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_clamp.py b/tests/layer_tests/pytorch_tests/test_clamp.py
index b4241101c4a..fea492d038a 100644
--- a/tests/layer_tests/pytorch_tests/test_clamp.py
+++ b/tests/layer_tests/pytorch_tests/test_clamp.py
@@ -8,15 +8,14 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestClamp(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, minimum, maximum, as_tensors=False, op_type='clamp'):
import torch
class aten_clamp(torch.nn.Module):
def __init__(self, minimum, maximum, as_tensors, op_type="clamp"):
- super(aten_clamp, self).__init__()
+ super().__init__()
if minimum is not None and as_tensors:
minimum = torch.tensor(minimum)
self.min = minimum
@@ -37,9 +36,8 @@ class TestClamp(PytorchLayerTest):
def forward_clip_(self, x):
return x.clip_(self.min, self.max), x
- ref_net = None
op_name = f"aten::{op_type}"
- return aten_clamp(minimum, maximum, as_tensors, op_type), ref_net, op_name
+ return aten_clamp(minimum, maximum, as_tensors, op_type), op_name
@pytest.mark.parametrize("minimum,maximum",
[(0., 1.), (-0.5, 1.5), (None, 10.), (None, -10.), (10., None), (-10., None), (100, 200), (1.0, 0.0)])
@@ -56,15 +54,14 @@ class TestClamp(PytorchLayerTest):
class TestClampMin(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, minimum, as_tensor=False, inplace=False):
import torch
class aten_clamp_min(torch.nn.Module):
def __init__(self, minimum, as_tensor, inplace):
- super(aten_clamp_min, self).__init__()
+ super().__init__()
self.min = torch.tensor(minimum) if as_tensor else minimum
if inplace:
self.forward = self.forward_inplace
@@ -77,7 +74,7 @@ class TestClampMin(PytorchLayerTest):
return x
op_name = "aten::clamp_min_" if inplace else "aten::clamp_min"
- return aten_clamp_min(minimum, as_tensor, inplace), None, op_name
+ return aten_clamp_min(minimum, as_tensor, inplace), op_name
@pytest.mark.parametrize("minimum", [0., 1., -1., 0.5, 2])
@pytest.mark.parametrize("as_tensor", [True, False])
@@ -92,15 +89,14 @@ class TestClampMin(PytorchLayerTest):
class TestClampMax(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, maximum, as_tensor=False, inplace=False):
import torch
class aten_clamp_max(torch.nn.Module):
def __init__(self, maximum, as_tensor, inplace):
- super(aten_clamp_max, self).__init__()
+ super().__init__()
self.max = torch.tensor(maximum) if as_tensor else maximum
if inplace:
self.forward = self.forward_inplace
@@ -113,7 +109,7 @@ class TestClampMax(PytorchLayerTest):
return x
op_name = "aten::clamp_max_" if inplace else "aten::clamp_max"
- return aten_clamp_max(maximum, as_tensor, inplace), None, op_name
+ return aten_clamp_max(maximum, as_tensor, inplace), op_name
@pytest.mark.parametrize("maximum", [0., 1., -1., 0.5, 2])
@pytest.mark.parametrize("as_tensor", [True, False])
diff --git a/tests/layer_tests/pytorch_tests/test_clone.py b/tests/layer_tests/pytorch_tests/test_clone.py
index c7241fe05be..8407d8027c8 100644
--- a/tests/layer_tests/pytorch_tests/test_clone.py
+++ b/tests/layer_tests/pytorch_tests/test_clone.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestClone(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self):
import torch
@@ -19,9 +18,8 @@ class TestClone(PytorchLayerTest):
def forward(self, x):
return torch.clone(x)
- ref_net = None
- return aten_clone(), ref_net, "aten::clone"
+ return aten_clone(), "aten::clone"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_col2im.py b/tests/layer_tests/pytorch_tests/test_col2im.py
index 24ab5a47489..7f164354b6e 100644
--- a/tests/layer_tests/pytorch_tests/test_col2im.py
+++ b/tests/layer_tests/pytorch_tests/test_col2im.py
@@ -9,15 +9,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestCol2Im(PytorchLayerTest):
def _prepare_input(self, input_shape):
- import numpy as np
- return (np.random.randn(*input_shape).astype(np.float32),)
+ return (self.random.randn(*input_shape),)
def create_model(self, output_size, kernel_size, dilation, padding, stride):
import torch
class aten_col2im(torch.nn.Module):
def __init__(self, output_size, kernel_size, dilation, padding, stride):
- super(aten_col2im, self).__init__()
+ super().__init__()
self.output_size = output_size
self.kernel_size = kernel_size
self.dilation = dilation
@@ -34,9 +33,8 @@ class TestCol2Im(PytorchLayerTest):
stride=self.stride
)
- ref_net = None
- return aten_col2im(output_size, kernel_size, dilation, padding, stride), ref_net, "aten::col2im"
+ return aten_col2im(output_size, kernel_size, dilation, padding, stride), "aten::col2im"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_comparision.py b/tests/layer_tests/pytorch_tests/test_comparision.py
index aedd089f162..f46e3a74447 100644
--- a/tests/layer_tests/pytorch_tests/test_comparision.py
+++ b/tests/layer_tests/pytorch_tests/test_comparision.py
@@ -9,8 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestComp(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 24, 24).astype(np.float32), np.random.randn(1, 3, 24, 24).astype(np.float32))
+ return (self.random.randn(1, 3, 24, 24), self.random.randn(1, 3, 24, 24))
def create_model(self, op_type):
class aten_eq(torch.nn.Module):
@@ -47,9 +46,8 @@ class TestComp(PytorchLayerTest):
}
model_cls = ops[op_type]
- ref_net = None
- return model_cls(), ref_net, f"aten::{op_type}"
+ return model_cls(), f"aten::{op_type}"
@pytest.mark.parametrize("op", ["eq", "ne", "lt", "gt", "le", "ge"])
@pytest.mark.nightly
@@ -64,11 +62,11 @@ class TestCompMixedTypes(PytorchLayerTest):
def _prepare_input(self):
if len(self.lhs_shape) == 0:
- return (torch.randint(0, 3, self.rhs_shape).to(self.rhs_type).numpy(),)
+ return (self.random.randint(0, 3, size=self.rhs_shape, dtype=self.rhs_type),)
elif len(self.rhs_shape) == 0:
- return (torch.randint(0, 3, self.lhs_shape).to(self.lhs_type).numpy(),)
- return (torch.randint(0, 3, self.lhs_shape).to(self.lhs_type).numpy(),
- torch.randint(0, 3, self.rhs_shape).to(self.rhs_type).numpy())
+ return (self.random.randint(0, 3, size=self.lhs_shape, dtype=self.lhs_type),)
+ return (self.random.randint(0, 3, size=self.lhs_shape, dtype=self.lhs_type),
+ self.random.randint(0, 3, size=self.rhs_shape, dtype=self.rhs_type))
def create_model(self, lhs_type, lhs_shape, rhs_type, rhs_shape, op):
@@ -105,9 +103,8 @@ class TestCompMixedTypes(PytorchLayerTest):
def forward3(self, lhs, rhs):
return self.op_fn(lhs.to(self.lhs_type), rhs.to(self.rhs_type))
- ref_net = None
- return aten_comp(lhs_type, lhs_shape, rhs_type, rhs_shape, op_fn), ref_net, f"aten::{op}"
+ return aten_comp(lhs_type, lhs_shape, rhs_type, rhs_shape, op_fn), f"aten::{op}"
@pytest.mark.parametrize(("lhs_type", "rhs_type"),
[[torch.int32, torch.int64],
diff --git a/tests/layer_tests/pytorch_tests/test_complex.py b/tests/layer_tests/pytorch_tests/test_complex.py
index 0530807264b..86218132742 100644
--- a/tests/layer_tests/pytorch_tests/test_complex.py
+++ b/tests/layer_tests/pytorch_tests/test_complex.py
@@ -9,8 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestComplex(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2).astype(np.float32),)
+ return (self.random.randn(2),)
def create_model(self, dtype):
class complex_model(torch.nn.Module):
@@ -36,7 +35,7 @@ class TestComplex(PytorchLayerTest):
result = real_result + imag_result
return result
- return complex_model(dtype), None, ["prim::GetAttr", "prim::Constant"]
+ return complex_model(dtype), ["prim::GetAttr", "prim::Constant"]
@pytest.mark.nightly
@pytest.mark.precommit
@@ -51,11 +50,10 @@ class TestComplex(PytorchLayerTest):
class TestReal(PytorchLayerTest):
def _prepare_input(self, y):
- import numpy as np
if y:
- return (np.random.randn(2, 3).astype(np.float32),
- np.random.randn(2, 3).astype(np.float32))
- return (np.random.randn(2, 3).astype(np.float32),)
+ return (self.random.randn(2, 3),
+ self.random.randn(2, 3))
+ return (self.random.randn(2, 3),)
def create_model(self):
class aten_real(torch.nn.Module):
@@ -66,7 +64,7 @@ class TestReal(PytorchLayerTest):
c = x
return torch.real(c)
- return aten_real(), None, "aten::real"
+ return aten_real(), "aten::real"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_compressed_mm.py b/tests/layer_tests/pytorch_tests/test_compressed_mm.py
index 24652e223ff..e9d617886d0 100644
--- a/tests/layer_tests/pytorch_tests/test_compressed_mm.py
+++ b/tests/layer_tests/pytorch_tests/test_compressed_mm.py
@@ -43,15 +43,14 @@ def decompress_symmetric(input, scale):
class TestMatMulU4Weights(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (np.round(5.00 * self.rng.random([2, 4], dtype=np.float32) - 2.50, 4),)
+ return (np.round(5.00 * self.random.rand(2, 4) - 2.50, 4),)
def create_model(self, group_size):
class aten_mm_u4(torch.nn.Module):
def __init__(self, compressed_weight, scale, zero_point, weight_shape):
- super(aten_mm_u4, self).__init__()
+ super().__init__()
self.compressed_weight_shape = compressed_weight.shape
self.packed_weight = torch.nn.Parameter(pack_uint4(compressed_weight), requires_grad=False)
@@ -77,22 +76,21 @@ class TestMatMulU4Weights(PytorchLayerTest):
return torch.matmul(x, weight)
- ref_net = None
weight_shape = (4, 2)
ngroups = weight_shape[0] // group_size
compressed_weight_shape = (ngroups, group_size, weight_shape[1])
zero_point_shape = scale_shape = (ngroups, 1, weight_shape[1])
- compressed_weight = (15.00 * self.rng.random(compressed_weight_shape, dtype=np.float32)).astype(dtype=np.uint8)
- scale = np.round(10.00 * self.rng.random(scale_shape, dtype=np.float32) - 5.00)
- zero_point = (15.00 * self.rng.random(zero_point_shape, dtype=np.float32)).astype(dtype=np.uint8)
+ compressed_weight = self.random.randint(0, 16, size=compressed_weight_shape, dtype=np.uint8)
+ scale = self.random.randint(-5, 6, size=scale_shape, dtype=np.int32)
+ zero_point = self.random.randint(0, 16, size=zero_point_shape, dtype=np.uint8)
t_compressed_weight = torch.from_numpy(compressed_weight)
t_scale = torch.from_numpy(scale)
t_zero_point = torch.from_numpy(zero_point)
- return aten_mm_u4(t_compressed_weight, t_scale, t_zero_point, weight_shape), ref_net, ["aten::matmul"]
+ return aten_mm_u4(t_compressed_weight, t_scale, t_zero_point, weight_shape), ["aten::matmul"]
@pytest.mark.nightly
@pytest.mark.precommit
@@ -110,15 +108,14 @@ class TestMatMulU4Weights(PytorchLayerTest):
class TestMatMulI4Weights(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (np.round(5.00 * self.rng.random([2, 4], dtype=np.float32) - 2.50, 4),)
+ return (np.round(5.00 * self.random.rand(2, 4) - 2.50, 4),)
def create_model(self, group_size):
class aten_mm_i4(torch.nn.Module):
def __init__(self, compressed_weight, scale, weight_shape):
- super(aten_mm_i4, self).__init__()
+ super().__init__()
self.compressed_weight_shape = compressed_weight.shape
self.packed_weight = torch.nn.Parameter(pack_int4(compressed_weight), requires_grad=False)
@@ -138,22 +135,19 @@ class TestMatMulI4Weights(PytorchLayerTest):
return torch.matmul(x, weight)
- ref_net = None
weight_shape = (4, 2)
ngroups = weight_shape[0] // group_size
compressed_weight_shape = (ngroups, group_size, weight_shape[1])
scale_shape = (ngroups, 1, weight_shape[1])
- compressed_weight = (16.00 * self.rng.random(compressed_weight_shape, dtype=np.float32) - 8.00).astype(
- dtype=np.int8
- )
- scale = np.round(10.00 * self.rng.random(scale_shape, dtype=np.float32) - 5.00)
+ compressed_weight = self.random.randint(-8, 8, size=compressed_weight_shape, dtype=np.int8)
+ scale = self.random.randint(-5, 6, size=scale_shape, dtype=np.int32)
t_compressed_weight = torch.from_numpy(compressed_weight)
t_scale = torch.from_numpy(scale)
- return aten_mm_i4(t_compressed_weight, t_scale, weight_shape), ref_net, ["aten::matmul"]
+ return aten_mm_i4(t_compressed_weight, t_scale, weight_shape), ["aten::matmul"]
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_cond.py b/tests/layer_tests/pytorch_tests/test_cond.py
index 6827b551618..92d7f1c945d 100644
--- a/tests/layer_tests/pytorch_tests/test_cond.py
+++ b/tests/layer_tests/pytorch_tests/test_cond.py
@@ -10,8 +10,7 @@ class TestCondFX(PytorchLayerTest):
"""Test torch.cond operation for FX export mode."""
def _prepare_input(self):
- rng = np.random.default_rng(43)
- return (rng.normal(size=self.input_shape).astype(np.float32), self.pred_value)
+ return (self.random.randn(*self.input_shape), self.pred_value)
def create_simple_cond_model(self):
import torch
@@ -26,7 +25,7 @@ class TestCondFX(PytorchLayerTest):
return torch.cond(pred, true_fn, false_fn, (x,))
- return SimpleCond(), None, "cond"
+ return SimpleCond(), "cond"
def create_multi_output_cond_model(self):
import torch
@@ -41,7 +40,7 @@ class TestCondFX(PytorchLayerTest):
return torch.cond(pred, true_fn, false_fn, (x,))
- return MultiOutputCond(), None, "cond"
+ return MultiOutputCond(), "cond"
def create_linear_cond_model(self, hidden_size):
import torch
@@ -60,7 +59,7 @@ class TestCondFX(PytorchLayerTest):
return torch.cond(is_prefill, prefill_fn, decode_fn, (x,))
- return LinearCond(hidden_size), None, "cond"
+ return LinearCond(hidden_size), "cond"
@pytest.mark.parametrize("pred_value", [np.array(True), np.array(False)])
@pytest.mark.parametrize("input_shape", [(1, 4), (2, 3, 4)])
diff --git a/tests/layer_tests/pytorch_tests/test_constant_pad_nd.py b/tests/layer_tests/pytorch_tests/test_constant_pad_nd.py
index 856bd40a925..35d4375c0c0 100644
--- a/tests/layer_tests/pytorch_tests/test_constant_pad_nd.py
+++ b/tests/layer_tests/pytorch_tests/test_constant_pad_nd.py
@@ -8,22 +8,21 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestConstantPadND(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 5, 3, 4).astype(np.float32),)
+ return (self.random.randn(2, 5, 3, 4),)
def create_model(self, pad, value):
import torch
class aten_constant_pad_nd(torch.nn.Module):
def __init__(self, pad=None, value=None):
- super(aten_constant_pad_nd, self).__init__()
+ super().__init__()
self.pad = pad
self.value = value
def forward(self, x):
return torch.constant_pad_nd(x, self.pad, self.value)
- return aten_constant_pad_nd(pad, value), None, "aten::constant_pad_nd"
+ return aten_constant_pad_nd(pad, value), "aten::constant_pad_nd"
@pytest.mark.parametrize(("pad", "value"),
[((1,1,1,1), 0),((0,2,0,2), -1.0),((3,1,5,2), 0.5),((0,0,0,0), 0),])
diff --git a/tests/layer_tests/pytorch_tests/test_conv_transposend.py b/tests/layer_tests/pytorch_tests/test_conv_transposend.py
index b10779e5dff..16b7db3e1bf 100644
--- a/tests/layer_tests/pytorch_tests/test_conv_transposend.py
+++ b/tests/layer_tests/pytorch_tests/test_conv_transposend.py
@@ -8,20 +8,19 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestConvTranspose2D(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 10, 10).astype(np.float32),)
+ return (self.random.randn(1, 3, 10, 10),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias, output_padding):
import torch
import torch.nn.functional as F
class aten_conv_transpose2d(torch.nn.Module):
- def __init__(self):
- super(aten_conv_transpose2d, self).__init__()
- self.weight = torch.randn(weights_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape)
self.bias = None
if bias:
- self.bias = torch.randn(groups)
+ self.bias = rng.torch_randn(groups)
self.strides = strides
self.pads = pads
self.dilations = dilations
@@ -31,9 +30,8 @@ class TestConvTranspose2D(PytorchLayerTest):
def forward(self, x):
return F.conv_transpose2d(x, weight=self.weight, bias=self.bias, stride=self.strides, padding=self.pads, output_padding=self.output_padding, dilation=self.dilations, groups=self.groups)
- ref_net = None
- return aten_conv_transpose2d(), ref_net, "aten::conv_transpose2d"
+ return aten_conv_transpose2d(self.random), "aten::conv_transpose2d"
@pytest.mark.parametrize("params",
[{'weights_shape': [3, 1, 1, 1], 'strides': [1, 1], 'pads': [0, 0],
@@ -70,20 +68,19 @@ class TestConvTranspose2D(PytorchLayerTest):
class TestConvTranspose1D(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 10).astype(np.float32),)
+ return (self.random.randn(1, 3, 10),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias, output_padding):
import torch
import torch.nn.functional as F
class aten_conv_transpose1d(torch.nn.Module):
- def __init__(self):
- super(aten_conv_transpose1d, self).__init__()
- self.weight = torch.randn(weights_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape)
self.bias = None
if bias:
- self.bias = torch.randn(groups)
+ self.bias = rng.torch_randn(groups)
self.strides = strides
self.pads = pads
self.dilations = dilations
@@ -102,9 +99,8 @@ class TestConvTranspose1D(PytorchLayerTest):
groups=self.groups
)
- ref_net = None
- return aten_conv_transpose1d(), ref_net, "aten::conv_transpose1d"
+ return aten_conv_transpose1d(self.random), "aten::conv_transpose1d"
@pytest.mark.parametrize("params",
[{'weights_shape': [3, 1, 1], 'strides': 1, 'pads': 0, 'dilations': 1, 'groups': 1, 'output_padding': 0},
@@ -130,20 +126,19 @@ class TestConvTranspose1D(PytorchLayerTest):
class TestConvTranspose3D(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 10, 10, 4).astype(np.float32),)
+ return (self.random.randn(1, 3, 10, 10, 4),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias, output_padding):
import torch
import torch.nn.functional as F
class aten_conv_transpose3d(torch.nn.Module):
- def __init__(self):
- super(aten_conv_transpose3d, self).__init__()
- self.weight = torch.randn(weights_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape)
self.bias = None
if bias:
- self.bias = torch.randn(groups)
+ self.bias = rng.torch_randn(groups)
self.strides = strides
self.pads = pads
self.dilations = dilations
@@ -162,9 +157,8 @@ class TestConvTranspose3D(PytorchLayerTest):
groups=self.groups
)
- ref_net = None
- return aten_conv_transpose3d(), ref_net, "aten::conv_transpose3d"
+ return aten_conv_transpose3d(self.random), "aten::conv_transpose3d"
@pytest.mark.parametrize("params",
[{'weights_shape': [3, 1, 1, 1, 1], 'strides': [1, 1, 1], 'pads': [0, 0, 0],
diff --git a/tests/layer_tests/pytorch_tests/test_convnd.py b/tests/layer_tests/pytorch_tests/test_convnd.py
index b548a4d1a17..0008ce43e16 100644
--- a/tests/layer_tests/pytorch_tests/test_convnd.py
+++ b/tests/layer_tests/pytorch_tests/test_convnd.py
@@ -10,19 +10,19 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestConv2D(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
- return (np.random.randn(2, 3, 25, 25).astype(np.float32),)
+ return (self.random.randn(2, 3, 25, 25),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias):
import torch
import torch.nn.functional as F
class aten_conv2d(torch.nn.Module):
- def __init__(self):
- super(aten_conv2d, self).__init__()
- self.weight = torch.randn(weights_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape)
self.bias = None
if bias:
- self.bias = torch.randn(weights_shape[0])
+ self.bias = rng.torch_randn(weights_shape[0])
self.strides = strides
self.pads = pads
self.dilations = dilations
@@ -31,9 +31,8 @@ class TestConv2D(PytorchLayerTest):
def forward(self, x):
return F.conv2d(x, self.weight, self.bias, self.strides, self.pads, self.dilations, self.groups)
- ref_net = None
- return aten_conv2d(), ref_net, "aten::conv2d"
+ return aten_conv2d(self.random), "aten::conv2d"
@pytest.mark.parametrize("params",
[{'weights_shape': [1, 3, 3, 3], 'strides': 1, 'pads': 0, 'dilations': 1, 'groups': 1},
@@ -62,19 +61,19 @@ class TestConv2D(PytorchLayerTest):
class TestConv1D(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
- return (np.random.randn(2, 3, 25).astype(np.float32),)
+ return (self.random.randn(2, 3, 25),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias):
import torch
import torch.nn.functional as F
class aten_conv1d(torch.nn.Module):
- def __init__(self):
- super(aten_conv1d, self).__init__()
- self.weight = torch.randn(weights_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape)
self.bias = None
if bias:
- self.bias = torch.randn(weights_shape[0])
+ self.bias = rng.torch_randn(weights_shape[0])
self.strides = strides
self.pads = pads
self.dilations = dilations
@@ -83,9 +82,8 @@ class TestConv1D(PytorchLayerTest):
def forward(self, x):
return F.conv1d(x, self.weight, self.bias, self.strides, self.pads, self.dilations, self.groups)
- ref_net = None
- return aten_conv1d(), ref_net, "aten::conv1d"
+ return aten_conv1d(self.random), "aten::conv1d"
@pytest.mark.parametrize("params",
[{'weights_shape': [3, 3, 3], 'strides': 1, 'pads': 0, 'dilations': 1, 'groups': 1},
@@ -108,19 +106,19 @@ class TestConv1D(PytorchLayerTest):
class TestConv3D(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
- return (np.random.randn(2, 3, 25, 25, 25).astype(np.float32),)
+ return (self.random.randn(2, 3, 25, 25, 25),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias):
import torch
import torch.nn.functional as F
class aten_conv3d(torch.nn.Module):
- def __init__(self):
- super(aten_conv3d, self).__init__()
- self.weight = torch.randn(weights_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape)
self.bias = None
if bias:
- self.bias = torch.randn(weights_shape[0])
+ self.bias = rng.torch_randn(weights_shape[0])
self.strides = strides
self.pads = pads
self.dilations = dilations
@@ -129,9 +127,8 @@ class TestConv3D(PytorchLayerTest):
def forward(self, x):
return F.conv3d(x, self.weight, self.bias, self.strides, self.pads, self.dilations, self.groups)
- ref_net = None
- return aten_conv3d(), ref_net, "aten::conv3d"
+ return aten_conv3d(self.random), "aten::conv3d"
@pytest.mark.parametrize("params",
[{'weights_shape': [1, 3, 3, 3, 3], 'strides': 1, 'pads': 0, 'dilations': 1, 'groups': 1},
@@ -167,7 +164,7 @@ class TestConv3D(PytorchLayerTest):
class TestConv2DInSubgraph(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
- return (np.random.randn(2, 3, 25, 25).astype(np.float32), np.array([1], dtype=np.int32))
+ return (self.random.randn(2, 3, 25, 25), np.array([1], dtype=np.int32))
def convert_directly_via_frontend(self, model, example_input, trace_model, dynamic_shapes, ov_inputs, freeze_model):
# Overload function to allow reproduction of issue caused by additional freeze.
@@ -213,9 +210,8 @@ class TestConv2DInSubgraph(PytorchLayerTest):
if y:
acc += self.convs(x)
return acc
- ref_net = None
- return aten_conv2d(), ref_net, "aten::conv2d"
+ return aten_conv2d(), "aten::conv2d"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_convolution.py b/tests/layer_tests/pytorch_tests/test_convolution.py
index 39ca5a82f3c..5954ff2c828 100644
--- a/tests/layer_tests/pytorch_tests/test_convolution.py
+++ b/tests/layer_tests/pytorch_tests/test_convolution.py
@@ -142,9 +142,8 @@ d3_params = [
class TestConvolution(PytorchLayerTest):
def _prepare_input(self, ndim=4):
- import numpy as np
shape = (1, 3, 10, 10, 10)
- return (np.random.randn(*shape[:ndim]).astype(np.float32),)
+ return (self.random.randn(*shape[:ndim]),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias, transposed, output_padding=0,
bias_shape=None, underscore=True):
@@ -154,13 +153,13 @@ class TestConvolution(PytorchLayerTest):
bias_dim = 0
class aten__convolution(torch.nn.Module):
- def __init__(self):
- super(aten__convolution, self).__init__()
- self.weight = torch.randn(weights_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape)
self.bias_shape = bias_shape
if self.bias_shape is None:
self.bias_shape = weights_shape[bias_dim]
- self.bias = torch.randn(self.bias_shape) if bias else None
+ self.bias = rng.torch_randn(self.bias_shape) if bias else None
self.strides = strides
self.pads = pads
self.dilations = dilations
@@ -176,13 +175,13 @@ class TestConvolution(PytorchLayerTest):
)
class aten_convolution(torch.nn.Module):
- def __init__(self):
- super(aten_convolution, self).__init__()
- self.weight = torch.randn(weights_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape)
self.bias_shape = bias_shape
if self.bias_shape is None:
self.bias_shape = weights_shape[bias_dim]
- self.bias = torch.randn(self.bias_shape) if bias else None
+ self.bias = rng.torch_randn(self.bias_shape) if bias else None
self.strides = strides
self.pads = pads
self.dilations = dilations
@@ -197,10 +196,9 @@ class TestConvolution(PytorchLayerTest):
self.output_padding, self.groups
)
- ref_net = None
if underscore:
- return aten__convolution(), ref_net, "aten::_convolution"
- return aten_convolution(), ref_net, "aten::convolution"
+ return aten__convolution(self.random), "aten::_convolution"
+ return aten_convolution(self.random), "aten::convolution"
@pytest.mark.parametrize("params", d1_params)
@pytest.mark.parametrize("bias", [True, False])
diff --git a/tests/layer_tests/pytorch_tests/test_convolution_mode.py b/tests/layer_tests/pytorch_tests/test_convolution_mode.py
index f9532dcf887..19e299fd4a4 100644
--- a/tests/layer_tests/pytorch_tests/test_convolution_mode.py
+++ b/tests/layer_tests/pytorch_tests/test_convolution_mode.py
@@ -8,20 +8,19 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestConv2D(PytorchLayerTest):
def _prepare_input(self, ndim=4):
- import numpy as np
input_shape = (1, 3, 10, 10, 10)
- return (np.random.randn(*input_shape[:ndim]).astype(np.float32),)
+ return (self.random.randn(*input_shape[:ndim]),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias):
import torch
class aten_convolution_mode(torch.nn.Module):
- def __init__(self):
- super(aten_convolution_mode, self).__init__()
- self.weight = torch.randn(weights_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape)
self.bias = None
if bias:
- self.bias = torch.randn(weights_shape[0])
+ self.bias = rng.torch_randn(weights_shape[0])
self.strides = strides
self.pads = pads
self.dilations = dilations
@@ -31,9 +30,8 @@ class TestConv2D(PytorchLayerTest):
return torch._convolution_mode(x, self.weight, self.bias, self.strides, self.pads, self.dilations,
self.groups)
- ref_net = None
- return aten_convolution_mode(), ref_net, "aten::_convolution_mode"
+ return aten_convolution_mode(self.random), "aten::_convolution_mode"
@pytest.mark.parametrize("params",
[
diff --git a/tests/layer_tests/pytorch_tests/test_copy.py b/tests/layer_tests/pytorch_tests/test_copy.py
index 38c3acffd1c..60dce51d637 100644
--- a/tests/layer_tests/pytorch_tests/test_copy.py
+++ b/tests/layer_tests/pytorch_tests/test_copy.py
@@ -9,22 +9,21 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestCopy(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, value):
import torch
class aten_copy(torch.nn.Module):
def __init__(self, value):
- super(aten_copy, self).__init__()
+ super().__init__()
self.value = torch.tensor(value)
def forward(self, x):
return x.copy_(self.value)
- ref_net = None
- return aten_copy(value), ref_net, "aten::copy_"
+ return aten_copy(value), "aten::copy_"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -38,15 +37,15 @@ class TestAliasCopy(PytorchLayerTest):
def _prepare_input(self, out):
import numpy as np
if not out:
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
- return (np.random.randn(1, 3, 224, 224).astype(np.float32), np.zeros((1, 3, 224, 224), dtype=np.float32))
+ return (self.random.randn(1, 3, 224, 224),)
+ return (self.random.randn(1, 3, 224, 224), np.zeros((1, 3, 224, 224), dtype=np.float32))
def create_model(self, out):
import torch
class aten_copy(torch.nn.Module):
def __init__(self, out):
- super(aten_copy, self).__init__()
+ super().__init__()
if out:
self.forward = self.forward_out
@@ -56,9 +55,8 @@ class TestAliasCopy(PytorchLayerTest):
def forward_out(self, x, y):
return torch.alias_copy(x, out=y), y
- ref_net = None
- return aten_copy(out), ref_net, "aten::alias_copy"
+ return aten_copy(out), "aten::alias_copy"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_cross.py b/tests/layer_tests/pytorch_tests/test_cross.py
index 97d26a54a6d..776470ed080 100644
--- a/tests/layer_tests/pytorch_tests/test_cross.py
+++ b/tests/layer_tests/pytorch_tests/test_cross.py
@@ -12,8 +12,8 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestLinalgCross(PytorchLayerTest):
def _prepare_input(self, x_shape, y_shape, out, dtype):
import numpy as np
- x = np.random.randn(*x_shape).astype(dtype)
- y = np.random.randn(*y_shape).astype(dtype)
+ x = self.random.randn(*x_shape, dtype=dtype)
+ y = self.random.randn(*y_shape, dtype=dtype)
if not out:
return (x, y)
return (x, y, np.zeros(np.maximum(np.array(x_shape), np.array(y_shape)).tolist(), dtype=dtype))
@@ -23,7 +23,7 @@ class TestLinalgCross(PytorchLayerTest):
class aten_linalg_cross(torch.nn.Module):
def __init__(self, dim, out):
- super(aten_linalg_cross, self).__init__()
+ super().__init__()
if dim is None:
self.forward = self.forward_no_dim_no_out if not out else self.forward_no_dim_out
elif out:
@@ -42,9 +42,8 @@ class TestLinalgCross(PytorchLayerTest):
def forward_no_dim_no_out(self, x, y):
return torch.linalg.cross(x, y)
- ref_net = None
- return aten_linalg_cross(dim, out), ref_net, "aten::linalg_cross"
+ return aten_linalg_cross(dim, out), "aten::linalg_cross"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -70,8 +69,8 @@ class TestLinalgCross(PytorchLayerTest):
class TestCross(PytorchLayerTest):
def _prepare_input(self, x_shape, y_shape, out, dtype):
import numpy as np
- x = np.random.randn(*x_shape).astype(dtype)
- y = np.random.randn(*y_shape).astype(dtype)
+ x = self.random.randn(*x_shape, dtype=dtype)
+ y = self.random.randn(*y_shape, dtype=dtype)
if not out:
return (x, y)
return (x, y, np.zeros(np.maximum(np.array(x_shape), np.array(y_shape)).tolist(), dtype=dtype))
@@ -81,7 +80,7 @@ class TestCross(PytorchLayerTest):
class aten_cross(torch.nn.Module):
def __init__(self, dim, out, shape):
- super(aten_cross, self).__init__()
+ super().__init__()
if dim is None:
self.forward = self.forward_no_dim_no_out if not out else self.forward_no_dim_out
elif out:
@@ -103,9 +102,8 @@ class TestCross(PytorchLayerTest):
x = torch.reshape(x, self.shape)
return torch.cross(x, y)
- ref_net = None
- return aten_cross(dim, out, shape), ref_net, "aten::cross"
+ return aten_cross(dim, out, shape), "aten::cross"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_cumsum.py b/tests/layer_tests/pytorch_tests/test_cumsum.py
index 665299595f4..a3cc646bbff 100644
--- a/tests/layer_tests/pytorch_tests/test_cumsum.py
+++ b/tests/layer_tests/pytorch_tests/test_cumsum.py
@@ -10,11 +10,10 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestCumSum(PytorchLayerTest):
def _prepare_input(self, out=False, out_dtype=None):
- import numpy as np
- x = np.random.randn(1, 3, 224, 224).astype(np.float32)
+ x = self.random.randn(1, 3, 224, 224)
if not out:
return (x, )
- y = np.random.randn(1, 3, 224, 224).astype(np.float32)
+ y = self.random.randn(1, 3, 224, 224)
if out_dtype is not None:
y = y.astype(out_dtype)
return (x, y)
@@ -36,7 +35,7 @@ class TestCumSum(PytorchLayerTest):
class aten_cumsum(torch.nn.Module):
def __init__(self, axis, dtype, out=False, dtype_from_input=False):
- super(aten_cumsum, self).__init__()
+ super().__init__()
self.axis = axis
self.dtype = dtype
if dtype_from_input:
@@ -62,9 +61,8 @@ class TestCumSum(PytorchLayerTest):
def forward_out_prim_dtype(self, x, y):
return y, torch.cumsum(x, self.axis, dtype=y.dtype, out=y)
- ref_net = None
- return aten_cumsum(axis, dtype, out, dtype_from_input), ref_net, "aten::cumsum"
+ return aten_cumsum(axis, dtype, out, dtype_from_input), "aten::cumsum"
@pytest.mark.parametrize("axis", [0, 1, 2, 3, -1, -2, -3, -4])
@pytest.mark.parametrize("dtype", [None, "float32", "float64", "int32", "int64", "int8"])
diff --git a/tests/layer_tests/pytorch_tests/test_data.py b/tests/layer_tests/pytorch_tests/test_data.py
index 97219c2472d..d84ed46ae66 100644
--- a/tests/layer_tests/pytorch_tests/test_data.py
+++ b/tests/layer_tests/pytorch_tests/test_data.py
@@ -21,14 +21,13 @@ class ModelGrad(torch.nn.Module):
class TestPrimData(PytorchLayerTest):
def _prepare_input(self):
- np.random.seed(self.seed)
if self.dtype in (torch.complex64, torch.complex128):
- real = (np.random.randn(*self.shape) * 10).astype(np.float32)
- imag = (np.random.randn(*self.shape) * 10).astype(np.float32)
+ real = self.random.randn(*self.shape) * 10
+ imag = self.random.randn(*self.shape) * 10
data = real + 1j * imag
data = data.astype(np.complex128 if self.dtype == torch.complex128 else np.complex64)
else:
- data = (np.random.randn(*self.shape) * 10).astype(np.float32)
+ data = self.random.randn(*self.shape) * 10
tensor = torch.from_numpy(data).to(self.dtype)
return (tensor.numpy(),)
@@ -37,15 +36,13 @@ class TestPrimData(PytorchLayerTest):
def test_data_basic(self, shape, dtype, ie_device, precision, ir_version):
self.shape = shape
self.dtype = dtype
- self.seed = 0
- self._test(Model(), None, "prim::data", ie_device, precision, ir_version)
+ self._test(Model(), "prim::data", ie_device, precision, ir_version)
@pytest.mark.parametrize("dtype", [torch.float32, torch.int32])
def test_data_requires_grad(self, dtype, ie_device, precision, ir_version):
self.shape = (3, 2)
self.dtype = dtype
- self.seed = 1
- self._test(ModelGrad(), None, "prim::data", ie_device, precision, ir_version)
+ self._test(ModelGrad(), "prim::data", ie_device, precision, ir_version)
@pytest.mark.parametrize("dtype", [torch.complex64, torch.complex128])
@pytest.mark.parametrize("shape", [[2, 3], [1, 5], [4]])
@@ -56,8 +53,7 @@ class TestPrimData(PytorchLayerTest):
def test_data_complex(self, shape, dtype, ie_device, precision, ir_version):
self.shape = shape
self.dtype = dtype
- self.seed = 2
- self._test(Model(), None, "prim::data", ie_device, precision, ir_version)
+ self._test(Model(), "prim::data", ie_device, precision, ir_version)
@pytest.mark.parametrize("dtype", [torch.complex64, torch.complex128])
@pytest.mark.xfail(
@@ -67,5 +63,4 @@ class TestPrimData(PytorchLayerTest):
def test_data_complex_requires_grad(self, dtype, ie_device, precision, ir_version):
self.shape = (2, 3)
self.dtype = dtype
- self.seed = 3
- self._test(ModelGrad(), None, "prim::data", ie_device, precision, ir_version)
+ self._test(ModelGrad(), "prim::data", ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_deformable_convolution.py b/tests/layer_tests/pytorch_tests/test_deformable_convolution.py
index 417dcc49bba..ff94924694c 100644
--- a/tests/layer_tests/pytorch_tests/test_deformable_convolution.py
+++ b/tests/layer_tests/pytorch_tests/test_deformable_convolution.py
@@ -3,7 +3,6 @@
from copy import deepcopy
-import numpy as np
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest
@@ -114,7 +113,7 @@ params = [
class TestDeformableConvolution(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.rand(1, 64, 64, 64).astype(np.float32),)
+ return (self.random.rand(1, 64, 64, 64),)
def create_model(
self,
@@ -129,17 +128,17 @@ class TestDeformableConvolution(PytorchLayerTest):
bias_shape=None,
):
class aten_deform_convolution(torch.nn.Module):
- def __init__(self):
- super(aten_deform_convolution, self).__init__()
- self.weight = torch.rand(weights_shape)
- self.offset = torch.rand(offset_shape)
+ def __init__(self, rng):
+ super().__init__()
+ self.weight = rng.torch_rand(*weights_shape)
+ self.offset = rng.torch_rand(*offset_shape)
if mask_shape is None:
self.mask_shape = deepcopy(offset_shape)
self.mask_shape[1] = self.mask_shape[1] // 2
else:
self.mask_shape = mask_shape
if mask:
- self.mask = torch.rand(self.mask_shape)
+ self.mask = rng.torch_rand(*self.mask_shape)
else:
self.mask = None
self.stride = stride
@@ -148,7 +147,7 @@ class TestDeformableConvolution(PytorchLayerTest):
self.bias_shape = bias_shape
if self.bias_shape is None:
self.bias_shape = weights_shape[0]
- self.bias = torch.rand(self.bias_shape) if bias else None
+ self.bias = rng.torch_rand(self.bias_shape) if bias else None
def forward(self, x):
return deform_conv2d(
@@ -162,8 +161,7 @@ class TestDeformableConvolution(PytorchLayerTest):
padding=self.padding,
)
- ref_net = None
- return aten_deform_convolution(), ref_net, "torchvision::deform_conv2d"
+ return aten_deform_convolution(self.random), "torchvision::deform_conv2d"
@pytest.mark.parametrize("params", params)
@pytest.mark.parametrize("bias", [True, False])
diff --git a/tests/layer_tests/pytorch_tests/test_derive_index_range_length.py b/tests/layer_tests/pytorch_tests/test_derive_index_range_length.py
index a33b77b44c8..4329d00cd8a 100644
--- a/tests/layer_tests/pytorch_tests/test_derive_index_range_length.py
+++ b/tests/layer_tests/pytorch_tests/test_derive_index_range_length.py
@@ -43,9 +43,8 @@ class TestDeriveIndexRangeLength(PytorchLayerTest):
accumulator += idx
return accumulator
- ref_net = None
- return prim_derive_index_range_length(), ref_net, ["aten::__range_length", "aten::__derive_index"]
+ return prim_derive_index_range_length(), ["aten::__range_length", "aten::__derive_index"]
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_device.py b/tests/layer_tests/pytorch_tests/test_device.py
index 20c196dea04..dc28d4ebc7d 100644
--- a/tests/layer_tests/pytorch_tests/test_device.py
+++ b/tests/layer_tests/pytorch_tests/test_device.py
@@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest
@@ -10,13 +9,13 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestDevice(PytorchLayerTest):
def _prepare_input(self):
- input_data = np.random.randint(127, size=(1, 3, 224, 224))
+ input_data = self.random.randint(127, size=(1, 3, 224, 224))
return (input_data,)
def create_model_device(self, device_string):
class prim_device(torch.nn.Module):
def __init__(self, device_string) -> None:
- super(prim_device, self).__init__()
+ super().__init__()
self.device_string = device_string
def forward(self, x):
@@ -25,16 +24,15 @@ class TestDevice(PytorchLayerTest):
else:
return torch.add(x, 1)
- ref_net = None
- return prim_device(device_string), ref_net, "prim::device"
+ return prim_device(device_string), "prim::device"
def create_model_type(self, device_string):
import torch
class prim_device(torch.nn.Module):
def __init__(self, device_string) -> None:
- super(prim_device, self).__init__()
+ super().__init__()
self.device_string = device_string
def forward(self, x):
@@ -43,9 +41,8 @@ class TestDevice(PytorchLayerTest):
else:
return torch.add(x, 1)
- ref_net = None
- return prim_device(device_string), ref_net, "prim::device"
+ return prim_device(device_string), "prim::device"
@pytest.mark.parametrize("device_string", ["cpu", "cuda"])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_dict.py b/tests/layer_tests/pytorch_tests/test_dict.py
index 7fcbb18ffa7..e3dc08bd84d 100644
--- a/tests/layer_tests/pytorch_tests/test_dict.py
+++ b/tests/layer_tests/pytorch_tests/test_dict.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import platform
import pytest
import torch
@@ -12,15 +11,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestDict(PytorchLayerTest):
def _prepare_input(self):
- rng = np.random.default_rng(0)
- return (rng.standard_normal((2, 5, 3, 4), dtype=np.float32),)
+ return (self.random.randn(2, 5, 3, 4),)
def create_model(self):
class aten_dict(torch.nn.Module):
def forward(self, x):
return {"b": x, "a": x + x, "c": 2 * x}, x / 2
- return aten_dict(), None, "prim::DictConstruct"
+ return aten_dict(), "prim::DictConstruct"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -42,30 +40,29 @@ class aten_dict_no_types(torch.nn.Module):
class TestDictParam(PytorchLayerTest):
def _prepare_input(self):
- rng = np.random.default_rng(0)
- return ({"x1": rng.standard_normal((2, 5, 3, 4), dtype=np.float32),
- "x2": rng.standard_normal((2, 5, 3, 4), dtype=np.float32)},)
+ return ({"x1": self.random.randn(2, 5, 3, 4),
+ "x2": self.random.randn(2, 5, 3, 4)},)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.skipif(platform.system() == 'Darwin' and platform.machine() in ('x86_64', 'AMD64'),
reason='Ticket - 142190')
def test_dict_param(self, ie_device, precision, ir_version):
- self._test(aten_dict_with_types(), None, "aten::__getitem__", ie_device, precision,
+ self._test(aten_dict_with_types(), "aten::__getitem__", ie_device, precision,
ir_version, trace_model=True)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.skipif(platform.system() == 'Darwin', reason='Ticket - 142190')
def test_dict_param_convert_model(self, ie_device, precision, ir_version):
- self._test(aten_dict_with_types(), None, "aten::__getitem__", ie_device, precision,
+ self._test(aten_dict_with_types(), "aten::__getitem__", ie_device, precision,
ir_version, trace_model=True, use_convert_model=True)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.skipif(platform.system() == 'Darwin', reason='Ticket - 142190')
def test_dict_param_no_types(self, ie_device, precision, ir_version):
- self._test(aten_dict_no_types(), None, "aten::__getitem__", ie_device, precision,
+ self._test(aten_dict_no_types(), "aten::__getitem__", ie_device, precision,
ir_version, trace_model=True, freeze_model=False)
@@ -78,15 +75,14 @@ class aten_dict_mixed_inputs(torch.nn.Module):
class TestDictParamMixed(PytorchLayerTest):
def _prepare_input(self):
- rng = np.random.default_rng(0)
- x1 = rng.standard_normal((1, 3, 4), dtype=np.float32)
- x2 = rng.standard_normal((1, 3, 4), dtype=np.float32)
- y = rng.standard_normal((1, 3, 4), dtype=np.float32)
+ x1 = self.random.randn(1, 3, 4)
+ x2 = self.random.randn(1, 3, 4)
+ y = self.random.randn(1, 3, 4)
return ({"x1": x1, "x2": x2}, y)
@pytest.mark.nightly
@pytest.mark.precommit
def test_dict_param_mixed_inputs(self, ie_device, precision, ir_version):
# Regression: ensure dict parameter resolution does not drop unrelated inputs
- self._test(aten_dict_mixed_inputs(), None, "aten::__getitem__", ie_device, precision,
+ self._test(aten_dict_mixed_inputs(), "aten::__getitem__", ie_device, precision,
ir_version, trace_model=True, freeze_model=False)
diff --git a/tests/layer_tests/pytorch_tests/test_distance.py b/tests/layer_tests/pytorch_tests/test_distance.py
index bb3756fe2f3..857ec289b32 100644
--- a/tests/layer_tests/pytorch_tests/test_distance.py
+++ b/tests/layer_tests/pytorch_tests/test_distance.py
@@ -10,23 +10,21 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestCdist(PytorchLayerTest):
def _prepare_input(self, x_dtype="float32", y_dtype="float32"):
- import numpy as np
- return (np.random.randint(-10, 10, (2, 2)).astype(x_dtype), np.random.randint(-10, 10, (3, 2)).astype(y_dtype))
+ return (self.random.randint(-10, 10, (2, 2), dtype=x_dtype), self.random.randint(-10, 10, (3, 2), dtype=y_dtype))
def create_model(self, p):
import torch
class aten_cdist(torch.nn.Module):
def __init__(self, p):
- super(aten_cdist, self).__init__()
+ super().__init__()
self.p = p
def forward(self, x, y):
return torch.cdist(x, y, self.p)
- ref_net = None
- return aten_cdist(p), ref_net, "aten::cdist"
+ return aten_cdist(p), "aten::cdist"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -40,8 +38,7 @@ class TestCdist(PytorchLayerTest):
class TestPairwiseDistance(PytorchLayerTest):
def _prepare_input(self, x_dtype="float32", y_dtype="float32"):
- import numpy as np
- return (np.random.randint(-10, 10, (20, 100)).astype(x_dtype), np.random.randint(-10, 10, (20, 100)).astype(y_dtype))
+ return (self.random.randint(-10, 10, (20, 100), dtype=x_dtype), self.random.randint(-10, 10, (20, 100), dtype=y_dtype))
def create_model(self, p, eps, keepdim):
import torch
@@ -49,7 +46,7 @@ class TestPairwiseDistance(PytorchLayerTest):
class aten_cdist(torch.nn.Module):
def __init__(self, p, eps, keepdim):
- super(aten_cdist, self).__init__()
+ super().__init__()
self.p = p
self.eps = eps
self.keepdim = keepdim
@@ -57,9 +54,8 @@ class TestPairwiseDistance(PytorchLayerTest):
def forward(self, x, y):
return F.pairwise_distance(x, y, self.p, self.eps, self.keepdim)
- ref_net = None
- return aten_cdist(p, eps, keepdim), ref_net, "aten::pairwise_distance"
+ return aten_cdist(p, eps, keepdim), "aten::pairwise_distance"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_div.py b/tests/layer_tests/pytorch_tests/test_div.py
index 1cf350b7f22..d9b99bfd914 100644
--- a/tests/layer_tests/pytorch_tests/test_div.py
+++ b/tests/layer_tests/pytorch_tests/test_div.py
@@ -15,18 +15,15 @@ class TestDiv(PytorchLayerTest):
return (self.input_array.astype(self.input_type), self.other_array.astype(self.other_type))
def create_model(self, rounding_mode):
-
class aten_div(torch.nn.Module):
def __init__(self, rounding_mode):
- super(aten_div, self).__init__()
+ super().__init__()
self.rounding_mode = rounding_mode
def forward(self, input_tensor, other_tensor):
return torch.div(input_tensor, other_tensor, rounding_mode=self.rounding_mode)
- ref_net = None
-
- return aten_div(rounding_mode), ref_net, "aten::div"
+ return aten_div(rounding_mode), "aten::div"
@pytest.mark.parametrize(("input_array", "other_array"), [
[np.array([0.7620, 2.5548, -0.5944, -0.7438, 0.9274]), np.array(0.5)],
@@ -58,14 +55,13 @@ class TestDivTypes(PytorchLayerTest):
def _prepare_input(self):
if len(self.lhs_shape) == 0:
- return (torch.randint(2, 5, self.rhs_shape).to(self.rhs_type).numpy(),)
+ return (self.random.randint(2, 5, size=self.rhs_shape, dtype=self.rhs_dtype),)
elif len(self.rhs_shape) == 0:
- return (10 * torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),)
- return (10 * torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),
- torch.randint(2, 5, self.rhs_shape).to(self.rhs_type).numpy())
+ return (10 * self.random.randn(*self.lhs_shape, dtype=self.lhs_dtype),)
+ return (10 * self.random.randn(*self.lhs_shape, dtype=self.lhs_dtype),
+ self.random.randint(2, 5, size=self.rhs_shape, dtype=self.rhs_dtype))
def create_model(self, lhs_type, lhs_shape, rhs_type, rhs_shape, rounding_mode):
-
class aten_div(torch.nn.Module):
def __init__(self, lhs_type, lhs_shape, rhs_type, rhs_shape, rounding_mode):
super().__init__()
@@ -88,9 +84,7 @@ class TestDivTypes(PytorchLayerTest):
def forward3(self, lhs, rhs):
return torch.div(lhs.to(self.lhs_type), rhs.to(self.rhs_type), rounding_mode=self.rm)
- ref_net = None
-
- return aten_div(lhs_type, lhs_shape, rhs_type, rhs_shape, rounding_mode), ref_net, "aten::div"
+ return aten_div(lhs_type, lhs_shape, rhs_type, rhs_shape, rounding_mode), "aten::div"
@pytest.mark.parametrize(("lhs_type", "rhs_type"),
[[torch.int32, torch.int64],
@@ -130,6 +124,14 @@ class TestDivTypes(PytorchLayerTest):
self.lhs_shape = lhs_shape
self.rhs_type = rhs_type
self.rhs_shape = rhs_shape
+ # Map torch dtypes to numpy for _prepare_input
+ dtype_map = {
+ torch.int32: np.int32, torch.int64: np.int64,
+ torch.float32: np.float32, torch.float64: np.float64,
+ torch.float16: np.float16, torch.uint8: np.uint8
+ }
+ self.lhs_dtype = dtype_map.get(lhs_type, np.float32)
+ self.rhs_dtype = dtype_map.get(rhs_type, np.float32)
if rounding_mode == "floor" and not lhs_type.is_floating_point and not rhs_type.is_floating_point:
pytest.skip("Floor rounding mode and int inputs produce wrong results")
self._test(*self.create_model(lhs_type, lhs_shape, rhs_type, rhs_shape, rounding_mode),
diff --git a/tests/layer_tests/pytorch_tests/test_divmod.py b/tests/layer_tests/pytorch_tests/test_divmod.py
index 81cee693863..ac137499809 100644
--- a/tests/layer_tests/pytorch_tests/test_divmod.py
+++ b/tests/layer_tests/pytorch_tests/test_divmod.py
@@ -6,6 +6,8 @@ import openvino as ov
import pytest
import torch
+from pytorch_layer_test_class import SeededRandom
+
# do not test via PytorchLayerTest since PytorchLayerTest triggers own TorchScript tracing
# this test validates TorchScript patched inside ov.convert_model
@@ -31,7 +33,7 @@ class TestBuiltinDivmod():
@pytest.mark.precommit
def test_divmod_on_assert_path(self, ie_device, precision):
fw_model = self.divmod_on_assert_path()
- inputs = torch.randn(2, 3, 28)
+ inputs = SeededRandom(42).torch_randn(2, 3, 28)
example_input = inputs
ov_model = ov.convert_model(input_model=fw_model, example_input=example_input)
@@ -51,7 +53,7 @@ class TestBuiltinDivmod():
@pytest.mark.precommit
def test_divmod_on_compute_path(self, ie_device, precision, x_shape):
fw_model = self.divmod_on_compute_path()
- x = torch.randn(x_shape)
+ x = SeededRandom(42).torch_randn(*x_shape)
example_input = x
ov_model = ov.convert_model(input_model=fw_model,
diff --git a/tests/layer_tests/pytorch_tests/test_dot.py b/tests/layer_tests/pytorch_tests/test_dot.py
index af37b6bfcf0..37ab701d320 100644
--- a/tests/layer_tests/pytorch_tests/test_dot.py
+++ b/tests/layer_tests/pytorch_tests/test_dot.py
@@ -43,9 +43,8 @@ class TestDot(PytorchLayerTest):
dtype = dtype_map.get(dtype)
- ref_net = None
- return aten_dot(mode, dtype), ref_net, "aten::dot"
+ return aten_dot(mode, dtype), "aten::dot"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_einsum.py b/tests/layer_tests/pytorch_tests/test_einsum.py
index 5ac84a0ddb9..19f623dc4de 100644
--- a/tests/layer_tests/pytorch_tests/test_einsum.py
+++ b/tests/layer_tests/pytorch_tests/test_einsum.py
@@ -8,9 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestEinsumBatchMatMul(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
-
- return (np.random.randn(5, 2, 3).astype(np.float32), np.random.randn(5, 3, 4).astype(np.float32),)
+ return (self.random.randn(5, 2, 3), self.random.randn(5, 3, 4),)
def create_model(self):
import torch
@@ -20,9 +18,8 @@ class TestEinsumBatchMatMul(PytorchLayerTest):
eqn = "bij, bjk -> bik"
return torch.einsum(eqn, x, y)
- ref_net = None
- return EinsumModelBatchMatmul(), ref_net, "aten::einsum"
+ return EinsumModelBatchMatmul(), "aten::einsum"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -32,9 +29,7 @@ class TestEinsumBatchMatMul(PytorchLayerTest):
class TestEinsumBatchDiagonal(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
-
- return (np.random.randn(3, 5, 5).astype(np.float32),)
+ return (self.random.randn(3, 5, 5),)
def create_model(self):
import torch
@@ -44,9 +39,8 @@ class TestEinsumBatchDiagonal(PytorchLayerTest):
eqn = "kii -> ki"
return torch.einsum(eqn, x)
- ref_net = None
- return EinsumModelBatchDiagonal(), ref_net, "aten::einsum"
+ return EinsumModelBatchDiagonal(), "aten::einsum"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -57,9 +51,7 @@ class TestEinsumBatchDiagonal(PytorchLayerTest):
class TestEinsumInnerProd(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
-
- return (np.random.randn(5).astype(np.float32), np.random.randn(5).astype(np.float32))
+ return (self.random.randn(5), self.random.randn(5))
def create_model(self):
import torch
@@ -69,9 +61,8 @@ class TestEinsumInnerProd(PytorchLayerTest):
eqn = "i,i"
return torch.einsum(eqn, x, y)
- ref_net = None
- return EinsumModelInnerProd(), ref_net, "aten::einsum"
+ return EinsumModelInnerProd(), "aten::einsum"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -81,9 +72,7 @@ class TestEinsumInnerProd(PytorchLayerTest):
class TestEinsumTranspose(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
-
- return (np.random.randn(3, 5).astype(np.float32),)
+ return (self.random.randn(3, 5),)
def create_model(self):
import torch
@@ -93,9 +82,8 @@ class TestEinsumTranspose(PytorchLayerTest):
eqn = "ij->ji"
return torch.einsum(eqn, x)
- ref_net = None
- return EinsumModelTranspose(), ref_net, "aten::einsum"
+ return EinsumModelTranspose(), "aten::einsum"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_elu.py b/tests/layer_tests/pytorch_tests/test_elu.py
index 5e0c0613daa..9429c93f202 100644
--- a/tests/layer_tests/pytorch_tests/test_elu.py
+++ b/tests/layer_tests/pytorch_tests/test_elu.py
@@ -10,7 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class aten_elu(torch.nn.Module):
def __init__(self, alpha, dtype, inplace):
- super(aten_elu, self).__init__()
+ super().__init__()
self.alpha = alpha
self.dtype = dtype
self.inplace = inplace
@@ -28,8 +28,7 @@ class aten_elu(torch.nn.Module):
class TestElu(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 4, 224, 224).astype(np.float32),)
+ return (self.random.randn(2, 4, 224, 224),)
@pytest.mark.nightly
@pytest.mark.precommit
@@ -41,5 +40,5 @@ class TestElu(PytorchLayerTest):
kwargs = {}
if dtype == torch.float16:
kwargs["custom_eps"] = 1e-2
- self._test(aten_elu(alpha, dtype, inplace), None,
+ self._test(aten_elu(alpha, dtype, inplace),
"aten::elu_" if inplace else "aten::elu", ie_device, precision, ir_version, **kwargs)
diff --git a/tests/layer_tests/pytorch_tests/test_embedding.py b/tests/layer_tests/pytorch_tests/test_embedding.py
index 5d1b4b33580..6dc0dd56e3b 100644
--- a/tests/layer_tests/pytorch_tests/test_embedding.py
+++ b/tests/layer_tests/pytorch_tests/test_embedding.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestEmbedding(PytorchLayerTest):
def _prepare_input(self, indicies_size, indicies_dtype):
- import numpy as np
- return (np.random.randint(0, 9, size=indicies_size).astype(indicies_dtype), np.random.randn(10, 10).astype(np.float32))
+ return (self.random.randint(0, 9, size=indicies_size, dtype=indicies_dtype), self.random.randn(10, 10))
def create_model(self):
import torch
@@ -20,9 +19,8 @@ class TestEmbedding(PytorchLayerTest):
def forward(self, indicies, weight):
return F.embedding(indicies, weight)
- ref_net = None
- return aten_embedding(), ref_net, "aten::embedding"
+ return aten_embedding(), "aten::embedding"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_embedding_bag.py b/tests/layer_tests/pytorch_tests/test_embedding_bag.py
index 47cbeffcae0..c5028788200 100644
--- a/tests/layer_tests/pytorch_tests/test_embedding_bag.py
+++ b/tests/layer_tests/pytorch_tests/test_embedding_bag.py
@@ -13,10 +13,10 @@ class TestEmbeddingBag1dOffsets(PytorchLayerTest):
import numpy as np
indices = np.array([2, 2, 2, 2, 4, 3, 2, 9]).astype(indicies_dtype)
- weights = np.random.randn(10, 10).astype(np.float32)
+ weights = self.random.randn(10, 10)
offsets = np.array([0, 4, 4]).astype(indicies_dtype)
if per_sample_weights:
- per_sample_weights = np.random.randn(*indices.shape).astype(np.float32)
+ per_sample_weights = self.random.randn(*indices.shape)
return (indices, weights, offsets, per_sample_weights)
return (indices, weights, offsets)
@@ -45,11 +45,9 @@ class TestEmbeddingBag1dOffsets(PytorchLayerTest):
per_sample_weights=per_sample_wights,
)
- ref_net = None
return (
aten_embedding_bag(mode, per_sample_weights),
- ref_net,
"aten::embedding_bag",
)
@@ -86,10 +84,10 @@ class TestEmbeddingBag2d(PytorchLayerTest):
def _prepare_input(self, indicies_size, indicies_dtype, per_sample_weights):
import numpy as np
- indices = np.random.randint(0, 9, size=indicies_size).astype(indicies_dtype)
- weights = np.random.randn(10, 10).astype(np.float32)
+ indices = self.random.randint(0, 9, size=indicies_size, dtype=indicies_dtype)
+ weights = self.random.randn(10, 10)
if per_sample_weights:
- per_sample_weights = np.random.randn(*indices.shape).astype(np.float32)
+ per_sample_weights = self.random.randn(*indices.shape)
return (indices, weights, per_sample_weights)
return (indices, weights)
@@ -115,11 +113,9 @@ class TestEmbeddingBag2d(PytorchLayerTest):
per_sample_weights=per_sample_wights,
)
- ref_net = None
return (
aten_embedding_bag(mode, per_sample_weights),
- ref_net,
"aten::embedding_bag",
)
@@ -165,9 +161,9 @@ class TestEmbeddingBagPretrained(PytorchLayerTest):
def _prepare_input(self, indicies_size, indicies_dtype, per_sample_weights):
import numpy as np
- indices = np.random.randint(0, 9, size=indicies_size).astype(indicies_dtype)
+ indices = self.random.randint(0, 9, size=indicies_size, dtype=indicies_dtype)
if per_sample_weights:
- per_sample_weights = np.random.randn(*indices.shape).astype(np.float32)
+ per_sample_weights = self.random.randn(*indices.shape)
return (indices, per_sample_weights)
return (indices,)
@@ -175,14 +171,16 @@ class TestEmbeddingBagPretrained(PytorchLayerTest):
import torch
import numpy as np
+ # Generate weights outside the inner class to use test's seeded random
+ embedding_weights = torch.from_numpy(self.random.randn(10, 10))
+
class aten_embedding_bag(torch.nn.Module):
def __init__(self, mode=None, per_sample_weights=False) -> None:
super().__init__()
self.mode = mode
- weights = torch.from_numpy(np.random.randn(10, 10).astype(np.float32))
self.embeddings = torch.nn.EmbeddingBag.from_pretrained(
- weights, mode=mode
+ embedding_weights, mode=mode
)
if per_sample_weights:
self.forward = self.forward_per_sample_weights
@@ -195,11 +193,9 @@ class TestEmbeddingBagPretrained(PytorchLayerTest):
self.embeddings(indicies, per_sample_weights=per_sample_wights),
)
- ref_net = None
return (
aten_embedding_bag(mode, per_sample_weights),
- ref_net,
"aten::embedding_bag",
)
diff --git a/tests/layer_tests/pytorch_tests/test_empty.py b/tests/layer_tests/pytorch_tests/test_empty.py
index c7735d3ea54..a2ed4730dbe 100644
--- a/tests/layer_tests/pytorch_tests/test_empty.py
+++ b/tests/layer_tests/pytorch_tests/test_empty.py
@@ -11,7 +11,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestEmptyNumeric(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(10, 10, 10),)
+ return (self.random.randn(10, 10, 10),)
def create_model(self, dtype):
@@ -37,9 +37,8 @@ class TestEmptyNumeric(PytorchLayerTest):
# produce sporadic errors if nan would be in empty.
return torch.zeros_like(empty)
- ref_net = None
- return aten_empty(dtype), ref_net, "aten::empty"
+ return aten_empty(dtype), "aten::empty"
@pytest.mark.parametrize('dtype', ("float32", "float64", "int64", "int32", "uint8", "int8"))
@pytest.mark.nightly
@@ -52,8 +51,8 @@ class TestEmptyLike(PytorchLayerTest):
def _prepare_input(self, shape, dtype=np.float32, out=False):
if not out:
- return (np.random.randn(*shape).astype(dtype if dtype is not None else np.float32),)
- return (np.random.randn(*shape), np.ones(shape, dtype=(dtype if dtype is not None else np.float32)))
+ return (self.random.randn(*shape, dtype=dtype if dtype is not None else np.float32),)
+ return (self.random.randn(*shape), np.ones(shape, dtype=(dtype if dtype is not None else np.float32)))
def create_model(self, dtype, out, no_expose_dtype=False):
@@ -97,9 +96,8 @@ class TestEmptyLike(PytorchLayerTest):
# produce sporadic errors if nan would be in empty.
return torch.zeros_like(out_tensor)
- ref_net = None
- return aten_empty_like(dtype, out, no_expose_dtype), ref_net, "aten::empty_like"
+ return aten_empty_like(dtype, out, no_expose_dtype), "aten::empty_like"
@pytest.mark.parametrize('dtype', (None, "float32", "float64", "int64", "int32", "uint8", "int8"))
@pytest.mark.parametrize("input_shape", [[2,], [1, 10], [10, 5, 2]])
@@ -122,7 +120,7 @@ class TestEmptyLike(PytorchLayerTest):
class TestEmptyBoolean(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(10, 10, 10),)
+ return (self.random.randn(10, 10, 10),)
def create_model(self):
@@ -139,9 +137,8 @@ class TestEmptyBoolean(PytorchLayerTest):
# so we do "and" operation with False.
return empty & self.false
- ref_net = None
- return aten_empty(), ref_net, "aten::empty"
+ return aten_empty(), "aten::empty"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -150,7 +147,7 @@ class TestEmptyBoolean(PytorchLayerTest):
class TestNewEmpty(PytorchLayerTest):
def _prepare_input(self, input_dtype=np.float32):
- return (np.random.randn(1, 3, 10, 10).astype(input_dtype),)
+ return (self.random.randn(1, 3, 10, 10, dtype=input_dtype),)
def create_model(self, shape, dtype=None, used_dtype=False):
import torch
@@ -166,7 +163,7 @@ class TestNewEmpty(PytorchLayerTest):
class aten_empty(torch.nn.Module):
def __init__(self, shape):
- super(aten_empty, self).__init__()
+ super().__init__()
self.shape = shape
self.zero = torch.tensor([0])
@@ -179,7 +176,7 @@ class TestNewEmpty(PytorchLayerTest):
class aten_empty_with_dtype(torch.nn.Module):
def __init__(self, shape, dtype):
- super(aten_empty_with_dtype, self).__init__()
+ super().__init__()
self.shape = shape
self.dtype = dtype
self.zero = torch.tensor([0], dtype=self.dtype)
@@ -191,14 +188,13 @@ class TestNewEmpty(PytorchLayerTest):
# produce sporadic errors if nan would be in empty.
return torch.zeros_like(empty)
- ref_net = None
model = aten_empty(shape)
if used_dtype:
dtype = dtype_map[dtype]
model = aten_empty_with_dtype(shape, dtype)
- return model, ref_net, "aten::new_empty"
+ return model, "aten::new_empty"
@pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]])
@pytest.mark.parametrize("input_dtype", [np.uint8, np.int8, np.int32, np.int64, np.float32, np.float64])
diff --git a/tests/layer_tests/pytorch_tests/test_eq.py b/tests/layer_tests/pytorch_tests/test_eq.py
index fd277c50fed..7386c166bec 100644
--- a/tests/layer_tests/pytorch_tests/test_eq.py
+++ b/tests/layer_tests/pytorch_tests/test_eq.py
@@ -16,14 +16,13 @@ class TestEq(PytorchLayerTest):
class aten_eq(torch.nn.Module):
def __init__(self):
- super(aten_eq, self).__init__()
+ super().__init__()
def forward(self, input_tensor, other_tensor):
return torch.eq(input_tensor, other_tensor)
- ref_net = None
- return aten_eq(), ref_net, "aten::eq"
+ return aten_eq(), "aten::eq"
@pytest.mark.parametrize(("input_array", "other_array"), [
[np.array([[1, 2], [3, 4]]), np.array([[1, 1], [4, 4]])],
diff --git a/tests/layer_tests/pytorch_tests/test_expand.py b/tests/layer_tests/pytorch_tests/test_expand.py
index 9502b38c575..307cedbeb37 100644
--- a/tests/layer_tests/pytorch_tests/test_expand.py
+++ b/tests/layer_tests/pytorch_tests/test_expand.py
@@ -9,15 +9,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestExpand(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3).astype(np.float32),)
+ return (self.random.randn(1, 3),)
def create_model(self, dim, op_type="expand"):
import torch
class aten_expand(torch.nn.Module):
def __init__(self, dims, op_type="expand"):
- super(aten_expand, self).__init__()
+ super().__init__()
self.dims = dims
if op_type == "broadcast_to":
self.forward = self.forward_broadcast
@@ -28,9 +27,8 @@ class TestExpand(PytorchLayerTest):
def forward_broadcast(self, x):
return x.broadcast_to(self.dims)
- ref_net = None
- return aten_expand(dim, op_type), ref_net, f"aten::{op_type}"
+ return aten_expand(dim, op_type), f"aten::{op_type}"
@pytest.mark.parametrize("dims", [(4, 3), (-1, -1), (1, 2, 3), (1, 2, 2, 3)])
@pytest.mark.parametrize("op_type", ["expand", "broadcast_to"])
@@ -44,23 +42,21 @@ class TestExpand(PytorchLayerTest):
class TestExpandCopy(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3).astype(np.float32),)
+ return (self.random.randn(1, 3),)
def create_model(self, dim):
import torch
class aten_expand_copy(torch.nn.Module):
def __init__(self, dims):
- super(aten_expand_copy, self).__init__()
+ super().__init__()
self.dims = dims
def forward(self, x):
return torch.expand_copy(x, self.dims)
- ref_net = None
- return aten_expand_copy(dim), ref_net, f"aten::expand_copy"
+ return aten_expand_copy(dim), f"aten::expand_copy"
@pytest.mark.parametrize("dims", [(4, 3), (-1, -1), (1, 2, 3), (1, 2, 2, 3)])
@pytest.mark.precommit_fx_backend
@@ -70,15 +66,14 @@ class TestExpandCopy(PytorchLayerTest):
class TestExpandList(PytorchLayerTest):
def _prepare_input(self, broadcast_shape):
- import numpy as np
- return (np.random.randn(1, 3).astype(np.float32), np.random.randn(*broadcast_shape).astype(np.float32))
+ return (self.random.randn(1, 3), self.random.randn(*broadcast_shape))
def create_model(self, op_type="expand"):
import torch
class aten_expand(torch.nn.Module):
def __init__(self, op_type="expand"):
- super(aten_expand, self).__init__()
+ super().__init__()
if op_type == "broadcast_to":
self.forward = self.forward_broadcast
@@ -90,9 +85,8 @@ class TestExpandList(PytorchLayerTest):
y_shape = y.shape
return x.broadcast_to([y_shape[0], y_shape[1]])
- ref_net = None
- return aten_expand(op_type), ref_net, [f"aten::{op_type}", "prim::ListConstruct"]
+ return aten_expand(op_type), [f"aten::{op_type}", "prim::ListConstruct"]
@pytest.mark.parametrize("dims", [(3, 3), (2, 3), (1, 3), [4, 3]])
@pytest.mark.parametrize("op_type", ["expand", "broadcast_to"])
@@ -107,22 +101,20 @@ class TestExpandList(PytorchLayerTest):
class TestExpandAs(PytorchLayerTest):
def _prepare_input(self, input_shape, broadcast_shape):
- import numpy as np
- return (np.random.randn(*input_shape).astype(np.float32), np.random.randn(*broadcast_shape).astype(np.float32),)
+ return (self.random.randn(*input_shape), self.random.randn(*broadcast_shape),)
def create_model(self):
import torch
class aten_expand_as(torch.nn.Module):
def __init__(self):
- super(aten_expand_as, self).__init__()
+ super().__init__()
def forward(self, x, y):
return x.expand_as(y)
- ref_net = None
- return aten_expand_as(), ref_net, "aten::expand_as"
+ return aten_expand_as(), "aten::expand_as"
@pytest.mark.parametrize("kwargs_to_prepare_input", [
{'input_shape': [1, 2], "broadcast_shape": [1, 2]},
@@ -145,25 +137,23 @@ class TestExpandAs(PytorchLayerTest):
class TestDynamicExpand(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
last_dym = random.randint(2,8)
- return (np.random.randn(1, 3, 1).astype(np.float32), last_dym)
+ return (self.random.randn(1, 3, 1), last_dym)
def create_model(self, dim):
import torch
class aten_expand(torch.nn.Module):
def __init__(self, dims):
- super(aten_expand, self).__init__()
+ super().__init__()
self.dims = dims
# TODO: Remove the add op after fixing the issue with expand being the last node
def forward(self, x, dym):
return torch.add(x.expand((self.dims+(dym,))), 0)
- ref_net = None
- return aten_expand(dim), ref_net, f"aten::expand"
+ return aten_expand(dim), f"aten::expand"
@pytest.mark.parametrize("dims", [(4, 3), (-1, -1)])
@pytest.mark.precommit_fx_backend
@@ -173,8 +163,7 @@ class TestDynamicExpand(PytorchLayerTest):
class TestComplexExpand(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 2).astype(np.float32),)
+ return (self.random.randn(1, 3, 2),)
def create_model(self, dim):
import torch
@@ -189,7 +178,7 @@ class TestComplexExpand(PytorchLayerTest):
x = x.expand(self.dims)
return torch.view_as_real(x)
- return aten_expand(dim), None, "aten::expand"
+ return aten_expand(dim), "aten::expand"
@pytest.mark.parametrize("dims", [(4, 3),
(-1, -1),
diff --git a/tests/layer_tests/pytorch_tests/test_eye.py b/tests/layer_tests/pytorch_tests/test_eye.py
index b65b58cde1b..95982540b59 100644
--- a/tests/layer_tests/pytorch_tests/test_eye.py
+++ b/tests/layer_tests/pytorch_tests/test_eye.py
@@ -46,7 +46,7 @@ class TestEye(PytorchLayerTest):
return torch.eye(x, y, dtype=self.dtype)
model = aten_eye_1_input(pt_dtype) if num_inputs == 1 else aten_eye_2_inputs(pt_dtype)
- return model, None, ["aten::eye", "aten::IntImplicit"]
+ return model, ["aten::eye", "aten::IntImplicit"]
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_fake_quantize.py b/tests/layer_tests/pytorch_tests/test_fake_quantize.py
index 8d9d9633606..5d4e69bcf57 100644
--- a/tests/layer_tests/pytorch_tests/test_fake_quantize.py
+++ b/tests/layer_tests/pytorch_tests/test_fake_quantize.py
@@ -3,17 +3,15 @@
import platform
-import numpy as np
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest, skip_check
class TestFakeQuantizePerTensorAffine(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (self.rng.standard_normal([3, 2, 2], dtype=np.float32),)
+ return (self.random.randn(3, 2, 2),)
def create_model(self, scale, zero_point, quant_min, quant_max):
class fake_quantize_per_tensor_affine(torch.nn.Module):
@@ -31,7 +29,6 @@ class TestFakeQuantizePerTensorAffine(PytorchLayerTest):
return (
fake_quantize_per_tensor_affine(scale, zero_point, quant_min, quant_max),
- None,
"aten::fake_quantize_per_tensor_affine",
)
@@ -66,10 +63,9 @@ class TestFakeQuantizePerTensorAffine(PytorchLayerTest):
class TestFakeQuantizePerTensorAffineCacheMaskTensorQParams(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (self.rng.standard_normal([3, 2, 2], dtype=np.float32),)
+ return (self.random.randn(3, 2, 2),)
def create_model(self, scale, zero_point, quant_min, quant_max):
class _fake_quantize_per_tensor_affine_cachemask_tensor_qparams(torch.nn.Module):
@@ -89,7 +85,6 @@ class TestFakeQuantizePerTensorAffineCacheMaskTensorQParams(PytorchLayerTest):
return (
_fake_quantize_per_tensor_affine_cachemask_tensor_qparams(scale, zero_point, quant_min, quant_max),
- None,
"aten::_fake_quantize_per_tensor_affine_cachemask_tensor_qparams",
)
@@ -122,10 +117,9 @@ class TestFakeQuantizePerTensorAffineCacheMaskTensorQParams(PytorchLayerTest):
class TestFakeQuantizePerChannelAffine(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (self.rng.standard_normal([3, 2, 2], dtype=np.float32),)
+ return (self.random.randn(3, 2, 2),)
def create_model(self, scale, zero_point, axis, quant_min, quant_max):
class fake_quantize_per_channel_affine(torch.nn.Module):
@@ -144,7 +138,6 @@ class TestFakeQuantizePerChannelAffine(PytorchLayerTest):
return (
fake_quantize_per_channel_affine(scale, zero_point, axis, quant_min, quant_max),
- None,
"aten::fake_quantize_per_channel_affine",
)
diff --git a/tests/layer_tests/pytorch_tests/test_fft.py b/tests/layer_tests/pytorch_tests/test_fft.py
index a9fe02c705f..8ea00872af1 100644
--- a/tests/layer_tests/pytorch_tests/test_fft.py
+++ b/tests/layer_tests/pytorch_tests/test_fft.py
@@ -3,7 +3,6 @@
from sys import platform
-import numpy as np
import pytest
import torch
@@ -12,12 +11,12 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestRFFTN(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(*self.input_shape).astype(np.float32),)
+ return (self.random.randn(*self.input_shape),)
def create_model(self, dim, s, norm):
class aten_fft_rfftn(torch.nn.Module):
def __init__(self, dim, s, norm):
- super(aten_fft_rfftn, self).__init__()
+ super().__init__()
self.dim = dim
self.s = s
self.norm = norm
@@ -29,11 +28,9 @@ class TestRFFTN(PytorchLayerTest):
irfftn = torch.fft.irfftn(torch.complex(r, i), s=self.s, dim=self.dim, norm=self.norm)
return irfftn, r, i
- ref_net = None
return (
aten_fft_rfftn(dim, s, norm),
- ref_net,
["aten::fft_irfftn", "aten::complex", "aten::fft_rfftn", "aten::real", "aten::imag"],
)
@@ -69,7 +66,7 @@ class aten_fft(torch.nn.Module):
class TestFFT(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(*self.input_shape).astype(np.float32),)
+ return (self.random.randn(*self.input_shape),)
@pytest.mark.nightly
@pytest.mark.precommit
@@ -94,7 +91,7 @@ class TestFFT(PytorchLayerTest):
else:
self.input_shape = input_shape
m = aten_fft(op, n, dim, norm)
- self._test(m, None, aten_name, ie_device,
+ self._test(m, aten_name, ie_device,
precision, ir_version, trace_model=True, dynamic_shapes=False, custom_eps=1e-3)
@pytest.mark.nightly
@@ -118,7 +115,7 @@ class TestFFT(PytorchLayerTest):
else:
self.input_shape = input_shape
m = aten_fft(op, s, dim, norm)
- self._test(m, None, aten_name, ie_device,
+ self._test(m, aten_name, ie_device,
precision, ir_version, trace_model=True, dynamic_shapes=False, custom_eps=1e-3)
@pytest.mark.nightly
@@ -156,5 +153,5 @@ class TestFFT(PytorchLayerTest):
else:
self.input_shape = input_shape
m = aten_fft(op, s, dim, norm)
- self._test(m, None, aten_name, ie_device,
+ self._test(m, aten_name, ie_device,
precision, ir_version, trace_model=True, dynamic_shapes=False, custom_eps=1e-3)
diff --git a/tests/layer_tests/pytorch_tests/test_flatten.py b/tests/layer_tests/pytorch_tests/test_flatten.py
index 6a71820a484..4d901e16b87 100644
--- a/tests/layer_tests/pytorch_tests/test_flatten.py
+++ b/tests/layer_tests/pytorch_tests/test_flatten.py
@@ -8,24 +8,22 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestFlatten(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 3, 4, 5).astype(np.float32),)
+ return (self.random.randn(2, 3, 4, 5),)
def create_model(self, dim0, dim1):
import torch
class aten_flatten(torch.nn.Module):
def __init__(self, dim0, dim1):
- super(aten_flatten, self).__init__()
+ super().__init__()
self.dim0 = dim0
self.dim1 = dim1
def forward(self, x):
return torch.flatten(x, self.dim0, self.dim1)
- ref_net = None
- return aten_flatten(dim0, dim1), ref_net, "aten::flatten"
+ return aten_flatten(dim0, dim1), "aten::flatten"
@pytest.mark.parametrize("dim0,dim1", [[0, -1],
[-2, -1],
diff --git a/tests/layer_tests/pytorch_tests/test_flip.py b/tests/layer_tests/pytorch_tests/test_flip.py
index d4af21e5db5..74359e0728a 100644
--- a/tests/layer_tests/pytorch_tests/test_flip.py
+++ b/tests/layer_tests/pytorch_tests/test_flip.py
@@ -9,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestFlip(PytorchLayerTest):
def _prepare_input(self, out=False, dtype="float32"):
import numpy as np
- x = np.random.randn(2, 3, 4, 5).astype(dtype)
+ x = self.random.randn(2, 3, 4, 5, dtype=dtype)
if not out:
return (x,)
return (x, np.zeros_like(x).astype(dtype))
@@ -19,7 +19,7 @@ class TestFlip(PytorchLayerTest):
import torch
class aten_flip(torch.nn.Module):
def __init__(self, dim, out):
- super(aten_flip, self).__init__()
+ super().__init__()
self.dim = dim
if out:
self.forward = self.forward_out
@@ -30,9 +30,8 @@ class TestFlip(PytorchLayerTest):
def forward_out(self, x, y):
return torch.flip(x, self.dim, out=y), y
- ref_net = None
- return aten_flip(axis, out), ref_net, "aten::flip"
+ return aten_flip(axis, out), "aten::flip"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_floor_divide.py b/tests/layer_tests/pytorch_tests/test_floor_divide.py
index 60ea8fa92eb..e8d13a66778 100644
--- a/tests/layer_tests/pytorch_tests/test_floor_divide.py
+++ b/tests/layer_tests/pytorch_tests/test_floor_divide.py
@@ -10,7 +10,6 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestFloorDivide(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
return (self.input_tensor, self.other_tensor)
@@ -20,36 +19,36 @@ class TestFloorDivide(PytorchLayerTest):
class aten_floor_divide(torch.nn.Module):
def __init__(self):
- super(aten_floor_divide, self).__init__()
+ super().__init__()
def forward(self, input_tensor, other_tensor):
return torch.floor_divide(input_tensor, other_tensor)
- return aten_floor_divide(), None, "aten::floor_divide"
+ return aten_floor_divide(), "aten::floor_divide"
def create_model_int(self):
import torch
class aten_floor_divide(torch.nn.Module):
def __init__(self):
- super(aten_floor_divide, self).__init__()
+ super().__init__()
def forward(self, input_tensor, other_tensor):
return torch.floor_divide(input_tensor.to(torch.int32), other_tensor.to(torch.int64))
- return aten_floor_divide(), None, "aten::floor_divide"
+ return aten_floor_divide(), "aten::floor_divide"
def create_model_inplace(self):
import torch
class aten_floor_divide_(torch.nn.Module):
def __init__(self):
- super(aten_floor_divide_, self).__init__()
+ super().__init__()
def forward(self, input_tensor, other_tensor):
return input_tensor.floor_divide_(other_tensor), input_tensor
- return aten_floor_divide_(), None, "aten::floor_divide_"
+ return aten_floor_divide_(), "aten::floor_divide_"
@pytest.mark.parametrize('input_tensor', [
[5], [5, 5, 1], [1, 1, 5, 5],
@@ -64,11 +63,11 @@ class TestFloorDivide(PytorchLayerTest):
reason='Ticket - 122715')
def test_floor_divide(self, input_tensor, other_tensor, ie_device, precision, ir_version):
if isinstance(input_tensor, list):
- self.input_tensor = self.rng.standard_normal(input_tensor, dtype=np.float32)
+ self.input_tensor = self.random.randn(*input_tensor)
else:
self.input_tensor = input_tensor
if isinstance(other_tensor, list):
- self.other_tensor = self.rng.standard_normal(other_tensor, dtype=np.float32)
+ self.other_tensor = self.random.randn(*other_tensor)
else:
self.other_tensor = other_tensor
self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, use_convert_model=True)
@@ -85,11 +84,11 @@ class TestFloorDivide(PytorchLayerTest):
reason='Ticket - 122715')
def test_floor_divide_(self, input_tensor, other_tensor, ie_device, precision, ir_version):
if isinstance(input_tensor, list):
- self.input_tensor = self.rng.standard_normal(input_tensor, dtype=np.float32)
+ self.input_tensor = self.random.randn(*input_tensor)
else:
self.input_tensor = input_tensor
if isinstance(other_tensor, list):
- self.other_tensor = self.rng.standard_normal(other_tensor, dtype=np.float32)
+ self.other_tensor = self.random.randn(*other_tensor)
else:
self.other_tensor = other_tensor
self._test(*self.create_model_inplace(), ie_device, precision, ir_version, trace_model=True, use_convert_model=True)
@@ -111,17 +110,17 @@ class TestFloorDivide(PytorchLayerTest):
def test_floor_divide_int(self, input_data, other_data, ie_device, precision, ir_version):
input_tensor = input_data["tensor"]
if isinstance(input_tensor, list):
- self.input_tensor = self.rng.integers(low=input_data["low"],
- high=input_data["high"],
- size=input_tensor).astype(np.float32)
+ self.input_tensor = self.random.randint(input_data["low"],
+ input_data["high"],
+ size=input_tensor, dtype=np.float32)
else:
self.input_tensor = input_tensor
other_tensor = other_data["tensor"]
if isinstance(other_tensor, list):
- self.other_tensor = self.rng.integers(low=other_data["low"],
- high=other_data["high"],
- size=other_tensor).astype(np.float32)
+ self.other_tensor = self.random.randint(other_data["low"],
+ other_data["high"],
+ size=other_tensor, dtype=np.float32)
else:
self.other_tensor = other_tensor
self._test(*self.create_model_int(), ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_fmod.py b/tests/layer_tests/pytorch_tests/test_fmod.py
index c5ac7a68219..55a44b4efd2 100644
--- a/tests/layer_tests/pytorch_tests/test_fmod.py
+++ b/tests/layer_tests/pytorch_tests/test_fmod.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -12,11 +11,11 @@ class TestFmodTypes(PytorchLayerTest):
def _prepare_input(self):
if len(self.lhs_shape) == 0:
- return (torch.randint(2, 5, self.rhs_shape).to(self.rhs_type).numpy(),)
+ return (self.random.randint(2, 5, size=self.rhs_shape, dtype=self.rhs_type),)
elif len(self.rhs_shape) == 0:
- return (10 * torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),)
- return (10 * torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),
- torch.randint(2, 5, self.rhs_shape).to(self.rhs_type).numpy())
+ return (10 * self.random.randn(*self.lhs_shape, dtype=self.lhs_type),)
+ return (10 * self.random.randn(*self.lhs_shape, dtype=self.lhs_type),
+ self.random.randint(2, 5, size=self.rhs_shape, dtype=self.rhs_type))
def create_model(self, lhs_type, lhs_shape, rhs_type, rhs_shape):
@@ -41,7 +40,7 @@ class TestFmodTypes(PytorchLayerTest):
def forward3(self, lhs, rhs):
return torch.fmod(lhs.to(self.lhs_type), rhs.to(self.rhs_type))
- return aten_div(lhs_type, lhs_shape, rhs_type, rhs_shape), None, "aten::fmod"
+ return aten_div(lhs_type, lhs_shape, rhs_type, rhs_shape), "aten::fmod"
@pytest.mark.parametrize(("lhs_type", "rhs_type"),
[[torch.int32, torch.int64],
diff --git a/tests/layer_tests/pytorch_tests/test_fork_wait.py b/tests/layer_tests/pytorch_tests/test_fork_wait.py
index e57d0c79298..ca69da5a34d 100644
--- a/tests/layer_tests/pytorch_tests/test_fork_wait.py
+++ b/tests/layer_tests/pytorch_tests/test_fork_wait.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -11,7 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestForkWait(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(10, 20),)
+ return (self.random.randn(10, 20),)
def create_model(self):
@@ -28,7 +27,7 @@ class TestForkWait(PytorchLayerTest):
fut = torch.jit.fork(self.mod, a=input, b=2)
return torch.jit.wait(fut)
- return Mod(), None, ["prim::fork", "aten::wait"]
+ return Mod(), ["prim::fork", "aten::wait"]
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_fp16.py b/tests/layer_tests/pytorch_tests/test_fp16.py
index 63ea2452569..2827fd1ee0d 100644
--- a/tests/layer_tests/pytorch_tests/test_fp16.py
+++ b/tests/layer_tests/pytorch_tests/test_fp16.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -11,18 +10,18 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestBF16(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(10).astype(np.float32),)
+ return (self.random.randn(10),)
def create_model(self):
class aten_add(torch.nn.Module):
- def __init__(self):
- super(aten_add, self).__init__()
- self.y = torch.randn(10, dtype=torch.bfloat16)
+ def __init__(self, rng):
+ super().__init__()
+ self.y = rng.torch_randn(10, dtype=torch.bfloat16)
def forward(self, x):
return x + self.y.to(torch.float32)
- return aten_add(), None, "aten::add"
+ return aten_add(self.random), "aten::add"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -36,18 +35,18 @@ class TestBF16(PytorchLayerTest):
class TestFP16(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(10).astype(np.float32),)
+ return (self.random.randn(10),)
def create_model(self):
class aten_add(torch.nn.Module):
- def __init__(self):
- super(aten_add, self).__init__()
- self.y = torch.randn(10, dtype=torch.float16)
+ def __init__(self, rng):
+ super().__init__()
+ self.y = rng.torch_randn(10, dtype=torch.float16)
def forward(self, x):
return x + self.y.to(torch.float32)
- return aten_add(), None, "aten::add"
+ return aten_add(self.random), "aten::add"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_full.py b/tests/layer_tests/pytorch_tests/test_full.py
index 0ed45aef8d1..3371076e5a2 100644
--- a/tests/layer_tests/pytorch_tests/test_full.py
+++ b/tests/layer_tests/pytorch_tests/test_full.py
@@ -27,7 +27,7 @@ class TestFull(PytorchLayerTest):
class aten_full(torch.nn.Module):
def __init__(self, shape):
- super(aten_full, self).__init__()
+ super().__init__()
self.shape = shape
def forward(self, x: float):
@@ -35,7 +35,7 @@ class TestFull(PytorchLayerTest):
class aten_full_dtype(torch.nn.Module):
def __init__(self, shape, dtype):
- super(aten_full_dtype, self).__init__()
+ super().__init__()
self.shape = shape
self.dtype = dtype
@@ -44,7 +44,7 @@ class TestFull(PytorchLayerTest):
class aten_full_dtype_with_names(torch.nn.Module):
def __init__(self, shape, dtype):
- super(aten_full_dtype_with_names, self).__init__()
+ super().__init__()
self.shape = shape
self.dtype = dtype
@@ -53,7 +53,7 @@ class TestFull(PytorchLayerTest):
class aten_full_out(torch.nn.Module):
def __init__(self, shape, dtype):
- super(aten_full_out, self).__init__()
+ super().__init__()
self.shape = shape
self.dtype = dtype
@@ -62,14 +62,13 @@ class TestFull(PytorchLayerTest):
class aten_full_out_with_names(torch.nn.Module):
def __init__(self, shape, dtype):
- super(aten_full_out_with_names, self).__init__()
+ super().__init__()
self.shape = shape
self.dtype = dtype
def forward(self, x: float):
return torch.full(self.shape, x, out=torch.tensor(1, dtype=self.dtype), names=None)
- ref_net = None
model = aten_full(shape)
if use_dtype or use_out:
dtype = dtype_map.get(dtype, dtype)
@@ -78,7 +77,7 @@ class TestFull(PytorchLayerTest):
else:
model = aten_full_out(shape, dtype) if not with_names else aten_full_out_with_names(shape, dtype)
- return model, ref_net, "aten::full"
+ return model, "aten::full"
@pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]])
@pytest.mark.parametrize("value", [0, 1, -1, 0.5])
@@ -111,8 +110,8 @@ class TestFull(PytorchLayerTest):
class TestFill(PytorchLayerTest):
def _prepare_input(self, value, shape, input_dtype, value_dtype, out=False):
if not out:
- return (np.random.randn(*shape).astype(input_dtype), np.array(value, dtype=value_dtype),)
- return (np.random.randn(*shape).astype(input_dtype), np.array(value, dtype=value_dtype), np.zeros(shape, dtype=input_dtype))
+ return (self.random.randn(*shape, dtype=input_dtype), np.array(value, dtype=value_dtype),)
+ return (self.random.randn(*shape, dtype=input_dtype), np.array(value, dtype=value_dtype), np.zeros(shape, dtype=input_dtype))
def create_model(self, mode):
@@ -136,11 +135,10 @@ class TestFill(PytorchLayerTest):
def forward(self, input_t: torch.Tensor, x:float):
return input_t.fill(x)
- ref_net = None
model = aten_fill(mode)
- return model, ref_net, "aten::fill_" if mode == "inplace" else "aten::fill"
+ return model, "aten::fill_" if mode == "inplace" else "aten::fill"
@pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]])
@pytest.mark.parametrize("value", [0, 1, -1, 0.5])
@@ -178,10 +176,9 @@ class TestFillDiagonal(PytorchLayerTest):
x = x.reshape(self.input_shape)
return x.fill_diagonal_(y, wrap=self.wrap), x
- ref_net = None
model = aten_fill_diagonal(shape, wrap)
- return model, "aten::fill_diagonal_", ref_net
+ return model, "aten::fill_diagonal_"
@pytest.mark.parametrize("shape", ([4, 4], [5, 4], [8, 4], [4, 3], [5, 5, 5], [3, 3, 3, 3], [4, 4, 4, 4, 4]))
@pytest.mark.parametrize("value", [0, 1, -1, 2.5])
@@ -206,7 +203,7 @@ class TestFillDiagonal(PytorchLayerTest):
class TestZero(PytorchLayerTest):
def _prepare_input(self, shape, input_dtype):
- return (np.random.randn(*shape).astype(input_dtype),)
+ return (self.random.randn(*shape, dtype=input_dtype),)
def create_model(self):
import torch
@@ -215,11 +212,10 @@ class TestZero(PytorchLayerTest):
def forward(self, input_t: torch.Tensor):
return input_t.zero_()
- ref_net = None
model = aten_zero()
- return model, ref_net, "aten::zero_"
+ return model, "aten::zero_"
@pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]])
@pytest.mark.parametrize("input_dtype", ["int8", "int32", "int64", "float32", "float64"])
@@ -233,7 +229,7 @@ class TestZero(PytorchLayerTest):
class TestFullLike(PytorchLayerTest):
def _prepare_input(self, value, shape):
- return (np.random.randn(*shape).astype(np.float32), np.array(value, dtype=np.float32),)
+ return (self.random.randn(*shape), np.array(value, dtype=np.float32),)
def create_model(self, dtype=None, use_dtype=False, use_out=False):
import torch
@@ -254,7 +250,7 @@ class TestFullLike(PytorchLayerTest):
class aten_full_like_dtype(torch.nn.Module):
def __init__(self, dtype):
- super(aten_full_like_dtype, self).__init__()
+ super().__init__()
self.dtype = dtype
def forward(self, input_t: torch.Tensor, x: float):
@@ -262,13 +258,12 @@ class TestFullLike(PytorchLayerTest):
class aten_full_like_out(torch.nn.Module):
def __init__(self, dtype):
- super(aten_full_like_out, self).__init__()
+ super().__init__()
self.dtype = dtype
def forward(self, input_t: torch.Tensor, x: float):
return torch.full_like(input_t, x, out=torch.tensor(1, dtype=self.dtype))
- ref_net = None
model = aten_full_like()
if use_dtype or use_out:
@@ -278,7 +273,7 @@ class TestFullLike(PytorchLayerTest):
else:
model = aten_full_like_out(dtype)
- return model, ref_net, "aten::full_like"
+ return model, "aten::full_like"
@pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]])
@pytest.mark.parametrize("value", [0, 1, -1, 0.5])
@@ -308,7 +303,7 @@ class TestFullLike(PytorchLayerTest):
class TestNewFull(PytorchLayerTest):
def _prepare_input(self, value, input_dtype=np.float32):
- return (np.random.randn(1, 3, 10, 10).astype(input_dtype), np.array(value, dtype=np.float32))
+ return (self.random.randn(1, 3, 10, 10, dtype=input_dtype), np.array(value, dtype=np.float32))
def create_model(self, shape, dtype=None, used_dtype=False):
import torch
@@ -324,7 +319,7 @@ class TestNewFull(PytorchLayerTest):
class aten_full(torch.nn.Module):
def __init__(self, shape):
- super(aten_full, self).__init__()
+ super().__init__()
self.shape = shape
def forward(self, input_tensor: torch.Tensor, x: float):
@@ -332,21 +327,20 @@ class TestNewFull(PytorchLayerTest):
class aten_full_with_dtype(torch.nn.Module):
def __init__(self, shape, dtype):
- super(aten_full_with_dtype, self).__init__()
+ super().__init__()
self.shape = shape
self.dtype = dtype
def forward(self, input_tensor: torch.Tensor, x: float):
return input_tensor.new_full(size=self.shape, fill_value=x, dtype=self.dtype), input_tensor
- ref_net = None
model = aten_full(shape)
if used_dtype:
dtype = dtype_map[dtype]
model = aten_full_with_dtype(shape, dtype)
- return model, ref_net, "aten::new_full"
+ return model, "aten::new_full"
@pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]])
@pytest.mark.parametrize("value,input_dtype", [(0, np.uint8), (1, np.int32), (-1, np.float32), (0.5, np.float64)])
@@ -368,7 +362,7 @@ class TestNewFull(PytorchLayerTest):
class TestZerosAndOnes(PytorchLayerTest):
def _prepare_input(self, shape):
- return (np.random.randn(*shape).astype(np.float32),)
+ return (self.random.randn(*shape),)
def create_model(self, op_type, dtype=None, with_dtype=False, with_out=False, with_names=False):
import torch
@@ -390,7 +384,7 @@ class TestZerosAndOnes(PytorchLayerTest):
class aten_op(torch.nn.Module):
def __init__(self, op):
- super(aten_op, self).__init__()
+ super().__init__()
self.op = op
def forward(self, x):
@@ -399,7 +393,7 @@ class TestZerosAndOnes(PytorchLayerTest):
class aten_op_like(torch.nn.Module):
def __init__(self, op):
- super(aten_op_like, self).__init__()
+ super().__init__()
self.op = op
def forward(self, x):
@@ -407,7 +401,7 @@ class TestZerosAndOnes(PytorchLayerTest):
class aten_op_dtype(torch.nn.Module):
def __init__(self, op, dtype):
- super(aten_op_dtype, self).__init__()
+ super().__init__()
self.op = op
self.dtype = dtype
@@ -422,7 +416,7 @@ class TestZerosAndOnes(PytorchLayerTest):
class aten_op_like_dtype(torch.nn.Module):
def __init__(self, op, dtype):
- super(aten_op_like_dtype, self).__init__()
+ super().__init__()
self.op = op
self.dtype = dtype
@@ -431,7 +425,7 @@ class TestZerosAndOnes(PytorchLayerTest):
class aten_op_out(torch.nn.Module):
def __init__(self, op, dtype):
- super(aten_op_out, self).__init__()
+ super().__init__()
self.op = op
self.dtype = dtype
@@ -441,7 +435,7 @@ class TestZerosAndOnes(PytorchLayerTest):
class aten_op_out_with_names(torch.nn.Module):
def __init__(self, op, dtype):
- super(aten_op_out_with_names, self).__init__()
+ super().__init__()
self.op = op
self.dtype = dtype
@@ -451,7 +445,7 @@ class TestZerosAndOnes(PytorchLayerTest):
class aten_op_like_out(torch.nn.Module):
def __init__(self, op, dtype):
- super(aten_op_like_out, self).__init__()
+ super().__init__()
self.op = op
self.dtype = dtype
@@ -474,9 +468,8 @@ class TestZerosAndOnes(PytorchLayerTest):
dtype = dtype_map[dtype]
model_cls = aten_op_like_dtype(op, dtype) if not with_out else aten_op_like_out(op, dtype)
- ref_net = None
- return model_cls, ref_net, op_type
+ return model_cls, op_type
@pytest.mark.parametrize("shape", [(1, 1), (1, 2), (1, 2, 3), (1, 2, 3, 4), (2, 3, 4, 5, 6)])
@pytest.mark.parametrize("op_type", ["aten::zeros", "aten::ones", "aten::zeros_like", "aten::ones_like"])
@@ -531,7 +524,7 @@ class TestZerosAndOnes(PytorchLayerTest):
class TestNewZeros(PytorchLayerTest):
def _prepare_input(self, input_dtype=np.float32):
- return (np.random.randn(1, 3, 10, 10).astype(input_dtype),)
+ return (self.random.randn(1, 3, 10, 10, dtype=input_dtype),)
def create_model(self, shape, dtype=None, used_dtype=False):
import torch
@@ -547,7 +540,7 @@ class TestNewZeros(PytorchLayerTest):
class aten_full(torch.nn.Module):
def __init__(self, shape):
- super(aten_full, self).__init__()
+ super().__init__()
self.shape = shape
def forward(self, input_tensor: torch.Tensor):
@@ -555,21 +548,20 @@ class TestNewZeros(PytorchLayerTest):
class aten_full_with_dtype(torch.nn.Module):
def __init__(self, shape, dtype):
- super(aten_full_with_dtype, self).__init__()
+ super().__init__()
self.shape = shape
self.dtype = dtype
def forward(self, input_tensor: torch.Tensor):
return input_tensor.new_zeros(self.shape, dtype=self.dtype), input_tensor
- ref_net = None
model = aten_full(shape)
if used_dtype:
dtype = dtype_map[dtype]
model = aten_full_with_dtype(shape, dtype)
- return model, ref_net, "aten::new_zeros"
+ return model, "aten::new_zeros"
@pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]])
@pytest.mark.parametrize("input_dtype", [np.uint8, np.int8, np.int32, np.int64, np.float32, np.float64])
@@ -592,7 +584,7 @@ class TestNewZeros(PytorchLayerTest):
class TestNewOnes(PytorchLayerTest):
def _prepare_input(self, input_dtype=np.float32):
- return (np.random.randn(1, 3, 10, 10).astype(input_dtype),)
+ return (self.random.randn(1, 3, 10, 10, dtype=input_dtype),)
def create_model(self, shape, dtype=None, used_dtype=False):
import torch
@@ -608,7 +600,7 @@ class TestNewOnes(PytorchLayerTest):
class aten_full(torch.nn.Module):
def __init__(self, shape):
- super(aten_full, self).__init__()
+ super().__init__()
self.shape = shape
def forward(self, input_tensor: torch.Tensor):
@@ -616,21 +608,20 @@ class TestNewOnes(PytorchLayerTest):
class aten_full_with_dtype(torch.nn.Module):
def __init__(self, shape, dtype):
- super(aten_full_with_dtype, self).__init__()
+ super().__init__()
self.shape = shape
self.dtype = dtype
def forward(self, input_tensor: torch.Tensor):
return input_tensor.new_ones(self.shape, dtype=self.dtype), input_tensor
- ref_net = None
model = aten_full(shape)
if used_dtype:
dtype = dtype_map[dtype]
model = aten_full_with_dtype(shape, dtype)
- return model, ref_net, "aten::new_ones"
+ return model, "aten::new_ones"
@pytest.mark.parametrize("shape", [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 5, 6]])
@pytest.mark.parametrize("input_dtype", [np.uint8, np.int8, np.int32, np.int64, np.float32, np.float64])
diff --git a/tests/layer_tests/pytorch_tests/test_gather.py b/tests/layer_tests/pytorch_tests/test_gather.py
index 6b515b7a6ef..fe7c590941f 100644
--- a/tests/layer_tests/pytorch_tests/test_gather.py
+++ b/tests/layer_tests/pytorch_tests/test_gather.py
@@ -9,8 +9,8 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestGather(PytorchLayerTest):
def _prepare_input(self, m, n, max_val, out=False):
import numpy as np
- index = np.random.randint(0, max_val, (m, n)).astype(np.int64)
- inp = np.random.randn(m, n).astype(np.float32)
+ index = self.random.randint(0, max_val, (m, n), dtype=np.int64)
+ inp = self.random.randn(m, n)
if out:
axis = int(max_val == n)
out = np.zeros_like(np.take(inp, index, axis))
@@ -22,7 +22,7 @@ class TestGather(PytorchLayerTest):
class aten_gather(torch.nn.Module):
def __init__(self, axis, out=False):
- super(aten_gather, self).__init__()
+ super().__init__()
self.axis = axis
if out:
self.forward = self.forward_out
@@ -33,9 +33,8 @@ class TestGather(PytorchLayerTest):
def forward_out(self, x, index, out):
return torch.gather(x, self.axis, index, out=out)
- ref_net = None
- return aten_gather(axis, out), ref_net, "aten::gather"
+ return aten_gather(axis, out), "aten::gather"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_gcd.py b/tests/layer_tests/pytorch_tests/test_gcd.py
index 1bbf9cec904..6aea028f55c 100644
--- a/tests/layer_tests/pytorch_tests/test_gcd.py
+++ b/tests/layer_tests/pytorch_tests/test_gcd.py
@@ -20,9 +20,8 @@ class TestGcd(PytorchLayerTest):
def forward(self, tensor_a, tensor_b):
return torch.gcd(tensor_a, tensor_b)
- ref_net = None
- return aten_gcd_tensor(), ref_net, "aten::gcd"
+ return aten_gcd_tensor(), "aten::gcd"
def create_model_int_input(self):
class aten_gcd_int(torch.nn.Module):
@@ -32,9 +31,8 @@ class TestGcd(PytorchLayerTest):
def forward(self, int_a: int, int_b: int):
return torch.tensor(torch.gcd(int_a, int_b))
- ref_net = None
- return aten_gcd_int(), ref_net, "aten::gcd"
+ return aten_gcd_int(), "aten::gcd"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_gelu.py b/tests/layer_tests/pytorch_tests/test_gelu.py
index 8c9c7d9360f..28e9882c229 100644
--- a/tests/layer_tests/pytorch_tests/test_gelu.py
+++ b/tests/layer_tests/pytorch_tests/test_gelu.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestGelu(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 3).astype(np.float32),)
+ return (self.random.randn(2, 3),)
def create_model(self, approximate):
import torch
@@ -17,15 +16,14 @@ class TestGelu(PytorchLayerTest):
class aten_gelu(torch.nn.Module):
def __init__(self, approximate='none'):
- super(aten_gelu, self).__init__()
+ super().__init__()
self.approximate = approximate
def forward(self, x):
return F.gelu(x, approximate=self.approximate)
- ref_net = None
- return aten_gelu(approximate), ref_net, "aten::gelu"
+ return aten_gelu(approximate), "aten::gelu"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_getitem.py b/tests/layer_tests/pytorch_tests/test_getitem.py
index d8212e36be3..fa4d76ffa2c 100644
--- a/tests/layer_tests/pytorch_tests/test_getitem.py
+++ b/tests/layer_tests/pytorch_tests/test_getitem.py
@@ -9,8 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestGetItem(PytorchLayerTest):
def _prepare_input(self, input_shape):
- import numpy as np
- return (np.random.randn(*input_shape).astype(np.float32),)
+ return (self.random.randn(*input_shape),)
def create_model(self, idx, case="size_with_getitem"):
class aten_size_get_item(torch.nn.Module):
@@ -33,14 +32,13 @@ class TestGetItem(PytorchLayerTest):
res = x.shape[-self.idx]
return res
- ref_net = None
op_cls = {
"getitem": (aten_size_get_item, ["aten::size", "aten::__getitem__"]),
"getitem_with_if": (aten_size_get_item_with_if, ["aten::size", "aten::__getitem__", "prim::If"])
}
op, op_in_graph = op_cls[case]
- return op(idx), ref_net, op_in_graph
+ return op(idx), op_in_graph
@pytest.mark.nightly
@pytest.mark.precommit
@@ -94,12 +92,11 @@ class aten_add_getitem(torch.nn.Module):
class TestAddGetItem(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 1, 3),)
+ return (self.random.randn(2, 1, 3),)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.parametrize("idx", [-4, -3, -2, -1, 0, 1, 2, 3])
def test_add_cat(self, ie_device, precision, ir_version, idx):
- self._test(aten_add_getitem(idx), None, ["aten::__getitem__", "aten::add", "prim::ListConstruct"],
+ self._test(aten_add_getitem(idx), ["aten::__getitem__", "aten::add", "prim::ListConstruct"],
ie_device, precision, ir_version, freeze_model=False, use_convert_model=True)
diff --git a/tests/layer_tests/pytorch_tests/test_glu.py b/tests/layer_tests/pytorch_tests/test_glu.py
index 2ad9011c7c8..c29c57e9bf5 100644
--- a/tests/layer_tests/pytorch_tests/test_glu.py
+++ b/tests/layer_tests/pytorch_tests/test_glu.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestGlu(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 4, 224, 224).astype(np.float32),)
+ return (self.random.randn(2, 4, 224, 224),)
def create_model(self, dim):
import torch
@@ -17,15 +16,14 @@ class TestGlu(PytorchLayerTest):
class aten_glu(torch.nn.Module):
def __init__(self, dim):
- super(aten_glu, self).__init__()
+ super().__init__()
self.dim = dim
def forward(self, x):
return F.glu(x, self.dim)
- ref_net = None
- return aten_glu(dim), ref_net, "aten::glu"
+ return aten_glu(dim), "aten::glu"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_grid_sampler.py b/tests/layer_tests/pytorch_tests/test_grid_sampler.py
index f82c2b465bc..6834ba0ed22 100644
--- a/tests/layer_tests/pytorch_tests/test_grid_sampler.py
+++ b/tests/layer_tests/pytorch_tests/test_grid_sampler.py
@@ -10,8 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestGridSampler(PytorchLayerTest):
def _prepare_input(self, h_in, w_in, h_out, w_out):
- import numpy as np
- return (np.random.randn(1, 3, h_in, w_in).astype(np.float32), np.random.randn(1, h_out, w_out, 2).astype(np.float32))
+ return (self.random.randn(1, 3, h_in, w_in), self.random.randn(1, h_out, w_out, 2))
def create_model(self, mode, padding_mode, align_corners):
import torch
@@ -19,7 +18,7 @@ class TestGridSampler(PytorchLayerTest):
class aten_grid_sampler(torch.nn.Module):
def __init__(self, mode, padding_mode, align_corners):
- super(aten_grid_sampler, self).__init__()
+ super().__init__()
self.mode = mode
self.padding_mode = padding_mode
self.align_corners = align_corners
@@ -27,14 +26,13 @@ class TestGridSampler(PytorchLayerTest):
def forward(self, input, grid):
return F.grid_sample(input, grid, self.mode, self.padding_mode, self.align_corners)
- ref_net = None
- return aten_grid_sampler(mode, padding_mode, align_corners), ref_net, "aten::grid_sampler"
+ return aten_grid_sampler(mode, padding_mode, align_corners), "aten::grid_sampler"
@pytest.mark.parametrize(["h_in", "w_in", "h_out", "w_out"], ([10, 10, 5, 5], [10, 15, 3, 5]))
@pytest.mark.parametrize("mode", ["bilinear", "nearest", "bicubic"])
@pytest.mark.parametrize("padding_mode", ["zeros", "border", "reflection"])
- @pytest.mark.parametrize("align_corners", [True, False, None])
+ @pytest.mark.parametrize("align_corners", [True, False])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
diff --git a/tests/layer_tests/pytorch_tests/test_group_norm.py b/tests/layer_tests/pytorch_tests/test_group_norm.py
index 1240d900a17..302f7693012 100644
--- a/tests/layer_tests/pytorch_tests/test_group_norm.py
+++ b/tests/layer_tests/pytorch_tests/test_group_norm.py
@@ -8,31 +8,29 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestGroupNorm(PytorchLayerTest):
def _prepare_input(self, ndim=4):
- import numpy as np
shape5d = [20, 6, 10, 10, 10]
shape = shape5d[:ndim]
- return (np.random.randn(*shape).astype(np.float32),)
+ return (self.random.randn(*shape),)
def create_model(self, n_groups, weights_shape=None, bias=False, eps=1e-05):
import torch
import torch.nn.functional as F
class aten_group_norm(torch.nn.Module):
- def __init__(self, n_groups, weights_shape=None, bias=True, eps=1e-05):
- super(aten_group_norm, self).__init__()
- self.weight = torch.randn(weights_shape) if weights_shape else None
+ def __init__(self, rng, n_groups, weights_shape=None, bias=True, eps=1e-05):
+ super().__init__()
+ self.weight = rng.torch_randn(*weights_shape) if weights_shape else None
self.bias = None
if bias:
- self.bias = torch.randn(weights_shape)
+ self.bias = rng.torch_randn(*weights_shape)
self.n_groups = n_groups
self.eps = eps
def forward(self, x):
return F.group_norm(x, self.n_groups, self.weight, self.bias, self.eps)
- ref_net = None
- return aten_group_norm(n_groups, weights_shape, bias, eps), ref_net, "aten::group_norm"
+ return aten_group_norm(self.random, n_groups, weights_shape, bias, eps), "aten::group_norm"
@pytest.mark.parametrize("params",
[
diff --git a/tests/layer_tests/pytorch_tests/test_hadsigmoid.py b/tests/layer_tests/pytorch_tests/test_hadsigmoid.py
index 53719b083b7..53317e8e409 100644
--- a/tests/layer_tests/pytorch_tests/test_hadsigmoid.py
+++ b/tests/layer_tests/pytorch_tests/test_hadsigmoid.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestHardSigmoid(PytorchLayerTest):
def _prepare_input(self, shape, dtype):
- import numpy as np
- return (np.random.randn(*shape).astype(dtype),)
+ return (self.random.randn(*shape, dtype=dtype),)
def create_model(self, inplace):
import torch
@@ -17,15 +16,14 @@ class TestHardSigmoid(PytorchLayerTest):
class aten_hardsigmoid(torch.nn.Module):
def __init__(self, inplace):
- super(aten_hardsigmoid, self).__init__()
+ super().__init__()
self.inplace = inplace
def forward(self, x):
return F.hardsigmoid(x, self.inplace), x
- ref_net = None
- return aten_hardsigmoid(inplace), ref_net, "aten::hardsigmoid" if not inplace else "aten::hardsigmoid_"
+ return aten_hardsigmoid(inplace), "aten::hardsigmoid" if not inplace else "aten::hardsigmoid_"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_hann_window.py b/tests/layer_tests/pytorch_tests/test_hann_window.py
index 74aef403f85..a59ee392151 100644
--- a/tests/layer_tests/pytorch_tests/test_hann_window.py
+++ b/tests/layer_tests/pytorch_tests/test_hann_window.py
@@ -27,7 +27,7 @@ class TestHannWindow(PytorchLayerTest):
class aten_hann_window(torch.nn.Module):
def __init__(self, periodic, dtype, out):
- super(aten_hann_window, self).__init__()
+ super().__init__()
self.periodic = periodic
self.dtype = dtype
@@ -56,9 +56,8 @@ class TestHannWindow(PytorchLayerTest):
def forward_periodic(self, x):
return torch.hann_window(x, periodic=self.periodic)
- ref_net = None
- return aten_hann_window(periodic, torch_dtype, out), ref_net, "aten::hann_window"
+ return aten_hann_window(periodic, torch_dtype, out), "aten::hann_window"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_hardtanh.py b/tests/layer_tests/pytorch_tests/test_hardtanh.py
index 4123821f493..a6de6a11a3c 100644
--- a/tests/layer_tests/pytorch_tests/test_hardtanh.py
+++ b/tests/layer_tests/pytorch_tests/test_hardtanh.py
@@ -1,9 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import platform
-
-import numpy as np
import pytest
import torch
@@ -12,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestHardtanh(PytorchLayerTest):
def _prepare_input(self, input_dtype="float32", input_shape=(1, 3, 10, 10)):
- return (np.random.default_rng().uniform(-100.0, 100.0, input_shape).astype(input_dtype),)
+ return (self.random.uniform(-100.0, 100.0, input_shape, dtype=input_dtype),)
def create_model(self, min_val, max_val, inplace):
import torch
@@ -20,7 +17,7 @@ class TestHardtanh(PytorchLayerTest):
class aten_hardtanh(torch.nn.Module):
def __init__(self, min_val, max_val, inplace):
- super(aten_hardtanh, self).__init__()
+ super().__init__()
self.min_val = min_val
self.max_val = max_val
self.inplace = inplace
@@ -28,9 +25,8 @@ class TestHardtanh(PytorchLayerTest):
def forward(self, x):
return F.hardtanh(x, min_val=self.min_val, max_val=self.max_val, inplace=self.inplace)
- ref_net = None
- return aten_hardtanh(min_val, max_val, inplace), ref_net, "aten::hardtanh"
+ return aten_hardtanh(min_val, max_val, inplace), "aten::hardtanh"
@pytest.mark.parametrize(("min_val", "max_val"), [[-1.0,1.0], [0, 1.0], [-2.0, 2.0]])
@pytest.mark.parametrize("inplace", [True, False])
diff --git a/tests/layer_tests/pytorch_tests/test_hstack.py b/tests/layer_tests/pytorch_tests/test_hstack.py
index 0a0bca1d4fc..6c0b856e2ee 100644
--- a/tests/layer_tests/pytorch_tests/test_hstack.py
+++ b/tests/layer_tests/pytorch_tests/test_hstack.py
@@ -21,7 +21,7 @@ class aten_hstack_out(aten_hstack):
class TestHstack(PytorchLayerTest):
def _prepare_input(self, out=False, num_repeats=2):
- data = np.random.randn(2, 1, 3)
+ data = self.random.randn(2, 1, 3)
if not out:
return (data, )
concat = [data for _ in range(num_repeats)]
@@ -33,7 +33,7 @@ class TestHstack(PytorchLayerTest):
@pytest.mark.parametrize("out", [False, True])
def test_hstack(self, out, ie_device, precision, ir_version):
model = aten_hstack() if not out else aten_hstack_out()
- self._test(model, None, "aten::hstack", ie_device,
+ self._test(model, "aten::hstack", ie_device,
precision, ir_version, kwargs_to_prepare_input={"out": out, "num_repeats": 2})
@@ -42,7 +42,7 @@ class TestHstackAlignTypes(PytorchLayerTest):
in_vals = []
for i in range(len(in_types)):
dtype = in_types[i]
- in_vals.append(np.random.randn(2, 1, 3).astype(dtype))
+ in_vals.append(self.random.randn(2, 1, 3, dtype=dtype))
return in_vals
def create_model(self, in_count):
@@ -83,5 +83,5 @@ class TestHstackAlignTypes(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_align_types_hstack(self, ie_device, precision, ir_version, in_types):
- self._test(self.create_model(len(in_types)), None, "aten::hstack",
+ self._test(self.create_model(len(in_types)), "aten::hstack",
ie_device, precision, ir_version, kwargs_to_prepare_input={"in_types": in_types})
\ No newline at end of file
diff --git a/tests/layer_tests/pytorch_tests/test_if.py b/tests/layer_tests/pytorch_tests/test_if.py
index 7d97f6d7b7e..ffdd870ad72 100644
--- a/tests/layer_tests/pytorch_tests/test_if.py
+++ b/tests/layer_tests/pytorch_tests/test_if.py
@@ -10,15 +10,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestIf(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(1, 3, 224, 224).astype(np.float32), self.y)
+ return (self.random.randn(1, 3, 224, 224), self.y)
def create_model(self):
import torch
- import torch.nn.functional as F
class prim_if(torch.nn.Module):
def __init__(self):
- super(prim_if, self).__init__()
+ super().__init__()
def forward(self, x, y):
if y > 0:
@@ -27,9 +26,8 @@ class TestIf(PytorchLayerTest):
res = torch.zeros(x.shape[:2], dtype=torch.bool)
return res.to(torch.bool)
- ref_net = None
- return prim_if(), ref_net, "prim::If"
+ return prim_if(), "prim::If"
@pytest.mark.parametrize("y", [np.array(1),
np.array(-1)
diff --git a/tests/layer_tests/pytorch_tests/test_im2col.py b/tests/layer_tests/pytorch_tests/test_im2col.py
index dc2afc1bf4f..8255c28bc24 100644
--- a/tests/layer_tests/pytorch_tests/test_im2col.py
+++ b/tests/layer_tests/pytorch_tests/test_im2col.py
@@ -8,15 +8,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestIm2Col(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(10, 3, 24, 24).astype(np.float32),)
+ return (self.random.randn(10, 3, 24, 24),)
def create_model(self, kernel_size, dilation, padding, stride):
import torch
class aten_im2col(torch.nn.Module):
def __init__(self, kernel_size, dilation, padding, stride):
- super(aten_im2col, self).__init__()
+ super().__init__()
self.kernel_size = kernel_size
self.dilation = dilation
self.padding = padding
@@ -31,9 +30,8 @@ class TestIm2Col(PytorchLayerTest):
stride=self.stride
)
- ref_net = None
- return aten_im2col(kernel_size, dilation, padding, stride), ref_net, "aten::im2col"
+ return aten_im2col(kernel_size, dilation, padding, stride), "aten::im2col"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_index.py b/tests/layer_tests/pytorch_tests/test_index.py
index 762de2cd671..8adf1c82187 100644
--- a/tests/layer_tests/pytorch_tests/test_index.py
+++ b/tests/layer_tests/pytorch_tests/test_index.py
@@ -10,8 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestIndex(PytorchLayerTest):
def _prepare_input(self, input_shape, idx=None):
- rng = np.random.default_rng(42)
- x = rng.standard_normal(size=input_shape, dtype=np.float32)
+ x = self.random.randn(*input_shape)
return (x,) if idx is None else (x, idx)
def create_model(self, model="list"):
@@ -49,7 +48,7 @@ class TestIndex(PytorchLayerTest):
aten_index = cases[model]
- return aten_index(), None, "aten::index"
+ return aten_index(), "aten::index"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -87,8 +86,7 @@ class TestIndex(PytorchLayerTest):
class TestIndexRange(PytorchLayerTest):
def _prepare_input(self, input_shape, idx):
- rng = np.random.default_rng(42)
- x = rng.standard_normal(size=input_shape, dtype=np.float32)
+ x = self.random.randn(*input_shape)
return (x, np.array(idx).astype(np.int32))
def create_model(self):
@@ -98,7 +96,7 @@ class TestIndexRange(PytorchLayerTest):
x = x.reshape(x.shape[0], -1)
return x[torch.arange(x.shape[0]), y]
- return aten_index_arange(), None, "aten::index"
+ return aten_index_arange(), "aten::index"
def create_model2(self):
class aten_index_arange(torch.nn.Module):
@@ -107,7 +105,7 @@ class TestIndexRange(PytorchLayerTest):
x = x.reshape(x.shape[0], x.shape[1], -1, 1)
return x[torch.arange(x.shape[0]), y]
- return aten_index_arange(), None, "aten::index"
+ return aten_index_arange(), "aten::index"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -134,8 +132,7 @@ class TestIndexRange(PytorchLayerTest):
class TestIndexMask(PytorchLayerTest):
def _prepare_input(self, input_shape):
- rng = np.random.default_rng(42)
- return (rng.standard_normal(size=input_shape, dtype=np.float32),)
+ return (self.random.randn(*input_shape),)
def create_model(self):
import torch
@@ -144,7 +141,7 @@ class TestIndexMask(PytorchLayerTest):
def forward(self, x):
return x[x > 0]
- return aten_index_mask(), None, "aten::index"
+ return aten_index_mask(), "aten::index"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -158,9 +155,8 @@ class TestIndexMask(PytorchLayerTest):
class TestIndexNone(PytorchLayerTest):
- def _prepare_input(self, input_shape):
- rng = np.random.default_rng(42)
- return (rng.standard_normal(size=input_shape, dtype=np.float32),)
+ def _prepare_input(self):
+ return (self.random.randn(2, 3, 4, 5),)
class aten_index_list(torch.nn.Module):
def __init__(self, idxs):
@@ -171,11 +167,17 @@ class TestIndexNone(PytorchLayerTest):
return x[self.idxs]
@pytest.mark.nightly
- @pytest.mark.parametrize(("input_shape,idxs"), [
- ((2, 3, 4, 5), (torch.unsqueeze(torch.randint(0, 2, [14], dtype=torch.int32), 1),)),
- ((2, 3, 4, 5), (torch.unsqueeze(torch.randint(0, 2, [14], dtype=torch.int32), 1), torch.randint(0, 3, [14], dtype=torch.int32))),
- ((2, 3, 4, 5), (None, None, torch.unsqueeze(torch.randint(0, 2, [14], dtype=torch.int32), 1), torch.randint(0, 3, [14], dtype=torch.int32))),
- ])
- def test_index(self, input_shape, idxs, ie_device, precision, ir_version):
- self._test(self.aten_index_list(idxs), None, "aten::index", ie_device, precision,
- ir_version,kwargs_to_prepare_input={"input_shape": input_shape}, use_convert_model=True, trace_model=True)
+ @pytest.mark.precommit
+ @pytest.mark.parametrize("case", ["two_nones", "none_second"])
+ def test_index(self, case, ie_device, precision, ir_version):
+ idx_a = self.random.torch_randint(0, 2, [14], dtype=torch.int32)
+ idx_b = self.random.torch_randint(0, 3, [14], dtype=torch.int32)
+ idx_c = self.random.torch_randint(0, 2, [14, 1], dtype=torch.int32)
+
+ if case == "two_nones":
+ idxs = (None, None, idx_c, idx_b)
+ else:
+ idxs = (idx_a, None, idx_c, idx_b)
+
+ self._test(self.aten_index_list(idxs), "aten::index", ie_device, precision,
+ ir_version, use_convert_model=True, trace_model=True)
diff --git a/tests/layer_tests/pytorch_tests/test_index_add.py b/tests/layer_tests/pytorch_tests/test_index_add.py
index b3f827d5369..7def7a0f3fa 100644
--- a/tests/layer_tests/pytorch_tests/test_index_add.py
+++ b/tests/layer_tests/pytorch_tests/test_index_add.py
@@ -16,7 +16,7 @@ class TestIndexAdd(PytorchLayerTest):
def create_model(self, dim, index, src, mode, alpha):
class aten_index_add(torch.nn.Module):
def __init__(self, dim, index, src, mode, alpha):
- super(aten_index_add, self).__init__()
+ super().__init__()
self.dim = dim
self.index = index
self.src = src
@@ -38,7 +38,7 @@ class TestIndexAdd(PytorchLayerTest):
op_name = "aten::index_add_" if mode == "inplace" else "aten::index_add"
- return aten_index_add(dim, index, src, mode, alpha), None, op_name
+ return aten_index_add(dim, index, src, mode, alpha), op_name
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_index_copy_.py b/tests/layer_tests/pytorch_tests/test_index_copy_.py
index 835338ff51d..dcd7fb9482d 100644
--- a/tests/layer_tests/pytorch_tests/test_index_copy_.py
+++ b/tests/layer_tests/pytorch_tests/test_index_copy_.py
@@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -27,9 +26,8 @@ class TestIndexCopy(PytorchLayerTest):
input_tensor.index_copy_(self.dim, self.index, values)
return input_tensor
- ref_net = None
op_name = "aten::index_copy_" if inplace else "aten::index_copy"
- return aten_index_copy_(dim, index, inplace), ref_net, op_name
+ return aten_index_copy_(dim, index, inplace), op_name
@pytest.mark.parametrize(
"input_data",
@@ -84,8 +82,8 @@ class TestIndexCopy(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
@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)
+ self.input_tensor = self.random.randn(*input_data["input_shape"])
+ self.values = self.random.randn(*input_data["values_shape"])
index = input_data["index"]
dim = input_data["dim"]
self._test(*self.create_model(dim, index, inplace), ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_index_fill_.py b/tests/layer_tests/pytorch_tests/test_index_fill_.py
index 81fa24b212b..6f70cf7a195 100644
--- a/tests/layer_tests/pytorch_tests/test_index_fill_.py
+++ b/tests/layer_tests/pytorch_tests/test_index_fill_.py
@@ -25,9 +25,8 @@ class TestIndexFill(PytorchLayerTest):
input_tensor.index_fill_(self.dim, self.index, self.values)
return input_tensor
- ref_net = None
- return aten_index_fill_(dim, index, values), ref_net, "aten::index_fill_"
+ return aten_index_fill_(dim, index, values), "aten::index_fill_"
@pytest.mark.parametrize(
"input_data",
@@ -73,11 +72,11 @@ class TestIndexFill(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_index_fill_single_index(self, ie_device, precision, ir_version, input_data):
- self.input_tensor = np.random.randn(*input_data["input_shape"]).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_data["input_shape"])
values = torch.tensor(np.float32(input_data["input_value"]))
dim = input_data["dim"]
shape = self.input_tensor.shape
max_idx = shape[dim]
- n_select = np.random.randint(1, max_idx + 1)
- index = torch.from_numpy(np.random.choice(np.arange(0, max_idx), n_select, replace=False)).to(torch.long)
+ n_select = self.random.randint(1, max_idx + 1)
+ index = torch.from_numpy(self.random.choice(np.arange(0, max_idx), n_select, replace=False)).to(torch.long)
self._test(*self.create_model(dim, index, values), ie_device, precision, ir_version)
\ No newline at end of file
diff --git a/tests/layer_tests/pytorch_tests/test_index_put_.py b/tests/layer_tests/pytorch_tests/test_index_put_.py
index b1eeba5a8f0..3b19aeaa781 100644
--- a/tests/layer_tests/pytorch_tests/test_index_put_.py
+++ b/tests/layer_tests/pytorch_tests/test_index_put_.py
@@ -24,9 +24,8 @@ class TestIndexPut_SingleIndices(PytorchLayerTest):
input_tensor.index_put_((self.indices,), values, self.accumulate)
return input_tensor
- ref_net = None
- return aten_index_put_(indices, accumulate), ref_net, "aten::index_put_"
+ return aten_index_put_(indices, accumulate), "aten::index_put_"
@pytest.mark.parametrize(
"input_data",
@@ -54,7 +53,7 @@ class TestIndexPut_SingleIndices(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_index_put_single_indices(self, ie_device, precision, ir_version, input_data, indices, accumulate):
- self.input_tensor = np.random.randn(*input_data["input_shape"]).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_data["input_shape"])
self.values = input_data["values"]
self._test(*self.create_model(indices, accumulate), ie_device, precision, ir_version)
@@ -75,9 +74,8 @@ class TestIndexPut_ManyIndices(PytorchLayerTest):
input_tensor.index_put_((self.indices_first, self.indices_second), values, self.accumulate)
return input_tensor
- ref_net = None
- return aten_index_put_(indices, accumulate), ref_net, "aten::index_put_"
+ return aten_index_put_(indices, accumulate), "aten::index_put_"
@pytest.mark.parametrize(
"input_data",
@@ -107,7 +105,7 @@ class TestIndexPut_ManyIndices(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_index_put_many_indices(self, ie_device, precision, ir_version, input_data, indices, accumulate):
- self.input_tensor = np.random.randn(*input_data["input_shape"]).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_data["input_shape"])
self.values = input_data["values"]
self._test(*self.create_model(indices, accumulate), ie_device, precision, ir_version)
@@ -128,9 +126,8 @@ class TestIndexPut_ManyIndicesWithNone(PytorchLayerTest):
def forward(self, input_tensor, values):
return torch.ops.aten.index_put_.default(input_tensor, (self.indices_first, self.indices_second, self.indices_third), values, self.accumulate)
- ref_net = None
- return aten_index_put_(indices, accumulate), ref_net, "aten::index_put_"
+ return aten_index_put_(indices, accumulate), "aten::index_put_"
@pytest.mark.parametrize(
"input_data",
@@ -171,9 +168,8 @@ class TestNonZero_IndexPut(PytorchLayerTest):
input_tensor.index_put_((nonzero,), values, self.accumulate)
return input_tensor
- ref_net = None
- return aten_index_put_(accumulate), ref_net, "aten::index_put_"
+ return aten_index_put_(accumulate), "aten::index_put_"
@pytest.mark.parametrize(
"input_data",
@@ -214,11 +210,11 @@ class TestNonZero_IndexPut(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_nonzero_index_put_(self, ie_device, precision, ir_version, input_data, indices, accumulate):
- self.input_tensor = np.random.randn(*input_data["input_shape"]).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_data["input_shape"])
self.values = input_data["values"]
for i in range(len(indices)):
if type(indices[i]) is list:
- indices[i] = np.random.randint(0, 2, indices[i])
+ indices[i] = self.random.randint(0, 2, indices[i])
self.indices_0 = indices[0]
self.indices_1 = indices[1]
self._test(*self.create_model(accumulate), ie_device, precision, ir_version, trace_model=True, use_convert_model=True)
@@ -226,7 +222,7 @@ class TestNonZero_IndexPut(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_nonzero_index_put_different_ranks(self, ie_device, precision, ir_version):
- self.input_tensor = np.random.randn(1, 10, 2).astype(np.float32)
+ self.input_tensor = self.random.randn(1, 10, 2)
self.values = np.zeros((10, 2), dtype=np.float32)
self.indices_0 = np.array([[0, 0, 1, 1, 1, 1, 1, 1, 0, 0]]).astype(np.float32)
self.indices_1 = np.zeros((1, 10), dtype=np.float32)
@@ -235,7 +231,7 @@ class TestNonZero_IndexPut(PytorchLayerTest):
class TestMask_IndexPut(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(100, 5).astype(np.float32), np.random.randn(100, 5).astype(np.float32))
+ return (self.random.randn(100, 5), self.random.randn(100, 5))
class aten_index_put_mask(torch.nn.Module):
def forward(self, x, y):
@@ -250,21 +246,21 @@ class TestMask_IndexPut(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_nonzero_index_put_(self, ie_device, precision, ir_version):
- self._test(self.aten_index_put_mask(), None, "aten::index_put_", ie_device, precision,
+ self._test(self.aten_index_put_mask(), "aten::index_put_", ie_device, precision,
ir_version, trace_model=True, use_convert_model=True)
@pytest.mark.nightly
@pytest.mark.precommit
def test_index_put_masked_fill(self, ie_device, precision, ir_version):
- self._test(self.aten_index_put_mask2(), None, "aten::index_put_", ie_device, precision,
+ self._test(self.aten_index_put_mask2(), "aten::index_put_", ie_device, precision,
ir_version, trace_model=True, use_convert_model=True)
class TestMaskKosmos_IndexPut(PytorchLayerTest):
def _prepare_input(self):
- mask = np.random.randint(0, 2, [1, 30]).astype(np.bool_)
+ mask = self.random.randint(0, 2, [1, 30], dtype=np.bool_)
num = mask.sum()
- return (np.random.randn(1, 30, 50).astype(np.float32), mask.astype(np.int32), np.random.randn(num, 50).astype(np.float32))
+ return (self.random.randn(1, 30, 50), mask.astype(np.int32), self.random.randn(num, 50))
def create_model(self):
class aten_index_put_mask(torch.nn.Module):
@@ -272,9 +268,8 @@ class TestMaskKosmos_IndexPut(PytorchLayerTest):
x[y.to(dtype=torch.bool)] = z
return x
- ref_net = None
- return aten_index_put_mask(), ref_net, "aten::index_put_"
+ return aten_index_put_mask(), "aten::index_put_"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_index_select.py b/tests/layer_tests/pytorch_tests/test_index_select.py
index 37808653954..d32920631de 100644
--- a/tests/layer_tests/pytorch_tests/test_index_select.py
+++ b/tests/layer_tests/pytorch_tests/test_index_select.py
@@ -10,7 +10,7 @@ class TestIndexSelect(PytorchLayerTest):
def _prepare_input(self, index, out=False, dim=0):
import numpy as np
index = np.array(index).astype(np.int32)
- input_data = np.random.randn(2, 3, 10, 10).astype(np.float32)
+ input_data = self.random.randn(2, 3, 10, 10)
if not out:
return (input_data, index)
out = np.zeros_like(np.take(input_data, axis=dim, indices=index))
@@ -21,7 +21,7 @@ class TestIndexSelect(PytorchLayerTest):
class aten_index_select(torch.nn.Module):
def __init__(self, dim, out=False):
- super(aten_index_select, self).__init__()
+ super().__init__()
self.dim = dim
if out:
self.forward = self.forward_out
@@ -32,9 +32,8 @@ class TestIndexSelect(PytorchLayerTest):
def forward_out(self, x, indices, out):
return out, torch.index_select(x, self.dim, indices, out=out)
- ref_net = None
- return aten_index_select(dim, out), ref_net, "aten::index_select"
+ return aten_index_select(dim, out), "aten::index_select"
@pytest.mark.parametrize("dim", [0, 1, 2, 3, -1, -2, -3])
@pytest.mark.parametrize("indices", [[0, 1], [0], [1, 0]])
diff --git a/tests/layer_tests/pytorch_tests/test_index_tensor.py b/tests/layer_tests/pytorch_tests/test_index_tensor.py
index 589b727dae8..5fefcdb337e 100644
--- a/tests/layer_tests/pytorch_tests/test_index_tensor.py
+++ b/tests/layer_tests/pytorch_tests/test_index_tensor.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestIndexTensor(PytorchLayerTest):
def _prepare_input(self, input_shape):
- import numpy as np
- return (np.random.randn(*input_shape).astype(np.float32),)
+ return (self.random.randn(*input_shape),)
def create_model(self, indices_list, safe: bool):
import torch
@@ -31,7 +30,7 @@ class TestIndexTensor(PytorchLayerTest):
continue
adjusted_indices_list.append(None)
- return aten_index_tensor(adjusted_indices_list), None, None
+ return aten_index_tensor(adjusted_indices_list), None
@pytest.mark.nightly
@pytest.mark.precommit_torch_export
diff --git a/tests/layer_tests/pytorch_tests/test_instance_norm.py b/tests/layer_tests/pytorch_tests/test_instance_norm.py
index d4585dd7948..5533590b09f 100644
--- a/tests/layer_tests/pytorch_tests/test_instance_norm.py
+++ b/tests/layer_tests/pytorch_tests/test_instance_norm.py
@@ -10,37 +10,35 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestInstanceNorm(PytorchLayerTest):
def _prepare_input(self, ndim=4):
- import numpy as np
shape5d = [3, 6, 10, 5, 2]
shape = shape5d[:ndim]
- return (np.random.randn(*shape).astype(np.float32),)
+ return (self.random.randn(*shape),)
def create_model(self, weights=False, bias=False, mean_var=False, eps=1e-05):
import torch
class aten_instance_norm(torch.nn.Module):
- def __init__(self, weights=False, bias=False, mean_var=False, eps=1e-05):
- super(aten_instance_norm, self).__init__()
+ def __init__(self, rng, weights=False, bias=False, mean_var=False, eps=1e-05):
+ super().__init__()
weights_shape = (6, )
- self.weight = torch.randn(weights_shape) if weights else None
+ self.weight = rng.torch_randn(*weights_shape) if weights else None
self.bias = None
self.use_input_stats = not mean_var
if bias:
- self.bias = torch.randn(weights_shape)
+ self.bias = rng.torch_randn(*weights_shape)
self.mean = None
self.var = None
if mean_var:
- self.mean = torch.randn(weights_shape)
- self.var = torch.randn(weights_shape)
+ self.mean = rng.torch_randn(*weights_shape)
+ self.var = rng.torch_randn(*weights_shape)
self.eps = eps
def forward(self, x):
return torch.instance_norm(x, self.weight, self.bias, self.mean, self.var, self.use_input_stats, 0.1, self.eps, False)
- ref_net = None
- return aten_instance_norm(weights, bias, mean_var, eps), ref_net, "aten::instance_norm"
+ return aten_instance_norm(self.random, weights, bias, mean_var, eps), "aten::instance_norm"
@pytest.mark.parametrize("params",
[
diff --git a/tests/layer_tests/pytorch_tests/test_inverse.py b/tests/layer_tests/pytorch_tests/test_inverse.py
index e18724171e6..6c0d47dc409 100644
--- a/tests/layer_tests/pytorch_tests/test_inverse.py
+++ b/tests/layer_tests/pytorch_tests/test_inverse.py
@@ -73,10 +73,10 @@ class TestInverse(PytorchLayerTest):
if ie_device == "GPU":
pytest.xfail(reason="Inverse-14 is not supported on GPU")
if not out:
- self._test(aten_inverse(), None, "aten::linalg_inv",
+ self._test(aten_inverse(), "aten::linalg_inv",
ie_device, precision, ir_version, trace_model=True, freeze_model=False)
else:
- self._test(aten_inverse_out(), None, "aten::linalg_inv",
+ self._test(aten_inverse_out(), "aten::linalg_inv",
ie_device, precision, ir_version, trace_model=True, freeze_model=False, kwargs_to_prepare_input={"out": out})
@pytest.mark.parametrize("shape", [
@@ -99,11 +99,13 @@ class TestInverse(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_inverse(self, shape, dtype, seed, out, ie_device, precision, ir_version):
- rng = np.random.default_rng(seed)
- self.input_tensor = rng.uniform(-10.0, 10.0, shape).astype(dtype)
+ base = self.random.uniform(-1.0, 1.0, size=shape, dtype=dtype)
+ n = shape[-1]
+ eye = np.eye(n, dtype=dtype).reshape((1,) * (len(shape) - 2) + (n, n))
+ self.input_tensor = base + eye * n
if not out:
- self._test(aten_inverse(), None, "aten::linalg_inv",
+ self._test(aten_inverse(), "aten::linalg_inv",
ie_device, precision, ir_version, trace_model=True, freeze_model=False)
else:
- self._test(aten_inverse_out(), None, "aten::linalg_inv",
+ self._test(aten_inverse_out(), "aten::linalg_inv",
ie_device, precision, ir_version, trace_model=True, freeze_model=False, kwargs_to_prepare_input={"out": out})
diff --git a/tests/layer_tests/pytorch_tests/test_is_nonzero.py b/tests/layer_tests/pytorch_tests/test_is_nonzero.py
index b22c72cf06f..0df0191d555 100644
--- a/tests/layer_tests/pytorch_tests/test_is_nonzero.py
+++ b/tests/layer_tests/pytorch_tests/test_is_nonzero.py
@@ -21,9 +21,8 @@ class TestIsNonZero(PytorchLayerTest):
def forward(self, input_tensor):
return torch.is_nonzero(input_tensor)
- ref_net = None
- return aten_is_nonzero(), ref_net, "aten::is_nonzero"
+ return aten_is_nonzero(), "aten::is_nonzero"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_isfinite.py b/tests/layer_tests/pytorch_tests/test_isfinite.py
index 927899fd62e..dd9c66ddde5 100644
--- a/tests/layer_tests/pytorch_tests/test_isfinite.py
+++ b/tests/layer_tests/pytorch_tests/test_isfinite.py
@@ -21,7 +21,7 @@ class TestIsFinite(PytorchLayerTest):
def forward(self, input_tensor):
return torch.isfinite(torch.pow(input_tensor.to(torch.float32), 1000))
- return aten_isfinite(), None, "aten::isfinite"
+ return aten_isfinite(), "aten::isfinite"
@pytest.mark.precommit_fx_backend
def test_isfinite(self, ie_device, precision, ir_version, input_tensor):
diff --git a/tests/layer_tests/pytorch_tests/test_isinf.py b/tests/layer_tests/pytorch_tests/test_isinf.py
index 370942ac6a6..7ec5f27d85a 100644
--- a/tests/layer_tests/pytorch_tests/test_isinf.py
+++ b/tests/layer_tests/pytorch_tests/test_isinf.py
@@ -21,7 +21,7 @@ class TestIsInf(PytorchLayerTest):
def forward(self, input_tensor):
return torch.isinf(input_tensor * float("inf"))
- return aten_isinf(), None, "aten::isinf"
+ return aten_isinf(), "aten::isinf"
@pytest.mark.precommit_fx_backend
def test_isinf(self, ie_device, precision, ir_version, input_tensor):
diff --git a/tests/layer_tests/pytorch_tests/test_isnan.py b/tests/layer_tests/pytorch_tests/test_isnan.py
index 24ef4a2cbe6..5830be6212b 100644
--- a/tests/layer_tests/pytorch_tests/test_isnan.py
+++ b/tests/layer_tests/pytorch_tests/test_isnan.py
@@ -21,7 +21,7 @@ class TestIsNan(PytorchLayerTest):
def forward(self, input_tensor):
return torch.isnan(input_tensor)
- return aten_isnan(), None, "aten::isnan"
+ return aten_isnan(), "aten::isnan"
@pytest.mark.precommit_fx_backend
def test_isnan(self, ie_device, precision, ir_version, input_tensor):
diff --git a/tests/layer_tests/pytorch_tests/test_istft.py b/tests/layer_tests/pytorch_tests/test_istft.py
index 22a91d2f001..58757da656c 100644
--- a/tests/layer_tests/pytorch_tests/test_istft.py
+++ b/tests/layer_tests/pytorch_tests/test_istft.py
@@ -12,7 +12,7 @@ class TestISTFT(PytorchLayerTest):
import numpy as np
if rand_data:
- signal = np.random.randn(*signal_shape).astype(out_dtype)
+ signal = self.random.randn(*signal_shape, dtype=out_dtype)
else:
num_samples = signal_shape[-1]
half_idx = num_samples // 2
@@ -59,7 +59,7 @@ class TestISTFT(PytorchLayerTest):
class aten_istft(torch.nn.Module):
def __init__(self, n_fft, hop_length, win_length, normalized, center):
- super(aten_istft, self).__init__()
+ super().__init__()
self.n_fft = n_fft
self.hop_length = hop_length
self.win_length = win_length
@@ -81,16 +81,15 @@ class TestISTFT(PytorchLayerTest):
length = None
)
- ref_net = None
- return aten_istft(n_fft, hop_length, win_length, normalized, center), ref_net, "aten::istft"
+ return aten_istft(n_fft, hop_length, win_length, normalized, center), "aten::istft"
def create_model_with_sig_len(self, n_fft, hop_length, win_length, normalized, center):
class aten_istft(torch.nn.Module):
def __init__(self, n_fft, hop_length, win_length, normalized, center):
- super(aten_istft, self).__init__()
+ super().__init__()
self.n_fft = n_fft
self.hop_length = hop_length
self.win_length = win_length
@@ -112,9 +111,8 @@ class TestISTFT(PytorchLayerTest):
length = sig_length.item()
)
- ref_net = None
- return aten_istft(n_fft, hop_length, win_length, normalized, center), ref_net, "aten::istft"
+ return aten_istft(n_fft, hop_length, win_length, normalized, center), "aten::istft"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -176,7 +174,7 @@ class TestISTFTDefaultParams(PytorchLayerTest):
def _prepare_input(self, n_fft, hop_length, win_length, center, normalized, signal_shape, out_dtype="float32"):
import numpy as np
- signal = np.random.randn(*signal_shape).astype(out_dtype)
+ signal = self.random.randn(*signal_shape, dtype=out_dtype)
signal = torch.from_numpy(signal)
stft_kwargs = {
@@ -205,7 +203,7 @@ class TestISTFTDefaultParams(PytorchLayerTest):
class aten_istft(torch.nn.Module):
def __init__(self, n_fft, hop_length, win_length, normalized, center):
- super(aten_istft, self).__init__()
+ super().__init__()
self.n_fft = n_fft
self.hop_length = hop_length
self.win_length = win_length
@@ -230,9 +228,8 @@ class TestISTFTDefaultParams(PytorchLayerTest):
return torch.istft(torch.view_as_complex(x), **istft_kwargs)
- ref_net = None
- return aten_istft(n_fft, hop_length, win_length, normalized, center), ref_net, "aten::istft"
+ return aten_istft(n_fft, hop_length, win_length, normalized, center), "aten::istft"
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_item.py b/tests/layer_tests/pytorch_tests/test_item.py
index 1190c0ecdc7..789c249c8b9 100644
--- a/tests/layer_tests/pytorch_tests/test_item.py
+++ b/tests/layer_tests/pytorch_tests/test_item.py
@@ -15,16 +15,15 @@ from pytorch_layer_test_class import PytorchLayerTest
@pytest.mark.parametrize("shape", [[], [1], [1, 1, 1]])
class TestItem(PytorchLayerTest):
def _prepare_input(self):
- return [np.random.randn(1).astype(self.dtype).reshape(self.shape)]
+ return [self.random.randn(1, dtype=self.dtype).reshape(self.shape)]
def create_model(self):
class aten_item(torch.nn.Module):
def forward(self, x: torch.Tensor):
return x.item()
- ref_net = None
- return aten_item(), ref_net, "aten::item"
+ return aten_item(), "aten::item"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_kthvalue.py b/tests/layer_tests/pytorch_tests/test_kthvalue.py
index 71cf57f44d4..ac7a883d275 100644
--- a/tests/layer_tests/pytorch_tests/test_kthvalue.py
+++ b/tests/layer_tests/pytorch_tests/test_kthvalue.py
@@ -28,7 +28,7 @@ class TestKthValue(PytorchLayerTest):
def _prepare_input(self, shape, dtype):
size = np.prod(shape)
data = np.arange(size, dtype=dtype)
- np.random.shuffle(data)
+ self.random.shuffle(data)
data = data.reshape(shape)
return (data,)
@@ -47,7 +47,6 @@ class TestKthValue(PytorchLayerTest):
@pytest.mark.precommit
def test_kthvalue(self, shape, k, dim, keepdim, dtype, ie_device, precision, ir_version):
self._test(aten_kthvalue(k, dim, keepdim),
- None,
"aten::kthvalue",
ie_device, precision, ir_version,
kwargs_to_prepare_input={"shape": shape, "dtype": dtype},
diff --git a/tests/layer_tests/pytorch_tests/test_layer_norm.py b/tests/layer_tests/pytorch_tests/test_layer_norm.py
index 2671deed424..9d8fb6ea826 100644
--- a/tests/layer_tests/pytorch_tests/test_layer_norm.py
+++ b/tests/layer_tests/pytorch_tests/test_layer_norm.py
@@ -4,13 +4,11 @@
import pytest
from pytorch_layer_test_class import PytorchLayerTest
-import numpy as np
class TestLayerNorm(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(20, 5, 10, 10).astype(np.float32),)
+ return (self.random.randn(20, 5, 10, 10),)
def create_model(self, normalized_shape, weight, bias, eps):
import torch
@@ -20,17 +18,17 @@ class TestLayerNorm(PytorchLayerTest):
weight = torch.ones(normalized_shape)
if weight == "random":
- weight = torch.randn(normalized_shape)
+ weight = self.random.torch_randn(*normalized_shape)
if bias == "zeros":
bias = torch.zeros(normalized_shape)
if bias == "random":
- bias = torch.randn(normalized_shape)
+ bias = self.random.torch_randn(*normalized_shape)
class aten_layer_norm(torch.nn.Module):
def __init__(self, normalized_shape, weight, bias, eps):
- super(aten_layer_norm, self).__init__()
+ super().__init__()
self.normalized_shape = normalized_shape
self.weight = weight
self.bias = bias
@@ -39,9 +37,8 @@ class TestLayerNorm(PytorchLayerTest):
def forward(self, x):
return F.layer_norm(x, self.normalized_shape, self.weight, self.bias, self.eps)
- ref_net = None
- return aten_layer_norm(normalized_shape, weight, bias, eps), ref_net, "aten::layer_norm"
+ return aten_layer_norm(normalized_shape, weight, bias, eps), "aten::layer_norm"
@pytest.mark.parametrize("normalized_shape", [[10,], [10, 10], [5, 10, 10]])
@pytest.mark.parametrize("weight", [None, "ones", "random"])
diff --git a/tests/layer_tests/pytorch_tests/test_leaky_relu.py b/tests/layer_tests/pytorch_tests/test_leaky_relu.py
index f14d565b525..d508a6e9ba3 100644
--- a/tests/layer_tests/pytorch_tests/test_leaky_relu.py
+++ b/tests/layer_tests/pytorch_tests/test_leaky_relu.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_check
class TestLeakyRelu(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, alpha, inplace):
import torch
@@ -17,16 +16,15 @@ class TestLeakyRelu(PytorchLayerTest):
class aten_leaky_relu(torch.nn.Module):
def __init__(self, alpha, inplace):
- super(aten_leaky_relu, self).__init__()
+ super().__init__()
self.alpha = alpha
self.inplace = inplace
def forward(self, x):
return x, F.leaky_relu(x, self.alpha, inplace=self.inplace)
- ref_net = None
- return aten_leaky_relu(alpha, inplace), ref_net, "aten::leaky_relu" if not inplace else "aten::leaky_relu_"
+ return aten_leaky_relu(alpha, inplace), "aten::leaky_relu" if not inplace else "aten::leaky_relu_"
@pytest.mark.parametrize("alpha", [0.01, 1.01, -0.01])
@pytest.mark.parametrize("inplace", [skip_check(True), False])
diff --git a/tests/layer_tests/pytorch_tests/test_len.py b/tests/layer_tests/pytorch_tests/test_len.py
index 6afb8b91481..22080241446 100644
--- a/tests/layer_tests/pytorch_tests/test_len.py
+++ b/tests/layer_tests/pytorch_tests/test_len.py
@@ -24,9 +24,8 @@ class TestLen(PytorchLayerTest):
def forward(self, input_tensor):
return torch.tensor(len(input_tensor))
- ref_net = None
- return aten_len(), ref_net, "aten::len"
+ return aten_len(), "aten::len"
def create_model_int_list(self):
class aten_len(torch.nn.Module):
@@ -35,20 +34,19 @@ class TestLen(PytorchLayerTest):
int_list = input_tensor.size()
return torch.tensor(len(int_list))
- ref_net = None
- return aten_len(), ref_net, "aten::len"
+ return aten_len(), "aten::len"
@pytest.mark.nightly
@pytest.mark.precommit
def test_len(self, ie_device, precision, ir_version, input_tensor):
- self.input_tensor = np.random.randn(*input_tensor).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_tensor)
self._test(*self.create_model(), ie_device, precision, ir_version)
@pytest.mark.nightly
@pytest.mark.precommit
def test_len_int_list(self, ie_device, precision, ir_version, input_tensor):
- self.input_tensor = np.random.randn(*input_tensor).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_tensor)
self._test(*self.create_model_int_list(),
ie_device, precision, ir_version, use_convert_model=True)
@@ -56,7 +54,7 @@ class TestLen(PytorchLayerTest):
class TestLenEmpty(PytorchLayerTest):
def _prepare_input(self):
- input_tensor = np.random.randn(1, 2, 3) * 10
+ input_tensor = self.random.randn(1, 2, 3) * 10
return (input_tensor.astype(np.int64),)
def create_model_empty(self):
@@ -66,9 +64,8 @@ class TestLenEmpty(PytorchLayerTest):
# len of empty slice
return torch.tensor(len(input_tensor[0:0]))
- ref_net = None
- return aten_len(), ref_net, "aten::len"
+ return aten_len(), "aten::len"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_lerp.py b/tests/layer_tests/pytorch_tests/test_lerp.py
index 782b93b82d8..12e984950e4 100644
--- a/tests/layer_tests/pytorch_tests/test_lerp.py
+++ b/tests/layer_tests/pytorch_tests/test_lerp.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
from packaging import version
@@ -11,7 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestLerp(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 5, 3, 4).astype(np.float32), self.input_rhs)
+ return (self.random.randn(2, 5, 3, 4), self.input_rhs)
def create_model(self, weight, op_type):
class aten_lerp(torch.nn.Module):
@@ -26,7 +25,7 @@ class TestLerp(PytorchLayerTest):
def forward2(self, lhs, rhs):
return lhs.lerp_(rhs, weight=self.weight)
- return aten_lerp(weight, op_type), None, f"aten::{op_type}"
+ return aten_lerp(weight, op_type), f"aten::{op_type}"
@pytest.mark.parametrize("weight", (-0.5,
0,
@@ -48,9 +47,9 @@ class TestLerp(PytorchLayerTest):
if (op_type == "lerp_" and PytorchLayerTest.use_torch_export() and
version.parse(torch.__version__) < version.parse("2.5")):
pytest.skip("Not supported in PyTorch versions earlier than 2.5.")
- self.input_rhs = np.random.randn(*input_shape_rhs).astype(np.float32)
+ self.input_rhs = self.random.randn(*input_shape_rhs)
if isinstance(weight, list):
- weight = torch.rand(weight)
+ weight = self.random.torch_rand(*weight)
fx_op = "aten.lerp_" if op_type == "lerp_" else "aten.lerp"
self._test(
*self.create_model(weight, op_type),
diff --git a/tests/layer_tests/pytorch_tests/test_linear.py b/tests/layer_tests/pytorch_tests/test_linear.py
index fed79c6e112..4a2fc106b53 100644
--- a/tests/layer_tests/pytorch_tests/test_linear.py
+++ b/tests/layer_tests/pytorch_tests/test_linear.py
@@ -8,18 +8,17 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestMatMul(PytorchLayerTest):
def _prepare_input(self, m1_shape=(2, 2), m2_shape=(2, 2), bias_shape=None):
- import numpy as np
if bias_shape is None:
- return (np.random.randn(*m1_shape).astype(np.float32), np.random.randn(*m2_shape).astype(np.float32))
+ return (self.random.randn(*m1_shape), self.random.randn(*m2_shape))
else:
- return (np.random.randn(*m1_shape).astype(np.float32), np.random.randn(*m2_shape).astype(np.float32), np.random.randn(*bias_shape).astype(np.float32))
+ return (self.random.randn(*m1_shape), self.random.randn(*m2_shape), self.random.randn(*bias_shape))
def create_model(self, is_bias):
import torch
class aten_mm(torch.nn.Module):
def __init__(self, is_bias):
- super(aten_mm, self).__init__()
+ super().__init__()
self.forward = self.forward2 if is_bias else self.forward1
def forward1(self, m1, m2):
@@ -28,9 +27,8 @@ class TestMatMul(PytorchLayerTest):
def forward2(self, m1, m2, bias):
return torch.nn.functional.linear(m1, m2, bias)
- ref_net = None
- return aten_mm(is_bias), ref_net, "aten::linear"
+ return aten_mm(is_bias), "aten::linear"
@pytest.mark.parametrize("kwargs_to_prepare_input", [
{'m1_shape': [9], 'm2_shape': [10, 9]},
@@ -53,24 +51,23 @@ class TestMatMul(PytorchLayerTest):
class TestLinearBiasList(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 15, 10).astype(np.float32), np.random.randn(66, 10).astype(np.float32))
+ return (self.random.randn(1, 15, 10), self.random.randn(66, 10))
def create_model(self):
import torch
class aten_mm(torch.nn.Module):
- def __init__(self):
- super(aten_mm, self).__init__()
- self.bias = [torch.randn(22),
- torch.randn(22),
- torch.randn(22)]
+ def __init__(self, rng):
+ super().__init__()
+ self.bias = [rng.torch_randn(22),
+ rng.torch_randn(22),
+ rng.torch_randn(22)]
def forward(self, m1, m2):
m2 = m2.reshape([66, -1])
return torch.nn.functional.linear(m1, m2, torch.cat(self.bias, 0))
- return aten_mm(), None, "aten::linear"
+ return aten_mm(self.random), "aten::linear"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_linspace.py b/tests/layer_tests/pytorch_tests/test_linspace.py
index 90e4275b840..c901e8d868f 100644
--- a/tests/layer_tests/pytorch_tests/test_linspace.py
+++ b/tests/layer_tests/pytorch_tests/test_linspace.py
@@ -55,9 +55,8 @@ class TestLinspace(PytorchLayerTest):
else:
model_class = aten_linspace_out(dtype)
- ref_net = None
- return model_class, ref_net, "aten::linspace"
+ return model_class, "aten::linspace"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_listunpack.py b/tests/layer_tests/pytorch_tests/test_listunpack.py
index 7649cd9c5d8..61b66f2b19f 100644
--- a/tests/layer_tests/pytorch_tests/test_listunpack.py
+++ b/tests/layer_tests/pytorch_tests/test_listunpack.py
@@ -12,10 +12,10 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestListUnpack(PytorchLayerTest):
def _prepare_input(self):
return (
- np.random.randn(8, 3, 512, 512).astype(np.float32),
- np.random.randn(1, 3, 224, 224).astype(np.float32),
- np.random.randn(10, 1, 8, 8).astype(np.float32),
- np.random.randn(1, 1, 1, 1).astype(np.float32),
+ self.random.randn(8, 3, 512, 512),
+ self.random.randn(1, 3, 224, 224),
+ self.random.randn(10, 1, 8, 8),
+ self.random.randn(1, 1, 1, 1),
)
def create_model_size_listunpack(self):
@@ -24,12 +24,9 @@ class TestListUnpack(PytorchLayerTest):
a, b, c, d = in1.size()
return a, b, c, d
- ref_net = None
return (
- prim_listunpack(),
- ref_net,
- "prim::ListUnpack",
+ prim_listunpack(), "prim::ListUnpack",
)
def create_model_size_slice_listunpack(self, slices):
@@ -38,15 +35,14 @@ class TestListUnpack(PytorchLayerTest):
self.start = slices[0]
self.stop = slices[1]
self.step = slices[2]
- super(prim_listunpack, self).__init__()
+ super().__init__()
def forward(self, in1, in2, in3, in4):
a, b = in1.size()[self.start: self.stop: self.step]
return a, b
- ref_net = None
- return prim_listunpack(slices), ref_net, "prim::ListUnpack"
+ return prim_listunpack(slices), "prim::ListUnpack"
def create_model_listconstruct_append_listunpack(self):
class prim_listunpack(torch.nn.Module):
@@ -57,15 +53,14 @@ class TestListUnpack(PytorchLayerTest):
a, b, c, d = in_list
return a, b, c, d
- ref_net = None
- return prim_listunpack(), ref_net, "prim::ListUnpack"
+ return prim_listunpack(), "prim::ListUnpack"
def create_model_listconstruct_getitem_listunpack(self, idx):
class prim_listunpack(torch.nn.Module):
def __init__(self, idx):
self.idx = idx
- super(prim_listunpack, self).__init__()
+ super().__init__()
def forward(self, in1, in2, in3, in4):
items: list[list[int]] = []
@@ -77,9 +72,8 @@ class TestListUnpack(PytorchLayerTest):
a, b, c, d = getitem_0
return a, b, c, d
- ref_net = None
- return prim_listunpack(idx), ref_net, "prim::ListUnpack"
+ return prim_listunpack(idx), "prim::ListUnpack"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -129,17 +123,17 @@ class TestListUnpack(PytorchLayerTest):
class TestMeshgridListUnpack(PytorchLayerTest):
def _prepare_input(self):
return (
- np.random.randn(3),
- np.random.randn(5),
- np.random.randn(7),
- np.random.randn(11),
+ self.random.randn(3),
+ self.random.randn(5),
+ self.random.randn(7),
+ self.random.randn(11),
)
def create_model_meshgrid_listunpack_1_in(self, idx):
class prim_listunpack(torch.nn.Module):
def __init__(self, idx):
self.idx = idx
- super(prim_listunpack, self).__init__()
+ super().__init__()
def forward(self, in1, in2, in3, in4):
(
@@ -147,15 +141,14 @@ class TestMeshgridListUnpack(PytorchLayerTest):
) = torch.meshgrid(in1, indexing=self.idx)
return a
- ref_net = None
- return prim_listunpack(idx), ref_net, ["aten::meshgrid", "prim::ListUnpack"]
+ return prim_listunpack(idx), ["aten::meshgrid", "prim::ListUnpack"]
def create_model_meshgrid_listunpack_2_in(self, idx):
class prim_listunpack(torch.nn.Module):
def __init__(self, idx):
self.idx = idx
- super(prim_listunpack, self).__init__()
+ super().__init__()
def forward(self, in1, in2, in3, in4):
(
@@ -164,38 +157,35 @@ class TestMeshgridListUnpack(PytorchLayerTest):
) = torch.meshgrid(in1, in2, indexing=self.idx)
return a, b
- ref_net = None
- return prim_listunpack(idx), ref_net, ["aten::meshgrid", "prim::ListUnpack"]
+ return prim_listunpack(idx), ["aten::meshgrid", "prim::ListUnpack"]
def create_model_meshgrid_listunpack_3_in(self, idx):
class prim_listunpack(torch.nn.Module):
def __init__(self, idx):
self.idx = idx
- super(prim_listunpack, self).__init__()
+ super().__init__()
def forward(self, in1, in2, in3, in4):
a, b, c = torch.meshgrid(in1, in2, in3, indexing=self.idx)
return a, b, c
- ref_net = None
- return prim_listunpack(idx), ref_net, ["aten::meshgrid", "prim::ListUnpack"]
+ return prim_listunpack(idx), ["aten::meshgrid", "prim::ListUnpack"]
def create_model_meshgrid_listunpack_4_in(self, idx):
class prim_listunpack(torch.nn.Module):
def __init__(self, idx):
self.idx = idx
- super(prim_listunpack, self).__init__()
+ super().__init__()
def forward(self, in1, in2, in3, in4):
a, b, c, d = torch.meshgrid(
in1, in2, in3, in4, indexing=self.idx)
return a, b, c, d
- ref_net = None
- return prim_listunpack(idx), ref_net, ["aten::meshgrid", "prim::ListUnpack"]
+ return prim_listunpack(idx), ["aten::meshgrid", "prim::ListUnpack"]
@pytest.mark.parametrize("idx", ["ij", "xy"])
@pytest.mark.parametrize("inp", [1, 2, 3, 4])
@@ -209,7 +199,7 @@ class TestMeshgridListUnpack(PytorchLayerTest):
class TestMeshgridListUnpackStack(PytorchLayerTest):
def _prepare_input(self):
return (
- np.random.randn(28, 28),
+ self.random.randn(28, 28),
)
def create_model(self):
@@ -221,7 +211,7 @@ class TestMeshgridListUnpackStack(PytorchLayerTest):
coords = torch.stack([coords2, coords1], dim=0)
return coords.float()
- return meshgrid_model(), None, ["aten::meshgrid", "aten::stack", "prim::ListUnpack"]
+ return meshgrid_model(), ["aten::meshgrid", "aten::stack", "prim::ListUnpack"]
@pytest.mark.nightly
@pytest.mark.precommit
@@ -232,7 +222,7 @@ class TestMeshgridListUnpackStack(PytorchLayerTest):
class TestListUnpackParameterSingle(PytorchLayerTest):
def _prepare_input(self):
def tensor_gen():
- return np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32)
+ return self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32)
return ((tensor_gen(), tensor_gen()), )
def create_model(self):
@@ -244,7 +234,7 @@ class TestListUnpackParameterSingle(PytorchLayerTest):
x1, x2 = x
return x1, x2
- return model(), None, ["prim::ListUnpack"]
+ return model(), ["prim::ListUnpack"]
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
@@ -254,11 +244,11 @@ class TestListUnpackParameterSingle(PytorchLayerTest):
class TestListUnpackParameterSingleMixed(PytorchLayerTest):
def _prepare_input(self):
def tensor_gen():
- return np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32)
+ return self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32)
# generate tensor with a different shape for easier mismatch detection in case of mixed input order
def tensor_gen_2():
- return np.random.uniform(0, 50, (2, 3)).astype(np.float32)
+ return self.random.uniform(0, 50, (2, 3), dtype=np.float32)
return (tensor_gen_2(), (tensor_gen(), tensor_gen()), tensor_gen_2())
def create_model(self):
@@ -270,7 +260,7 @@ class TestListUnpackParameterSingleMixed(PytorchLayerTest):
x1, x2 = x
return x1, x2, y1, y2
- return model(), None, ["prim::ListUnpack"]
+ return model(), ["prim::ListUnpack"]
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
@@ -280,7 +270,7 @@ class TestListUnpackParameterSingleMixed(PytorchLayerTest):
class TestListUnpackParameterNested(PytorchLayerTest):
def _prepare_input(self):
def tensor_gen():
- return np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32)
+ return self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32)
return (((tensor_gen(), tensor_gen()), (tensor_gen(), tensor_gen())), )
def create_model(self):
@@ -294,7 +284,7 @@ class TestListUnpackParameterNested(PytorchLayerTest):
y3, y4 = x2
return y1, y2, y3, y4
- return model(), None, ["prim::ListUnpack"]
+ return model(), ["prim::ListUnpack"]
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
@@ -304,7 +294,7 @@ class TestListUnpackParameterNested(PytorchLayerTest):
class TestListUnpackParameterMultiple(PytorchLayerTest):
def _prepare_input(self):
def tensor_gen():
- return np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32)
+ return self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32)
return ((tensor_gen(), tensor_gen()), (tensor_gen(), tensor_gen()))
def create_model(self):
@@ -317,7 +307,7 @@ class TestListUnpackParameterMultiple(PytorchLayerTest):
z3, z4 = y
return z1, z2, z3, z4
- return model(), None, ["prim::ListUnpack"]
+ return model(), ["prim::ListUnpack"]
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
@@ -332,15 +322,13 @@ class TestComplexListUnpack(PytorchLayerTest):
"""
def _prepare_input(self):
- rng = np.random.default_rng(43)
- return (rng.standard_normal((2, 4, 2)).astype(np.float32),)
+ return (self.random.randn(2, 4, 2),)
def create_model(self):
class ComplexListUnpack(torch.nn.Module):
- def __init__(self):
+ def __init__(self, rng):
super().__init__()
- g = torch.Generator().manual_seed(42)
- freqs = torch.randn(4, 2, generator=g)
+ freqs = rng.torch_randn(4, 2)
complex_freqs = torch.view_as_complex(freqs)
self.register_buffer('freqs', torch.view_as_real(complex_freqs))
@@ -350,7 +338,7 @@ class TestComplexListUnpack(PytorchLayerTest):
result = cx * cf
return torch.view_as_real(result)
- return ComplexListUnpack(), None, "aten::mul"
+ return ComplexListUnpack(self.random), "aten::mul"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_log_softmax.py b/tests/layer_tests/pytorch_tests/test_log_softmax.py
index a0bb095b377..6361b003ca8 100644
--- a/tests/layer_tests/pytorch_tests/test_log_softmax.py
+++ b/tests/layer_tests/pytorch_tests/test_log_softmax.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
import torch.nn.functional as F
@@ -20,9 +19,9 @@ class aten_log_softmax(torch.nn.Module):
class TestLogSoftmax(PytorchLayerTest):
def _prepare_input(self):
if self.input_dtype == torch.float:
- self.input_tensor = np.random.randn(5, 9, 7)
+ self.input_tensor = self.random.randn(5, 9, 7)
else:
- self.input_tensor = np.random.randint(-100, 100, (5, 9, 7))
+ self.input_tensor = self.random.randint(-100, 100, (5, 9, 7))
return (self.input_tensor,)
@pytest.mark.parametrize(["input_dtype", "convert_dtype"], [
@@ -43,5 +42,5 @@ class TestLogSoftmax(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_log_softmax(self, input_dtype, convert_dtype, dim, ie_device, precision, ir_version):
self.input_dtype = input_dtype
- self._test(aten_log_softmax(dim, convert_dtype), None, "aten::log_softmax",
+ self._test(aten_log_softmax(dim, convert_dtype), "aten::log_softmax",
ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_logaddexp.py b/tests/layer_tests/pytorch_tests/test_logaddexp.py
index 2f0ce6657d9..a2825b89b25 100644
--- a/tests/layer_tests/pytorch_tests/test_logaddexp.py
+++ b/tests/layer_tests/pytorch_tests/test_logaddexp.py
@@ -21,7 +21,7 @@ class TestLogAddExp(PytorchLayerTest):
class LogAddExpModel(torch.nn.Module):
def __init__(self, out):
- super(LogAddExpModel, self).__init__()
+ super().__init__()
if out:
self.forward = self.forward_out
@@ -32,9 +32,8 @@ class TestLogAddExp(PytorchLayerTest):
return torch.logaddexp(x, y, out=out), out
model_class = LogAddExpModel(out)
- ref_net = None
- return model_class, ref_net, "aten::logaddexp"
+ return model_class, "aten::logaddexp"
@pytest.mark.parametrize(
"dtype1",
@@ -120,8 +119,8 @@ class TestLogAddExp(PytorchLayerTest):
)
def test_logaddexp_shapes(self, dtype1, dtype2, shape, out, ie_device, precision, ir_version):
# Generate random inputs within a reasonable range
- input1 = np.random.uniform(-10, 10, shape)
- input2 = np.random.uniform(-10, 10, shape)
+ input1 = self.random.uniform(-10, 10, shape)
+ input2 = self.random.uniform(-10, 10, shape)
self._test(
*self.create_model(out),
diff --git a/tests/layer_tests/pytorch_tests/test_logical_ops.py b/tests/layer_tests/pytorch_tests/test_logical_ops.py
index 842d895542a..14a8b4b0346 100644
--- a/tests/layer_tests/pytorch_tests/test_logical_ops.py
+++ b/tests/layer_tests/pytorch_tests/test_logical_ops.py
@@ -5,10 +5,10 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestLogicalOp(PytorchLayerTest):
def _prepare_input(self, out, unary, first_dtype, second_dtype):
- x = np.random.randint(1, 5, (1, 10)).astype(first_dtype)
+ x = self.random.randint(1, 5, (1, 10), dtype=first_dtype)
if unary:
return (x, ) if not out else (x, np.zeros_like(x).astype(bool))
- y = np.random.randint(1, 5, (1, 10)).astype(second_dtype)
+ y = self.random.randint(1, 5, (1, 10), dtype=second_dtype)
if not out:
return x, y
return x, y, np.zeros_like(x).astype(bool)
@@ -46,9 +46,8 @@ class TestLogicalOp(PytorchLayerTest):
def forward_not_out(self, tensor_a, out):
return self.op(tensor_a, out=out), out
- ref_net = None
- return aten_logical(op, out), ref_net, f"aten::logical_{op_name}"
+ return aten_logical(op, out), f"aten::logical_{op_name}"
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_logsumexp.py b/tests/layer_tests/pytorch_tests/test_logsumexp.py
index 4fc2ccf649a..18b8b20bab0 100644
--- a/tests/layer_tests/pytorch_tests/test_logsumexp.py
+++ b/tests/layer_tests/pytorch_tests/test_logsumexp.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -20,7 +19,7 @@ class aten_logsumexp(torch.nn.Module):
class TestLogsumexp(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 5, 9, 7),)
+ return (self.random.randn(2, 5, 9, 7),)
@pytest.mark.parametrize("dim", [
0, 1, 2, 3, -1, -2, -3, -4
@@ -31,5 +30,5 @@ class TestLogsumexp(PytorchLayerTest):
@pytest.mark.precommit_torch_export
@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",
+ self._test(aten_logsumexp(dim, keepdim), "aten::logsumexp",
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 53ff0026f52..49bcdaab64d 100644
--- a/tests/layer_tests/pytorch_tests/test_loop.py
+++ b/tests/layer_tests/pytorch_tests/test_loop.py
@@ -3,7 +3,6 @@
import platform
import pytest
-import numpy as np
from pytorch_layer_test_class import PytorchLayerTest
import torch
@@ -13,7 +12,7 @@ class TestWhileLoopFX(PytorchLayerTest):
"""Tests for torch.while_loop support in FX export (torch.export)."""
def _prepare_input(self):
- return (np.random.randn(*self.input_shape).astype(np.float32),)
+ return (self.random.randn(*self.input_shape),)
def create_model_simple_counter(self, num_iterations):
"""Simple while_loop that counts up to num_iterations."""
@@ -33,7 +32,7 @@ class TestWhileLoopFX(PytorchLayerTest):
_, out = torch.while_loop(cond, body, (i, x))
return out
- return WhileLoopCounter(num_iterations), None, "while_loop"
+ return WhileLoopCounter(num_iterations), "while_loop"
def create_model_accumulator(self):
"""While loop that accumulates a value - with clone to avoid aliasing."""
@@ -51,7 +50,7 @@ class TestWhileLoopFX(PytorchLayerTest):
_, result, _ = torch.while_loop(cond, body, (i, acc, x))
return result
- return WhileLoopAccumulator(), None, "while_loop"
+ return WhileLoopAccumulator(), "while_loop"
def create_model_scalar_only(self):
"""While loop with only scalar values (no tensor input needed)."""
@@ -68,7 +67,7 @@ class TestWhileLoopFX(PytorchLayerTest):
# Use x to keep it as an input, but return scalar result
return result + x.sum() * 0
- return WhileLoopScalar(), None, "while_loop"
+ return WhileLoopScalar(), "while_loop"
@pytest.mark.parametrize("num_iterations", [1, 3, 5, 10])
@pytest.mark.nightly
@@ -95,14 +94,14 @@ class TestWhileLoopFX(PytorchLayerTest):
class TestLoopWithAlias(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(*self.shape).astype(np.float32),)
+ return (self.random.randn(*self.shape),)
def create_model(self, n):
import torch
class loop_alias_model(torch.nn.Module):
def __init__(self, n):
- super(loop_alias_model, self).__init__()
+ super().__init__()
self.n = n
def forward(self, x):
@@ -119,7 +118,7 @@ class TestLoopWithAlias(PytorchLayerTest):
f = torch.max(d, -1)[1]
return res
- return loop_alias_model(n), None, ["prim::Loop", "aten::copy_"]
+ return loop_alias_model(n), ["prim::Loop", "aten::copy_"]
@pytest.mark.parametrize("s,n", [([1, 1024, 3], 512), ([1, 512, 3], 128)])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_lstm.py b/tests/layer_tests/pytorch_tests/test_lstm.py
index b8105096748..43fb373d6d8 100644
--- a/tests/layer_tests/pytorch_tests/test_lstm.py
+++ b/tests/layer_tests/pytorch_tests/test_lstm.py
@@ -80,11 +80,11 @@ class TestLSTM(PytorchLayerTest):
if self.bidirectional:
n *= 2
if self.batch_first:
- input = np.random.randn(3, 5, self.input_size).astype(np.float32)
+ input = self.random.randn(3, 5, self.input_size)
else:
- input = np.random.randn(5, 3, self.input_size).astype(np.float32)
- h0 = np.random.randn(n, 3, self.hidden_size).astype(np.float32)
- c0 = np.random.randn(n, 3, self.hidden_size).astype(np.float32)
+ input = self.random.randn(5, 3, self.input_size)
+ h0 = self.random.randn(n, 3, self.hidden_size)
+ c0 = self.random.randn(n, 3, self.hidden_size)
return (input, h0, c0)
@pytest.mark.parametrize("input_size,hidden_size", [(10, 20),])
@@ -100,7 +100,7 @@ class TestLSTM(PytorchLayerTest):
self.num_layers = num_layers
self.bidirectional = bidirectional
self.batch_first = batch_first
- self._test(aten_lstm(input_size, hidden_size, num_layers, has_bias, bidirectional, batch_first), None, "aten::lstm",
+ self._test(aten_lstm(input_size, hidden_size, num_layers, has_bias, bidirectional, batch_first), "aten::lstm",
ie_device, precision, ir_version, trace_model=True)
@@ -108,12 +108,12 @@ class TestLSTMPacked(PytorchLayerTest):
def _prepare_input(self):
batch = 15
if self.batch_first:
- input = np.random.randn(
- batch, 50, self.input_size).astype(np.float32)
+ input = self.random.randn(
+ batch, 50, self.input_size)
else:
- input = np.random.randn(
- 50, batch, self.input_size).astype(np.float32)
- lengths = np.array(list(sorted(np.random.randint(
+ input = self.random.randn(
+ 50, batch, self.input_size)
+ lengths = np.array(list(sorted(self.random.randint(
1, 50, [batch - 1]).tolist() + [50], reverse=True)), dtype=np.int32)
return (input, lengths)
@@ -131,7 +131,6 @@ class TestLSTMPacked(PytorchLayerTest):
self.bidirectional = bidirectional
self.batch_first = batch_first
self._test(aten_lstm_packed(input_size, hidden_size, num_layers, has_bias, bidirectional, batch_first),
- None,
"aten::lstm",
ie_device,
precision,
@@ -147,10 +146,10 @@ class TestGRU(PytorchLayerTest):
if self.bidirectional:
n *= 2
if self.batch_first:
- input = np.random.randn(3, 5, self.input_size).astype(np.float32)
+ input = self.random.randn(3, 5, self.input_size)
else:
- input = np.random.randn(5, 3, self.input_size).astype(np.float32)
- h0 = np.random.randn(n, 3, self.hidden_size).astype(np.float32)
+ input = self.random.randn(5, 3, self.input_size)
+ h0 = self.random.randn(n, 3, self.hidden_size)
return (input, h0)
@pytest.mark.parametrize("input_size,hidden_size", [(10, 20),])
@@ -166,7 +165,7 @@ class TestGRU(PytorchLayerTest):
self.num_layers = num_layers
self.bidirectional = bidirectional
self.batch_first = batch_first
- self._test(aten_gru(input_size, hidden_size, num_layers, has_bias, bidirectional, batch_first), None, "aten::gru",
+ self._test(aten_gru(input_size, hidden_size, num_layers, has_bias, bidirectional, batch_first), "aten::gru",
ie_device, precision, ir_version, trace_model=True)
@@ -176,10 +175,10 @@ class TestRNN(PytorchLayerTest):
if self.bidirectional:
n *= 2
if self.batch_first:
- input = np.random.randn(3, 5, self.input_size).astype(np.float32)
+ input = self.random.randn(3, 5, self.input_size)
else:
- input = np.random.randn(5, 3, self.input_size).astype(np.float32)
- h0 = np.random.randn(n, 3, self.hidden_size).astype(np.float32)
+ input = self.random.randn(5, 3, self.input_size)
+ h0 = self.random.randn(n, 3, self.hidden_size)
return (input, h0)
@pytest.mark.parametrize("input_size,hidden_size", [(10, 20),])
@@ -196,5 +195,5 @@ class TestRNN(PytorchLayerTest):
self.num_layers = num_layers
self.bidirectional = bidirectional
self.batch_first = batch_first
- self._test(aten_rnn(input_size, hidden_size, num_layers, has_bias, bidirectional, batch_first, nonlinearity), None, f"aten::rnn_{nonlinearity}",
+ self._test(aten_rnn(input_size, hidden_size, num_layers, has_bias, bidirectional, batch_first, nonlinearity), f"aten::rnn_{nonlinearity}",
ie_device, precision, ir_version, trace_model=True)
diff --git a/tests/layer_tests/pytorch_tests/test_masked_fill.py b/tests/layer_tests/pytorch_tests/test_masked_fill.py
index 70d690fd7f1..cc6091280c8 100644
--- a/tests/layer_tests/pytorch_tests/test_masked_fill.py
+++ b/tests/layer_tests/pytorch_tests/test_masked_fill.py
@@ -16,17 +16,17 @@ class TestMaskedFill(PytorchLayerTest):
if mask_fill == 'ones':
mask = np.ones(input_shape).astype(mask_dtype)
if mask_fill == 'random':
- idx = np.random.choice(10, 5)
+ idx = self.random.choice(10, 5)
mask[:, idx] = 1
- return (np.random.randn(1, 10).astype(input_dtype), mask)
+ return (self.random.randn(1, 10, dtype=input_dtype), mask)
def create_model(self, value, inplace):
import torch
class aten_masked_fill(torch.nn.Module):
def __init__(self, value):
- super(aten_masked_fill, self).__init__()
+ super().__init__()
self.value = value
def forward(self, x, mask):
@@ -34,17 +34,16 @@ class TestMaskedFill(PytorchLayerTest):
class aten_masked_fill_(torch.nn.Module):
def __init__(self, value):
- super(aten_masked_fill_, self).__init__()
+ super().__init__()
self.value = value
def forward(self, x, mask):
return x.masked_fill_(mask, self.value)
- ref_net = None
if not inplace:
- return aten_masked_fill(value), ref_net, "aten::masked_fill"
- return aten_masked_fill_(value), ref_net, "aten::masked_fill_"
+ return aten_masked_fill(value), "aten::masked_fill"
+ return aten_masked_fill_(value), "aten::masked_fill_"
@pytest.mark.parametrize("value", [0.0, 1.0, -1.0, 2])
@pytest.mark.parametrize(
diff --git a/tests/layer_tests/pytorch_tests/test_masked_scatter.py b/tests/layer_tests/pytorch_tests/test_masked_scatter.py
index 1f96f0bb675..be0b895a05a 100644
--- a/tests/layer_tests/pytorch_tests/test_masked_scatter.py
+++ b/tests/layer_tests/pytorch_tests/test_masked_scatter.py
@@ -11,7 +11,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestMaskedScatter(PytorchLayerTest):
def _prepare_input(self, shape, x_dtype="float32", mask_dtype="bool", out=False):
import numpy as np
- x = np.random.randn(*shape).astype(x_dtype)
+ x = self.random.randn(*shape, dtype=x_dtype)
mask = (x > 0.5).astype(mask_dtype)
source = np.arange(np.size(x)).reshape(shape).astype(x_dtype)
if not out:
@@ -24,7 +24,7 @@ class TestMaskedScatter(PytorchLayerTest):
class aten_masked_scatter(torch.nn.Module):
def __init__(self, out, inplace):
- super(aten_masked_scatter, self).__init__()
+ super().__init__()
if inplace:
self.forward = self.forward_inplace
if out:
@@ -39,9 +39,8 @@ class TestMaskedScatter(PytorchLayerTest):
def forward_inplace(self, x, mask, source):
return x.masked_scatter_(mask, source), x
- ref_net = None
- return aten_masked_scatter(out, inplace), ref_net, "aten::masked_scatter" if not inplace else "aten::masked_scatter_"
+ return aten_masked_scatter(out, inplace), "aten::masked_scatter" if not inplace else "aten::masked_scatter_"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_masked_select.py b/tests/layer_tests/pytorch_tests/test_masked_select.py
index c86bbed38be..657c9ce3463 100644
--- a/tests/layer_tests/pytorch_tests/test_masked_select.py
+++ b/tests/layer_tests/pytorch_tests/test_masked_select.py
@@ -16,23 +16,22 @@ class TestMaskedSelect(PytorchLayerTest):
if mask_select == 'ones':
mask = np.ones(input_shape).astype(mask_dtype)
if mask_select == 'random':
- idx = np.random.choice(10, 5)
+ idx = self.random.choice(10, 5)
mask[:, idx] = 1
- return (np.random.randn(1, 10).astype(input_dtype), mask)
+ return (self.random.randn(1, 10, dtype=input_dtype), mask)
def create_model(self):
import torch
class aten_masked_select(torch.nn.Module):
def __init__(self):
- super(aten_masked_select, self).__init__()
+ super().__init__()
def forward(self, x, mask):
return x.masked_select(mask)
- ref_net = None
- return aten_masked_select(), ref_net, "aten::masked_select"
+ return aten_masked_select(), "aten::masked_select"
@pytest.mark.parametrize(
"mask_select", ['zeros', 'ones', 'random'])
diff --git a/tests/layer_tests/pytorch_tests/test_matmul.py b/tests/layer_tests/pytorch_tests/test_matmul.py
index 900171806cc..5b2fa98847d 100644
--- a/tests/layer_tests/pytorch_tests/test_matmul.py
+++ b/tests/layer_tests/pytorch_tests/test_matmul.py
@@ -3,20 +3,18 @@ import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest
+
class TestMatMulOperation(PytorchLayerTest):
def _prepare_input(self, matrix, vector):
- matrix_input = np.array(matrix, dtype=np.float32)
- vector_input = np.array(vector, dtype=np.float32)
- return matrix_input, vector_input
+ return matrix, vector
- def create_model(self, matrix, vector):
+ def create_model(self):
class CustomMatMulOperation(torch.nn.Module):
def forward(self, matrix, vector):
- return torch.mv(matrix, vector)
+ return torch.mv(matrix, vector)
model_class = CustomMatMulOperation()
- ref_net = None
- return model_class, ref_net, "aten::mv"
+ return model_class, "aten::mv"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -35,9 +33,10 @@ class TestMatMulOperation(PytorchLayerTest):
vector_input = vector_input.to(dtype=dtype)
self._test(
- *self.create_model(matrix_input, vector_input),
+ *self.create_model(),
ie_device,
precision,
ir_version,
- kwargs_to_prepare_input={"matrix": matrix_input, "vector": vector_input},
+ kwargs_to_prepare_input={"matrix": matrix_input.numpy(),
+ "vector": vector_input.numpy()},
)
diff --git a/tests/layer_tests/pytorch_tests/test_mean.py b/tests/layer_tests/pytorch_tests/test_mean.py
index 21d7f7cf133..6745e3993f6 100644
--- a/tests/layer_tests/pytorch_tests/test_mean.py
+++ b/tests/layer_tests/pytorch_tests/test_mean.py
@@ -12,8 +12,8 @@ class TestMean(PytorchLayerTest):
if keep_dim is None:
keep_dim = False
if not use_out:
- return (np.random.randint(-10, 10, (1, 3, 224, 224)).astype(np.float32),)
- inp = np.random.randint(-10, 10, (1, 3, 224, 224)).astype(np.float32)
+ return (self.random.randint(-10, 10, (1, 3, 224, 224), dtype=np.float32),)
+ inp = self.random.randint(-10, 10, (1, 3, 224, 224), dtype=np.float32)
calc_inp = inp.astype(dtype) if dtype is not None else inp
if axis is None:
out = np.mean(calc_inp, keepdims=keep_dim)
@@ -67,7 +67,7 @@ class TestMean(PytorchLayerTest):
return torch.mean(x, dim=self.axes, keepdim=self.keep_dims, out=out)
return torch.mean(x, dim=self.axes, keepdim=self.keep_dims, dtype=self.dtype, out=out)
- return aten_mean(axes, keep_dims, pt_dtype, out), None, "aten::mean"
+ return aten_mean(axes, keep_dims, pt_dtype, out), "aten::mean"
@pytest.mark.parametrize("axes,keep_dim,dtype,out",
[(None, None, None, False),
diff --git a/tests/layer_tests/pytorch_tests/test_min_max.py b/tests/layer_tests/pytorch_tests/test_min_max.py
index 29148381132..805975ab453 100644
--- a/tests/layer_tests/pytorch_tests/test_min_max.py
+++ b/tests/layer_tests/pytorch_tests/test_min_max.py
@@ -10,8 +10,8 @@ class TestMinMax(PytorchLayerTest):
def _prepare_input(self, input_dtype="float32", second_input=False, second_input_dtype="float32"):
import numpy as np
if not second_input:
- return (np.random.randn(1, 3, 10, 10).astype(input_dtype),)
- return (np.random.randn(1, 3, 10, 10).astype(input_dtype), np.random.randn(1, 3, 10, 10).astype(second_input_dtype))
+ return (self.random.randn(1, 3, 10, 10, dtype=input_dtype),)
+ return (self.random.randn(1, 3, 10, 10, dtype=input_dtype), self.random.randn(1, 3, 10, 10, dtype=second_input_dtype))
def create_model(self, op_type, axes, keep_dims, single_input=True, dtypes=("float32", "float32")):
import torch
@@ -32,7 +32,7 @@ class TestMinMax(PytorchLayerTest):
class aten_min_max(torch.nn.Module):
def __init__(self, op):
- super(aten_min_max, self).__init__()
+ super().__init__()
self.op = op
def forward(self, x):
@@ -40,7 +40,7 @@ class TestMinMax(PytorchLayerTest):
class aten_min_max_3args(torch.nn.Module):
def __init__(self, op, axes=None, keep_dims=None):
- super(aten_min_max_3args, self).__init__()
+ super().__init__()
self.op = op
self.axes = axes
self.keep_dims = keep_dims
@@ -50,7 +50,7 @@ class TestMinMax(PytorchLayerTest):
class aten_min_max_2args(torch.nn.Module):
def __init__(self, op, l_dtype, r_dtype):
- super(aten_min_max_2args, self).__init__()
+ super().__init__()
self.op = op
self.l_dtype = l_dtype
self.r_dtype = r_dtype
@@ -58,7 +58,6 @@ class TestMinMax(PytorchLayerTest):
def forward(self, x, y):
return self.op(x.to(self.l_dtype), y.to(self.r_dtype))
- ref_net = None
if axes is None and keep_dims is None:
if single_input:
model_cls = aten_min_max(op)
@@ -69,7 +68,7 @@ class TestMinMax(PytorchLayerTest):
else:
model_cls = aten_min_max_3args(op, axes, keep_dims)
- return model_cls, ref_net, f"aten::{op_type}"
+ return model_cls, f"aten::{op_type}"
@pytest.mark.parametrize("axes,keep_dims", [(None, None), (1, False), (1, True), (-1, False), (-1, True)])
@pytest.mark.parametrize("op_type", ['min', 'max'])
@@ -135,9 +134,8 @@ class TestPrimMax(PytorchLayerTest):
}
model_cls = cases[case]()
- ref_net = None
- return model_cls, ref_net, "prim::max"
+ return model_cls, "prim::max"
@pytest.mark.parametrize("case", ["2_values", "2_list_values", "list_several_values", "one_value"])
@pytest.mark.parametrize("kwargs_to_prepare_input", [
@@ -195,9 +193,8 @@ class TestPrimMin(PytorchLayerTest):
}
model_cls = cases[case]()
- ref_net = None
- return model_cls, ref_net, "prim::min"
+ return model_cls, "prim::min"
@pytest.mark.parametrize("case", ["2_values", "2_list_values", "list_several_values", "one_value"])
@pytest.mark.parametrize("kwargs_to_prepare_input", [
@@ -221,8 +218,8 @@ class TestPrimMin(PytorchLayerTest):
class TestMinimumMaximum(PytorchLayerTest):
def _prepare_input(self, input_dtype="float32", second_input_dtype="float32", out=False):
import numpy as np
- x = np.random.randn(1, 3, 10, 10).astype(input_dtype)
- y = np.random.randn(1, 3, 10, 10).astype(second_input_dtype)
+ x = self.random.randn(1, 3, 10, 10, dtype=input_dtype)
+ y = self.random.randn(1, 3, 10, 10, dtype=second_input_dtype)
if not out:
return x, y
return (x, y, np.zeros_like(x).astype(input_dtype))
@@ -245,7 +242,7 @@ class TestMinimumMaximum(PytorchLayerTest):
class aten_minimum_maximum(torch.nn.Module):
def __init__(self, op, l_dtype, r_dtype, out):
- super(aten_minimum_maximum, self).__init__()
+ super().__init__()
self.op = op
self.l_dtype = l_dtype
self.r_dtype = r_dtype
@@ -262,7 +259,7 @@ class TestMinimumMaximum(PytorchLayerTest):
r_dtype = dtypes_map[dtypes[1]]
model_cls = aten_minimum_maximum(op, l_dtype, r_dtype, out)
- return model_cls, None, f"aten::{op_type}"
+ return model_cls, f"aten::{op_type}"
@pytest.mark.parametrize("op_type", ["minimum", "maximum"])
@pytest.mark.parametrize("second_input_dtype", ["float32", "int32", "int64", "float64"])
@@ -297,7 +294,7 @@ class TestMinimumMaximum(PytorchLayerTest):
class TestAminAmax(PytorchLayerTest):
def _prepare_input(self, input_dtype="float32", out=False, axes=None, keep_dims=False):
import numpy as np
- x = np.random.randn(1, 3, 10, 10).astype(input_dtype)
+ x = self.random.randn(1, 3, 10, 10, dtype=input_dtype)
if not out:
return (x,)
if isinstance(axes, list):
@@ -333,7 +330,7 @@ class TestAminAmax(PytorchLayerTest):
model_cls = aten_amin_amax(op, axis, keep_dims, out)
- return model_cls, None, f"aten::{op_type}"
+ 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]])
diff --git a/tests/layer_tests/pytorch_tests/test_mm.py b/tests/layer_tests/pytorch_tests/test_mm.py
index a0e0fe2aa05..ba9aaee5dd4 100644
--- a/tests/layer_tests/pytorch_tests/test_mm.py
+++ b/tests/layer_tests/pytorch_tests/test_mm.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestMatMul(PytorchLayerTest):
def _prepare_input(self, matrix1_shape=(2, 2), matrix2_shape=(2, 2)):
- import numpy as np
- return (np.random.randn(*matrix1_shape).astype(np.float32), np.random.randn(*matrix2_shape).astype(np.float32))
+ return (self.random.randn(*matrix1_shape), self.random.randn(*matrix2_shape))
def create_model(self, op_type="aten::mm"):
import torch
@@ -21,15 +20,14 @@ class TestMatMul(PytorchLayerTest):
class aten_mm(torch.nn.Module):
def __init__(self, op):
- super(aten_mm, self).__init__()
+ super().__init__()
self.op = op
def forward(self, m1, m2):
return self.op(m1, m2)
- ref_net = None
- return aten_mm(ops[op_type]), ref_net, op_type
+ return aten_mm(ops[op_type]), op_type
@pytest.mark.parametrize("kwargs_to_prepare_input", [
{'matrix1_shape': (3, 3), 'matrix2_shape': (3, 3)},
diff --git a/tests/layer_tests/pytorch_tests/test_mul.py b/tests/layer_tests/pytorch_tests/test_mul.py
index b1876fa6646..453904b6503 100644
--- a/tests/layer_tests/pytorch_tests/test_mul.py
+++ b/tests/layer_tests/pytorch_tests/test_mul.py
@@ -15,14 +15,13 @@ class TestMul(PytorchLayerTest):
def create_model(self):
class aten_mul(torch.nn.Module):
def __init__(self):
- super(aten_mul, self).__init__()
+ super().__init__()
def forward(self, input_tensor, other_tensor):
return torch.mul(input_tensor, other_tensor)
- ref_net = None
- return aten_mul(), ref_net, "aten::mul"
+ return aten_mul(), "aten::mul"
@pytest.mark.parametrize(("input_array", "other_array"), [
[np.array([0.2015, -0.4255, 2.6087]), np.array(100)],
@@ -44,11 +43,11 @@ class TestMulTypes(PytorchLayerTest):
def _prepare_input(self):
if len(self.lhs_shape) == 0:
- return (torch.randn(self.rhs_shape).to(self.rhs_type).numpy(),)
+ return (self.random.randn(*self.rhs_shape, dtype=self.rhs_type),)
elif len(self.rhs_shape) == 0:
- return (torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),)
- return (torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),
- torch.randn(self.rhs_shape).to(self.rhs_type).numpy())
+ return (self.random.randn(*self.lhs_shape, dtype=self.lhs_type),)
+ return (self.random.randn(*self.lhs_shape, dtype=self.lhs_type),
+ self.random.randn(*self.rhs_shape, dtype=self.rhs_type))
def create_model(self, lhs_type, lhs_shape, rhs_type, rhs_shape):
@@ -73,9 +72,8 @@ class TestMulTypes(PytorchLayerTest):
def forward3(self, lhs, rhs):
return torch.mul(lhs.to(self.lhs_type), rhs.to(self.rhs_type))
- ref_net = None
- return aten_mul(lhs_type, lhs_shape, rhs_type, rhs_shape), ref_net, "aten::mul"
+ return aten_mul(lhs_type, lhs_shape, rhs_type, rhs_shape), "aten::mul"
@pytest.mark.parametrize(("lhs_type", "rhs_type"),
[[torch.int32, torch.int64],
@@ -112,8 +110,8 @@ class TestMulTypes(PytorchLayerTest):
class TestMulBool(PytorchLayerTest):
def _prepare_input(self):
- input_tensor = torch.randint(0, 2, size=(1, 100)).numpy()
- other_tensor = torch.randint(0, 2, size=(1, 100)).numpy()
+ input_tensor = self.random.randint(0, 2, size=(1, 100), dtype=np.int64)
+ other_tensor = self.random.randint(0, 2, size=(1, 100), dtype=np.int64)
return (input_tensor, other_tensor)
def create_model(self, lhs_type, rhs_type):
@@ -126,9 +124,8 @@ class TestMulBool(PytorchLayerTest):
def forward(self, input_tensor, other_tensor):
return torch.mul(input_tensor.to(self.lhs_type), other_tensor.to(self.rhs_type))
- ref_net = None
- return aten_mul(), ref_net, "aten::mul"
+ return aten_mul(), "aten::mul"
@pytest.mark.parametrize(("lhs_type", "rhs_type"), [
(torch.bool, torch.bool),
@@ -147,8 +144,8 @@ class TestMulWithLhsComplex(PytorchLayerTest):
def _prepare_input(self):
rhs_input_shape = [3, 4, 5]
lhs_input_shape = rhs_input_shape + [2]
- return [torch.randint(-10, 10, lhs_input_shape).to(self.lhs_type).numpy(),
- torch.randint(-10, 10, rhs_input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(-10, 10, size=lhs_input_shape, dtype=self.lhs_type),
+ self.random.randint(-10, 10, size=rhs_input_shape, dtype=self.rhs_type)]
def create_model(self, op_type):
class aten_mul(torch.nn.Module):
@@ -167,9 +164,8 @@ class TestMulWithLhsComplex(PytorchLayerTest):
lhs.mul_(rhs)
return torch.view_as_real(lhs)
- ref_net = None
- return aten_mul(op_type), ref_net, f"aten::{op_type}"
+ return aten_mul(op_type), f"aten::{op_type}"
@pytest.mark.parametrize("lhs_type",
[torch.float32,
@@ -194,8 +190,8 @@ class TestMulWithLhsComplex(PytorchLayerTest):
def _prepare_input(self):
rhs_input_shape = [3, 4, 5]
lhs_input_shape = rhs_input_shape + [2]
- return [torch.randint(-10, 10, lhs_input_shape).to(self.lhs_type).numpy(),
- torch.randint(-10, 10, rhs_input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(-10, 10, size=lhs_input_shape, dtype=self.lhs_type),
+ self.random.randint(-10, 10, size=rhs_input_shape, dtype=self.rhs_type)]
def create_model(self, op_type):
class aten_mul(torch.nn.Module):
@@ -214,9 +210,8 @@ class TestMulWithLhsComplex(PytorchLayerTest):
lhs.mul_(rhs)
return torch.view_as_real(lhs)
- ref_net = None
- return aten_mul(op_type), ref_net, f"aten::{op_type}"
+ return aten_mul(op_type), f"aten::{op_type}"
@pytest.mark.parametrize("lhs_type",
[torch.float32,
@@ -241,8 +236,8 @@ class TestMulWithRhsComplex(PytorchLayerTest):
def _prepare_input(self):
lhs_input_shape = [3, 4, 5]
rhs_input_shape = lhs_input_shape + [2]
- return [torch.randint(0, 10, lhs_input_shape).to(self.lhs_type).numpy(),
- torch.randint(0, 10, rhs_input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(0, 10, size=lhs_input_shape, dtype=self.lhs_type),
+ self.random.randint(0, 10, size=rhs_input_shape, dtype=self.rhs_type)]
def create_model(self):
class aten_mul(torch.nn.Module):
@@ -255,9 +250,8 @@ class TestMulWithRhsComplex(PytorchLayerTest):
res = torch.mul(lhs, rhs)
return torch.view_as_real(res)
- ref_net = None
- return aten_mul(), ref_net, f"aten::mul"
+ return aten_mul(), f"aten::mul"
@pytest.mark.parametrize("rhs_type",
[torch.float32,
@@ -282,8 +276,8 @@ class TestMulWithBothComplex(PytorchLayerTest):
def _prepare_input(self):
input_shape = [3, 4, 5]
input_shape = input_shape + [2]
- return [torch.randint(0, 10, input_shape).to(self.lhs_type).numpy(),
- torch.randint(0, 10, input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(0, 10, size=input_shape, dtype=self.lhs_type),
+ self.random.randint(0, 10, size=input_shape, dtype=self.rhs_type)]
def create_model(self, op_type):
class aten_mul(torch.nn.Module):
@@ -304,9 +298,8 @@ class TestMulWithBothComplex(PytorchLayerTest):
res = lhs.mul_(rhs)
return torch.view_as_real(res + lhs)
- ref_net = None
- return aten_mul(op_type), ref_net, f"aten::{op_type}"
+ return aten_mul(op_type), f"aten::{op_type}"
@pytest.mark.parametrize("lhs_type",
[torch.float32,
diff --git a/tests/layer_tests/pytorch_tests/test_multinomial.py b/tests/layer_tests/pytorch_tests/test_multinomial.py
index 310a1cfae57..defada140f1 100644
--- a/tests/layer_tests/pytorch_tests/test_multinomial.py
+++ b/tests/layer_tests/pytorch_tests/test_multinomial.py
@@ -41,9 +41,8 @@ class TestMultinomial(PytorchLayerTest):
return torch.sort(op)[0]
return op
- ref_net = None
- return aten_multinomial(replacement, out, test_type), ref_net, "aten::multinomial"
+ return aten_multinomial(replacement, out, test_type), "aten::multinomial"
@pytest.mark.parametrize(
("input", "num_samples", "replacement", "test_type"),
diff --git a/tests/layer_tests/pytorch_tests/test_narrow.py b/tests/layer_tests/pytorch_tests/test_narrow.py
index d8143568587..75f6023079e 100644
--- a/tests/layer_tests/pytorch_tests/test_narrow.py
+++ b/tests/layer_tests/pytorch_tests/test_narrow.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -10,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestNarrow(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(*self.input_shape).astype(np.float32),)
+ return (self.random.randn(*self.input_shape),)
def create_model(self, dim, start, length):
@@ -24,7 +23,7 @@ class TestNarrow(PytorchLayerTest):
def forward(self, input_tensor):
return torch.narrow(input_tensor, dim=self.dim, start=self.start, length=self.length)
- return aten_narrow(dim, start, length), None, "aten::narrow"
+ return aten_narrow(dim, start, length), "aten::narrow"
@pytest.mark.parametrize("input_shape", [
[3, 3], [3, 4, 5]
diff --git a/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py b/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py
index 1a4d2ad48de..e7f1363a3e3 100644
--- a/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py
+++ b/tests/layer_tests/pytorch_tests/test_native_multi_head_attention.py
@@ -3,7 +3,6 @@
import platform
-import numpy as np
import pytest
import torch
@@ -17,7 +16,7 @@ BATCH_SIZE = 1
NO_MASK, ATTN_MASK, KEY_PAD_MASK, MERGED_MASK = -1, 0, 1, 2
class aten_native_multi_head_attention(torch.nn.Module):
- def __init__(self, mask, need_weights, average_attn_weights) -> None:
+ def __init__(self, mask, need_weights, average_attn_weights, mask_data=None) -> None:
super().__init__()
self.qkv = torch.nn.Linear(EMBED_DIM, 3 * EMBED_DIM, dtype = torch.float32)
self.qkv.requires_grad_(False)
@@ -32,20 +31,18 @@ class aten_native_multi_head_attention(torch.nn.Module):
# Currently only int masks are working correctly, they are converted to bool.
# Float masks raise a warning in PyTorch and are (incorrectly) converted to bool,
# which later returns NaNs as MHA's output
- if mask == 0:
- self.mask = torch.from_numpy(np.random.randint(0, 2, (SEQ_LENGTH, SEQ_LENGTH)).astype("bool"))
- self.mask_type = 0
- elif mask == 1:
- self.mask = torch.from_numpy(np.random.randint(0, 2, (BATCH_SIZE, SEQ_LENGTH)).astype("bool"))
- self.mask_type = 1
- elif mask == 2:
- self.mask = torch.from_numpy(np.random.randint(0, 2, (BATCH_SIZE, NUM_HEADS, SEQ_LENGTH, SEQ_LENGTH)).astype("bool"))
- self.mask_type = 2
+ if mask == ATTN_MASK:
+ self.mask = torch.from_numpy(mask_data.astype("bool")) if mask_data is not None else None
+ self.mask_type = ATTN_MASK
+ elif mask == KEY_PAD_MASK:
+ self.mask = torch.from_numpy(mask_data.astype("bool")) if mask_data is not None else None
+ self.mask_type = KEY_PAD_MASK
+ elif mask == MERGED_MASK:
+ self.mask = torch.from_numpy(mask_data.astype("bool")) if mask_data is not None else None
+ self.mask_type = MERGED_MASK
else:
self.mask = None
- self.mask_type = None
-
- print(self.mask)
+ self.mask_type = NO_MASK
def forward(self, query, key, value):
return torch.ops.aten._native_multi_head_attention(
@@ -61,11 +58,21 @@ class aten_native_multi_head_attention(torch.nn.Module):
class TestNativeMultiHeadAttention(PytorchLayerTest):
def _prepare_input(self):
# NativeMHA is self-attention
- qkv_tensor = np.random.randn(BATCH_SIZE, SEQ_LENGTH, EMBED_DIM).astype(np.float32)
+ qkv_tensor = self.random.randn(BATCH_SIZE, SEQ_LENGTH, EMBED_DIM)
return (qkv_tensor.copy(),
qkv_tensor.copy(),
qkv_tensor.copy())
+ def _get_mask_data(self, mask):
+ """Generate mask data based on mask type."""
+ if mask == ATTN_MASK:
+ return self.random.randint(0, 2, (SEQ_LENGTH, SEQ_LENGTH))
+ elif mask == KEY_PAD_MASK:
+ return self.random.randint(0, 2, (BATCH_SIZE, SEQ_LENGTH))
+ elif mask == MERGED_MASK:
+ return self.random.randint(0, 2, (BATCH_SIZE, NUM_HEADS, SEQ_LENGTH, SEQ_LENGTH))
+ return None
+
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.parametrize(
@@ -81,5 +88,5 @@ class TestNativeMultiHeadAttention(PytorchLayerTest):
'arm64', 'ARM64'),
reason='Ticket - 122715')
def test_native_multi_head_attention(self, ie_device, precision, ir_version, mask, need_weights, average_attn_weights):
- self._test(aten_native_multi_head_attention(mask, need_weights, average_attn_weights),
- None, "aten::_native_multi_head_attention", ie_device, precision, ir_version)
+ mask_data = self._get_mask_data(mask)
+ self._test(aten_native_multi_head_attention(mask, need_weights, average_attn_weights, mask_data), "aten::_native_multi_head_attention", ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_neg.py b/tests/layer_tests/pytorch_tests/test_neg.py
index 1d23735f4c9..48938c5304b 100644
--- a/tests/layer_tests/pytorch_tests/test_neg.py
+++ b/tests/layer_tests/pytorch_tests/test_neg.py
@@ -14,15 +14,14 @@ class neg_model(torch.nn.Module):
class TestNeg(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 4, 224, 224).astype(np.float32),)
+ return (self.random.randn(2, 4, 224, 224),)
@pytest.mark.nightly
@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",
+ self._test(neg_model(), "aten::neg",
ie_device, precision, ir_version,
dynamic_shapes_for_export={
"x": {3: torch.export.Dim("width")}
diff --git a/tests/layer_tests/pytorch_tests/test_nms.py b/tests/layer_tests/pytorch_tests/test_nms.py
index 18b82b332aa..ed1b6b33b54 100644
--- a/tests/layer_tests/pytorch_tests/test_nms.py
+++ b/tests/layer_tests/pytorch_tests/test_nms.py
@@ -15,10 +15,10 @@ class TestNms(PytorchLayerTest):
def _prepare_input(self):
# PyTorch requires that boxes are in (x1, y1, x2, y2) format, where 0<=x1<x2 and 0<=y1<y2
- boxes = np.array([[np.random.uniform(1, 3), np.random.uniform(2, 6),
- np.random.uniform(4, 6), np.random.uniform(7, 9)] for _ in range(self.boxes_num)]).astype(np.float32)
+ boxes = np.array([[self.random.uniform(1, 3), self.random.uniform(2, 6),
+ self.random.uniform(4, 6), self.random.uniform(7, 9)] for _ in range(self.boxes_num)]).astype(np.float32)
# scores can be negative
- scores = np.random.randn(self.boxes_num).astype(np.float32)
+ scores = self.random.randn(self.boxes_num)
return (boxes, scores)
def create_model(self):
@@ -31,9 +31,8 @@ class TestNms(PytorchLayerTest):
def forward(self, boxes, scores):
return torchvision.ops.nms(boxes=boxes, scores=scores, iou_threshold=self.iou_threshold)
- ref_net = None
- return torchvision_nms(), ref_net, "torchvision::nms"
+ return torchvision_nms(), "torchvision::nms"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_nonzero.py b/tests/layer_tests/pytorch_tests/test_nonzero.py
index 888dc609133..13e9b741edc 100644
--- a/tests/layer_tests/pytorch_tests/test_nonzero.py
+++ b/tests/layer_tests/pytorch_tests/test_nonzero.py
@@ -14,7 +14,7 @@ class TestNonZero(PytorchLayerTest):
if mask_fill == 'ones':
mask = np.ones(input_shape).astype(mask_dtype)
if mask_fill == 'random':
- idx = np.random.choice(10, 5)
+ idx = self.random.choice(10, 5)
mask[:, idx, 1] = 1
return (mask,)
@@ -31,11 +31,10 @@ class TestNonZero(PytorchLayerTest):
def forward(self, cond):
return torch.nonzero(cond, as_tuple=True)
- ref_net = None
if not as_tuple:
- return aten_nonzero(), ref_net, "aten::nonzero"
- return aten_nonzero_numpy(), ref_net, "aten::nonzero_numpy"
+ return aten_nonzero(), "aten::nonzero"
+ return aten_nonzero_numpy(), "aten::nonzero_numpy"
@pytest.mark.parametrize(
"mask_fill", ['zeros', 'ones', 'random']) # np.float32 incorrectly casted to bool
diff --git a/tests/layer_tests/pytorch_tests/test_norm.py b/tests/layer_tests/pytorch_tests/test_norm.py
index 4bb2db220a7..44979f920e6 100644
--- a/tests/layer_tests/pytorch_tests/test_norm.py
+++ b/tests/layer_tests/pytorch_tests/test_norm.py
@@ -14,7 +14,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestNorm(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(1, 2, 3).astype(np.float32),)
+ return (self.random.randn(1, 2, 3),)
def create_model(self, p, dim, keepdim):
class aten_norm(torch.nn.Module):
@@ -28,9 +28,8 @@ class TestNorm(PytorchLayerTest):
def forward(self, input_data):
return torch._VF.norm(input_data, self.p, self.dim, self.keepdim)
- ref_net = None
- return aten_norm(p, dim, keepdim), ref_net, "aten::norm"
+ return aten_norm(p, dim, keepdim), "aten::norm"
def create_model_tensor_norm(self, p, dim, keepdim):
class aten_norm(torch.nn.Module):
@@ -51,9 +50,8 @@ class TestNorm(PytorchLayerTest):
def forward2(self, input_data):
return input_data.norm(self.p)
- ref_net = None
- return aten_norm(p, dim, keepdim), ref_net, "aten::norm"
+ return aten_norm(p, dim, keepdim), "aten::norm"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -76,13 +74,13 @@ class TestNorm(PytorchLayerTest):
class TestWeightNorm(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(1, 60, 20).astype(np.float32),)
+ return (self.random.randn(1, 60, 20),)
def create_model(self):
from torch import nn
from torch.nn.utils import weight_norm
- return weight_norm(nn.Linear(20, 40), name='weight'), None, "aten::_weight_norm"
+ return weight_norm(nn.Linear(20, 40), name='weight'), "aten::_weight_norm"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -92,7 +90,7 @@ class TestWeightNorm(PytorchLayerTest):
class TestFrobeniusNorm(PytorchLayerTest):
def _prepare_input(self, out=False, dtype="float32"):
- x = np.random.randn(10, 12, 14).astype(dtype)
+ x = self.random.randn(10, 12, 14, dtype=dtype)
if not out:
return (x,)
y = np.zeros_like(x)
@@ -114,9 +112,8 @@ class TestFrobeniusNorm(PytorchLayerTest):
def forward_out(self, input_data, out):
return torch._VF.frobenius_norm(input_data, self.dim, self.keepdim, out=out), out
- ref_net = None
- return aten_frobenius_norm(dim, keepdim, out), ref_net, "aten::frobenius_norm"
+ return aten_frobenius_norm(dim, keepdim, out), "aten::frobenius_norm"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -134,9 +131,9 @@ class TestLinalgVectorNorm(PytorchLayerTest):
def _prepare_input(self, out=False, out_dtype=None):
if not out:
- return (np.random.randn(1, 2, 3).astype(np.float32),)
- x = np.random.randn(1, 2, 3).astype(np.float32)
- y = np.random.randn(1, 2, 3).astype(
+ return (self.random.randn(1, 2, 3),)
+ x = self.random.randn(1, 2, 3)
+ y = self.random.randn(1, 2, 3, dtype=
out_dtype if out_dtype is not None else np.float32)
return (x, y)
@@ -182,9 +179,8 @@ class TestLinalgVectorNorm(PytorchLayerTest):
x, ord=self.ord, dim=self.dim, keepdim=self.keepdim, out=y
)
- ref_net = None
- return aten_linalg_vector_norm(p, dim, keepdim, dtype, out, out_as_dtype), ref_net, "aten::linalg_vector_norm"
+ return aten_linalg_vector_norm(p, dim, keepdim, dtype, out, out_as_dtype), "aten::linalg_vector_norm"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -204,9 +200,9 @@ class TestLinalgMatrixNorm(PytorchLayerTest):
def _prepare_input(self, out=False, out_dtype=None):
if not out:
- return (np.random.randn(3, 3).astype(np.float32),)
- x = np.random.randn(1, 3, 3).astype(np.float32)
- y = np.random.randn(1, 3, 3).astype(
+ return (self.random.randn(3, 3),)
+ x = self.random.randn(1, 3, 3)
+ y = self.random.randn(1, 3, 3, dtype=
out_dtype if out_dtype is not None else np.float32)
return (x, y)
@@ -252,9 +248,8 @@ class TestLinalgMatrixNorm(PytorchLayerTest):
x, ord=self.ord, dim=self.dim, keepdim=self.keepdim, out=y
)
- ref_net = None
- return aten_linalg_matrix_norm(p, dim, keepdim, dtype, out, out_as_dtype), ref_net, "aten::linalg_matrix_norm"
+ return aten_linalg_matrix_norm(p, dim, keepdim, dtype, out, out_as_dtype), "aten::linalg_matrix_norm"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -278,9 +273,9 @@ class TestLinalgNorm(PytorchLayerTest):
def _prepare_input(self, out=False, out_dtype=None, input_shape=(3, 3)):
if not out:
- return (np.random.randn(*input_shape).astype(np.float32),)
- x = np.random.randn(*input_shape).astype(np.float32)
- y = np.random.randn(*input_shape).astype(
+ return (self.random.randn(*input_shape),)
+ x = self.random.randn(*input_shape)
+ y = self.random.randn(*input_shape, dtype=
out_dtype if out_dtype is not None else np.float32)
return (x, y)
@@ -326,9 +321,8 @@ class TestLinalgNorm(PytorchLayerTest):
x, ord=self.ord, dim=self.dim, keepdim=self.keepdim, out=y
)
- ref_net = None
- return aten_linalg_matrix_norm(p, dim, keepdim, dtype, out, out_as_dtype), ref_net, "aten::linalg_norm"
+ return aten_linalg_matrix_norm(p, dim, keepdim, dtype, out, out_as_dtype), "aten::linalg_norm"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -355,14 +349,14 @@ class TestLinalgNorm(PytorchLayerTest):
class TestTrickyNorm(PytorchLayerTest):
def _prepare_input(self, input_shape=(3, 3)):
- return (np.random.randn(*input_shape).astype(np.float32),)
+ return (self.random.randn(*input_shape),)
def create_model(self):
class aten_norm(torch.nn.Module):
def forward(self, x):
return torch.nn.functional.normalize(x, eps=2)
- return aten_norm(), None, ["aten::linalg_vector_norm", "aten::clamp_min"]
+ return aten_norm(), ["aten::linalg_vector_norm", "aten::clamp_min"]
@pytest.mark.nightly
@pytest.mark.precommit
@@ -374,7 +368,7 @@ class TestTrickyNorm(PytorchLayerTest):
class TestRMSNorm(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 5, 10, 10).astype(np.float32),)
+ return (self.random.randn(2, 5, 10, 10),)
def create_model(self, normalized_shape, eps, gamma):
class aten_rms_norm(torch.nn.Module):
@@ -387,7 +381,7 @@ class TestRMSNorm(PytorchLayerTest):
def forward(self, input_data):
return self.rms(input_data)
- return aten_rms_norm(normalized_shape, eps, gamma), None, "aten::rms_norm"
+ return aten_rms_norm(normalized_shape, eps, gamma), "aten::rms_norm"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_numel.py b/tests/layer_tests/pytorch_tests/test_numel.py
index 6c3a8844be9..78d52acba54 100644
--- a/tests/layer_tests/pytorch_tests/test_numel.py
+++ b/tests/layer_tests/pytorch_tests/test_numel.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestNumel(PytorchLayerTest):
def _prepare_input(self, input_shape=(2)):
- import numpy as np
- return (np.random.randn(*input_shape).astype(np.float32),)
+ return (self.random.randn(*input_shape),)
def create_model(self):
import torch
@@ -18,9 +17,8 @@ class TestNumel(PytorchLayerTest):
def forward(self, x):
return torch.numel(x)
- ref_net = None
- return aten_numel(), ref_net, 'aten::numel'
+ return aten_numel(), 'aten::numel'
@pytest.mark.parametrize("kwargs_to_prepare_input", [
{'input_shape': (1,)},
diff --git a/tests/layer_tests/pytorch_tests/test_one_hot.py b/tests/layer_tests/pytorch_tests/test_one_hot.py
index 3ce79fabee8..701169cb843 100644
--- a/tests/layer_tests/pytorch_tests/test_one_hot.py
+++ b/tests/layer_tests/pytorch_tests/test_one_hot.py
@@ -9,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestOneHot(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randint(0, 100, (1,1000)).astype(np.int32),)
+ return (self.random.randint(0, 100, (1,1000), dtype=np.int32),)
def create_model(self, num_classes):
import torch
@@ -17,13 +17,13 @@ class TestOneHot(PytorchLayerTest):
class aten_one_hot(torch.nn.Module):
def __init__(self, num_classes):
- super(aten_one_hot, self).__init__()
+ super().__init__()
self.num_classes = num_classes
def forward(self, x):
return F.one_hot(torch.arange(0, x.numel()) % 3, self.num_classes)
- return aten_one_hot(num_classes), None, "aten::one_hot"
+ return aten_one_hot(num_classes), "aten::one_hot"
@pytest.mark.parametrize(("num_classes"), [-1, 3, 1000,])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_or.py b/tests/layer_tests/pytorch_tests/test_or.py
index 8bc418bf2ee..3b26acae193 100644
--- a/tests/layer_tests/pytorch_tests/test_or.py
+++ b/tests/layer_tests/pytorch_tests/test_or.py
@@ -20,9 +20,8 @@ class TestOr(PytorchLayerTest):
def forward(self, tensor_a, tensor_b):
return tensor_a | tensor_b
- ref_net = None
- return aten_or_tensor(), ref_net, "aten::__or__"
+ return aten_or_tensor(), "aten::__or__"
def create_model_bool_input(self):
class aten_or_bool(torch.nn.Module):
@@ -32,9 +31,8 @@ class TestOr(PytorchLayerTest):
def forward(self, bool_a: bool, bool_b: bool):
return bool_a | bool_b
- ref_net = None
- return aten_or_bool(), ref_net, "aten::__or__"
+ return aten_or_bool(), "aten::__or__"
def create_model_int_input(self):
class aten_or_int(torch.nn.Module):
@@ -44,9 +42,8 @@ class TestOr(PytorchLayerTest):
def forward(self, int_a: int, int_b: int):
return int_a | int_b
- ref_net = None
- return aten_or_int(), ref_net, "aten::__or__"
+ return aten_or_int(), "aten::__or__"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_outer.py b/tests/layer_tests/pytorch_tests/test_outer.py
index be9d468fbcf..abba8d45a15 100644
--- a/tests/layer_tests/pytorch_tests/test_outer.py
+++ b/tests/layer_tests/pytorch_tests/test_outer.py
@@ -9,8 +9,8 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestOuter(PytorchLayerTest):
def _prepare_input(self, x_shape, y_shape, x_dtype, y_dtype, out=False):
import numpy as np
- x = np.random.randn(*x_shape).astype(x_dtype)
- y = np.random.randn(*y_shape).astype(y_dtype)
+ x = self.random.randn(*x_shape, dtype=x_dtype)
+ y = self.random.randn(*y_shape, dtype=y_dtype)
if not out:
return (x, y)
out = np.zeros((x_shape[0], y_shape[0]))
@@ -40,9 +40,8 @@ class TestOuter(PytorchLayerTest):
def forward_out(self, x, y, out):
return torch.outer(x.to(self.x_dtype), y.to(self.y_dtype), out=out), out
- ref_net = None
- return aten_outer(out, x_dtype, y_dtype), ref_net, 'aten::outer'
+ return aten_outer(out, x_dtype, y_dtype), 'aten::outer'
@pytest.mark.parametrize("x_shape", ([1], [2], [3]))
@pytest.mark.parametrize("y_shape", ([1], [7], [5]))
diff --git a/tests/layer_tests/pytorch_tests/test_pad.py b/tests/layer_tests/pytorch_tests/test_pad.py
index b5d5344a6df..1c0c72dc39b 100644
--- a/tests/layer_tests/pytorch_tests/test_pad.py
+++ b/tests/layer_tests/pytorch_tests/test_pad.py
@@ -10,7 +10,7 @@ class TestPad(PytorchLayerTest):
def _prepare_input(self, ndim=4, dtype="float32"):
import numpy as np
input_5d_shape = [1, 3, 14, 14, 18]
- return (np.random.randn(*input_5d_shape[:ndim]).astype(dtype),)
+ return (self.random.randn(*input_5d_shape[:ndim], dtype=dtype),)
def create_model(self, pads, mode, value=None):
import torch
@@ -26,9 +26,8 @@ class TestPad(PytorchLayerTest):
def forward(self, x):
return F.pad(x, self.pads, mode=self.mode, value=self.value)
- ref_net = None
- return aten_pad(pads, mode, value), ref_net, "aten::pad"
+ return aten_pad(pads, mode, value), "aten::pad"
@pytest.mark.parametrize("pads,mode,value,dtype", [
((1, 2, 3, 4), "reflect", None, "float32"),
@@ -114,7 +113,7 @@ class TestPadListPaddingings(PytorchLayerTest):
def _prepare_input(self, ndim=4, pad_w=0, pad_h=0, dtype="float32"):
import numpy as np
input_5d_shape = [1, 3, 14, 14, 18]
- return (np.random.randn(*input_5d_shape[:ndim]).astype(dtype), np.array(pad_w, dtype=np.int32), np.array(pad_h, dtype=np.int32))
+ return (self.random.randn(*input_5d_shape[:ndim], dtype=dtype), np.array(pad_w, dtype=np.int32), np.array(pad_h, dtype=np.int32))
def create_model(self, mode, value=None):
import torch
@@ -129,9 +128,8 @@ class TestPadListPaddingings(PytorchLayerTest):
def forward(self, x, pad_w: int, pad_h: int):
return F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h - pad_h // 2], value=self.value)
- ref_net = None
- return aten_pad(mode, value), ref_net, "aten::pad"
+ return aten_pad(mode, value), "aten::pad"
@pytest.mark.parametrize("pad_w,pad_h,mode,value,dtype", [
(2, 0, "reflect", None, "float32"),
@@ -206,7 +204,7 @@ class TestReflectionPad(PytorchLayerTest):
def _prepare_input(self, ndim=4, dtype="float32"):
import numpy as np
input_5d_shape = [1, 3, 14, 14, 18]
- return (np.random.randn(*input_5d_shape[:ndim]).astype(dtype),)
+ return (self.random.randn(*input_5d_shape[:ndim], dtype=dtype),)
def create_model(self, pads):
import torch
@@ -229,7 +227,7 @@ class TestReflectionPad(PytorchLayerTest):
return self.pad(x)
# it will be a reflection_pad in export, but not in TS
- return aten_pad(pads), None, "aten::pad"
+ return aten_pad(pads), "aten::pad"
@pytest.mark.parametrize("dtype", ["float32", "float64", "int32"])
@pytest.mark.parametrize("pads", [
@@ -241,6 +239,5 @@ class TestReflectionPad(PytorchLayerTest):
@pytest.mark.precommit_torch_export
def test_reflection_padnd(self, pads, dtype, ie_device, precision, ir_version):
ndim = len(pads) // 2 + 2
- print(ndim)
self._test(*self.create_model(pads), ie_device, precision, ir_version,
kwargs_to_prepare_input={"ndim": ndim, "dtype": dtype})
diff --git a/tests/layer_tests/pytorch_tests/test_permute.py b/tests/layer_tests/pytorch_tests/test_permute.py
index 2be5345b96f..a3dbd54f5fd 100644
--- a/tests/layer_tests/pytorch_tests/test_permute.py
+++ b/tests/layer_tests/pytorch_tests/test_permute.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestPermute(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, order, complex_type):
import torch
@@ -29,7 +28,7 @@ class TestPermute(PytorchLayerTest):
res = torch.view_as_real(res)
return res
- return aten_permute(order, complex_type), None, "aten::permute"
+ return aten_permute(order, complex_type), "aten::permute"
@pytest.mark.parametrize("order", [[0, 2, 3, 1],
[0, 3, 1, 2],
@@ -44,23 +43,21 @@ class TestPermute(PytorchLayerTest):
class TestPermuteCopy(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, order):
import torch
class aten_permute_copy(torch.nn.Module):
def __init__(self, order):
- super(aten_permute_copy, self).__init__()
+ super().__init__()
self.order = order
def forward(self, x):
return torch.permute_copy(x, self.order)
- ref_net = None
- return aten_permute_copy(order), ref_net, "aten::permute_copy"
+ return aten_permute_copy(order), "aten::permute_copy"
@pytest.mark.parametrize("order", [[0, 2, 3, 1], [0, 3, 1, 2], [0, -1, 1, -2]])
@pytest.mark.precommit_fx_backend
@@ -70,9 +67,8 @@ class TestPermuteCopy(PytorchLayerTest):
class TestPermuteList(PytorchLayerTest):
def _prepare_input(self, permute_shape):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),
- np.random.randn(*permute_shape).astype(np.float32))
+ return (self.random.randn(1, 3, 224, 224),
+ self.random.randn(*permute_shape))
def create_model(self):
import torch
@@ -82,9 +78,8 @@ class TestPermuteList(PytorchLayerTest):
y_shape = y.shape
return torch.permute(x, [y_shape[0] - 1, y_shape[1] - 1, y_shape[2] - 1, y_shape[3] - 1])
- ref_net = None
- return aten_permute_list(), ref_net, ["aten::permute", "prim::ListConstruct"]
+ return aten_permute_list(), ["aten::permute", "prim::ListConstruct"]
@pytest.mark.parametrize("order", [[1, 3, 4, 2], [1, 4, 2, 3]])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py b/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py
index b8744adf82e..af6df992d65 100644
--- a/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py
+++ b/tests/layer_tests/pytorch_tests/test_pixel_shuffle.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
from pytorch_layer_test_class import PytorchLayerTest
@@ -9,7 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestPixelShuffle(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(*self.shape).astype(np.float32),)
+ return (self.random.randn(*self.shape),)
def create_model(self, upscale_factor):
import torch
@@ -17,13 +16,13 @@ class TestPixelShuffle(PytorchLayerTest):
class aten_pixel_shuffle(torch.nn.Module):
def __init__(self, upscale_factor):
- super(aten_pixel_shuffle, self).__init__()
+ super().__init__()
self.upscale_factor = upscale_factor
def forward(self, x):
return F.pixel_shuffle(x, self.upscale_factor)
- return aten_pixel_shuffle(upscale_factor), None, "aten::pixel_shuffle"
+ return aten_pixel_shuffle(upscale_factor), "aten::pixel_shuffle"
@pytest.mark.parametrize(("upscale_factor,shape"), [(3, [1, 9, 4, 4]),
(2, [1, 2, 3, 8, 4, 4]),])
@@ -38,7 +37,7 @@ class TestPixelShuffle(PytorchLayerTest):
class TestPixelUnshuffle(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(*self.shape).astype(np.float32),)
+ return (self.random.randn(*self.shape),)
def create_model(self, upscale_factor):
import torch
@@ -46,13 +45,13 @@ class TestPixelUnshuffle(PytorchLayerTest):
class aten_pixel_unshuffle(torch.nn.Module):
def __init__(self, upscale_factor):
- super(aten_pixel_unshuffle, self).__init__()
+ super().__init__()
self.upscale_factor = upscale_factor
def forward(self, x):
return F.pixel_unshuffle(x, self.upscale_factor)
- return aten_pixel_unshuffle(upscale_factor), None, "aten::pixel_unshuffle"
+ return aten_pixel_unshuffle(upscale_factor), "aten::pixel_unshuffle"
@pytest.mark.parametrize(("upscale_factor,shape"), [(3, [1, 1, 12, 12]),
(2, [1, 2, 3, 2, 8, 8]),])
@@ -67,7 +66,7 @@ class TestPixelUnshuffle(PytorchLayerTest):
class TestChannelShuffle(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(*self.shape).astype(np.float32),)
+ return (self.random.randn(*self.shape),)
def create_model(self, groups):
import torch
@@ -75,13 +74,13 @@ class TestChannelShuffle(PytorchLayerTest):
class aten_channel_shuffle(torch.nn.Module):
def __init__(self, upscale_factor):
- super(aten_channel_shuffle, self).__init__()
+ super().__init__()
self.upscale_factor = upscale_factor
def forward(self, x):
return F.channel_shuffle(x, self.upscale_factor)
- return aten_channel_shuffle(groups), None, "aten::channel_shuffle"
+ return aten_channel_shuffle(groups), "aten::channel_shuffle"
@pytest.mark.parametrize(("groups,shape"), [
(3, [1, 9, 4, 4]),
diff --git a/tests/layer_tests/pytorch_tests/test_polar.py b/tests/layer_tests/pytorch_tests/test_polar.py
index 6992d37c26a..565e635ee5c 100644
--- a/tests/layer_tests/pytorch_tests/test_polar.py
+++ b/tests/layer_tests/pytorch_tests/test_polar.py
@@ -4,14 +4,13 @@
import numpy as np
import pytest
import torch
-import openvino as ov
from pytorch_layer_test_class import PytorchLayerTest
class TestPolar(PytorchLayerTest):
def _prepare_input(self, input_shape=(1, 1000), dtype=np.float32):
return (
- np.random.uniform(0, 10, input_shape).astype(dtype),
- np.random.uniform(-np.pi, np.pi, input_shape).astype(dtype)
+ self.random.uniform(0, 10, input_shape, dtype=dtype),
+ self.random.uniform(-np.pi, np.pi, input_shape, dtype=dtype)
)
def create_model(self):
@@ -19,8 +18,7 @@ class TestPolar(PytorchLayerTest):
def forward(self, abs, angle):
complex_tensor = torch.polar(abs, angle)
return torch.view_as_real(complex_tensor)
- ref_net = None
- return PolarModel(), None, "aten::polar"
+ return PolarModel(), "aten::polar"
@pytest.mark.parametrize("input_case", [
(1, 1000),
diff --git a/tests/layer_tests/pytorch_tests/test_pooling.py b/tests/layer_tests/pytorch_tests/test_pooling.py
index 7bd26be5e5c..e348e5628bd 100644
--- a/tests/layer_tests/pytorch_tests/test_pooling.py
+++ b/tests/layer_tests/pytorch_tests/test_pooling.py
@@ -42,7 +42,7 @@ class TestPooling(PytorchLayerTest):
def create_model(self, op_type, kernel_size, stride, padding, dilation=1, ceil_mode=True, count_include_pad=True, dtype=torch.float32):
class aten_avg_pooling_base(torch.nn.Module):
def __init__(self):
- super(aten_avg_pooling_base, self).__init__()
+ super().__init__()
self.kernel_size = kernel_size
self.stride = stride
self.padding = padding
@@ -54,7 +54,7 @@ class TestPooling(PytorchLayerTest):
class aten_max_pooling_base(torch.nn.Module):
def __init__(self):
- super(aten_max_pooling_base, self).__init__()
+ super().__init__()
self.kernel_size = kernel_size
self.stride = stride
self.padding = padding
@@ -122,10 +122,9 @@ class TestPooling(PytorchLayerTest):
"max_pool3d_with_indices": aten_max_pool3d_indices,
}
- ref_net = None
aten_pooling = ops[op_type]
- return aten_pooling(), ref_net, f"aten::{op_type}"
+ return aten_pooling(), f"aten::{op_type}"
@pytest.mark.parametrize("input_shape", [[1, 3, 15], [3, 15]])
@pytest.mark.parametrize("params", d1_params)
@@ -138,7 +137,7 @@ class TestPooling(PytorchLayerTest):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
def test_avg_pool1d(self, input_shape, params, ceil_mode, count_include_pad, ie_device, precision, ir_version, is_dynamic_shapes):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model("avg_pool1d", **params, ceil_mode=ceil_mode, count_include_pad=count_include_pad),
ie_device, precision, ir_version, trace_model=True,
dynamic_shapes=is_dynamic_shapes)
@@ -157,7 +156,7 @@ class TestPooling(PytorchLayerTest):
def test_avg_pool2d(self, input_shape, params, ceil_mode, count_include_pad, ie_device, precision, ir_version, is_dynamic_shapes):
if ceil_mode and count_include_pad and np.array_equal(np.array(params["kernel_size"]), np.array([8, 8])):
pytest.xfail("Ticket - 150292")
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model("avg_pool2d", **params, ceil_mode=ceil_mode, count_include_pad=count_include_pad),
ie_device, precision, ir_version, trace_model=True, freeze_model=False, dynamic_shapes=is_dynamic_shapes)
@@ -173,7 +172,7 @@ class TestPooling(PytorchLayerTest):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
def test_avg_pool3d(self, input_shape, params, ceil_mode, count_include_pad, ie_device, precision, ir_version, is_dynamic_shapes):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model("avg_pool3d", **params, ceil_mode=ceil_mode, count_include_pad=count_include_pad),
ie_device, precision, ir_version, trace_model=True,
dynamic_shapes=is_dynamic_shapes)
@@ -189,7 +188,7 @@ class TestPooling(PytorchLayerTest):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
def test_max_pool1d(self, input_shape, params, ceil_mode, dilation, ie_device, precision, ir_version, is_dynamic_shapes):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model("max_pool1d", **params, ceil_mode=ceil_mode, dilation=dilation),
ie_device, precision, ir_version, dynamic_shapes=is_dynamic_shapes)
@@ -208,7 +207,7 @@ class TestPooling(PytorchLayerTest):
to_trace = False
if params["stride"] == []:
to_trace = True
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model("max_pool2d", **params, ceil_mode=ceil_mode, dilation=dilation, dtype=dtype),
ie_device, precision, ir_version, dynamic_shapes=is_dynamic_shapes, trace_model=to_trace)
@@ -223,7 +222,7 @@ class TestPooling(PytorchLayerTest):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
def test_max_pool3d(self, input_shape, params, ceil_mode, dilation, ie_device, precision, ir_version, is_dynamic_shapes):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model("max_pool3d", **params, ceil_mode=ceil_mode, dilation=dilation),
ie_device, precision, ir_version, dynamic_shapes=is_dynamic_shapes)
@@ -238,7 +237,7 @@ class TestPooling(PytorchLayerTest):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
def test_max_pool1d_indices(self, input_shape, params, ceil_mode, dilation, ie_device, precision, ir_version, is_dynamic_shapes):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model("max_pool1d_with_indices", **params, ceil_mode=ceil_mode, dilation=dilation),
ie_device, precision, ir_version, dynamic_shapes=is_dynamic_shapes)
@@ -257,7 +256,7 @@ class TestPooling(PytorchLayerTest):
to_trace = False
if params["stride"] == []:
to_trace = True
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model("max_pool2d_with_indices", **params, ceil_mode=ceil_mode, dilation=dilation),
ie_device, precision, ir_version, dynamic_shapes=is_dynamic_shapes, trace_model=to_trace)
@@ -273,6 +272,6 @@ class TestPooling(PytorchLayerTest):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
def test_max_pool3d_indices(self, input_shape, params, ceil_mode, dilation, ie_device, precision, ir_version, is_dynamic_shapes):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model("max_pool3d_with_indices", **params, ceil_mode=ceil_mode, dilation=dilation),
ie_device, precision, ir_version, dynamic_shapes=is_dynamic_shapes)
diff --git a/tests/layer_tests/pytorch_tests/test_pow.py b/tests/layer_tests/pytorch_tests/test_pow.py
index 5097194347a..06414c95499 100644
--- a/tests/layer_tests/pytorch_tests/test_pow.py
+++ b/tests/layer_tests/pytorch_tests/test_pow.py
@@ -30,7 +30,7 @@ class TestPow(PytorchLayerTest):
def create_model(self, inplace):
class aten_pow(torch.nn.Module):
def __init__(self, inplace):
- super(aten_pow, self).__init__()
+ super().__init__()
if inplace:
self.forward = self.forward_inplace
else:
@@ -42,7 +42,7 @@ class TestPow(PytorchLayerTest):
def forward_inplace(self, input_data, exponent):
return input_data.pow_(exponent)
- return aten_pow(inplace), None, "aten::pow_" if inplace else "aten::pow"
+ return aten_pow(inplace), "aten::pow_" if inplace else "aten::pow"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -59,11 +59,11 @@ class TestPow(PytorchLayerTest):
class TestPowMixedTypes(PytorchLayerTest):
def _prepare_input(self):
if len(self.lhs_shape) == 0:
- return (torch.randn(self.rhs_shape) * 2 + 0.6).to(self.rhs_type).numpy(),
+ return (self.random.randn(*self.rhs_shape, dtype=self.rhs_type) * 2 + 0.6,)
elif len(self.rhs_shape) == 0:
- return (torch.randint(1, 3, self.lhs_shape).to(self.lhs_type).numpy(),)
- return (torch.randint(1, 3, self.lhs_shape).to(self.lhs_type).numpy(),
- (torch.randn(self.rhs_shape) * 2 + 0.6).to(self.rhs_type).numpy())
+ return (self.random.randint(1, 3, size=self.lhs_shape, dtype=self.lhs_type),)
+ return (self.random.randint(1, 3, size=self.lhs_shape, dtype=self.lhs_type),
+ self.random.randn(*self.rhs_shape, dtype=self.rhs_type) * 2 + 0.6)
def create_model(self, lhs_type, lhs_shape, rhs_type, rhs_shape):
@@ -88,9 +88,8 @@ class TestPowMixedTypes(PytorchLayerTest):
def forward3(self, lhs, rhs):
return torch.pow(lhs.to(self.lhs_type), rhs.to(self.rhs_type))
- ref_net = None
- return aten_pow(lhs_type, lhs_shape, rhs_type, rhs_shape), ref_net, "aten::pow"
+ return aten_pow(lhs_type, lhs_shape, rhs_type, rhs_shape), "aten::pow"
@pytest.mark.parametrize(("lhs_type", "rhs_type"),
[[torch.int32, torch.int64],
@@ -124,7 +123,7 @@ class TestPowMixedTypes(PytorchLayerTest):
class TestPowMixedTypesScalars(PytorchLayerTest):
def _prepare_input(self):
- return (torch.randn([1, 2, 3, 4]).numpy(),)
+ return (self.random.randn(1, 2, 3, 4),)
def create_model(self):
@@ -132,9 +131,8 @@ class TestPowMixedTypesScalars(PytorchLayerTest):
def forward(self, x):
return torch.pow(x.size(2), -0.5)
- ref_net = None
- return aten_pow(), ref_net, "aten::pow"
+ return aten_pow(), "aten::pow"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_prelu.py b/tests/layer_tests/pytorch_tests/test_prelu.py
index d4752396e0a..d4ae9d6e4df 100644
--- a/tests/layer_tests/pytorch_tests/test_prelu.py
+++ b/tests/layer_tests/pytorch_tests/test_prelu.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestPRelu(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, alpha):
import torch
@@ -17,15 +16,14 @@ class TestPRelu(PytorchLayerTest):
class aten_prelu(torch.nn.Module):
def __init__(self, alpha):
- super(aten_prelu, self).__init__()
+ super().__init__()
self.alpha = torch.Tensor([alpha])
def forward(self, x):
return x, F.prelu(x, self.alpha)
- ref_net = None
- return aten_prelu(alpha), ref_net, "aten::prelu"
+ return aten_prelu(alpha), "aten::prelu"
@pytest.mark.parametrize("alpha", [0.01, 1.01, -0.01])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_prod.py b/tests/layer_tests/pytorch_tests/test_prod.py
index 8dbbc25a1f0..4a906ce0918 100644
--- a/tests/layer_tests/pytorch_tests/test_prod.py
+++ b/tests/layer_tests/pytorch_tests/test_prod.py
@@ -10,7 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class aten_prod(torch.nn.Module):
def __init__(self, in_dtype):
- super(aten_prod, self).__init__()
+ super().__init__()
self.in_dtype = in_dtype
def forward(self, x):
@@ -19,7 +19,7 @@ class aten_prod(torch.nn.Module):
class aten_prod_dtype(torch.nn.Module):
def __init__(self, dtype, in_dtype):
- super(aten_prod_dtype, self).__init__()
+ super().__init__()
self.dtype = dtype
self.in_dtype = in_dtype
@@ -29,7 +29,7 @@ class aten_prod_dtype(torch.nn.Module):
class aten_prod_dim(torch.nn.Module):
def __init__(self, dim, keepdims, in_dtype):
- super(aten_prod_dim, self).__init__()
+ super().__init__()
self.dim = dim
self.keepdims = keepdims
self.in_dtype = in_dtype
@@ -40,7 +40,7 @@ class aten_prod_dim(torch.nn.Module):
class aten_prod_dim_dtype(torch.nn.Module):
def __init__(self, dim, keepdims, dtype, in_dtype):
- super(aten_prod_dim_dtype, self).__init__()
+ super().__init__()
self.dim = dim
self.keepdims = keepdims
self.dtype = dtype
@@ -52,7 +52,7 @@ class aten_prod_dim_dtype(torch.nn.Module):
class TestProd(PytorchLayerTest):
def _prepare_input(self, input_shape=(2), dtype=torch.float32):
- return (torch.randn(*input_shape).to(dtype).numpy(),)
+ return (self.random.randn(*input_shape, dtype=dtype),)
@pytest.mark.parametrize("shape", [(1,),
(2,),
@@ -83,5 +83,5 @@ class TestProd(PytorchLayerTest):
in_dtype)
else:
m = aten_prod(in_dtype)
- self._test(m, None, 'aten::prod', ie_device, precision, ir_version,
+ self._test(m, 'aten::prod', ie_device, precision, ir_version,
kwargs_to_prepare_input={'input_shape': shape, 'dtype': in_dtype})
diff --git a/tests/layer_tests/pytorch_tests/test_pythonop.py b/tests/layer_tests/pytorch_tests/test_pythonop.py
index 652dd5b638d..c70086a9206 100644
--- a/tests/layer_tests/pytorch_tests/test_pythonop.py
+++ b/tests/layer_tests/pytorch_tests/test_pythonop.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
from pytorch_layer_test_class import PytorchLayerTest
@@ -9,7 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestPythonOp(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(1, 3, 128, 128),)
+ return (self.random.randn(1, 3, 128, 128),)
def create_model(self):
import torch
@@ -28,9 +27,8 @@ class TestPythonOp(PytorchLayerTest):
def forward(self, input_tensor):
return exp_f(input_tensor)
- ref_net = None
- return prim_pythonop(), ref_net, "prim::PythonOp"
+ return prim_pythonop(), "prim::PythonOp"
@pytest.mark.parametrize(
("use_trace"),
diff --git a/tests/layer_tests/pytorch_tests/test_quantize.py b/tests/layer_tests/pytorch_tests/test_quantize.py
index 1602440e2ce..1d74c4ffeeb 100644
--- a/tests/layer_tests/pytorch_tests/test_quantize.py
+++ b/tests/layer_tests/pytorch_tests/test_quantize.py
@@ -73,10 +73,9 @@ class quantized_decomposed_quantize_per_channel_aten_dequantize(torch.nn.Module)
class TestQuantizePerTensorDequantize(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (5.00 * self.rng.random([100, 100], dtype=np.float32) + 5.00,)
+ return (5.00 * self.random.rand(100, 100) + 5.00,)
@pytest.mark.parametrize("scale", [
1.0, 0.21, 0.62
@@ -96,15 +95,14 @@ class TestQuantizePerTensorDequantize(PytorchLayerTest):
reason='Ticket - 122715')
def test_quantize_per_tensor_dequantize(self, scale, zero_point, dtype, ie_device, precision, ir_version):
if dtype == torch.quint8: zero_point = abs(zero_point)
- self._test(aten_quantize_per_tensor_aten_dequantize(scale, zero_point, dtype), None, ["aten::quantize_per_tensor", "aten::dequantize"],
+ self._test(aten_quantize_per_tensor_aten_dequantize(scale, zero_point, dtype), ["aten::quantize_per_tensor", "aten::dequantize"],
ie_device, precision, ir_version, quantized_ops=True, quant_size=scale)
class TestDecomposedQuantizePerTensorDequantize(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (5.00 * self.rng.random([100, 100], dtype=np.float32) + 5.00,)
+ return (5.00 * self.random.rand(100, 100) + 5.00,)
@pytest.mark.parametrize("scale", [
1.0, 0.21, 0.62
@@ -127,15 +125,14 @@ class TestDecomposedQuantizePerTensorDequantize(PytorchLayerTest):
quant_min = 0
quant_max = 255
self._test(quantized_decomposed_quantize_per_tensor_aten_dequantize(scale,
- zero_point, quant_min, quant_max, dtype), None, ["aten::quantize_per_tensor", "aten::dequantize"],
+ zero_point, quant_min, quant_max, dtype), ["aten::quantize_per_tensor", "aten::dequantize"],
ie_device, precision, ir_version, quantized_ops=True, quant_size=scale, **kwargs)
class TestQuantizePerChannelDequantize(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (5.00 * self.rng.random([5, 6, 7, 8], dtype=np.float32) + 5.00,)
+ return (5.00 * self.random.rand(5, 6, 7, 8) + 5.00,)
@pytest.mark.parametrize("scale, zero_point, axis", [
[
@@ -170,18 +167,17 @@ class TestQuantizePerChannelDequantize(PytorchLayerTest):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
def test_quantize_per_channel_dequantize(self, scale, zero_point, dtype, axis, ie_device, precision, ir_version):
- self.rng.shuffle(scale)
- self.rng.shuffle(zero_point)
+ self.random.shuffle(scale)
+ self.random.shuffle(zero_point)
if dtype == torch.quint8: zero_point = abs(zero_point)
- self._test(aten_quantize_per_channel_aten_dequantize(scale, zero_point, dtype, axis), None, ["aten::quantize_per_channel", "aten::dequantize"],
+ self._test(aten_quantize_per_channel_aten_dequantize(scale, zero_point, dtype, axis), ["aten::quantize_per_channel", "aten::dequantize"],
ie_device, precision, ir_version, quantized_ops=True, quant_size=scale)
class TestDecomposedQuantizePerChannelDequantize(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (5.00 * self.rng.random([5, 6, 7, 8], dtype=np.float32) + 5.00,)
+ return (5.00 * self.random.rand(5, 6, 7, 8) + 5.00,)
@pytest.mark.parametrize("scale, zero_point, axis", [
[
@@ -213,8 +209,8 @@ class TestDecomposedQuantizePerChannelDequantize(PytorchLayerTest):
def test_decomposed_quantize_per_channel_dequantize(self, scale, zero_point, dtype, axis, ie_device, precision, ir_version):
kwargs = {}
kwargs["custom_eps"] = 0.15
- self.rng.shuffle(scale)
- self.rng.shuffle(zero_point)
+ self.random.shuffle(scale)
+ self.random.shuffle(zero_point)
quant_min = -128
quant_max = 127
if dtype == torch.uint8:
@@ -222,5 +218,5 @@ class TestDecomposedQuantizePerChannelDequantize(PytorchLayerTest):
quant_min = 0
quant_max = 255
self._test(quantized_decomposed_quantize_per_channel_aten_dequantize(scale,
- zero_point, quant_min, quant_max, dtype, axis), None, ["aten::quantize_per_tensor", "aten::dequantize"],
+ zero_point, quant_min, quant_max, dtype, axis), ["aten::quantize_per_tensor", "aten::dequantize"],
ie_device, precision, ir_version, quantized_ops=True, quant_size=scale, **kwargs)
diff --git a/tests/layer_tests/pytorch_tests/test_quantized_add.py b/tests/layer_tests/pytorch_tests/test_quantized_add.py
index e7f35750fc5..5be016ea4e3 100644
--- a/tests/layer_tests/pytorch_tests/test_quantized_add.py
+++ b/tests/layer_tests/pytorch_tests/test_quantized_add.py
@@ -26,11 +26,10 @@ class quantized_add(torch.nn.Module):
class TestQuantizedAdd(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (np.round(5.00 * self.rng.random([10, 10], dtype=np.float32) - 2.50, 4),
- np.round(5.00 * self.rng.random([10, 10], dtype=np.float32) - 2.50, 4))
+ return (np.round(5.00 * self.random.rand(10, 10) - 2.50, 4),
+ np.round(5.00 * self.random.rand(10, 10) - 2.50, 4))
@pytest.mark.parametrize("scale", [
1.0, 0.21, 0.62, 0.9999
@@ -49,5 +48,5 @@ class TestQuantizedAdd(PytorchLayerTest):
def test_quantized_add(self, scale, zero_point, dtype, ie_device, precision, ir_version):
if dtype == torch.quint8:
zero_point = abs(zero_point)
- self._test(quantized_add(scale, zero_point, dtype), None, ["quantized::add"],
+ self._test(quantized_add(scale, zero_point, dtype), ["quantized::add"],
ie_device, precision, ir_version, quantized_ops=True, quant_size=scale)
diff --git a/tests/layer_tests/pytorch_tests/test_quantized_add_relu.py b/tests/layer_tests/pytorch_tests/test_quantized_add_relu.py
index 3ff9f0b6d66..5b1f2162bc8 100644
--- a/tests/layer_tests/pytorch_tests/test_quantized_add_relu.py
+++ b/tests/layer_tests/pytorch_tests/test_quantized_add_relu.py
@@ -26,11 +26,10 @@ class quantized_add_relu(torch.nn.Module):
class TestQuantizedAddReLU(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (np.round(5.00 * self.rng.random([10, 10], dtype=np.float32) - 2.50, 4),
- np.round(5.00 * self.rng.random([10, 10], dtype=np.float32) - 2.50, 4))
+ return (np.round(5.00 * self.random.rand(10, 10) - 2.50, 4),
+ np.round(5.00 * self.random.rand(10, 10) - 2.50, 4))
@pytest.mark.parametrize("scale", [
1.0, 0.21, 0.62, 0.9999
@@ -49,5 +48,5 @@ class TestQuantizedAddReLU(PytorchLayerTest):
def test_quantized_add_relu(self, scale, zero_point, dtype, ie_device, precision, ir_version):
if dtype == torch.quint8:
zero_point = abs(zero_point)
- self._test(quantized_add_relu(scale, zero_point, dtype), None, ["quantized::add_relu"],
+ self._test(quantized_add_relu(scale, zero_point, dtype), ["quantized::add_relu"],
ie_device, precision, ir_version, quantized_ops=True, quant_size=scale)
diff --git a/tests/layer_tests/pytorch_tests/test_quantized_cat.py b/tests/layer_tests/pytorch_tests/test_quantized_cat.py
index c97cb2f7b78..beaa61f7b6f 100644
--- a/tests/layer_tests/pytorch_tests/test_quantized_cat.py
+++ b/tests/layer_tests/pytorch_tests/test_quantized_cat.py
@@ -67,10 +67,9 @@ class aten_add_quantized_cat(torch.nn.Module):
class TestQuantizedCat(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (np.round(self.rng.random([2, 1, 3], dtype=np.float32), 4),)
+ return (np.round(self.random.rand(2, 1, 3), 4),)
@pytest.mark.parametrize("scale", [1.0, 0.3, 1.3])
@pytest.mark.parametrize("zero_point", [0, 1])
@@ -82,7 +81,6 @@ class TestQuantizedCat(PytorchLayerTest):
def test_quantized_cat(self, scale, zero_point, dtype, ie_device, precision, ir_version):
self._test(
aten_quantized_cat(scale, zero_point, dtype),
- None,
["quantized::cat", "prim::ListConstruct"],
ie_device,
precision,
@@ -102,7 +100,6 @@ class TestQuantizedCat(PytorchLayerTest):
def test_append_quantized_cat(self, scale, zero_point, dtype, ie_device, precision, ir_version):
self._test(
aten_append_quantized_cat(scale, zero_point, dtype),
- None,
["quantized::cat", "aten::append", "prim::ListConstruct"],
ie_device,
precision,
@@ -123,7 +120,6 @@ class TestQuantizedCat(PytorchLayerTest):
def test_loop_append_quantized_cat(self, scale, zero_point, dtype, ie_device, precision, ir_version):
self._test(
aten_loop_append_quantized_cat(scale, zero_point, dtype),
- None,
["quantized::cat", "aten::append", "prim::ListConstruct", "prim::Loop"],
ie_device,
precision,
@@ -143,7 +139,6 @@ class TestQuantizedCat(PytorchLayerTest):
def test_add_quantized_cat(self, scale, zero_point, dtype, ie_device, precision, ir_version):
self._test(
aten_add_quantized_cat(scale, zero_point, dtype),
- None,
["quantized::cat", "aten::add", "prim::ListConstruct"],
ie_device,
precision,
diff --git a/tests/layer_tests/pytorch_tests/test_quantized_convnd.py b/tests/layer_tests/pytorch_tests/test_quantized_convnd.py
index 84cae45da73..802283f1842 100644
--- a/tests/layer_tests/pytorch_tests/test_quantized_convnd.py
+++ b/tests/layer_tests/pytorch_tests/test_quantized_convnd.py
@@ -7,21 +7,18 @@ import pytest
import numpy as np
import torch
-from openvino.frontend import FrontEndManager
-from openvino.frontend.pytorch.ts_decoder import TorchScriptPythonDecoder
from pytorch_layer_test_class import PytorchLayerTest
class TestQuantizedConv2D(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (np.round(self.rng.random([2, 3, 25, 25], dtype=np.float32), 4),)
+ return (np.round(self.random.rand(2, 3, 25, 25), 4),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias, relu, scale, zero_point):
class quantized_conv2d(torch.nn.Module):
def __init__(self):
- super(quantized_conv2d, self).__init__()
+ super().__init__()
if not relu:
conv_func = torch.ao.nn.quantized.Conv2d
else:
@@ -47,13 +44,12 @@ class TestQuantizedConv2D(PytorchLayerTest):
conv = self.conv(x_quantized)
return torch.dequantize(conv)
- ref_net = None
if not relu:
op_name = "quantized::conv2d"
else:
op_name = "quantized::conv2d_relu"
- return quantized_conv2d(), ref_net, op_name
+ return quantized_conv2d(), op_name
@pytest.mark.parametrize(
"params",
diff --git a/tests/layer_tests/pytorch_tests/test_quantized_hardswish.py b/tests/layer_tests/pytorch_tests/test_quantized_hardswish.py
index bbddd9002dc..6a552ad3a12 100644
--- a/tests/layer_tests/pytorch_tests/test_quantized_hardswish.py
+++ b/tests/layer_tests/pytorch_tests/test_quantized_hardswish.py
@@ -25,10 +25,9 @@ class quantized_hardswish(torch.nn.Module):
class TestQuantizedHardswish(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (np.round(5.00 * self.rng.random([10, 10], dtype=np.float32) - 2.50, 4),)
+ return (np.round(5.00 * self.random.rand(10, 10) - 2.50, 4),)
@pytest.mark.parametrize("scale", [
1.0, 0.21, 0.62, 0.9999
@@ -47,5 +46,5 @@ class TestQuantizedHardswish(PytorchLayerTest):
def test_quantized_hardswish(self, scale, zero_point, dtype, ie_device, precision, ir_version):
if dtype == torch.quint8:
zero_point = abs(zero_point)
- self._test(quantized_hardswish(scale, zero_point, dtype), None, ["quantized::hardswish"],
+ self._test(quantized_hardswish(scale, zero_point, dtype), ["quantized::hardswish"],
ie_device, precision, ir_version, quantized_ops=True, quant_size=scale)
diff --git a/tests/layer_tests/pytorch_tests/test_quantized_linear.py b/tests/layer_tests/pytorch_tests/test_quantized_linear.py
index 88e215c1835..ac04f840a7a 100644
--- a/tests/layer_tests/pytorch_tests/test_quantized_linear.py
+++ b/tests/layer_tests/pytorch_tests/test_quantized_linear.py
@@ -10,16 +10,15 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestQuantizedLinear(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self, input_shape=(2, 2)):
- return (np.round(self.rng.random(input_shape, dtype=np.float32), 4),)
+ return (np.round(self.random.rand(*input_shape), 4),)
def create_model(self, weight_shape, is_bias, scale, zero_point):
class aten_quantized_linear(torch.nn.Module):
def __init__(self, weight_shape, is_bias, scale, zero_point):
- super(aten_quantized_linear, self).__init__()
+ super().__init__()
if is_bias:
self.linear = torch.ao.nn.quantized.Linear(
weight_shape[-1], weight_shape[0], True)
@@ -34,15 +33,14 @@ class TestQuantizedLinear(PytorchLayerTest):
inp_q = torch.quantize_per_tensor(inp, 1.0, 0, torch.quint8)
return torch.dequantize(self.linear(inp_q))
- ref_net = None
- return aten_quantized_linear(weight_shape, is_bias, scale, zero_point), ref_net, "quantized::linear"
+ return aten_quantized_linear(weight_shape, is_bias, scale, zero_point), "quantized::linear"
def create_hardtanh_model(self, weight_shape, is_bias, scale, zero_point, inplace):
class aten_quantized_linear(torch.nn.Module):
def __init__(self, weight_shape, is_bias, scale, zero_point, inplace):
- super(aten_quantized_linear, self).__init__()
+ super().__init__()
self.hardtanh = torch.nn.Hardtanh(inplace=inplace)
if is_bias:
self.linear = torch.ao.nn.quantized.Linear(
@@ -59,7 +57,7 @@ class TestQuantizedLinear(PytorchLayerTest):
inp_q = self.hardtanh(inp_q)
return torch.dequantize(self.linear(inp_q))
- return aten_quantized_linear(weight_shape, is_bias, scale, zero_point, inplace), None, ["quantized::linear", "aten::hardtanh_" if inplace else "aten::hardtanh"]
+ return aten_quantized_linear(weight_shape, is_bias, scale, zero_point, inplace), ["quantized::linear", "aten::hardtanh_" if inplace else "aten::hardtanh"]
@pytest.mark.parametrize("params", [
{'input_shape': [3, 9], 'weight_shape': [10, 9]},
diff --git a/tests/layer_tests/pytorch_tests/test_quantized_mul.py b/tests/layer_tests/pytorch_tests/test_quantized_mul.py
index fd0b8c7ece3..3d315ae698d 100644
--- a/tests/layer_tests/pytorch_tests/test_quantized_mul.py
+++ b/tests/layer_tests/pytorch_tests/test_quantized_mul.py
@@ -26,11 +26,10 @@ class quantized_mul(torch.nn.Module):
class TestQuantizedMul(PytorchLayerTest):
- rng = np.random.default_rng(seed=123)
def _prepare_input(self):
- return (np.round(5.00 * self.rng.random([10, 10], dtype=np.float32) - 2.50, 4),
- np.round(5.00 * self.rng.random([10, 10], dtype=np.float32) - 2.50, 4))
+ return (np.round(5.00 * self.random.rand(10, 10) - 2.50, 4),
+ np.round(5.00 * self.random.rand(10, 10) - 2.50, 4))
@pytest.mark.parametrize("scale", [
1.0, 0.21, 0.62, 0.9999
@@ -49,5 +48,5 @@ class TestQuantizedMul(PytorchLayerTest):
def test_quantized_mul(self, scale, zero_point, dtype, ie_device, precision, ir_version):
if dtype == torch.quint8:
zero_point = abs(zero_point)
- self._test(quantized_mul(scale, zero_point, dtype), None, ["quantized::mul"],
+ self._test(quantized_mul(scale, zero_point, dtype), ["quantized::mul"],
ie_device, precision, ir_version, quantized_ops=True, quant_size=scale)
diff --git a/tests/layer_tests/pytorch_tests/test_rad2deg.py b/tests/layer_tests/pytorch_tests/test_rad2deg.py
index 10f1e53ea3d..57585541f77 100644
--- a/tests/layer_tests/pytorch_tests/test_rad2deg.py
+++ b/tests/layer_tests/pytorch_tests/test_rad2deg.py
@@ -9,14 +9,13 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestRad2Deg(PytorchLayerTest):
def _prepare_input(self, input_shape=(2, 2), dtype=np.float32):
- return (np.random.uniform(-np.pi, np.pi, size=input_shape).astype(dtype),)
+ return (self.random.uniform(-np.pi, np.pi, size=input_shape, dtype=dtype),)
def create_model(self):
class aten_rad2deg(torch.nn.Module):
def forward(self, x):
return torch.rad2deg(x)
- ref_net = None
- return aten_rad2deg(), ref_net, "aten::rad2deg"
+ return aten_rad2deg(), "aten::rad2deg"
@pytest.mark.parametrize("input_shape", [(3, 3)])
@pytest.mark.parametrize("dtype", [np.float32, np.float64, np.int32])
diff --git a/tests/layer_tests/pytorch_tests/test_rand.py b/tests/layer_tests/pytorch_tests/test_rand.py
index 174bade4687..a98ddf33db9 100644
--- a/tests/layer_tests/pytorch_tests/test_rand.py
+++ b/tests/layer_tests/pytorch_tests/test_rand.py
@@ -10,12 +10,12 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestInplaceNormal(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, mean, std):
class aten_normal(torch.nn.Module):
def __init__(self, mean, std):
- super(aten_normal, self).__init__()
+ super().__init__()
self.mean = mean
self.std = std
@@ -23,7 +23,7 @@ class TestInplaceNormal(PytorchLayerTest):
x = x.to(torch.float32)
return x.normal_(mean=self.mean, std=self.std), x
- return aten_normal(mean, std), None, "aten::normal_"
+ return aten_normal(mean, std), "aten::normal_"
@pytest.mark.parametrize("mean,std", [(0., 1.), (5., 20.)])
@pytest.mark.nightly
@@ -37,7 +37,7 @@ class TestNormal(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
if isinstance(self.inputs, list):
- return (np.random.randn(*self.inputs).astype(np.float32),)
+ return (self.random.randn(*self.inputs),)
return self.inputs
class aten_normal1(torch.nn.Module):
@@ -86,7 +86,7 @@ class TestNormal(PytorchLayerTest):
])
def test_inplace_normal(self, model, inputs, ie_device, precision, ir_version):
self.inputs = inputs
- self._test(model, None, "aten::normal",
+ self._test(model, "aten::normal",
ie_device, precision, ir_version, custom_eps=1e30)
diff --git a/tests/layer_tests/pytorch_tests/test_randperm.py b/tests/layer_tests/pytorch_tests/test_randperm.py
index 7f22bd6c9ce..7a4e350af12 100644
--- a/tests/layer_tests/pytorch_tests/test_randperm.py
+++ b/tests/layer_tests/pytorch_tests/test_randperm.py
@@ -33,7 +33,7 @@ class TestSortedRandperm(PytorchLayerTest):
sorted_tensor, _ = torch.sort(x_permuted)
return sorted_tensor
- return AtenSortedRandperm(n, num_inputs, dtype_value), None, "aten::randperm"
+ return AtenSortedRandperm(n, num_inputs, dtype_value), "aten::randperm"
@pytest.mark.parametrize(("n", "num_inputs", "dtype_value"), [
(0, 1, None),
diff --git a/tests/layer_tests/pytorch_tests/test_reflection_pad.py b/tests/layer_tests/pytorch_tests/test_reflection_pad.py
index 5053c279006..8ce5e5d1c43 100644
--- a/tests/layer_tests/pytorch_tests/test_reflection_pad.py
+++ b/tests/layer_tests/pytorch_tests/test_reflection_pad.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestReflectionPad(PytorchLayerTest):
def _prepare_input(self, n):
- import numpy as np
- return (np.random.randn(*(2, 5, 6, 7, 8)[:n+2]).astype(np.float32),)
+ return (self.random.randn(*(2, 5, 6, 7, 8)[:n+2]),)
def create_model(self, pad, n):
@@ -31,7 +30,7 @@ class TestReflectionPad(PytorchLayerTest):
model = aten_reflection_pad(pad)
model.forward = model.__getattribute__(f"forward_{n}d")
- return model, None, f"aten::reflection_pad{n}d"
+ return model, f"aten::reflection_pad{n}d"
@pytest.mark.parametrize(("pad", "n"), [
((1, 1), 1),
diff --git a/tests/layer_tests/pytorch_tests/test_remainder.py b/tests/layer_tests/pytorch_tests/test_remainder.py
index 98a5af94030..a97518ab78e 100644
--- a/tests/layer_tests/pytorch_tests/test_remainder.py
+++ b/tests/layer_tests/pytorch_tests/test_remainder.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest
@@ -17,33 +16,32 @@ from pytorch_layer_test_class import PytorchLayerTest
)
class TestRemainder(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 5, 3, 4).astype(np.float32), self.input_rhs)
+ return (self.random.randn(2, 5, 3, 4), self.input_rhs)
def create_model(self):
class aten_remainder(torch.nn.Module):
def forward(self, lhs, rhs):
return torch.remainder(lhs, rhs)
- ref_net = None
- return aten_remainder(), ref_net, "aten::remainder"
+ return aten_remainder(), "aten::remainder"
@pytest.mark.nightly
@pytest.mark.precommit
def test_remainder(self, ie_device, precision, ir_version, input_shape_rhs):
- self.input_rhs = np.random.randn(*input_shape_rhs).astype(np.float32)
+ self.input_rhs = self.random.randn(*input_shape_rhs)
self._test(*self.create_model(), ie_device, precision, ir_version, use_convert_model=True)
class TestRemainderTypes(PytorchLayerTest):
def _prepare_input(self):
if len(self.lhs_shape) == 0:
- return (torch.randint(2, 5, self.rhs_shape).to(self.rhs_type).numpy(),)
+ return (self.random.randint(2, 5, size=self.rhs_shape, dtype=self.rhs_type),)
elif len(self.rhs_shape) == 0:
- return (10 * torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),)
+ return (10 * self.random.randn(*self.lhs_shape, dtype=self.lhs_type),)
return (
- 10 * torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),
- torch.randint(2, 5, self.rhs_shape).to(self.rhs_type).numpy(),
+ 10 * self.random.randn(*self.lhs_shape, dtype=self.lhs_type),
+ self.random.randint(2, 5, size=self.rhs_shape, dtype=self.rhs_type),
)
def create_model(self, lhs_type, lhs_shape, rhs_type, rhs_shape):
@@ -68,9 +66,8 @@ class TestRemainderTypes(PytorchLayerTest):
def forward3(self, lhs, rhs):
return torch.remainder(lhs.to(self.lhs_type), rhs.to(self.rhs_type))
- ref_net = None
- return aten_remainder(lhs_type, lhs_shape, rhs_type, rhs_shape), ref_net, "aten::remainder"
+ return aten_remainder(lhs_type, lhs_shape, rhs_type, rhs_shape), "aten::remainder"
@pytest.mark.parametrize(
("lhs_type", "rhs_type"),
diff --git a/tests/layer_tests/pytorch_tests/test_repeat.py b/tests/layer_tests/pytorch_tests/test_repeat.py
index 1e4529eb50f..730ea1aa348 100644
--- a/tests/layer_tests/pytorch_tests/test_repeat.py
+++ b/tests/layer_tests/pytorch_tests/test_repeat.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestRepeat(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 10).astype(np.float32),)
+ return (self.random.randn(2, 10),)
def create_model(self, repeats):
import torch
@@ -22,9 +21,8 @@ class TestRepeat(PytorchLayerTest):
def forward(self, x):
return x.repeat(self.repeats)
- ref_net = None
- return aten_repeat(repeats), ref_net, "aten::repeat"
+ return aten_repeat(repeats), "aten::repeat"
@pytest.mark.parametrize("repeats", [(4, 3), (1, 1), (1, 2, 3), (1, 2, 2, 3)])
@pytest.mark.nightly
@@ -37,8 +35,7 @@ class TestRepeat(PytorchLayerTest):
class TestRepeatList(PytorchLayerTest):
def _prepare_input(self, repeats_shape):
- import numpy as np
- return (np.random.randn(2, 10).astype(np.float32), np.random.randn(*repeats_shape).astype(np.float32),)
+ return (self.random.randn(2, 10), self.random.randn(*repeats_shape),)
def create_model(self):
import torch
@@ -49,9 +46,8 @@ class TestRepeatList(PytorchLayerTest):
y_shape = y.shape
return x.repeat([y_shape[0], y_shape[1]])
- ref_net = None
- return aten_repeat(), ref_net, ["aten::repeat", "prim::ListConstruct"]
+ return aten_repeat(), ["aten::repeat", "prim::ListConstruct"]
@pytest.mark.parametrize("repeats", [(4, 3), (1, 1), (1, 3, 3), (1, 2, 2, 3)])
@pytest.mark.nightly
@@ -65,8 +61,7 @@ class TestRepeatList(PytorchLayerTest):
class TestRepeatFromFlanT5(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 15).astype(np.float32),)
+ return (self.random.randn(1, 15),)
def create_model(self):
import torch
@@ -76,7 +71,7 @@ class TestRepeatFromFlanT5(PytorchLayerTest):
def forward(self, x):
return ModuleUtilsMixin.create_extended_attention_mask_for_decoder(x.size(), x)
- return aten_repeat(), None, "aten::repeat"
+ return aten_repeat(), "aten::repeat"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_repeat_interleave.py b/tests/layer_tests/pytorch_tests/test_repeat_interleave.py
index 173aa039a58..2acc76f4f7e 100644
--- a/tests/layer_tests/pytorch_tests/test_repeat_interleave.py
+++ b/tests/layer_tests/pytorch_tests/test_repeat_interleave.py
@@ -17,7 +17,7 @@ import torch
class TestRepeatInterleaveConstRepeats(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 2, 3, 3),)
+ return (self.random.randn(2, 2, 3, 3),)
def create_model_const_repeat(self, repeats, dim):
class aten_repeat_interleave_const_repeat(torch.nn.Module):
@@ -30,9 +30,8 @@ class TestRepeatInterleaveConstRepeats(PytorchLayerTest):
def forward(self, input_tensor):
return input_tensor.repeat_interleave(self.repeats, self.dim)
- ref_net = None
- return aten_repeat_interleave_const_repeat(), ref_net, "aten::repeat_interleave"
+ return aten_repeat_interleave_const_repeat(), "aten::repeat_interleave"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -53,7 +52,7 @@ class TestRepeatInterleaveConstRepeats(PytorchLayerTest):
class TestRepeatInterleaveNonConstRepeats(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 2, 3, 3), self.repeats)
+ return (self.random.randn(2, 2, 3, 3), self.repeats)
def create_model_non_const_repeat(self, dim):
class aten_repeat_interleave_non_const_repeat(torch.nn.Module):
@@ -65,9 +64,8 @@ class TestRepeatInterleaveNonConstRepeats(PytorchLayerTest):
def forward(self, input_tensor, repeats):
return input_tensor.repeat_interleave(repeats, self.dim)
- ref_net = None
- return aten_repeat_interleave_non_const_repeat(), ref_net, "aten::repeat_interleave"
+ return aten_repeat_interleave_non_const_repeat(), "aten::repeat_interleave"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -80,7 +78,7 @@ class TestRepeatInterleaveNonConstRepeats(PytorchLayerTest):
class TestRepeatInterleaveTensorRepeats(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(10), self.repeats)
+ return (self.random.randn(10), self.repeats)
def create_model_non_const_repeat(self, dim):
class aten_repeat_interleave_non_const_repeat(torch.nn.Module):
@@ -92,7 +90,7 @@ class TestRepeatInterleaveTensorRepeats(PytorchLayerTest):
def forward(self, input_tensor, repeats):
return input_tensor.repeat_interleave(repeats, self.dim)
- return aten_repeat_interleave_non_const_repeat(), None, "aten::repeat_interleave"
+ return aten_repeat_interleave_non_const_repeat(), "aten::repeat_interleave"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -120,7 +118,7 @@ class TestRepeatInterleaveWithOutputSize(PytorchLayerTest):
def forward(self, input_tensor):
return input_tensor.repeat_interleave(self.repeats, self.dim, output_size=self.output_size)
- return aten_repeat_interleave_output_size(dim, repeats, output_size), None, "aten::repeat_interleave"
+ return aten_repeat_interleave_output_size(dim, repeats, output_size), "aten::repeat_interleave"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_replication_pad.py b/tests/layer_tests/pytorch_tests/test_replication_pad.py
index 2a686c3e8be..fb805df433f 100644
--- a/tests/layer_tests/pytorch_tests/test_replication_pad.py
+++ b/tests/layer_tests/pytorch_tests/test_replication_pad.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestReplicationPad(PytorchLayerTest):
def _prepare_input(self, n):
- import numpy as np
- return (np.random.randn(*(2, 5, 6, 7, 8)[:n+2]).astype(np.float32),)
+ return (self.random.randn(*(2, 5, 6, 7, 8)[:n+2]),)
def create_model(self, pad, n):
@@ -31,7 +30,7 @@ class TestReplicationPad(PytorchLayerTest):
model = aten_replication_pad(pad)
model.forward = model.__getattribute__(f"forward_{n}d")
- return model, None, f"aten::replication_pad{n}d"
+ return model, f"aten::replication_pad{n}d"
@pytest.mark.parametrize(("pad", "n"), [
((1, 1), 1),
diff --git a/tests/layer_tests/pytorch_tests/test_reshape.py b/tests/layer_tests/pytorch_tests/test_reshape.py
index 007322e7509..64f5aac9910 100644
--- a/tests/layer_tests/pytorch_tests/test_reshape.py
+++ b/tests/layer_tests/pytorch_tests/test_reshape.py
@@ -13,7 +13,7 @@ class TestReshape(PytorchLayerTest):
shape = (1, 12, 12, 24)
if complex_type:
shape += (2,)
- return (np.random.uniform(0, 50, shape).astype(np.float32))
+ return (self.random.uniform(0, 50, shape, dtype=np.float32),)
def create_model(self, shape, complex_type):
import torch
@@ -32,7 +32,7 @@ class TestReshape(PytorchLayerTest):
res = torch.view_as_real(res)
return res
- return aten_reshape(shape, complex_type), None, "aten::reshape"
+ return aten_reshape(shape, complex_type), "aten::reshape"
@pytest.mark.parametrize(("shape"), [
[-1, 6],
@@ -58,7 +58,7 @@ class TestReshape(PytorchLayerTest):
class TestDynamicReshape(PytorchLayerTest):
def _prepare_input(self):
last_dym = random.randint(1, 2)
- return (np.random.uniform(0, 50, (1, 12, 12, 24)).astype(np.float32), last_dym)
+ return (self.random.uniform(0, 50, (1, 12, 12, 24), dtype=np.float32), last_dym)
def create_model(self, shape):
import torch
@@ -72,7 +72,7 @@ class TestDynamicReshape(PytorchLayerTest):
dym2 = int(torch.ops.aten.sym_size(x, 3)/dym)
return torch.reshape(x, [12, 12, dym2, dym])
- return aten_reshape(shape), None, "aten::reshape"
+ return aten_reshape(shape), "aten::reshape"
@pytest.mark.parametrize(("shape"), [
[12, 12, 24, 1],
diff --git a/tests/layer_tests/pytorch_tests/test_reshape_as.py b/tests/layer_tests/pytorch_tests/test_reshape_as.py
index dc83bce4db7..0a825de90aa 100644
--- a/tests/layer_tests/pytorch_tests/test_reshape_as.py
+++ b/tests/layer_tests/pytorch_tests/test_reshape_as.py
@@ -26,9 +26,8 @@ class TestReshapeAs(PytorchLayerTest):
def forward_view(self, input_tensor, shape_tensor):
return input_tensor.view_as(shape_tensor)
- ref_net = None
- return aten_reshape_as(op), ref_net, f"aten::{op}"
+ return aten_reshape_as(op), f"aten::{op}"
@pytest.mark.nightly
@pytest.mark.precommit
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 5006e726236..c837eee36fb 100644
--- a/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py
+++ b/tests/layer_tests/pytorch_tests/test_resolve_conj_neg.py
@@ -9,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestResolveConjNeg(PytorchLayerTest):
def _prepare_input(self, dtype="float32"):
import numpy as np
- return (np.random.randn(2, 4).astype(dtype),)
+ return (self.random.randn(2, 4, dtype=dtype),)
def _prepare_input_complex(self):
import numpy as np
@@ -28,15 +28,14 @@ class TestResolveConjNeg(PytorchLayerTest):
class aten_resolve(torch.nn.Module):
def __init__(self, op):
- super(aten_resolve, self).__init__()
+ super().__init__()
self.op = op
def forward(self, x):
return self.op(x)
- ref_net = None
- return aten_resolve(op), ref_net, f"aten::{op_type}"
+ return aten_resolve(op), f"aten::{op_type}"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_roi_align.py b/tests/layer_tests/pytorch_tests/test_roi_align.py
index b5dd80ef6c3..81e0bfe0750 100644
--- a/tests/layer_tests/pytorch_tests/test_roi_align.py
+++ b/tests/layer_tests/pytorch_tests/test_roi_align.py
@@ -34,10 +34,9 @@ class TestROIAlign(PytorchLayerTest):
self.aligned,
)
- ref_net = None
return (torchvision_roi_align(output_size, spatial_scale, sampling_ratio, aligned),
- ref_net, "torchvision::roi_align")
+ "torchvision::roi_align")
@pytest.mark.parametrize('input_shape', [
[4, 5, 6, 7],
@@ -56,7 +55,7 @@ class TestROIAlign(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_roi_align(self, ie_device, precision, ir_version, input_shape, boxes, output_size,
spatial_scale, sampling_ratio, aligned):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self.boxes = boxes
self._test(*self.create_model(output_size, spatial_scale, sampling_ratio, aligned),
ie_device, precision, ir_version, trace_model=True)
diff --git a/tests/layer_tests/pytorch_tests/test_roll.py b/tests/layer_tests/pytorch_tests/test_roll.py
index ce2cd747745..9c539d31a27 100644
--- a/tests/layer_tests/pytorch_tests/test_roll.py
+++ b/tests/layer_tests/pytorch_tests/test_roll.py
@@ -9,14 +9,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestRoll(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.uniform(0, 50, (2, 3, 4)).astype(np.float32),)
+ return (self.random.uniform(0, 50, (2, 3, 4), dtype=np.float32),)
def create_model(self, shifts, dim):
import torch
class aten_roll(torch.nn.Module):
def __init__(self, shifts, dim=None):
- super(aten_roll, self).__init__()
+ super().__init__()
self.dim = dim
self.shifts = shifts
@@ -25,9 +25,8 @@ class TestRoll(PytorchLayerTest):
return torch.roll(x, self.shifts, self.dim)
return torch.roll(x, self.shifts)
- ref_net = None
- return aten_roll(shifts, dim), ref_net, "aten::roll"
+ return aten_roll(shifts, dim), "aten::roll"
@pytest.mark.parametrize(("shifts", "dim"), [
[(2, 1), (0, 1)],
diff --git a/tests/layer_tests/pytorch_tests/test_rope_pattern.py b/tests/layer_tests/pytorch_tests/test_rope_pattern.py
index 1725b0e68ea..95b33960a40 100644
--- a/tests/layer_tests/pytorch_tests/test_rope_pattern.py
+++ b/tests/layer_tests/pytorch_tests/test_rope_pattern.py
@@ -4,7 +4,6 @@
"""Test Rotary Position Embedding (RoPE) pattern with complex tensors.
"""
-import numpy as np
import pytest
import torch
@@ -18,16 +17,14 @@ class TestRoPEPattern(PytorchLayerTest):
"""
def _prepare_input(self, seq_len=8, dim=64):
- rng = np.random.default_rng(43)
- return (rng.standard_normal((1, seq_len, dim)).astype(np.float32),)
+ return (self.random.randn(1, seq_len, dim),)
def create_model(self, dim=64):
class RoPEModule(torch.nn.Module):
- def __init__(self, dim):
+ def __init__(self, rng, dim):
super().__init__()
# Create freqs_cis as complex buffer (like in Qwen-Image)
- g = torch.Generator().manual_seed(42)
- freqs = torch.randn(8, dim // 2, generator=g)
+ freqs = rng.torch_randn(8, dim // 2)
self.register_buffer("freqs_cis",
torch.polar(torch.ones_like(freqs), freqs))
@@ -40,7 +37,7 @@ class TestRoPEPattern(PytorchLayerTest):
result = x_reshaped * freqs_real
return result.view(batch, seq_len, dim)
- return RoPEModule(dim), None, ["aten::unsqueeze", "aten::view_as_real"]
+ return RoPEModule(self.random, dim), ["aten::unsqueeze", "aten::view_as_real"]
@pytest.mark.parametrize("dim", [32, 64, 128])
@pytest.mark.nightly
@@ -62,16 +59,14 @@ class TestComplexBufferUnsqueeze(PytorchLayerTest):
"""
def _prepare_input(self):
- rng = np.random.default_rng(43)
- return (rng.standard_normal((1, 4, 8)).astype(np.float32),)
+ return (self.random.randn(1, 4, 8),)
def create_model(self):
class ComplexBufferUnsqueeze(torch.nn.Module):
- def __init__(self):
+ def __init__(self, rng):
super().__init__()
- g = torch.Generator().manual_seed(42)
- real = torch.randn(4, 8, generator=g)
- imag = torch.randn(4, 8, generator=g)
+ real = rng.torch_randn(4, 8)
+ imag = rng.torch_randn(4, 8)
self.register_buffer("pos_embed", torch.complex(real, imag))
def forward(self, x):
@@ -80,7 +75,7 @@ class TestComplexBufferUnsqueeze(PytorchLayerTest):
pos_real = torch.view_as_real(pos)
return x.unsqueeze(-1) + pos_real
- return ComplexBufferUnsqueeze(), None, "aten::unsqueeze"
+ return ComplexBufferUnsqueeze(self.random), "aten::unsqueeze"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -96,15 +91,13 @@ class TestComplexBufferMultipleOps(PytorchLayerTest):
"""
def _prepare_input(self):
- rng = np.random.default_rng(43)
- return (rng.standard_normal((1, 4, 2)).astype(np.float32),)
+ return (self.random.randn(1, 4, 2),)
def create_model(self):
class ComplexBufferMultipleOps(torch.nn.Module):
- def __init__(self):
+ def __init__(self, rng):
super().__init__()
- g = torch.Generator().manual_seed(42)
- freqs = torch.randn(4, 2, generator=g)
+ freqs = rng.torch_randn(4, 2)
complex_freqs = torch.view_as_complex(freqs)
self.register_buffer("freqs_a", complex_freqs)
self.register_buffer("freqs_b", complex_freqs * 2)
@@ -117,7 +110,7 @@ class TestComplexBufferMultipleOps(PytorchLayerTest):
result = cx * a + cx * b
return torch.view_as_real(result)
- return ComplexBufferMultipleOps(), None, ["aten::unsqueeze", "aten::mul"]
+ return ComplexBufferMultipleOps(self.random), ["aten::unsqueeze", "aten::mul"]
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_round.py b/tests/layer_tests/pytorch_tests/test_round.py
index 9d521e9eb16..e18fec42123 100644
--- a/tests/layer_tests/pytorch_tests/test_round.py
+++ b/tests/layer_tests/pytorch_tests/test_round.py
@@ -9,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestRound(PytorchLayerTest):
def _prepare_input(self, out=False, dtype="float32"):
import numpy as np
- input = np.random.randn(1, 3, 224, 224).astype(dtype)
+ input = self.random.randn(1, 3, 224, 224, dtype=dtype)
if dtype == "float64":
# fp64 can fail by accuracy, because pytorch rounds fp64 value and ov will round fp32 value.
# To remove sporadic accuracy fails we will round the number to 6 decimal places.
@@ -23,7 +23,7 @@ class TestRound(PytorchLayerTest):
class aten_round(torch.nn.Module):
def __init__(self, out):
- super(aten_round, self).__init__()
+ super().__init__()
if out:
self.forward = self.forward_out
@@ -34,9 +34,8 @@ class TestRound(PytorchLayerTest):
def forward_out(self, x, y):
return torch.round(x, out=y), y
- ref_net = None
- return aten_round(out), ref_net, "aten::round"
+ return aten_round(out), "aten::round"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -51,18 +50,18 @@ class TestRound(PytorchLayerTest):
class TestRoundScalar(PytorchLayerTest):
def _prepare_input_int(self):
import numpy as np
- return (np.array(np.random.randint(low=-5, high=5)), )
+ return (np.array(self.random.randint(low=-5, high=5)), )
def _prepare_input_float(self):
import numpy as np
- return (np.array(np.random.uniform(low=-5, high=5)), )
+ return (np.array(self.random.uniform(low=-5, high=5)), )
def create_model(self, input_type="float"):
import torch
class aten_round(torch.nn.Module):
def __init__(self, input_type):
- super(aten_round, self).__init__()
+ super().__init__()
if input_type == "int":
self.forward = self.forward_int
else:
@@ -75,9 +74,8 @@ class TestRoundScalar(PytorchLayerTest):
def forward_float(self, x:float):
return torch.round(x)
- ref_net = None
- return aten_round(input_type), ref_net, "aten::round"
+ return aten_round(input_type), "aten::round"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_rsub.py b/tests/layer_tests/pytorch_tests/test_rsub.py
index a787a4fc195..e95141ce459 100644
--- a/tests/layer_tests/pytorch_tests/test_rsub.py
+++ b/tests/layer_tests/pytorch_tests/test_rsub.py
@@ -30,9 +30,8 @@ class TestRsub(PytorchLayerTest):
model = model_cls[second_type]
- ref_net = None
- return model(), ref_net, "aten::rsub"
+ return model(), "aten::rsub"
@pytest.mark.parametrize('input_data',
[
@@ -44,7 +43,7 @@ class TestRsub(PytorchLayerTest):
self.input_data = []
for input in input_data:
if type(input) is list:
- self.input_data.append(np.random.randn(*input).astype(np.float32))
+ self.input_data.append(self.random.randn(*input))
else:
self.input_data.append(input)
self._test(*self.create_model(second_type="float"), ie_device, precision, ir_version, use_convert_model=True)
@@ -59,7 +58,7 @@ class TestRsub(PytorchLayerTest):
self.input_data = []
for input in input_data:
if type(input) is list:
- self.input_data.append(np.random.randn(*input).astype(np.float32))
+ self.input_data.append(self.random.randn(*input))
else:
self.input_data.append(input)
self._test(*self.create_model(second_type="int"), ie_device, precision, ir_version, use_convert_model=True)
@@ -68,7 +67,7 @@ class TestRsub(PytorchLayerTest):
class TestRsubTypes(PytorchLayerTest):
def _prepare_input(self):
- return (torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),
+ return (self.random.randn(*self.lhs_shape, dtype=self.lhs_type),
np.array([1]).astype(self.rhs_type))
def create_model(self, lhs_type, rhs_type):
@@ -88,9 +87,8 @@ class TestRsubTypes(PytorchLayerTest):
def forward2(self, lhs, rhs:int):
return torch.rsub(lhs.to(self.lhs_type), rhs, alpha=2)
- ref_net = None
- return aten_rsub(lhs_type, rhs_type), ref_net, "aten::rsub"
+ return aten_rsub(lhs_type, rhs_type), "aten::rsub"
@pytest.mark.parametrize(("lhs_type", "rhs_type"),
[[torch.int32, np.int32],
diff --git a/tests/layer_tests/pytorch_tests/test_scalar_tensor.py b/tests/layer_tests/pytorch_tests/test_scalar_tensor.py
index 7b2720c1b7d..cce20ac011f 100644
--- a/tests/layer_tests/pytorch_tests/test_scalar_tensor.py
+++ b/tests/layer_tests/pytorch_tests/test_scalar_tensor.py
@@ -5,13 +5,13 @@ import numpy as np
import pytest
import torch
-from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
+from pytorch_layer_test_class import PytorchLayerTest
class TestScalarTensor(PytorchLayerTest):
def _prepare_input(self):
- return (np.array(np.random.randn(), dtype=np.float32),)
+ return (np.array(self.random.randn(), dtype=np.float32),)
def create_model(self):
class aten_scalar_tensor(torch.nn.Module):
@@ -22,9 +22,8 @@ class TestScalarTensor(PytorchLayerTest):
def forward(self, lhs):
return torch.scalar_tensor(lhs.item())
- ref_net = None
- return aten_scalar_tensor(), ref_net, f"aten::scalar_tensor"
+ return aten_scalar_tensor(), f"aten::scalar_tensor"
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
diff --git a/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py b/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py
index 828236f6713..c1b9fc965e8 100644
--- a/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py
+++ b/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py
@@ -9,25 +9,24 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestScaledDotProductAttention(PytorchLayerTest):
def _prepare_input(self, dtype):
- rng = np.random.default_rng(42)
- return (rng.standard_normal((1, 2, 8, 4), dtype=dtype),
- rng.standard_normal((1, 2, 16, 4), dtype=dtype),
- rng.standard_normal((1, 2, 16, 6), dtype=dtype))
+ return (self.random.randn(1, 2, 8, 4, dtype=dtype),
+ self.random.randn(1, 2, 16, 4, dtype=dtype),
+ self.random.randn(1, 2, 16, 6, dtype=dtype))
def create_model(self, mask, is_causal, dtype, mask_shape, enable_gqa):
import torch.nn.functional as F
import torch
+ # Generate mask outside inner class to use test's seeded random
+ attn_mask = None if not mask else torch.from_numpy(
+ self.random.randint(0, 2, mask_shape, dtype=dtype))
+
class aten_sdpa(torch.nn.Module):
def __init__(self, mask=False, is_causal=False,
dtype=np.float32, mask_shape=None, enable_gqa=False) -> None:
super().__init__()
- self.mask = None if not mask else torch.from_numpy(
- np.random.randint(0, 2, mask_shape).astype(dtype))
- self.is_causal = is_causal
- if is_causal and mask:
- self.mask.to(torch.bool)
- self.is_causal = False
+ self.mask = attn_mask
+ self.is_causal = False if (is_causal and mask) else is_causal
self.enable_gqa = enable_gqa
def forward(self, query, key, value):
@@ -39,7 +38,6 @@ class TestScaledDotProductAttention(PytorchLayerTest):
return a, b
return (aten_sdpa(mask, is_causal, dtype, mask_shape, enable_gqa),
- None,
'aten::scaled_dot_product_attention')
@pytest.mark.nightly
@@ -92,26 +90,25 @@ class TestScaledDotProductAttention(PytorchLayerTest):
class TestScaledDotProductAttentionWithGroupQuery(PytorchLayerTest):
def _prepare_input(self, dtype):
- rng = np.random.default_rng(42)
# with group size equal to 2 = 6 / 3
- return (rng.standard_normal((1, 7, 6, 8, 4), dtype=dtype),
- rng.standard_normal((1, 7, 3, 16, 4), dtype=dtype),
- rng.standard_normal((1, 7, 3, 16, 6), dtype=dtype))
+ return (self.random.randn(1, 7, 6, 8, 4, dtype=dtype),
+ self.random.randn(1, 7, 3, 16, 4, dtype=dtype),
+ self.random.randn(1, 7, 3, 16, 6, dtype=dtype))
def create_model(self, mask, is_causal, dtype, mask_shape):
import torch.nn.functional as F
import torch
+ # Generate mask outside inner class to use test's seeded random
+ attn_mask = None if not mask else torch.from_numpy(
+ self.random.randint(0, 2, mask_shape, dtype=dtype))
+
class aten_sdpa(torch.nn.Module):
def __init__(self, mask=False, is_causal=False,
dtype=np.float32, mask_shape=None) -> None:
super().__init__()
- self.mask = None if not mask else torch.from_numpy(
- np.random.randint(0, 2, mask_shape).astype(dtype))
- self.is_causal = is_causal
- if is_causal and mask:
- self.mask.to(torch.bool)
- self.is_causal = False
+ self.mask = attn_mask
+ self.is_causal = False if (is_causal and mask) else is_causal
def forward(self, query, key, value):
# torch export struggles with dynamic scale
@@ -122,7 +119,6 @@ class TestScaledDotProductAttentionWithGroupQuery(PytorchLayerTest):
return a, b
return (aten_sdpa(mask, is_causal, dtype, mask_shape),
- None,
'aten::scaled_dot_product_attention')
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_scatter.py b/tests/layer_tests/pytorch_tests/test_scatter.py
index e3c2a0a0ab8..daa6975cffc 100644
--- a/tests/layer_tests/pytorch_tests/test_scatter.py
+++ b/tests/layer_tests/pytorch_tests/test_scatter.py
@@ -9,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestScatter(PytorchLayerTest):
def _prepare_input(self, dtype, out=False):
- inp = np.random.randn(6, 6).astype(dtype)
+ inp = self.random.randn(6, 6, dtype=dtype)
if not out:
return (inp,)
return (inp, np.zeros_like(inp, dtype=dtype))
@@ -17,7 +17,7 @@ class TestScatter(PytorchLayerTest):
def create_model(self, dim, index, src, inplace, reduce, has_out):
class aten_scatter(torch.nn.Module):
def __init__(self, dim, index, src, inplace, reduce, has_out=False):
- super(aten_scatter, self).__init__()
+ super().__init__()
self.dim = dim
self.use_empty_index = False
if index is None:
@@ -81,13 +81,12 @@ class TestScatter(PytorchLayerTest):
index = self.index
return x.scatter_(self.dim, index, self.src, reduce=self.reduce)
- ref_net = None
if inplace:
op_name = "aten::scatter_"
else:
op_name = "aten::scatter"
- return aten_scatter(dim, index, src, inplace, reduce, has_out), ref_net, op_name
+ return aten_scatter(dim, index, src, inplace, reduce, has_out), op_name
@pytest.mark.nightly
@pytest.mark.precommit
@@ -128,7 +127,7 @@ class TestScatter(PytorchLayerTest):
class TestScatterReduce(PytorchLayerTest):
def _prepare_input(self, dtype, out=False):
- inp = np.random.randn(6, 6).astype(dtype)
+ inp = self.random.randn(6, 6, dtype=dtype)
if not out:
return (inp,)
return (inp, np.zeros_like(inp, dtype=dtype))
@@ -136,7 +135,7 @@ class TestScatterReduce(PytorchLayerTest):
def create_model(self, dim, index, src, inplace, reduce, include_self, has_out):
class aten_scatter_reduce(torch.nn.Module):
def __init__(self, dim, index, src, inplace, reduce, include_self, has_out=False):
- super(aten_scatter_reduce, self).__init__()
+ super().__init__()
self.dim = dim
self.use_empty_index = False
if index is None:
@@ -177,13 +176,12 @@ class TestScatterReduce(PytorchLayerTest):
index = self.index
return x.scatter_reduce_(self.dim, index, self.src, self.reduce, include_self=self.include_self)
- ref_net = None
if inplace:
op_name = "aten::scatter_reduce_"
else:
op_name = "aten::scatter_reduce"
- return aten_scatter_reduce(dim, index, src, inplace, reduce, include_self, has_out), ref_net, op_name
+ return aten_scatter_reduce(dim, index, src, inplace, reduce, include_self, has_out), op_name
@pytest.mark.nightly
@pytest.mark.precommit
@@ -226,12 +224,12 @@ class TestScatterReduce(PytorchLayerTest):
class TestScatterAdd(PytorchLayerTest):
def _prepare_input(self, dtype):
- return (np.random.randn(6, 6).astype(dtype),)
+ return (self.random.randn(6, 6, dtype=dtype),)
def create_model(self, dim, index, src, inplace):
class aten_scatter_reduce(torch.nn.Module):
def __init__(self, dim, index, src, inplace):
- super(aten_scatter_reduce, self).__init__()
+ super().__init__()
self.dim = dim
self.use_empty_index = False
if index is None:
@@ -255,7 +253,7 @@ class TestScatterAdd(PytorchLayerTest):
op_name = "aten::scatter_add_" if inplace else "aten::scatter_add"
- return aten_scatter_reduce(dim, index, src, inplace), None, op_name
+ return aten_scatter_reduce(dim, index, src, inplace), op_name
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_search_sorted.py b/tests/layer_tests/pytorch_tests/test_search_sorted.py
index dd1592857f4..dea2c248264 100644
--- a/tests/layer_tests/pytorch_tests/test_search_sorted.py
+++ b/tests/layer_tests/pytorch_tests/test_search_sorted.py
@@ -16,15 +16,14 @@ class TestSearchSorted(PytorchLayerTest):
class aten_searchsorted(torch.nn.Module):
def __init__(self, right_mode):
- super(aten_searchsorted, self).__init__()
+ super().__init__()
self.right_mode = right_mode
def forward(self, sorted, values):
return torch.searchsorted(sorted, values, right=self.right_mode)
- ref_net = None
- return aten_searchsorted(right_mode), ref_net, "aten::searchsorted"
+ return aten_searchsorted(right_mode), "aten::searchsorted"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_select.py b/tests/layer_tests/pytorch_tests/test_select.py
index 41ff31d8c2f..3fc862e72a1 100644
--- a/tests/layer_tests/pytorch_tests/test_select.py
+++ b/tests/layer_tests/pytorch_tests/test_select.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -13,7 +12,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestSelect(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(4, 4, 5, 5).astype(np.float32),)
+ return (self.random.randn(4, 4, 5, 5),)
def create_model(self, input_dim, input_index):
class aten_select(torch.nn.Module):
@@ -26,9 +25,8 @@ class TestSelect(PytorchLayerTest):
def forward(self, input_tensor):
return torch.select(input_tensor, int(self.dim), int(self.index))
- ref_net = None
- return aten_select(input_dim, input_index), ref_net, "aten::select"
+ return aten_select(input_dim, input_index), "aten::select"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -43,7 +41,7 @@ class TestSelect(PytorchLayerTest):
class TestSelectCopy(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(4, 4, 5, 5).astype(np.float32),)
+ return (self.random.randn(4, 4, 5, 5),)
def create_model(self, input_dim, input_index):
class aten_select_copy(torch.nn.Module):
@@ -56,9 +54,8 @@ class TestSelectCopy(PytorchLayerTest):
def forward(self, input_tensor):
return torch.select_copy(input_tensor, int(self.dim), int(self.index))
- ref_net = None
- return aten_select_copy(input_dim, input_index), ref_net, "aten::select_copy"
+ return aten_select_copy(input_dim, input_index), "aten::select_copy"
@pytest.mark.precommit_fx_backend
def test_select_copy(self, ie_device, precision, ir_version, input_dim, input_index):
diff --git a/tests/layer_tests/pytorch_tests/test_select_scatter.py b/tests/layer_tests/pytorch_tests/test_select_scatter.py
index f3155480a72..d843e34d5f9 100644
--- a/tests/layer_tests/pytorch_tests/test_select_scatter.py
+++ b/tests/layer_tests/pytorch_tests/test_select_scatter.py
@@ -8,14 +8,13 @@ import torch
class TestSelectScatter(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 5, 3, 4).astype(np.float32),)
+ return (self.random.randn(2, 5, 3, 4),)
def create_model(self, src, dim, index):
class aten_select_scatter(torch.nn.Module):
def __init__(self, src=None, dim=None, index=None):
- super(aten_select_scatter, self).__init__()
+ super().__init__()
self.src = src
self.dim = dim
self.index = index
@@ -24,9 +23,8 @@ class TestSelectScatter(PytorchLayerTest):
return torch.select_scatter(x, self.src, self.dim, self.index);
- ref_net = None
- return aten_select_scatter(src, dim, index), ref_net, "aten::select_scatter"
+ return aten_select_scatter(src, dim, index), "aten::select_scatter"
@pytest.mark.precommit_fx_backend
@pytest.mark.parametrize(("src", "dim", "index"),
diff --git a/tests/layer_tests/pytorch_tests/test_set_item.py b/tests/layer_tests/pytorch_tests/test_set_item.py
index bd8e0a7aa9c..aa7432f7b67 100644
--- a/tests/layer_tests/pytorch_tests/test_set_item.py
+++ b/tests/layer_tests/pytorch_tests/test_set_item.py
@@ -2,31 +2,27 @@
# SPDX-License-Identifier: Apache-2.0
import pytest
-import platform
-
from pytorch_layer_test_class import PytorchLayerTest
class TestSetItem(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return [np.random.randint(-10, 10, [10]).tolist()]
+ return [self.random.randint(-10, 10, [10]).tolist()]
def create_model(self, idx):
import torch
class aten_set_item(torch.nn.Module):
def __init__(self, idx):
- super(aten_set_item, self).__init__()
+ super().__init__()
self.idx = idx
def forward(self, x: list[int]):
x[self.idx] = 0
return torch.tensor(x).to(torch.int)
- ref_net = None
- return aten_set_item(idx), ref_net, "aten::_set_item"
+ return aten_set_item(idx), "aten::_set_item"
@pytest.mark.parametrize("idx", [0, 1, -1])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_shape_as_tensor.py b/tests/layer_tests/pytorch_tests/test_shape_as_tensor.py
index 3d75e30b966..5a5d3c490bc 100644
--- a/tests/layer_tests/pytorch_tests/test_shape_as_tensor.py
+++ b/tests/layer_tests/pytorch_tests/test_shape_as_tensor.py
@@ -28,5 +28,5 @@ class TestShapeAsTensor(PytorchLayerTest):
@pytest.mark.precommit
def test_all_noparams(self, shape, ie_device, precision, ir_version):
self.input_tensor = np.zeros(shape)
- self._test(aten_shape_as_tensor(), None, "aten::_shape_as_tensor",
+ self._test(aten_shape_as_tensor(), "aten::_shape_as_tensor",
ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_shift_operations.py b/tests/layer_tests/pytorch_tests/test_shift_operations.py
index 8f6fe5cdf6d..dd40cca6f5c 100644
--- a/tests/layer_tests/pytorch_tests/test_shift_operations.py
+++ b/tests/layer_tests/pytorch_tests/test_shift_operations.py
@@ -4,7 +4,7 @@
import numpy as np
import pytest
import torch
-from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
+from pytorch_layer_test_class import PytorchLayerTest
class TestShiftOperators(PytorchLayerTest):
@@ -12,8 +12,8 @@ class TestShiftOperators(PytorchLayerTest):
choices = np.array([1, 2, 4, 8, 16, 32])
shifts = np.array([0, 1, 2, 3, 4, 5])
- x = np.random.choice(choices, lhs_shape).astype(lhs_dtype)
- y = np.random.choice(shifts, rhs_shape).astype(rhs_dtype)
+ x = self.random.choice(choices, lhs_shape).astype(lhs_dtype)
+ y = self.random.choice(shifts, rhs_shape).astype(rhs_dtype)
return x, y
def create_model(self):
@@ -21,8 +21,7 @@ class TestShiftOperators(PytorchLayerTest):
def forward(self, lhs, rhs):
return lhs << rhs, lhs >> rhs
- ref_net = None
- return aten_shift(), ref_net, ("aten::__lshift__", "aten::__rshift__")
+ return aten_shift(), ("aten::__lshift__", "aten::__rshift__")
@pytest.mark.nightly
@pytest.mark.precommit
@@ -62,8 +61,8 @@ class TestBitwiseShiftFunctions(PytorchLayerTest):
choices = np.array([1, 2, 4, 8, 16, 32])
shifts = np.array([0, 1, 2, 3, 4, 5])
- x = np.random.choice(choices, lhs_shape).astype(lhs_dtype)
- y = np.random.choice(shifts, rhs_shape).astype(rhs_dtype)
+ x = self.random.choice(choices, lhs_shape).astype(lhs_dtype)
+ y = self.random.choice(shifts, rhs_shape).astype(rhs_dtype)
return x, y
def create_model(self):
@@ -74,7 +73,7 @@ class TestBitwiseShiftFunctions(PytorchLayerTest):
# torch.bitwise_right_shift(lhs, rhs) - temporarily disable
)
- return aten_bitwise_shift(), None, ("aten::bitwise_left_shift",) # "aten::bitwise_right_shift")
+ return aten_bitwise_shift(), ("aten::bitwise_left_shift",) # "aten::bitwise_right_shift")
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_sign.py b/tests/layer_tests/pytorch_tests/test_sign.py
index d149eef4566..f73ced35929 100644
--- a/tests/layer_tests/pytorch_tests/test_sign.py
+++ b/tests/layer_tests/pytorch_tests/test_sign.py
@@ -18,7 +18,7 @@ class TestSilu(PytorchLayerTest):
elif inp_type == "zeros":
inp *= 0
else:
- idx = np.random.choice(inp, 3)
+ idx = self.random.choice(inp, 3)
inp[idx.astype(int)] *= -1
if out:
return (inp, np.zeros_like(inp))
@@ -29,7 +29,7 @@ class TestSilu(PytorchLayerTest):
class aten_sign(torch.nn.Module):
def __init__(self, out):
- super(aten_sign, self).__init__()
+ super().__init__()
if out:
self.forward = self.forward_out
@@ -39,9 +39,8 @@ class TestSilu(PytorchLayerTest):
def forward_out(self, x, out):
return torch.sign(x), out
- ref_net = None
- return aten_sign(out), ref_net, "aten::sign"
+ return aten_sign(out), "aten::sign"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_size.py b/tests/layer_tests/pytorch_tests/test_size.py
index 4483ed8a733..b0a68031032 100644
--- a/tests/layer_tests/pytorch_tests/test_size.py
+++ b/tests/layer_tests/pytorch_tests/test_size.py
@@ -8,10 +8,9 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestSize(PytorchLayerTest):
def _prepare_input(self, input_shape, complex_type):
- import numpy as np
if complex_type:
input_shape += [2]
- return (np.random.randn(*input_shape).astype(np.float32),)
+ return (self.random.randn(*input_shape),)
def create_model(self, complex_type):
import torch
@@ -28,7 +27,7 @@ class TestSize(PytorchLayerTest):
op = aten_size(complex_type)
- return op, None, "aten::size"
+ return op, "aten::size"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_slice.py b/tests/layer_tests/pytorch_tests/test_slice.py
index 9f85e3880f1..af7606e859b 100644
--- a/tests/layer_tests/pytorch_tests/test_slice.py
+++ b/tests/layer_tests/pytorch_tests/test_slice.py
@@ -16,9 +16,8 @@ class TestSlice1D(PytorchLayerTest):
def forward(self, x, params):
return x[params[0] : params[1] : params[2]]
- ref_net = None
- return aten_slice(), ref_net, "aten::slice"
+ return aten_slice(), "aten::slice"
@pytest.mark.parametrize(
"params",
@@ -49,9 +48,8 @@ class TestSlice2D(PytorchLayerTest):
def forward(self, x, params_0a, params_1a):
return x[params_0a[0] : params_0a[1] : params_0a[2], params_1a[0] : params_1a[1] : params_1a[2]]
- ref_net = None
- return aten_slice(), ref_net, "aten::slice"
+ return aten_slice(), "aten::slice"
@pytest.mark.parametrize(
"params_0a",
@@ -86,7 +84,7 @@ class TestSliceComplex(PytorchLayerTest):
x = x[params[0]: params[1]: params[2]]
return torch.view_as_real(x)
- return aten_slice(), None, "aten::slice"
+ return aten_slice(), "aten::slice"
@pytest.mark.parametrize("params", [[0, -1, 1],
[0, -1, 3],
@@ -104,7 +102,7 @@ class TestSliceComplex(PytorchLayerTest):
class TestSliceAndSqueeze(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(1, 1, 32).astype(np.float32),)
+ return (self.random.randn(1, 1, 32),)
def create_model(self):
class aten_slice(torch.nn.Module):
@@ -112,7 +110,7 @@ class TestSliceAndSqueeze(PytorchLayerTest):
a = torch.squeeze(x, 1)
return a[:, None, :]
- return aten_slice(), None, "aten::slice"
+ return aten_slice(), "aten::slice"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_slice_scatter.py b/tests/layer_tests/pytorch_tests/test_slice_scatter.py
index 2838970f0eb..b6445bfe4fd 100644
--- a/tests/layer_tests/pytorch_tests/test_slice_scatter.py
+++ b/tests/layer_tests/pytorch_tests/test_slice_scatter.py
@@ -9,15 +9,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestSliceScatter(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 5, 3, 4).astype(np.float32),)
+ return (self.random.randn(2, 5, 3, 4),)
def create_model(self, src, dim, start, end, step):
import torch
class aten_slice_scatter(torch.nn.Module):
def __init__(self, src=None, dim=None, start=None, end=None, step=None):
- super(aten_slice_scatter, self).__init__()
+ super().__init__()
self.src = src
self.dim = dim
self.start = start
@@ -28,9 +27,8 @@ class TestSliceScatter(PytorchLayerTest):
return torch.slice_scatter(x, src=self.src, dim=self.dim, start=self.start, end=self.end, step=self.step);
- ref_net = None
- return aten_slice_scatter(src, dim, start, end, step), ref_net, "aten::slice_scatter"
+ return aten_slice_scatter(src, dim, start, end, step), "aten::slice_scatter"
import torch
@pytest.mark.precommit_fx_backend
diff --git a/tests/layer_tests/pytorch_tests/test_softmax.py b/tests/layer_tests/pytorch_tests/test_softmax.py
index 3a4f7f2e623..51264995369 100644
--- a/tests/layer_tests/pytorch_tests/test_softmax.py
+++ b/tests/layer_tests/pytorch_tests/test_softmax.py
@@ -8,10 +8,9 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestSoftmax(PytorchLayerTest):
def _prepare_input(self, second_input_dtype=None):
- import numpy as np
if second_input_dtype is None:
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
- return (np.random.randn(1, 3, 224, 224).astype(np.float32), np.random.randn(1).astype(second_input_dtype))
+ return (self.random.randn(1, 3, 224, 224),)
+ return (self.random.randn(1, 3, 224, 224), self.random.randn(1, dtype=second_input_dtype))
def create_model(self, dim, dtype=None, use_prim_dtype=False):
import torch
@@ -25,7 +24,7 @@ class TestSoftmax(PytorchLayerTest):
class aten_softmax(torch.nn.Module):
def __init__(self, dim, dtype, use_prim_dtype):
- super(aten_softmax, self).__init__()
+ super().__init__()
self.dim = dim
self.dtype = dtype
if use_prim_dtype:
@@ -42,9 +41,8 @@ class TestSoftmax(PytorchLayerTest):
def forward_prim_dtype(self, x, y):
return F.softmax(x, self.dim, dtype=y.dtype)
- ref_net = None
- return aten_softmax(dim, dtype, use_prim_dtype), ref_net, "aten::softmax"
+ return aten_softmax(dim, dtype, use_prim_dtype), "aten::softmax"
@pytest.mark.parametrize("dim", [-1, 3])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_softplus.py b/tests/layer_tests/pytorch_tests/test_softplus.py
index e9befd6aa63..91e005f6d0d 100644
--- a/tests/layer_tests/pytorch_tests/test_softplus.py
+++ b/tests/layer_tests/pytorch_tests/test_softplus.py
@@ -14,12 +14,11 @@ class aten_softplus(torch.nn.Module):
class TestSoftplus(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 4, 224, 224).astype(np.float32),)
+ return (self.random.randn(2, 4, 224, 224),)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_softplus(self, ie_device, precision, ir_version):
- self._test(aten_softplus(), None, "aten::softplus",
+ self._test(aten_softplus(), "aten::softplus",
ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_sort.py b/tests/layer_tests/pytorch_tests/test_sort.py
index 5edce84e9bd..ac93a83f33a 100644
--- a/tests/layer_tests/pytorch_tests/test_sort.py
+++ b/tests/layer_tests/pytorch_tests/test_sort.py
@@ -33,8 +33,7 @@ class TestSortConstants(PytorchLayerTest):
descending=self.descending
)[0]
- ref_net = None
- return aten_sort(dim, descending, stable), ref_net, "aten::sort"
+ return aten_sort(dim, descending, stable), "aten::sort"
@pytest.mark.parametrize("input_shape", [
[16],
@@ -82,7 +81,7 @@ class TestSortConstants(PytorchLayerTest):
def test_sort(self, input_shape, descending, stable, ie_device, precision, ir_version):
self.input_tensor = []
if type(input_shape) is list:
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
else:
self.input_tensor = input_shape
dims = len(self.input_tensor.shape)
diff --git a/tests/layer_tests/pytorch_tests/test_split.py b/tests/layer_tests/pytorch_tests/test_split.py
index d18a3692f79..e242d7d4687 100644
--- a/tests/layer_tests/pytorch_tests/test_split.py
+++ b/tests/layer_tests/pytorch_tests/test_split.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -10,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestSplit(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(1, 10, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 10, 224, 224),)
def create_model_split_getitem(self):
class aten_split(torch.nn.Module):
@@ -25,7 +24,6 @@ class TestSplit(PytorchLayerTest):
return (
aten_split(self.split_param, self.axis, self.getitem),
- None,
"aten::split",
)
@@ -41,7 +39,7 @@ class TestSplit(PytorchLayerTest):
a, b, c, d, e = torch.split(input, self.split, self.axis)
return b
- return aten_split(self.split_param, self.axis), None, "aten::split"
+ return aten_split(self.split_param, self.axis), "aten::split"
# Test case - (split_param, axis), always split into 5 due to hardcoded number of outputs in ListUnpack test.
test_cases = [
@@ -78,8 +76,7 @@ class TestSplit(PytorchLayerTest):
class TestSplitWithSizes(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(20).astype(np.float32),np.random.randn(20).astype(np.float32))
+ return (self.random.randn(20),self.random.randn(20))
def create_model(self):
import torch
@@ -88,7 +85,7 @@ class TestSplitWithSizes(PytorchLayerTest):
def forward(self, x, y):
return x.split([y.shape[0]], dim=0)
- return aten_split_with_sizes(), None, ["aten::split_with_sizes", "prim::ListConstruct"]
+ return aten_split_with_sizes(), ["aten::split_with_sizes", "prim::ListConstruct"]
@pytest.mark.nightly
@pytest.mark.precommit
@@ -102,8 +99,7 @@ class TestSplitWithSizes(PytorchLayerTest):
class TestSplitWithSizesCopy(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(20).astype(np.float32),np.random.randn(20).astype(np.float32))
+ return (self.random.randn(20),self.random.randn(20))
def create_model(self):
import torch
@@ -112,9 +108,8 @@ class TestSplitWithSizesCopy(PytorchLayerTest):
def forward(self, x, y):
return torch.split_with_sizes_copy(x, [y.shape[0]], dim=0)
- ref_net = None
- return aten_split_with_sizes_copy(), ref_net, ["aten::split_with_sizes", "prim::ListConstruct"]
+ return aten_split_with_sizes_copy(), ["aten::split_with_sizes", "prim::ListConstruct"]
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
@@ -126,9 +121,8 @@ class TestSplitWithSizesCopy(PytorchLayerTest):
class TestSplitWithSizesComplex(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(20, 2).astype(np.float32),
- np.random.randn(5).astype(np.float32))
+ return (self.random.randn(20, 2),
+ self.random.randn(5))
def create_model(self):
import torch
@@ -142,7 +136,7 @@ class TestSplitWithSizesComplex(PytorchLayerTest):
torch.view_as_real(x3),
torch.view_as_real(x4))
- return aten_split_with_sizes(), None, ["aten::split_with_sizes", "prim::ListConstruct"]
+ return aten_split_with_sizes(), ["aten::split_with_sizes", "prim::ListConstruct"]
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_square.py b/tests/layer_tests/pytorch_tests/test_square.py
index d8538bdea02..fa601ee8ea3 100644
--- a/tests/layer_tests/pytorch_tests/test_square.py
+++ b/tests/layer_tests/pytorch_tests/test_square.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -11,7 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestSquareTypes(PytorchLayerTest):
def _prepare_input(self):
- return (torch.randn(self.shape).to(self.type).numpy(),)
+ return (self.random.randn(*self.shape, dtype=self.type),)
def create_model(self, type):
@@ -23,7 +22,7 @@ class TestSquareTypes(PytorchLayerTest):
def forward(self, lhs):
return torch.square(lhs.to(self.type))
- return aten_square(type), None, "aten::square"
+ return aten_square(type), "aten::square"
@pytest.mark.parametrize(("type"), [torch.int32, torch.int64, torch.float32])
@pytest.mark.parametrize(("shape"), [[2, 3], [],])
diff --git a/tests/layer_tests/pytorch_tests/test_squeeze.py b/tests/layer_tests/pytorch_tests/test_squeeze.py
index e50e66db330..0e2415b59e2 100644
--- a/tests/layer_tests/pytorch_tests/test_squeeze.py
+++ b/tests/layer_tests/pytorch_tests/test_squeeze.py
@@ -8,16 +8,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestSqueeze(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
-
- return (np.random.randn(1, 1, 32).astype(np.float32),)
+ return (self.random.randn(1, 1, 32),)
def create_model(self, dim):
import torch
class aten_squeeze(torch.nn.Module):
def __init__(self, dim):
- super(aten_squeeze, self).__init__()
+ super().__init__()
self.dim = dim
def forward(self, x):
@@ -25,9 +23,7 @@ class TestSqueeze(PytorchLayerTest):
return torch.squeeze(x, self.dim)
return torch.squeeze(x)
- ref_net = None
-
- return aten_squeeze(dim), ref_net, "aten::squeeze"
+ return aten_squeeze(dim), "aten::squeeze"
@pytest.mark.parametrize("dim,dynamic_shapes", [(-2, True), (0, True), (None, False)])
@pytest.mark.nightly
@@ -49,16 +45,14 @@ class TestSqueeze(PytorchLayerTest):
class TestSqueezeCopy(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
-
- return (np.random.randn(1, 1, 32).astype(np.float32),)
+ return (self.random.randn(1, 1, 32),)
def create_model(self, dim):
import torch
class aten_squeeze_copy(torch.nn.Module):
def __init__(self, dim):
- super(aten_squeeze_copy, self).__init__()
+ super().__init__()
self.dim = dim
def forward(self, x):
@@ -66,9 +60,7 @@ class TestSqueezeCopy(PytorchLayerTest):
return torch.squeeze_copy(x, self.dim)
return torch.squeeze_copy(x)
- ref_net = None
-
- return aten_squeeze_copy(dim), ref_net, "aten::squeeze_copy"
+ return aten_squeeze_copy(dim), "aten::squeeze_copy"
@pytest.mark.parametrize("dim,dynamic_shapes", [(-2, True), (0, True), (None, False)])
@pytest.mark.precommit_fx_backend
diff --git a/tests/layer_tests/pytorch_tests/test_stack.py b/tests/layer_tests/pytorch_tests/test_stack.py
index 6fd758a1932..09a6811ec62 100644
--- a/tests/layer_tests/pytorch_tests/test_stack.py
+++ b/tests/layer_tests/pytorch_tests/test_stack.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
from pytorch_layer_test_class import PytorchLayerTest
@@ -16,7 +15,7 @@ class TestStack2D(PytorchLayerTest):
class aten_stack(torch.nn.Module):
def __init__(self, dim):
- super(aten_stack, self).__init__()
+ super().__init__()
self.dim = dim
def forward(self, x, y):
@@ -25,9 +24,8 @@ class TestStack2D(PytorchLayerTest):
return torch.stack(inputs)
return torch.stack(inputs, self.dim)
- ref_net = None
- return aten_stack(dim), ref_net, "aten::stack"
+ return aten_stack(dim), "aten::stack"
@pytest.mark.parametrize("input_shape",
[
@@ -44,8 +42,8 @@ class TestStack2D(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_stack2D(self, input_shape, dim, ie_device, precision, ir_version):
self.input_tensors = [
- np.random.randn(*input_shape).astype(np.float32),
- np.random.randn(*input_shape).astype(np.float32),
+ self.random.randn(*input_shape),
+ self.random.randn(*input_shape),
]
self._test(*self.create_model(dim), ie_device, precision, ir_version)
@@ -59,7 +57,7 @@ class TestStack3D(PytorchLayerTest):
class aten_stack(torch.nn.Module):
def __init__(self, dim):
- super(aten_stack, self).__init__()
+ super().__init__()
self.dim = dim
def forward(self, x, y, z):
@@ -68,9 +66,8 @@ class TestStack3D(PytorchLayerTest):
return torch.stack(inputs)
return torch.stack(inputs, self.dim)
- ref_net = None
- return aten_stack(dim), ref_net, "aten::stack"
+ return aten_stack(dim), "aten::stack"
@pytest.mark.parametrize("input_shape",
[
@@ -87,8 +84,8 @@ class TestStack3D(PytorchLayerTest):
@pytest.mark.precommit_fx_backend
def test_stack3D(self, input_shape, dim, ie_device, precision, ir_version):
self.input_tensors = [
- np.random.randn(*input_shape).astype(np.float32),
- np.random.randn(*input_shape).astype(np.float32),
- np.random.randn(*input_shape).astype(np.float32)
+ self.random.randn(*input_shape),
+ self.random.randn(*input_shape),
+ self.random.randn(*input_shape)
]
self._test(*self.create_model(dim), ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_stft.py b/tests/layer_tests/pytorch_tests/test_stft.py
index a1734b91d8e..1d23f5332fe 100644
--- a/tests/layer_tests/pytorch_tests/test_stft.py
+++ b/tests/layer_tests/pytorch_tests/test_stft.py
@@ -11,7 +11,7 @@ class TestSTFT(PytorchLayerTest):
import numpy as np
if rand_data:
- signal = np.random.randn(*signal_shape).astype(out_dtype)
+ signal = self.random.randn(*signal_shape, dtype=out_dtype)
else:
num_samples = signal_shape[-1]
half_idx = num_samples // 2
@@ -30,7 +30,7 @@ class TestSTFT(PytorchLayerTest):
class aten_stft(torch.nn.Module):
def __init__(self, n_fft, hop_length, win_length, normalized):
- super(aten_stft, self).__init__()
+ super().__init__()
self.n_fft = n_fft
self.hop_length = hop_length
self.win_length = win_length
@@ -50,9 +50,8 @@ class TestSTFT(PytorchLayerTest):
return_complex=False,
)
- ref_net = None
- return aten_stft(n_fft, hop_length, win_length, normalized), ref_net, "aten::stft"
+ return aten_stft(n_fft, hop_length, win_length, normalized), "aten::stft"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -77,7 +76,7 @@ class TestSTFTAttrs(PytorchLayerTest):
def _prepare_input(self, out=False, out_dtype="float32"):
import numpy as np
- signal = np.random.randn(2, 512).astype(out_dtype)
+ signal = self.random.randn(2, 512, dtype=out_dtype)
return (signal,)
def create_model_with_attrs(self, n_fft, hop_length, win_length, center, pad_mode, normalized, onesided, return_complex):
@@ -86,7 +85,7 @@ class TestSTFTAttrs(PytorchLayerTest):
class aten_stft_attrs(torch.nn.Module):
def __init__(self, n_fft, hop_length, win_length, center, pad_mode, normalized, onesided, return_complex):
- super(aten_stft_attrs, self).__init__()
+ super().__init__()
self.n_fft = n_fft
self.hop_length = hop_length
self.win_length = win_length
@@ -115,9 +114,8 @@ class TestSTFTAttrs(PytorchLayerTest):
else:
return stft
- ref_net = None
- return aten_stft_attrs(n_fft, hop_length, win_length, center, pad_mode, normalized, onesided, return_complex), ref_net, "aten::stft"
+ return aten_stft_attrs(n_fft, hop_length, win_length, center, pad_mode, normalized, onesided, return_complex), "aten::stft"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_strided_const.py b/tests/layer_tests/pytorch_tests/test_strided_const.py
index 8d4b7e8d123..eb8b8efcd08 100644
--- a/tests/layer_tests/pytorch_tests/test_strided_const.py
+++ b/tests/layer_tests/pytorch_tests/test_strided_const.py
@@ -9,22 +9,22 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestStrides(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
- x = np.random.randint(0, 10, [1, 3, 2, 2]).astype(np.float32)
+ x = self.random.randint(0, 10, [1, 3, 2, 2], dtype=np.float32)
return (x,)
def create_model(self):
import torch
class strided_const(torch.nn.Module):
- def __init__(self):
+ def __init__(self, rng):
super().__init__()
- self.const = torch.randint(0, 10, [1, 3, 2, 2], dtype=torch.float32)
+ self.const = rng.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
- return strided_const(), None, "aten::add"
+ return strided_const(self.random), "aten::add"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_sub.py b/tests/layer_tests/pytorch_tests/test_sub.py
index 129055ef22c..2e58a160dc4 100644
--- a/tests/layer_tests/pytorch_tests/test_sub.py
+++ b/tests/layer_tests/pytorch_tests/test_sub.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -28,14 +27,13 @@ class TestSub(PytorchLayerTest):
def _forward_inplace(self, x, y, alpha: float):
return x.sub_(y, alpha=alpha)
- ref_net = None
if inplace:
op_name = "aten::sub_"
else:
op_name = "aten::sub"
- return aten_sub(inplace), ref_net, op_name
+ return aten_sub(inplace), op_name
@pytest.mark.parametrize('input_shapes',
[
@@ -52,7 +50,7 @@ class TestSub(PytorchLayerTest):
def test_sub(self, ie_device, precision, ir_version, input_shapes, inplace):
self.input_data = []
for input_shape in input_shapes:
- self.input_data.append(np.random.randn(*input_shape).astype(np.float32))
+ self.input_data.append(self.random.randn(*input_shape))
self._test(*self.create_model(inplace), ie_device, precision, ir_version, use_convert_model=True)
@@ -60,11 +58,11 @@ class TestSubTypes(PytorchLayerTest):
def _prepare_input(self):
if len(self.lhs_shape) == 0:
- return (torch.randn(self.rhs_shape).to(self.rhs_type).numpy(),)
+ return (self.random.randn(*self.rhs_shape, dtype=self.rhs_type),)
elif len(self.rhs_shape) == 0:
- return (torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),)
- return (torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),
- torch.randn(self.rhs_shape).to(self.rhs_type).numpy())
+ return (self.random.randn(*self.lhs_shape, dtype=self.lhs_type),)
+ return (self.random.randn(*self.lhs_shape, dtype=self.lhs_type),
+ self.random.randn(*self.rhs_shape, dtype=self.rhs_type))
def create_model(self, lhs_type, lhs_shape, rhs_type, rhs_shape):
@@ -89,9 +87,8 @@ class TestSubTypes(PytorchLayerTest):
def forward3(self, lhs, rhs):
return torch.sub(lhs.to(self.lhs_type), rhs.to(self.rhs_type), alpha=2)
- ref_net = None
- return aten_sub(lhs_type, lhs_shape, rhs_type, rhs_shape), ref_net, "aten::sub"
+ return aten_sub(lhs_type, lhs_shape, rhs_type, rhs_shape), "aten::sub"
@pytest.mark.parametrize(("lhs_type", "rhs_type"),
[[torch.int32, torch.int64],
@@ -124,8 +121,8 @@ class TestSubWithLhsComplex(PytorchLayerTest):
def _prepare_input(self):
rhs_input_shape = [3, 4, 5]
lhs_input_shape = rhs_input_shape + [2]
- return [torch.randint(-10, 10, lhs_input_shape).to(self.lhs_type).numpy(),
- torch.randint(-10, 10, rhs_input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(-10, 10, size=lhs_input_shape, dtype=self.lhs_type),
+ self.random.randint(-10, 10, size=rhs_input_shape, dtype=self.rhs_type)]
def create_model(self, alpha, op_type):
class aten_sub(torch.nn.Module):
@@ -145,9 +142,8 @@ class TestSubWithLhsComplex(PytorchLayerTest):
res = lhs.sub_(rhs, alpha=self.alpha)
return torch.view_as_real(res + lhs)
- ref_net = None
- return aten_sub(alpha, op_type), ref_net, f"aten::{op_type}"
+ return aten_sub(alpha, op_type), f"aten::{op_type}"
@pytest.mark.parametrize('alpha', (0, 0.5))
@pytest.mark.parametrize("lhs_type",
@@ -173,8 +169,8 @@ class TestSubWithRhsComplex(PytorchLayerTest):
def _prepare_input(self):
lhs_input_shape = [3, 4, 5]
rhs_input_shape = lhs_input_shape + [2]
- return [torch.randint(-10, 10, lhs_input_shape).to(self.lhs_type).numpy(),
- torch.randint(-10, 10, rhs_input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(-10, 10, size=lhs_input_shape, dtype=self.lhs_type),
+ self.random.randint(-10, 10, size=rhs_input_shape, dtype=self.rhs_type)]
def create_model(self, alpha):
class aten_sub(torch.nn.Module):
@@ -188,9 +184,8 @@ class TestSubWithRhsComplex(PytorchLayerTest):
res = torch.sub(lhs, rhs, alpha=self.alpha)
return torch.view_as_real(res)
- ref_net = None
- return aten_sub(alpha), ref_net, f"aten::sub"
+ return aten_sub(alpha), f"aten::sub"
@pytest.mark.parametrize('alpha', (0, 0.5))
@pytest.mark.parametrize("rhs_type",
@@ -215,8 +210,8 @@ class TestSubWithBothComplex(PytorchLayerTest):
def _prepare_input(self):
input_shape = [3, 4, 5]
input_shape = input_shape + [2]
- return [torch.randint(0, 10, input_shape).to(self.lhs_type).numpy(),
- torch.randint(0, 10, input_shape).to(self.rhs_type).numpy()]
+ return [self.random.randint(0, 10, size=input_shape, dtype=self.lhs_type),
+ self.random.randint(0, 10, size=input_shape, dtype=self.rhs_type)]
def create_model(self, alpha, op_type):
class aten_sub(torch.nn.Module):
@@ -238,9 +233,8 @@ class TestSubWithBothComplex(PytorchLayerTest):
res = lhs.sub_(rhs, alpha=self.alpha)
return torch.view_as_real(res + lhs)
- ref_net = None
- return aten_sub(alpha, op_type), ref_net, f"aten::{op_type}"
+ return aten_sub(alpha, op_type), f"aten::{op_type}"
@pytest.mark.parametrize('alpha', (0, 0.5))
@pytest.mark.parametrize("lhs_type",
diff --git a/tests/layer_tests/pytorch_tests/test_sum.py b/tests/layer_tests/pytorch_tests/test_sum.py
index 5a14c0b47b3..ef89f1a971e 100644
--- a/tests/layer_tests/pytorch_tests/test_sum.py
+++ b/tests/layer_tests/pytorch_tests/test_sum.py
@@ -12,7 +12,7 @@ class TestSum(PytorchLayerTest):
import numpy as np
min_value = -10 if input_dtype not in ["uint8", "bool"] else 0
max_value = 10 if input_dtype != "bool" else 2
- input = np.random.randint(min_value, max_value, (1, 3, 5, 5)).astype(input_dtype)
+ input = self.random.randint(min_value, max_value, (1, 3, 5, 5), dtype=input_dtype)
if not out:
return (input, )
if out_dtype is None:
@@ -35,7 +35,7 @@ class TestSum(PytorchLayerTest):
class aten_sum(torch.nn.Module):
def __init__(self, input_dtype, axes=None, keep_dims=None, dtype=None, out=None):
- super(aten_sum, self).__init__()
+ super().__init__()
self.axes = axes
self.keep_dims = keep_dims
self.dtype = dtype
@@ -85,9 +85,8 @@ class TestSum(PytorchLayerTest):
else:
return torch.sum(x, self.axes, self.keep_dims, out=out), out
- ref_net = None
- return aten_sum(input_torch_dtype, axes, keep_dims, torch_dtype, out), ref_net, "aten::sum"
+ return aten_sum(input_torch_dtype, axes, keep_dims, torch_dtype, out), "aten::sum"
@pytest.mark.parametrize("axes,keep_dims",
[(None, None), (None, False), (-1, None), (1, None), ((2, 3), False), ((3, 2), True)])
diff --git a/tests/layer_tests/pytorch_tests/test_take_along_dim.py b/tests/layer_tests/pytorch_tests/test_take_along_dim.py
index 93e80df002b..1f58bad3d02 100644
--- a/tests/layer_tests/pytorch_tests/test_take_along_dim.py
+++ b/tests/layer_tests/pytorch_tests/test_take_along_dim.py
@@ -6,8 +6,8 @@ class TestTakeAlongDim(PytorchLayerTest):
def _prepare_input(self, m, n, max_val, out=False, flattenize=False):
import numpy as np
shape = (m, n) if not flattenize else (m * n,)
- index = np.random.randint(0, max_val, shape).astype(np.int64)
- inp = np.random.randn(m, n).astype(np.float32)
+ index = self.random.randint(0, max_val, shape, dtype=np.int64)
+ inp = self.random.randn(m, n)
if out:
axis = int(max_val == n)
if flattenize:
@@ -22,7 +22,7 @@ class TestTakeAlongDim(PytorchLayerTest):
class aten_take_along_dim(torch.nn.Module):
def __init__(self, axis, out=False):
- super(aten_take_along_dim, self).__init__()
+ super().__init__()
self.axis = axis
if self.axis is None:
self.forward = self.forward_no_dim
@@ -41,7 +41,7 @@ class TestTakeAlongDim(PytorchLayerTest):
def forward_no_dim_out(self, x, index, out):
return torch.take_along_dim(x, index, out=out)
- return aten_take_along_dim(axis, out), None, "aten::take_along_dim"
+ return aten_take_along_dim(axis, out), "aten::take_along_dim"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_tensor_split.py b/tests/layer_tests/pytorch_tests/test_tensor_split.py
index 3d510a8c314..f9f1c009ea1 100644
--- a/tests/layer_tests/pytorch_tests/test_tensor_split.py
+++ b/tests/layer_tests/pytorch_tests/test_tensor_split.py
@@ -4,7 +4,6 @@
from collections.abc import Collection
from numbers import Number
-import numpy as np
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest
@@ -12,7 +11,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestTensorSplit(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.rand(*self.input_shape),)
+ return (self.random.rand(*self.input_shape),)
def create_model(self, splits, axis):
class aten_tensor_split(torch.nn.Module):
@@ -39,7 +38,7 @@ class TestTensorSplit(PytorchLayerTest):
a, b, c, d = torch.tensor_split(input_tensor, self.splits, dim=self.dim)
return a, b, c, d
- return aten_tensor_split(splits, axis), None, "aten::tensor_split"
+ return aten_tensor_split(splits, axis), "aten::tensor_split"
@pytest.mark.parametrize("input_shape", [(2, 1, 8), (3, 5, 7, 11)])
@pytest.mark.parametrize(
diff --git a/tests/layer_tests/pytorch_tests/test_tile.py b/tests/layer_tests/pytorch_tests/test_tile.py
index 54e8ddef891..f9389496b8d 100644
--- a/tests/layer_tests/pytorch_tests/test_tile.py
+++ b/tests/layer_tests/pytorch_tests/test_tile.py
@@ -8,23 +8,21 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestTile(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224, 224),)
def create_model(self, dims):
import torch
class aten_tile(torch.nn.Module):
def __init__(self, dims):
- super(aten_tile, self).__init__()
+ super().__init__()
self.dims = dims
def forward(self, x):
return torch.tile(x, self.dims)
- ref_net = None
- return aten_tile(dims), ref_net, "aten::tile"
+ return aten_tile(dims), "aten::tile"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_to.py b/tests/layer_tests/pytorch_tests/test_to.py
index b54472353f8..c83ee74f042 100644
--- a/tests/layer_tests/pytorch_tests/test_to.py
+++ b/tests/layer_tests/pytorch_tests/test_to.py
@@ -5,20 +5,19 @@ import numpy as np
import pytest
import torch
-from openvino.frontend import OpConversionFailure
from pytorch_layer_test_class import PytorchLayerTest
class TestAtenTo(PytorchLayerTest):
def _prepare_input(self, input_shape=(3,)):
- return (np.random.uniform(low=0.0, high=50.0, size=input_shape),)
+ return (self.random.uniform(low=0.0, high=50.0, size=input_shape),)
def create_model(self, type, non_blocking=False, copy=False, memory_format=None):
import torch
class aten_to(torch.nn.Module):
def __init__(self, type, non_blocking=False, copy=False, memory_format=None):
- super(aten_to, self).__init__()
+ super().__init__()
self.type = type
self.non_blocking = non_blocking
self.copy = copy
@@ -27,9 +26,8 @@ class TestAtenTo(PytorchLayerTest):
def forward(self, x):
return x.to(self.type, self.non_blocking, self.copy, self.memory_format)
- ref_net = None
- return aten_to(type, non_blocking, copy, memory_format), ref_net, "aten::to"
+ return aten_to(type, non_blocking, copy, memory_format), "aten::to"
# Cartesian product of input/output types
@pytest.mark.parametrize("input_type", [np.int32, np.float32, np.float64])
@@ -103,7 +101,7 @@ class TestAtenTo(PytorchLayerTest):
class TestAtenToDevice(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.uniform(low=0.0, high=50.0, size=(3,)), np.random.uniform(low=0.0, high=50.0, size=(3,)))
+ return (self.random.uniform(low=0.0, high=50.0, size=(3,)), self.random.uniform(low=0.0, high=50.0, size=(3,)))
def create_model(self):
import torch
@@ -113,9 +111,8 @@ class TestAtenToDevice(PytorchLayerTest):
def forward(self, x, y):
return x.to(y.device)
- ref_net = None
- return aten_to(), ref_net, "aten::to"
+ return aten_to(), "aten::to"
@pytest.mark.parametrize("use_trace", [True, False])
@pytest.mark.nightly
@@ -127,7 +124,7 @@ class TestAtenToDevice(PytorchLayerTest):
class TestAtenToDeviceConst(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.uniform(low=0.0, high=50.0, size=(3,)),)
+ return (self.random.uniform(low=0.0, high=50.0, size=(3,)),)
def create_model(self):
import torch
@@ -137,9 +134,8 @@ class TestAtenToDeviceConst(PytorchLayerTest):
def forward(self, x):
return x.to("cpu")
- ref_net = None
- return aten_to(), ref_net, "aten::to"
+ return aten_to(), "aten::to"
@pytest.mark.parametrize("use_trace", [True, False])
@pytest.mark.nightly
@@ -151,7 +147,7 @@ class TestAtenToDeviceConst(PytorchLayerTest):
class TestAtenToComplex(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 3),)
+ return (self.random.randn(2, 3),)
def create_model(self, dtype):
import torch
@@ -164,7 +160,7 @@ class TestAtenToComplex(PytorchLayerTest):
def forward(self, x):
return torch.view_as_real(x.to(self.dtype))
- return aten_to_complex(dtype), None, "aten::to"
+ return aten_to_complex(dtype), "aten::to"
@pytest.mark.parametrize("dtype", [torch.complex32,
torch.complex64,
@@ -179,7 +175,7 @@ class TestAtenToComplex(PytorchLayerTest):
class TestAtenToFromComplex(PytorchLayerTest):
def _prepare_input(self):
# double conversion to avoid accuracy issues due to different precision
- return (np.random.randn(2, 3, 2).astype(np.float16).astype(np.float32),)
+ return (self.random.randn(2, 3, 2, dtype=np.float16),)
def create_model(self, dtype):
import torch
@@ -193,7 +189,7 @@ class TestAtenToFromComplex(PytorchLayerTest):
c = torch.view_as_complex(x.to(self.dtype))
return c.to(torch.float32)
- return aten_to_from_complex(dtype), None, "aten::to"
+ return aten_to_from_complex(dtype), "aten::to"
@pytest.mark.parametrize("dtype", [torch.float16,
torch.float32,
@@ -208,7 +204,7 @@ class TestAtenToFromComplex(PytorchLayerTest):
class TestAtenToFromComplexTensor(PytorchLayerTest):
def _prepare_input(self):
# double conversion to avoid accuracy issues due to different precision
- return (np.random.randn(2, 3, 2).astype(np.float16).astype(np.float32),)
+ return (self.random.randn(2, 3, 2, dtype=np.float16),)
def create_model(self, dtype):
import torch
@@ -222,7 +218,7 @@ class TestAtenToFromComplexTensor(PytorchLayerTest):
c = torch.view_as_complex(x.to(self.dtype))
return c.to(x.dtype)
- return aten_to_from_complex(dtype), None, "aten::to"
+ return aten_to_from_complex(dtype), "aten::to"
@pytest.mark.parametrize("dtype", [torch.float16,
torch.float32,
diff --git a/tests/layer_tests/pytorch_tests/test_topk.py b/tests/layer_tests/pytorch_tests/test_topk.py
index f5c45516eaa..a868620e696 100644
--- a/tests/layer_tests/pytorch_tests/test_topk.py
+++ b/tests/layer_tests/pytorch_tests/test_topk.py
@@ -1,8 +1,5 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import os
-
-import numpy as np
import pytest
from pytorch_layer_test_class import PytorchLayerTest
@@ -17,7 +14,7 @@ class TestTopK(PytorchLayerTest):
class aten_topk(torch.nn.Module):
def __init__(self, k, dim, largest, sort):
- super(aten_topk, self).__init__()
+ super().__init__()
self.k = k
self.dim = dim
self.largest = largest
@@ -28,9 +25,8 @@ class TestTopK(PytorchLayerTest):
return torch.topk(input_tensor, k=self.k, largest=self.largest, sorted=self.sort)
else:
return torch.topk(input_tensor, k=self.k, dim=self.dim, largest=self.largest, sorted=self.sort)
- ref_net = None
- return aten_topk(k, dim, largest, sort), ref_net, "aten::topk"
+ return aten_topk(k, dim, largest, sort), "aten::topk"
@pytest.mark.parametrize(("input_shape"), [
[7, 5, 5, 4],
@@ -64,6 +60,5 @@ class TestTopK(PytorchLayerTest):
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_topK(self, input_shape, k, dim, largest, sort, ie_device, precision, ir_version):
- rng = np.random.default_rng(43)
- self.input_tensor = rng.normal(size=(input_shape)).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
self._test(*self.create_model(k, dim, largest, sort), ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_transpose.py b/tests/layer_tests/pytorch_tests/test_transpose.py
index d1010c75352..0332518e7ef 100644
--- a/tests/layer_tests/pytorch_tests/test_transpose.py
+++ b/tests/layer_tests/pytorch_tests/test_transpose.py
@@ -9,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestTranspose(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 3, 4, 5).astype(np.float32),)
+ return (self.random.randn(2, 3, 4, 5),)
def create_model(self, dim0, dim1, op_type):
class swapaxes(torch.nn.Module):
@@ -23,7 +23,7 @@ class TestTranspose(PytorchLayerTest):
class aten_transpose(torch.nn.Module):
def __init__(self, dim0, dim1, op_type):
- super(aten_transpose, self).__init__()
+ super().__init__()
self.dim0 = dim0
self.dim1 = dim1
op_types = {"transpose": self.forward_transpose, "swapaxes": self.forward_swapaxes}
@@ -37,9 +37,8 @@ class TestTranspose(PytorchLayerTest):
# To reproduce aten::swapaxes in graph, swapaxes need to be in separate graph and tracing need to be used.
return self.swapaxes(x)
- ref_net = None
- return aten_transpose(dim0, dim1, op_type), ref_net, f"aten::{op_type}"
+ return aten_transpose(dim0, dim1, op_type), f"aten::{op_type}"
@pytest.mark.parametrize("dim0", [0, 1, 2, 3, -1, -2, -3, -4])
@pytest.mark.parametrize("dim1", [0, 1, 2, 3, -1, -2, -3, -4])
@@ -52,21 +51,20 @@ class TestTranspose(PytorchLayerTest):
class TestMoveDim(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(2, 3, 4, 5).astype(np.float32),)
+ return (self.random.randn(2, 3, 4, 5),)
def create_model(self, dim0, dim1):
class aten_move_dim(torch.nn.Module):
def __init__(self, dim0, dim1):
- super(aten_move_dim, self).__init__()
+ super().__init__()
self.dim0 = dim0
self.dim1 = dim1
def forward(self, x):
return torch.movedim(x, self.dim0, self.dim1)
- ref_net = None
- return aten_move_dim(dim0, dim1), ref_net, f"aten::movedim"
+ return aten_move_dim(dim0, dim1), f"aten::movedim"
@pytest.mark.parametrize(("dim0", "dim1"), [[0, 1], [-1, 0], [2, -2], [3, 1], [3, 3], [[1, 2], [3, 0]], [[-4, 1], [1, -1]], [[1, 3, 2], [0, 1, 2 ]]])
@pytest.mark.nightly
@@ -79,12 +77,12 @@ class TestTSmall(PytorchLayerTest):
shape = (2, 3)
if num_dims == 0:
return (np.array(num_dims).astype(input_dtype),)
- return (np.random.randn(*shape[:num_dims]).astype(input_dtype),)
+ return (self.random.randn(*shape[:num_dims], dtype=input_dtype),)
def create_model(self, mode):
class aten_transpose(torch.nn.Module):
def __init__(self, mode):
- super(aten_transpose, self).__init__()
+ super().__init__()
if mode == "inplace":
self.forward = self.forward_inplace
elif mode == "numpy":
@@ -99,9 +97,8 @@ class TestTSmall(PytorchLayerTest):
def forward_numpy_t(self, x):
return x.T, x
- ref_net = None
- return aten_transpose(mode), ref_net, "aten::t_" if mode == "inplace" else ("aten::numpy_T" if mode == "numpy" else "aten::t")
+ return aten_transpose(mode), "aten::t_" if mode == "inplace" else ("aten::numpy_T" if mode == "numpy" else "aten::t")
@pytest.mark.parametrize("num_dims", [0, 1, 2])
@pytest.mark.parametrize("input_dtype", ["float32", "int32"])
diff --git a/tests/layer_tests/pytorch_tests/test_trilu.py b/tests/layer_tests/pytorch_tests/test_trilu.py
index 83256e0883b..b476a670169 100644
--- a/tests/layer_tests/pytorch_tests/test_trilu.py
+++ b/tests/layer_tests/pytorch_tests/test_trilu.py
@@ -8,8 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestTriuTril(PytorchLayerTest):
def _prepare_input(self, shape, dtype):
- import numpy as np
- return (np.random.randn(*shape).astype(dtype),)
+ return (self.random.randn(*shape, dtype=dtype),)
def create_model(self, op, diagonal):
@@ -24,16 +23,15 @@ class TestTriuTril(PytorchLayerTest):
class aten_trilu(torch.nn.Module):
def __init__(self, op, diagonal):
- super(aten_trilu, self).__init__()
+ super().__init__()
self.op = op
self.diagonal = diagonal
def forward(self, x):
return self.op(x, self.diagonal)
- ref_net = None
- return aten_trilu(pt_op, diagonal), ref_net, f"aten::{op}"
+ return aten_trilu(pt_op, diagonal), f"aten::{op}"
@pytest.mark.parametrize("dtype", ["float32", "float64", "int32", "int64", "int8", "uint8", "bool"])
@pytest.mark.parametrize("diagonal", [0, 1, 2, -1, -2])
@@ -48,8 +46,7 @@ class TestTriuTril(PytorchLayerTest):
class TestTriuTrilTensor(PytorchLayerTest):
def _prepare_input(self, shape, dtype):
- import numpy as np
- return (np.random.randn(*shape).astype(dtype),)
+ return (self.random.randn(*shape, dtype=dtype),)
def create_model(self, op, diagonal):
@@ -57,7 +54,7 @@ class TestTriuTrilTensor(PytorchLayerTest):
class aten_trilu(torch.nn.Module):
def __init__(self, op, diagonal):
- super(aten_trilu, self).__init__()
+ super().__init__()
op_map = {
"tril": self.tril,
"tril_": self.tril_,
@@ -79,9 +76,8 @@ class TestTriuTrilTensor(PytorchLayerTest):
def triu_(self, x):
return x.triu_(self.diagonal), x
- ref_net = None
- return aten_trilu(op, diagonal), ref_net, f"aten::{op}"
+ return aten_trilu(op, diagonal), f"aten::{op}"
@pytest.mark.parametrize("dtype", ["float32", "float64", "int32", "int64", "int8", "uint8", "bool"])
@pytest.mark.parametrize("diagonal", [0, 1, 2, -1, -2])
diff --git a/tests/layer_tests/pytorch_tests/test_tuple_construct.py b/tests/layer_tests/pytorch_tests/test_tuple_construct.py
index 7b7edf004f7..fd47424e130 100644
--- a/tests/layer_tests/pytorch_tests/test_tuple_construct.py
+++ b/tests/layer_tests/pytorch_tests/test_tuple_construct.py
@@ -8,7 +8,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestTupleConstruct(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.uniform(0, 50, (1, 10)).astype(np.float32),)
+ return (self.random.uniform(0, 50, (1, 10), dtype=np.float32),)
def create_model(self, case):
import torch
@@ -26,7 +26,7 @@ class TestTupleConstruct(PytorchLayerTest):
class prim_tuple_construct_with_none(torch.nn.Module):
def forward(self, x):
- return (x, None, x + x, None)
+ return (x, x + x, None)
class prim_tuple_construct_with_list(torch.nn.Module):
@@ -52,10 +52,9 @@ class TestTupleConstruct(PytorchLayerTest):
"list_and_tuple": prim_tuple_construct_with_list_and_tuple
}
- ref_net = None
model = cases[case]
- return model(), ref_net, "prim::TupleConstruct"
+ return model(), "prim::TupleConstruct"
@pytest.mark.parametrize("case", ["single", "multiple", "none", "list", "tensor_tail", "list_and_tuple"])
@pytest.mark.nightly
@@ -65,7 +64,7 @@ class TestTupleConstruct(PytorchLayerTest):
class TestTupleConstructTupleUnpack(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32),)
+ return (self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32),)
def create_model(self):
import torch
@@ -79,9 +78,8 @@ class TestTupleConstructTupleUnpack(PytorchLayerTest):
def prepare_input(self, x):
return x, x + 2, None, x.reshape(-1), (x * 10).to(torch.int32)
- ref_net = None
- return prim_tuple_construct_tuple_unpack(), ref_net, ["prim::TupleConstruct", "prim::TupleUnpack"]
+ return prim_tuple_construct_tuple_unpack(), ["prim::TupleConstruct", "prim::TupleUnpack"]
@pytest.mark.nightly
def test_tuple_construct_unpack(self, ie_device, precision, ir_version):
@@ -92,7 +90,7 @@ class TestTupleConstructTupleUnpack(PytorchLayerTest):
class TestTupleUnpackParameterSingle(PytorchLayerTest):
def _prepare_input(self):
def tensor_gen():
- return np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32)
+ return self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32)
return ((tensor_gen(), tensor_gen()), )
def create_model(self):
@@ -104,7 +102,7 @@ class TestTupleUnpackParameterSingle(PytorchLayerTest):
x1, x2 = x
return x1, x2
- return model(), None, ["prim::TupleUnpack"]
+ return model(), ["prim::TupleUnpack"]
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
@@ -114,11 +112,11 @@ class TestTupleUnpackParameterSingle(PytorchLayerTest):
class TestTupleUnpackParameterSingleMixed(PytorchLayerTest):
def _prepare_input(self):
def tensor_gen():
- return np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32)
+ return self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32)
# generate tensor with a different shape for easier mismatch detection in case of mixed input order
def tensor_gen_2():
- return np.random.uniform(0, 50, (2, 3)).astype(np.float32)
+ return self.random.uniform(0, 50, (2, 3), dtype=np.float32)
return (tensor_gen_2(), (tensor_gen(), tensor_gen()), tensor_gen_2())
def create_model(self):
@@ -130,7 +128,7 @@ class TestTupleUnpackParameterSingleMixed(PytorchLayerTest):
x1, x2 = x
return x1, x2, y1, y2
- return model(), None, ["prim::TupleUnpack"]
+ return model(), ["prim::TupleUnpack"]
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
@@ -140,7 +138,7 @@ class TestTupleUnpackParameterSingleMixed(PytorchLayerTest):
class TestTupleUnpackParameterNested(PytorchLayerTest):
def _prepare_input(self):
def tensor_gen():
- return np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32)
+ return self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32)
return (((tensor_gen(), tensor_gen()), (tensor_gen(), tensor_gen())), )
def create_model(self):
@@ -154,7 +152,7 @@ class TestTupleUnpackParameterNested(PytorchLayerTest):
y3, y4 = x2
return y1, y2, y3, y4
- return model(), None, ["prim::TupleUnpack"]
+ return model(), ["prim::TupleUnpack"]
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
@@ -164,7 +162,7 @@ class TestTupleUnpackParameterNested(PytorchLayerTest):
class TestTupleUnpackParameterMultiple(PytorchLayerTest):
def _prepare_input(self):
def tensor_gen():
- return np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32)
+ return self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32)
return ((tensor_gen(), tensor_gen()), (tensor_gen(), tensor_gen()))
def create_model(self):
@@ -177,7 +175,7 @@ class TestTupleUnpackParameterMultiple(PytorchLayerTest):
z3, z4 = y
return z1, z2, z3, z4
- return model(), None, ["prim::TupleUnpack"]
+ return model(), ["prim::TupleUnpack"]
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
@@ -186,7 +184,7 @@ class TestTupleUnpackParameterMultiple(PytorchLayerTest):
class TestTupleIndex(PytorchLayerTest):
def _prepare_input(self):
- return np.random.uniform(0, 50, (1, 2, 10)).astype(np.float32)
+ return self.random.uniform(0, 50, (1, 2, 10), dtype=np.float32)
def create_model(self):
import torch
@@ -198,7 +196,7 @@ class TestTupleIndex(PytorchLayerTest):
def some_func(self, x: tuple[torch.Tensor, torch.Tensor]):
return x[1] * 2, x[0] * 3
- return model(), None, "prim::TupleIndex"
+ return model(), "prim::TupleIndex"
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
@@ -208,7 +206,7 @@ class TestTupleIndex(PytorchLayerTest):
class TestTcOutsideTuInsideIfBody(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.randn(1, 2, 10).astype(np.float32), np.random.randn(1, 2, 10).astype(np.float32))
+ return (self.random.randn(1, 2, 10), self.random.randn(1, 2, 10))
def create_model(self):
import torch
@@ -225,7 +223,7 @@ class TestTcOutsideTuInsideIfBody(PytorchLayerTest):
n, m = x
return n - m
- return model(), None, ["prim::TupleConstruct", "prim::TupleUnpack", "prim::If"]
+ return model(), ["prim::TupleConstruct", "prim::TupleUnpack", "prim::If"]
@pytest.mark.nightly
def test(self, ie_device, precision, ir_version):
diff --git a/tests/layer_tests/pytorch_tests/test_tuple_unpack.py b/tests/layer_tests/pytorch_tests/test_tuple_unpack.py
index a56a44ac3cd..68077a3efd3 100644
--- a/tests/layer_tests/pytorch_tests/test_tuple_unpack.py
+++ b/tests/layer_tests/pytorch_tests/test_tuple_unpack.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -10,8 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestTupleUnpack(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 4, 6, 8).astype(np.float32),)
+ return (self.random.randn(2, 4, 6, 8),)
def create_model(self):
@@ -26,7 +24,7 @@ class TestTupleUnpack(PytorchLayerTest):
N, _, H, W = self.dims
return input_data * N * H * W
- return TupleArgument(), None, "prim::TupleUnpack"
+ return TupleArgument(), "prim::TupleUnpack"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -49,16 +47,14 @@ class TestComplexTupleUnpack(PytorchLayerTest):
"""
def _prepare_input(self):
- rng = np.random.default_rng(43)
- return (rng.standard_normal((2, 4, 2)).astype(np.float32),)
+ return (self.random.randn(2, 4, 2),)
def create_model(self):
class ComplexTupleUnpack(torch.nn.Module):
- def __init__(self):
+ def __init__(self, rng):
super().__init__()
# Use separate buffers instead of tuple
- g = torch.Generator().manual_seed(42)
- freqs = torch.randn(4, 2, generator=g)
+ freqs = rng.torch_randn(4, 2)
complex_freqs = torch.view_as_complex(freqs)
self.register_buffer('freqs_a', torch.view_as_real(complex_freqs))
self.register_buffer('freqs_b', torch.view_as_real(complex_freqs * 2))
@@ -71,7 +67,7 @@ class TestComplexTupleUnpack(PytorchLayerTest):
result = complex_x * a + complex_x * b
return torch.view_as_real(result)
- return ComplexTupleUnpack(), None, "aten::mul"
+ return ComplexTupleUnpack(self.random), "aten::mul"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -84,15 +80,13 @@ class TestComplexTupleUnpackMultiple(PytorchLayerTest):
"""Test TupleUnpack with multiple complex tensor outputs."""
def _prepare_input(self):
- rng = np.random.default_rng(43)
- return (rng.standard_normal((2, 4, 2)).astype(np.float32),)
+ return (self.random.randn(2, 4, 2),)
def create_model(self):
class ComplexTupleUnpackMultiple(torch.nn.Module):
- def __init__(self):
+ def __init__(self, rng):
super().__init__()
- g = torch.Generator().manual_seed(42)
- freqs = torch.randn(4, 2, generator=g)
+ freqs = rng.torch_randn(4, 2)
complex_freqs = torch.view_as_complex(freqs)
self.register_buffer('freqs_a', torch.view_as_real(complex_freqs))
self.register_buffer('freqs_b', torch.view_as_real(complex_freqs * 2))
@@ -106,7 +100,7 @@ class TestComplexTupleUnpackMultiple(PytorchLayerTest):
result = complex_x * a + complex_x * b + complex_x * c
return torch.view_as_real(result)
- return ComplexTupleUnpackMultiple(), None, "aten::mul"
+ return ComplexTupleUnpackMultiple(self.random), "aten::mul"
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_type_as.py b/tests/layer_tests/pytorch_tests/test_type_as.py
index c2dda54308a..23d50e6ba13 100644
--- a/tests/layer_tests/pytorch_tests/test_type_as.py
+++ b/tests/layer_tests/pytorch_tests/test_type_as.py
@@ -9,7 +9,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestTypeAs(PytorchLayerTest):
def _prepare_input(self, input_dtype=np.float32, cast_dtype=np.float32):
- input_data = np.random.randint(127, size=(1, 3, 224, 224))
+ input_data = self.random.randint(127, size=(1, 3, 224, 224))
return (input_data.astype(input_dtype), input_data.astype(cast_dtype))
def create_model(self):
@@ -20,9 +20,8 @@ class TestTypeAs(PytorchLayerTest):
def forward(self, x, y):
return x.type_as(y)
- ref_net = None
- return aten_type_as(), ref_net, "aten::type_as"
+ return aten_type_as(), "aten::type_as"
@pytest.mark.parametrize("input_dtype", [np.float64, np.float32, np.int64, np.int32, np.int16, np.int8, np.uint8])
@pytest.mark.parametrize("cast_dtype", [np.float64, np.float32, np.int64, np.int32, np.int16, np.int8, np.uint8])
@@ -39,9 +38,8 @@ class TestComplexTypeAs(PytorchLayerTest):
def _prepare_input(self, input_dtype=np.float32, cast_dtype=np.float64):
# Complex tensor represented as real with shape [..., 2]
- rng = np.random.default_rng(43)
- return (rng.standard_normal((2, 4, 2)).astype(input_dtype),
- rng.standard_normal((2, 4, 2)).astype(cast_dtype))
+ return (self.random.randn(2, 4, 2, dtype=input_dtype),
+ self.random.randn(2, 4, 2, dtype=cast_dtype))
def create_model(self):
import torch
@@ -54,7 +52,7 @@ class TestComplexTypeAs(PytorchLayerTest):
result = cx.type_as(cy)
return torch.view_as_real(result)
- return ComplexTypeAs(), None, "aten::type_as"
+ return ComplexTypeAs(), "aten::type_as"
@pytest.mark.parametrize("input_dtype", [np.float32, np.float64])
@pytest.mark.parametrize("cast_dtype", [np.float32, np.float64])
diff --git a/tests/layer_tests/pytorch_tests/test_unary_ops.py b/tests/layer_tests/pytorch_tests/test_unary_ops.py
index df235572520..ea3d9be1949 100644
--- a/tests/layer_tests/pytorch_tests/test_unary_ops.py
+++ b/tests/layer_tests/pytorch_tests/test_unary_ops.py
@@ -138,7 +138,7 @@ class unary_op_complex_net(torch.nn.Module):
class TestUnaryOp(PytorchLayerTest):
def _prepare_input(self):
# random number in range [1, 11)
- x = torch.rand(2, 10) * 10 + 1
+ x = self.random.torch_rand(2, 10) * 10 + 1
return (x.to(self.dtype).numpy(),)
@pytest.mark.nightly
@@ -185,7 +185,7 @@ class TestUnaryOp(PytorchLayerTest):
self.dtype = dtype
if self.use_torch_export() and op_type == "aten::atanh" and dtype in [torch.int8, torch.int32, torch.int64]:
pytest.xfail(reason="torch.export after 2.4.0 doesn't support unsigned int types for atanh in some configurations")
- self._test(unary_op_net(OPS[op_type], dtype), None, op_type,
+ self._test(unary_op_net(OPS[op_type], dtype), op_type,
ie_device, precision, ir_version)
@pytest.mark.nightly
@@ -232,7 +232,7 @@ class TestUnaryOp(PytorchLayerTest):
self.dtype = dtype
if self.use_torch_compile_backend() and op_type == "aten::sigmoid_":
pytest.xfail(reason="Accuracy issue, one or two values are off sometimes")
- self._test(unary_op_net(OPS[op_type], dtype), None, op_type,
+ self._test(unary_op_net(OPS[op_type], dtype), op_type,
ie_device, precision, ir_version)
@pytest.mark.nightly
@@ -272,7 +272,7 @@ class TestUnaryOp(PytorchLayerTest):
])
def test_unary_op_out(self, op_type, dtype, ie_device, precision, ir_version):
self.dtype = dtype
- self._test(unary_op_out_net(OPS[op_type], dtype), None, op_type,
+ self._test(unary_op_out_net(OPS[op_type], dtype), op_type,
ie_device, precision, ir_version)
@pytest.mark.nightly
@@ -288,7 +288,7 @@ class TestUnaryOp(PytorchLayerTest):
])
def test_unary_func_op_inplace(self, op_type, dtype, ie_device, precision, ir_version):
self.dtype = dtype
- self._test(unary_func_op_inplace_net(OPS[op_type], dtype), None, op_type + "_",
+ self._test(unary_func_op_inplace_net(OPS[op_type], dtype), op_type + "_",
ie_device, precision, ir_version)
@pytest.mark.nightly
@@ -298,7 +298,7 @@ class TestUnaryOp(PytorchLayerTest):
@pytest.mark.parametrize("dtype", [torch.float32, torch.float64, torch.int8, torch.uint8, torch.int32, torch.int64])
def test_prim_abs(self, dtype, ie_device, precision, ir_version):
self.dtype = dtype
- self._test(prim_abs_net(dtype), None, "prim::abs",
+ self._test(prim_abs_net(dtype), "prim::abs",
ie_device, precision, ir_version, fx_kind="aten.abs")
@pytest.mark.nightly
@@ -311,5 +311,5 @@ class TestUnaryOp(PytorchLayerTest):
])
def test_complex_unary_op(self, op_type, dtype, ie_device, precision, ir_version):
self.dtype = dtype
- self._test(unary_op_complex_net(OPS[op_type], dtype), None, op_type,
+ self._test(unary_op_complex_net(OPS[op_type], dtype), op_type,
ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_unbind.py b/tests/layer_tests/pytorch_tests/test_unbind.py
index 66beb7fd832..5a3abb8725d 100644
--- a/tests/layer_tests/pytorch_tests/test_unbind.py
+++ b/tests/layer_tests/pytorch_tests/test_unbind.py
@@ -9,14 +9,14 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestUnbind(PytorchLayerTest):
def _prepare_input(self):
- return (np.random.uniform(0, 50, (3, 3, 3, 3)).astype(np.float32),)
+ return (self.random.uniform(0, 50, (3, 3, 3, 3), dtype=np.float32),)
def create_model(self, shape):
import torch
class aten_unbind(torch.nn.Module):
def __init__(self, dim):
- super(aten_unbind, self).__init__()
+ super().__init__()
self.dim = dim
def forward(self, x):
@@ -24,9 +24,8 @@ class TestUnbind(PytorchLayerTest):
a, b, c = torch.unbind(x, self.dim)
return b
- ref_net = None
- return aten_unbind(shape), ref_net, "aten::unbind"
+ return aten_unbind(shape), "aten::unbind"
@pytest.mark.parametrize(("dim"), [0, 1, 2, 3])
@pytest.mark.nightly
diff --git a/tests/layer_tests/pytorch_tests/test_unflatten.py b/tests/layer_tests/pytorch_tests/test_unflatten.py
index 84fb8095b09..1046a9ba6cb 100644
--- a/tests/layer_tests/pytorch_tests/test_unflatten.py
+++ b/tests/layer_tests/pytorch_tests/test_unflatten.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
from pytorch_layer_test_class import PytorchLayerTest
@@ -9,23 +8,22 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestUnflatten(PytorchLayerTest):
def _prepare_input(self, dtype):
- return (np.random.uniform(0, 50, (6, 3, 4)).astype(dtype),)
+ return (self.random.uniform(0, 50, (6, 3, 4), dtype=dtype),)
def create_model(self, dim, shape):
import torch
class aten_unflatten(torch.nn.Module):
def __init__(self, dim, shape):
- super(aten_unflatten, self).__init__()
+ super().__init__()
self.dim = dim
self.shape = shape
def forward(self, x):
return x.unflatten(self.dim, self.shape)
- ref_net = None
- return aten_unflatten(dim, shape), ref_net, "aten::unflatten"
+ return aten_unflatten(dim, shape), "aten::unflatten"
@pytest.mark.parametrize(("dim", "shape"), [(0, [2, 1, 3]), (1, [1, 3]), (2, (2, -1)), (-1, (2, 2)), (-2, (-1, 1))])
@pytest.mark.parametrize("dtype", ["float32", "int32"])
@@ -38,14 +36,14 @@ class TestUnflatten(PytorchLayerTest):
class TestUnflattenListSizes(PytorchLayerTest):
def _prepare_input(self, dtype):
- return (np.random.uniform(0, 50, (6, 2, 4)).astype(dtype),)
+ return (self.random.uniform(0, 50, (6, 2, 4), dtype=dtype),)
def create_model(self, dim):
import torch
class aten_unflatten(torch.nn.Module):
def __init__(self, dim):
- super(aten_unflatten, self).__init__()
+ super().__init__()
self.dim = dim
def forward(self, x):
@@ -58,9 +56,8 @@ class TestUnflattenListSizes(PytorchLayerTest):
sizes = [2, dim3 // 2, -1]
return x.unflatten(self.dim, sizes)
- ref_net = None
- return aten_unflatten(dim), ref_net, "aten::unflatten"
+ return aten_unflatten(dim), "aten::unflatten"
@pytest.mark.parametrize("dim", [0, 1, 2])
@pytest.mark.parametrize("dtype", ["float32", "int32"])
diff --git a/tests/layer_tests/pytorch_tests/test_unfold.py b/tests/layer_tests/pytorch_tests/test_unfold.py
index 3b9c184347f..14de942d97a 100644
--- a/tests/layer_tests/pytorch_tests/test_unfold.py
+++ b/tests/layer_tests/pytorch_tests/test_unfold.py
@@ -1,7 +1,6 @@
# Copyright (C) 2018-2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
-import numpy as np
import pytest
import torch
@@ -32,16 +31,15 @@ class TestUnfold(PytorchLayerTest):
def forward(self, input_tensor):
return input_tensor.unfold(dimension=self.dimension, size=self.size, step=self.step)
- ref_net = None
- return aten_unfold(dimension, size, step), ref_net, "aten::unfold"
+ return aten_unfold(dimension, size, step), "aten::unfold"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_unfold(self, ie_device, precision, ir_version, dimension, size, step, input_shape):
- self.input_tensor = np.random.randn(*input_shape).astype(np.float32)
+ self.input_tensor = self.random.randn(*input_shape)
dyn_shape = True
if ie_device == "GPU" and size == 1 and step == 1:
dyn_shape = False
diff --git a/tests/layer_tests/pytorch_tests/test_unique.py b/tests/layer_tests/pytorch_tests/test_unique.py
index b86d07b1f56..f0de3a6fb16 100644
--- a/tests/layer_tests/pytorch_tests/test_unique.py
+++ b/tests/layer_tests/pytorch_tests/test_unique.py
@@ -19,7 +19,7 @@ class TestUnique2(PytorchLayerTest):
class aten_unique2_return_first(torch.nn.Module):
def __init__(self, sorted):
- super(aten_unique2_return_first, self).__init__()
+ super().__init__()
self.op = torch._unique2
self.sorted = sorted
@@ -29,7 +29,7 @@ class TestUnique2(PytorchLayerTest):
class aten_unique2_return_second(torch.nn.Module):
def __init__(self, sorted):
- super(aten_unique2_return_second, self).__init__()
+ super().__init__()
self.op = torch._unique2
self.sorted = sorted
@@ -39,7 +39,7 @@ class TestUnique2(PytorchLayerTest):
class aten_unique2_return_both(torch.nn.Module):
def __init__(self, sorted):
- super(aten_unique2_return_both, self).__init__()
+ super().__init__()
self.op = torch._unique2
self.sorted = sorted
@@ -49,7 +49,7 @@ class TestUnique2(PytorchLayerTest):
class aten_unique2_return_neither(torch.nn.Module):
def __init__(self, sorted):
- super(aten_unique2_return_neither, self).__init__()
+ super().__init__()
self.op = torch._unique2
self.sorted = sorted
@@ -66,7 +66,7 @@ class TestUnique2(PytorchLayerTest):
else:
model_class, op = (aten_unique2_return_neither, "aten::_unique2")
- return model_class(sorted), None, op
+ return model_class(sorted), op
@pytest.mark.parametrize("input_shape", [
[115], [24, 30], [5, 4, 6], [3, 7, 1, 4], [16, 3, 32, 32]
@@ -79,5 +79,5 @@ class TestUnique2(PytorchLayerTest):
def test_unique2(self, input_shape, sorted, return_inverse, return_counts, ie_device, precision, ir_version):
if sys.platform == "win32" and input_shape == [16, 3, 32, 32] and parse_version(torch.__version__).release == (2, 4, 0):
pytest.skip(reason="torch==2.4.0 fails on windows, but is fixed in nightly.")
- self.input_tensor = np.random.randint(0, 10, size=input_shape).astype(np.int32)
+ self.input_tensor = self.random.randint(0, 10, size=input_shape, dtype=np.int32)
self._test(*self.create_model(sorted, return_inverse, return_counts), ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_unsqueeze.py b/tests/layer_tests/pytorch_tests/test_unsqueeze.py
index 7f7919badc5..f9fd4df5205 100644
--- a/tests/layer_tests/pytorch_tests/test_unsqueeze.py
+++ b/tests/layer_tests/pytorch_tests/test_unsqueeze.py
@@ -8,15 +8,14 @@ from pytorch_layer_test_class import PytorchLayerTest, skip_if_export
class TestUnsqueeze(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(5, 10).astype(np.float32),)
+ return (self.random.randn(5, 10),)
def create_model(self, inplace=False, dim=0):
import torch
class aten_unsqueeze(torch.nn.Module):
def __init__(self, dim):
- super(aten_unsqueeze, self).__init__()
+ super().__init__()
self.op = torch.unsqueeze
self.dim = dim
@@ -25,16 +24,15 @@ class TestUnsqueeze(PytorchLayerTest):
class aten_unsqueeze_(torch.nn.Module):
def __init__(self, dim):
- super(aten_unsqueeze_, self).__init__()
+ super().__init__()
self.dim = dim
def forward(self, x):
return x, x.unsqueeze_(self.dim)
- ref_net = None
model_class, op = (aten_unsqueeze, "aten::unsqueeze") if not inplace else (aten_unsqueeze_, "aten::unsqueeze_")
- return model_class(dim), ref_net, op
+ return model_class(dim), op
@pytest.mark.parametrize("inplace", [False, skip_if_export(True)])
@pytest.mark.parametrize("dim", [0, 1, -1])
@@ -47,25 +45,23 @@ class TestUnsqueeze(PytorchLayerTest):
class TestUnsqueezeCopy(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(5, 10).astype(np.float32),)
+ return (self.random.randn(5, 10),)
def create_model(self, dim=0):
import torch
class aten_unsqueeze_copy(torch.nn.Module):
def __init__(self, dim):
- super(aten_unsqueeze_copy, self).__init__()
+ super().__init__()
self.op = torch.unsqueeze_copy
self.dim = dim
def forward(self, x):
return x, self.op(x, self.dim)
- ref_net = None
model_class, op = (aten_unsqueeze_copy, "aten::unsqueeze_copy")
- return model_class(dim), ref_net, op
+ return model_class(dim), op
@pytest.mark.parametrize("dim", [0, 1, -1])
@pytest.mark.precommit_fx_backend
@@ -74,15 +70,14 @@ class TestUnsqueezeCopy(PytorchLayerTest):
class TestUnsqueezeWithComplex(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(2, 3, 2).astype(np.float32),)
+ return (self.random.randn(2, 3, 2),)
def create_model(self, inplace=False, dim=0):
import torch
class aten_unsqueeze(torch.nn.Module):
def __init__(self, dim):
- super(aten_unsqueeze, self).__init__()
+ super().__init__()
self.op = torch.unsqueeze
self.dim = dim
@@ -92,17 +87,16 @@ class TestUnsqueezeWithComplex(PytorchLayerTest):
class aten_unsqueeze_(torch.nn.Module):
def __init__(self, dim):
- super(aten_unsqueeze_, self).__init__()
+ super().__init__()
self.dim = dim
def forward(self, x):
x = torch.view_as_complex(x)
return torch.view_as_real(x.unsqueeze_(self.dim))
- ref_net = None
model_class, op = (aten_unsqueeze, "aten::unsqueeze") if not inplace else (aten_unsqueeze_, "aten::unsqueeze_")
- return model_class(dim), ref_net, op
+ return model_class(dim), op
@pytest.mark.parametrize("inplace", [False, skip_if_export(True)])
@pytest.mark.parametrize("dim", [0, 1, -1, -2])
diff --git a/tests/layer_tests/pytorch_tests/test_upsample.py b/tests/layer_tests/pytorch_tests/test_upsample.py
index dc46fed75bb..56dbf99e2cc 100644
--- a/tests/layer_tests/pytorch_tests/test_upsample.py
+++ b/tests/layer_tests/pytorch_tests/test_upsample.py
@@ -10,8 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestUpsample1D(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224).astype(np.float32),)
+ return (self.random.randn(1, 3, 224),)
def create_model(self, size, scale, mode):
import torch
@@ -27,9 +26,8 @@ class TestUpsample1D(PytorchLayerTest):
def forward(self, x):
return F.interpolate(x, self.size, scale_factor=self.scale, mode=self.mode)
- ref_net = None
- return aten_upsample(size, scale, mode), ref_net, F"aten::upsample_{mode}1d"
+ return aten_upsample(size, scale, mode), F"aten::upsample_{mode}1d"
@pytest.mark.parametrize("mode,size,scale", [
('nearest', 300, None),
@@ -54,8 +52,7 @@ class TestUpsample1D(PytorchLayerTest):
class TestUpsample2D(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 200, 200).astype(np.float32),)
+ return (self.random.randn(1, 3, 200, 200),)
def create_model(self, size, scale, mode):
import torch
@@ -71,9 +68,8 @@ class TestUpsample2D(PytorchLayerTest):
def forward(self, x):
return F.interpolate(x, self.size, scale_factor=self.scale, mode=self.mode)
- ref_net = None
- return aten_upsample(size, scale, mode), ref_net, F"aten::upsample_{mode}2d"
+ return aten_upsample(size, scale, mode), F"aten::upsample_{mode}2d"
@pytest.mark.parametrize("mode,size,scale", [
('nearest', 300, None),
@@ -105,8 +101,7 @@ class TestUpsample2D(PytorchLayerTest):
class TestUpsample2DAntialias(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 200, 200).astype(np.float32),)
+ return (self.random.randn(1, 3, 200, 200),)
def create_model(self, size, scale, mode):
import torch
@@ -122,9 +117,8 @@ class TestUpsample2DAntialias(PytorchLayerTest):
def forward(self, x):
return F.interpolate(x, self.size, scale_factor=self.scale, mode=self.mode, antialias=True)
- ref_net = None
- return aten_upsample(size, scale, mode), ref_net, F"aten::_upsample_{mode}2d_aa"
+ return aten_upsample(size, scale, mode), F"aten::_upsample_{mode}2d_aa"
@pytest.mark.parametrize("mode,size,scale", [
('bilinear', 300, None),
@@ -149,8 +143,7 @@ class TestUpsample2DAntialias(PytorchLayerTest):
class TestUpsample3D(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 100, 100, 100).astype(np.float32),)
+ return (self.random.randn(1, 3, 100, 100, 100),)
def create_model(self, size, scale, mode):
import torch
@@ -166,9 +159,8 @@ class TestUpsample3D(PytorchLayerTest):
def forward(self, x):
return F.interpolate(x, self.size, scale_factor=self.scale, mode=self.mode)
- ref_net = None
- return aten_upsample(size, scale, mode), ref_net, F"aten::upsample_{mode}3d"
+ return aten_upsample(size, scale, mode), F"aten::upsample_{mode}3d"
@pytest.mark.parametrize("mode,size,scale", [
('nearest', 200, None),
@@ -195,8 +187,7 @@ class TestUpsample3D(PytorchLayerTest):
class TestUpsample2DListSizes(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 200, 200).astype(np.float32),)
+ return (self.random.randn(1, 3, 200, 200),)
def create_model(self, mode):
import torch
@@ -210,9 +201,8 @@ class TestUpsample2DListSizes(PytorchLayerTest):
def forward(self, x):
return F.interpolate(x, size=x.shape[-2:], mode=self.mode)
- ref_net = None
- return aten_upsample(mode), ref_net, F"aten::upsample_{mode}2d"
+ return aten_upsample(mode), F"aten::upsample_{mode}2d"
@pytest.mark.parametrize("mode", ['nearest', 'bilinear', 'bicubic'])
@pytest.mark.nightly
@@ -225,8 +215,7 @@ class TestUpsample2DListSizes(PytorchLayerTest):
class TestUpsampleScripted(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 200, 200).astype(np.float32),)
+ return (self.random.randn(1, 3, 200, 200),)
def create_model(self):
import torch.nn as nn
@@ -247,7 +236,7 @@ class TestUpsampleScripted(PytorchLayerTest):
x3 = self.up(x2)
return x3
- return TestModel(1, 3), None, ["prim::If", "aten::upsample_nearest1d", "aten::upsample_nearest2d", "aten::upsample_nearest3d"]
+ return TestModel(1, 3), ["prim::If", "aten::upsample_nearest1d", "aten::upsample_nearest2d", "aten::upsample_nearest3d"]
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_var_mean.py b/tests/layer_tests/pytorch_tests/test_var_mean.py
index dcd2a36fa8f..f2ef9ff1ed7 100644
--- a/tests/layer_tests/pytorch_tests/test_var_mean.py
+++ b/tests/layer_tests/pytorch_tests/test_var_mean.py
@@ -10,8 +10,7 @@ from pytorch_layer_test_class import PytorchLayerTest
class TestVarMean(PytorchLayerTest):
def _prepare_input(self):
- import numpy as np
- return (np.random.randn(1, 3, 224, 224).astype(np.float32),)
+ return (self.random.randn(2, 3, 224, 224),)
def create_model(self, unbiased, dim=None, keepdim=True, two_args_case=True, op_type="var"):
import torch
@@ -27,7 +26,7 @@ class TestVarMean(PytorchLayerTest):
class aten_var(torch.nn.Module):
def __init__(self, dim, unbiased, keepdim, op):
- super(aten_var, self).__init__()
+ super().__init__()
self.unbiased = unbiased
self.dim = dim
self.keepdim = keepdim
@@ -38,17 +37,16 @@ class TestVarMean(PytorchLayerTest):
class aten_var2args(torch.nn.Module):
def __init__(self, unbiased, op):
- super(aten_var2args, self).__init__()
+ super().__init__()
self.unbiased = unbiased
self.op = op
def forward(self, x):
return self.op(x, self.unbiased)
- ref_net = None
op_name = f"aten::{op_type}"
if two_args_case:
- return aten_var2args(unbiased, op), ref_net, op_name
- return aten_var(dim, unbiased, keepdim, op), ref_net, op_name
+ return aten_var2args(unbiased, op), op_name
+ return aten_var(dim, unbiased, keepdim, op), op_name
@pytest.mark.nightly
@pytest.mark.precommit
diff --git a/tests/layer_tests/pytorch_tests/test_view.py b/tests/layer_tests/pytorch_tests/test_view.py
index 7722520476f..8934e253095 100644
--- a/tests/layer_tests/pytorch_tests/test_view.py
+++ b/tests/layer_tests/pytorch_tests/test_view.py
@@ -28,9 +28,8 @@ class TestViewListConstruct(PytorchLayerTest):
def forward(self, input_tensor, dim1: int, dim2: int):
return input_tensor.view(dim1, dim2)
- ref_net = None
- return aten_view_list_construct(), ref_net, "aten::view"
+ return aten_view_list_construct(), "aten::view"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -38,7 +37,7 @@ class TestViewListConstruct(PytorchLayerTest):
self.input_data = []
for input_shape in input_shapes:
if type(input_shape) is list:
- self.input_data.append(np.random.randn(*input_shape).astype(np.float32))
+ self.input_data.append(self.random.randn(*input_shape))
else:
self.input_data.append(input_shape)
self._test(*self.create_model(), ie_device, precision, ir_version)
@@ -60,9 +59,8 @@ class TestViewDtype(PytorchLayerTest):
def forward(self, input_tensor, dtype):
return input_tensor.view(torch.int64)
- ref_net = None
- return aten_view_dtype(), ref_net, "aten::view"
+ return aten_view_dtype(), "aten::view"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -70,7 +68,7 @@ class TestViewDtype(PytorchLayerTest):
self.input_data = []
for input_shape in input_shapes:
if type(input_shape) is list:
- self.input_data.append(np.random.randn(*input_shape).astype(np.float32))
+ self.input_data.append(self.random.randn(*input_shape))
else:
self.input_data.append(input_shape)
self._test(*self.create_model(), ie_device, precision, ir_version)
@@ -93,9 +91,8 @@ class TestViewSize(PytorchLayerTest):
def forward(self, input_tensor, input_size):
return input_tensor.view(input_size.size()[:])
- ref_net = None
- return aten_view_size(), ref_net, "aten::view"
+ return aten_view_size(), "aten::view"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -103,7 +100,7 @@ class TestViewSize(PytorchLayerTest):
self.input_data = []
for input_shape in input_shapes:
if type(input_shape) is list:
- self.input_data.append(np.random.randn(*input_shape).astype(np.float32))
+ self.input_data.append(self.random.randn(*input_shape))
else:
self.input_data.append(input_shape)
self._test(*self.create_model(), ie_device, precision, ir_version)
@@ -136,9 +133,8 @@ class TestView(PytorchLayerTest):
def forward(self, input_tensor):
return input_tensor.view(self.dim1, int(self.dim2))
- ref_net = None
- return aten_view(self.input_data), ref_net, "aten::view"
+ return aten_view(self.input_data), "aten::view"
@pytest.mark.nightly
@pytest.mark.precommit
@@ -147,7 +143,7 @@ class TestView(PytorchLayerTest):
self.input_data = []
for input_shape in input_shapes:
if type(input_shape) is list:
- self.input_data.append(np.random.randn(*input_shape).astype(np.float32))
+ self.input_data.append(self.random.randn(*input_shape))
else:
self.input_data.append(input_shape)
self._test(*self.create_model(), ie_device, precision, ir_version)
@@ -180,16 +176,15 @@ class TestViewCopy(PytorchLayerTest):
def forward(self, input_tensor):
return torch.view_copy(input_tensor, [self.dim1, int(self.dim2)])
- ref_net = None
- return aten_view_copy(self.input_data), ref_net, "aten::view_copy"
+ return aten_view_copy(self.input_data), "aten::view_copy"
@pytest.mark.precommit_fx_backend
def test_view_copy(self, ie_device, precision, ir_version, input_shapes):
self.input_data = []
for input_shape in input_shapes:
if type(input_shape) is list:
- self.input_data.append(np.random.randn(*input_shape).astype(np.float32))
+ self.input_data.append(self.random.randn(*input_shape))
else:
self.input_data.append(input_shape)
self._test(*self.create_model(), ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_vstack.py b/tests/layer_tests/pytorch_tests/test_vstack.py
index b3638b89d37..c5de7e28bba 100644
--- a/tests/layer_tests/pytorch_tests/test_vstack.py
+++ b/tests/layer_tests/pytorch_tests/test_vstack.py
@@ -21,7 +21,7 @@ class aten_vstack_out(aten_vstack):
class TestVstack(PytorchLayerTest):
def _prepare_input(self, out=False, num_repeats=2):
- data = np.random.randn(2, 1, 3)
+ data = self.random.randn(2, 1, 3)
if not out:
return (data, )
concat = [data for _ in range(num_repeats)]
@@ -33,7 +33,7 @@ class TestVstack(PytorchLayerTest):
@pytest.mark.parametrize("out", [False, True])
def test_vstack(self, out, ie_device, precision, ir_version):
model = aten_vstack() if not out else aten_vstack_out()
- self._test(model, None, "aten::vstack", ie_device,
+ self._test(model, "aten::vstack", ie_device,
precision, ir_version, kwargs_to_prepare_input={"out": out, "num_repeats": 2})
@@ -42,7 +42,7 @@ class TestVstackAlignTypes(PytorchLayerTest):
in_vals = []
for i in range(len(in_types)):
dtype = in_types[i]
- in_vals.append(np.random.randn(2, 1, 3).astype(dtype))
+ in_vals.append(self.random.randn(2, 1, 3, dtype=dtype))
return in_vals
def create_model(self, in_count):
@@ -83,5 +83,5 @@ class TestVstackAlignTypes(PytorchLayerTest):
@pytest.mark.nightly
@pytest.mark.precommit
def test_align_types_vstack(self, ie_device, precision, ir_version, in_types):
- self._test(self.create_model(len(in_types)), None, "aten::vstack",
+ self._test(self.create_model(len(in_types)), "aten::vstack",
ie_device, precision, ir_version, kwargs_to_prepare_input={"in_types": in_types})
\ No newline at end of file
diff --git a/tests/layer_tests/pytorch_tests/test_where.py b/tests/layer_tests/pytorch_tests/test_where.py
index d81aca6a670..1f9fc5767b6 100644
--- a/tests/layer_tests/pytorch_tests/test_where.py
+++ b/tests/layer_tests/pytorch_tests/test_where.py
@@ -14,10 +14,10 @@ class Testwhere(PytorchLayerTest):
if mask_fill == 'ones':
mask = np.ones(input_shape).astype(mask_dtype)
if mask_fill == 'random':
- idx = np.random.choice(10, 5)
+ idx = self.random.choice(10, 5)
mask[:, idx] = 1
- x = np.random.randn(*input_shape).astype(x_dtype)
- y = np.random.randn(*input_shape).astype(y_dtype or x_dtype)
+ x = self.random.randn(*input_shape, dtype=x_dtype)
+ y = self.random.randn(*input_shape, dtype=y_dtype or x_dtype)
return (mask,) if not return_x_y else (mask, x, y)
def create_model(self, as_non_zero, dtypes=None):
@@ -46,11 +46,10 @@ class Testwhere(PytorchLayerTest):
def forward(self, cond):
return torch.where(cond)
- ref_net = None
if as_non_zero:
- return aten_where_as_nonzero(), ref_net, "aten::where"
- return aten_where(torch_dtypes), ref_net, "aten::where"
+ return aten_where_as_nonzero(), "aten::where"
+ return aten_where(torch_dtypes), "aten::where"
@pytest.mark.parametrize(
"mask_fill", ['zeros', 'ones', 'random'])
diff --git a/tests/layer_tests/pytorch_tests/test_xor.py b/tests/layer_tests/pytorch_tests/test_xor.py
index 2da165d669e..beb96a86f5b 100644
--- a/tests/layer_tests/pytorch_tests/test_xor.py
+++ b/tests/layer_tests/pytorch_tests/test_xor.py
@@ -20,9 +20,8 @@ class TestXor(PytorchLayerTest):
def forward(self, tensor_a, tensor_b):
return tensor_a ^ tensor_b
- ref_net = None
- return aten_xor_tensor(), ref_net, "aten::__xor__"
+ return aten_xor_tensor(), "aten::__xor__"
def create_model_bool_input(self):
class aten_xor_bool(torch.nn.Module):
@@ -32,9 +31,8 @@ class TestXor(PytorchLayerTest):
def forward(self, bool_a: bool, bool_b: bool):
return bool_a ^ bool_b
- ref_net = None
- return aten_xor_bool(), ref_net, "aten::__xor__"
+ return aten_xor_bool(), "aten::__xor__"
def create_model_int_input(self):
class aten_xor_int(torch.nn.Module):
@@ -44,9 +42,8 @@ class TestXor(PytorchLayerTest):
def forward(self, int_a: int, int_b: int):
return int_a ^ int_b
- ref_net = None
- return aten_xor_int(), ref_net, "aten::__xor__"
+ return aten_xor_int(), "aten::__xor__"
@pytest.mark.nightly
@pytest.mark.precommit