Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mryzhov committed Oct 20, 2023
1 parent feefc7f commit 471187c
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 129 deletions.
38 changes: 17 additions & 21 deletions tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ def forward(self, input_tensor):

return aten_adaptive_max_pool3d(output_size, return_indices), ref_net, "aten::adaptive_max_pool3d"

@pytest.mark.parametrize('input_tensor', ([
np.random.randn(2, 1, 1, 4, 4).astype(np.float32),
np.random.randn(4, 1, 3, 32, 32).astype(np.float32),
np.random.randn(1, 3, 32, 32).astype(np.float32)
]))
@pytest.mark.parametrize('input_shape', [[2, 1, 1, 4, 4],
[4, 1, 3, 32, 32],
[1, 3, 32, 32]])
@pytest.mark.parametrize('output_size', ([
[2, 2, 2],
[4, 4, 4],
Expand All @@ -49,8 +47,8 @@ def forward(self, input_tensor):
@pytest.mark.precommit
@pytest.mark.precommit_ts_backend
@pytest.mark.precommit_fx_backend
def test_adaptive_max_pool3d(self, ie_device, precision, ir_version, input_tensor, output_size, return_indices):
self.input_tensor = input_tensor
def test_adaptive_max_pool3d(self, ie_device, precision, ir_version, input_shape, output_size, return_indices):
self.input_tensor = np.random.random_sample(input_shape).astype(np.float32)
self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version)


Expand All @@ -77,11 +75,9 @@ def forward(self, input_tensor):

return aten_adaptive_max_pool2d(output_size, return_indices), ref_net, "aten::adaptive_max_pool2d"

@pytest.mark.parametrize('input_tensor', ([
np.random.randn(2, 1, 4, 4).astype(np.float32),
np.random.randn(1, 3, 32, 32).astype(np.float32),
np.random.randn(3, 32, 32).astype(np.float32)
]))
@pytest.mark.parametrize('input_shape', [[2, 1, 4, 4],
[1, 3, 32, 32],
[3, 32, 32]])
@pytest.mark.parametrize('output_size', ([
[2, 2],
[4, 4],
Expand All @@ -94,8 +90,8 @@ def forward(self, input_tensor):
@pytest.mark.precommit
@pytest.mark.precommit_ts_backend
@pytest.mark.precommit_fx_backend
def test_adaptive_max_pool2d(self, ie_device, precision, ir_version, input_tensor, output_size, return_indices):
self.input_tensor = input_tensor
def test_adaptive_max_pool2d(self, ie_device, precision, ir_version, input_shape, output_size, return_indices):
self.input_tensor = np.random.random_sample(input_shape).astype(np.float32)
self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version)


Expand All @@ -122,11 +118,11 @@ def forward(self, input_tensor):

return aten_adaptive_max_pool1d(output_size, return_indices), ref_net, "aten::adaptive_max_pool1d"

@pytest.mark.parametrize('input_tensor', ([
np.random.randn(1, 4, 4).astype(np.float32),
np.random.randn(3, 32, 32).astype(np.float32),
np.random.randn(16, 8).astype(np.float32),
]))
@pytest.mark.parametrize('input_shape', [
[1, 4, 4],
[3, 32, 32],
[16, 8]
])
@pytest.mark.parametrize('output_size', ([
2,
4,
Expand All @@ -139,6 +135,6 @@ def forward(self, input_tensor):
@pytest.mark.precommit
@pytest.mark.precommit_ts_backend
@pytest.mark.precommit_fx_backend
def test_adaptive_max_pool1d(self, ie_device, precision, ir_version, input_tensor, output_size, return_indices):
self.input_tensor = input_tensor
def test_adaptive_max_pool1d(self, ie_device, precision, ir_version, input_shape, output_size, return_indices):
self.input_tensor = np.random.random_sample(input_shape).astype(np.float32)
self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version)
13 changes: 7 additions & 6 deletions tests/layer_tests/pytorch_tests/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@


@pytest.mark.parametrize('alpha', (-0.5, 0, 0.5, 1, 2))
@pytest.mark.parametrize('input_rhs', (np.random.randn(2, 5, 3, 4).astype(np.float32),
np.random.randn(
1, 5, 3, 4).astype(np.float32),
np.random.randn(1).astype(np.float32)))
@pytest.mark.parametrize('input_shape_rhs', [
[2, 5, 3, 4],
[1, 5, 3, 4],
[1]
])
class TestAdd(PytorchLayerTest):

def _prepare_input(self):
Expand Down Expand Up @@ -41,8 +42,8 @@ def forward2(self, lhs, rhs):
@pytest.mark.precommit_ts_backend
@pytest.mark.precommit_fx_backend
@pytest.mark.parametrize("op_type", ["add", "add_"])
def test_add(self, ie_device, precision, ir_version, alpha, input_rhs, op_type):
self.input_rhs = input_rhs
def test_add(self, ie_device, precision, ir_version, alpha, input_shape_rhs, op_type):
self.input_rhs = np.random.random_sample(input_shape_rhs).astype(np.float32)
self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version)


Expand Down
64 changes: 36 additions & 28 deletions tests/layer_tests/pytorch_tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def __init__(self, dim, keepdim) -> None:

def forward(self, input_tensor):
return torch.all(
input_tensor,
input_tensor,
dim = self.dim
) if self.keepdim is None else torch.all(
input_tensor,
input_tensor,
dim = self.dim,
keepdim = self.keepdim
)
Expand All @@ -34,32 +34,35 @@ class TestAll(PytorchLayerTest):
def _prepare_input(self):
return (self.input_tensor,)

@pytest.mark.parametrize("input_tensor", [
np.eye(5,5),
np.zeros((5, 5)),
np.zeros((9,8)) + 1,
np.random.randint(0, 2, (5, 9, 7)),
np.random.randint(0, 2, (10, 13, 11)),
np.random.randint(0, 2, (8, 7, 6, 5, 4)),
np.random.randint(0, 2, (11, 11), dtype=np.uint8),
np.random.randint(0, 2, (7, 7), dtype=np.uint8),
@pytest.mark.parametrize("input_shape, d_type", [
(np.eye(5,5), np.int16),
(np.zeros((5, 5)), np.int16),
(np.zeros((9,8)) + 1, np.int16),
([5, 9, 7], np.int16),
([10, 13, 11], np.int16),
([8, 7, 6, 5, 4], np.int16),
([11, 11], np.uint8),
([7, 7], np.uint8)
])
@pytest.mark.nightly
@pytest.mark.precommit
def test_all_noparams(self, input_tensor, ie_device, precision, ir_version):
self.input_tensor = input_tensor
self._test(aten_all_noparam(), None, "aten::all",
def test_all_noparams(self, input_shape, d_type, ie_device, precision, ir_version):
if type(input_shape) is list:
self.input_tensor = np.random.randint(0, 2, input_shape, dtype=d_type)
else:
self.input_tensor = input_shape
self._test(aten_all_noparam(), None, "aten::all",
ie_device, precision, ir_version, trace_model=True, freeze_model=False)
@pytest.mark.parametrize("input_tensor", [
np.eye(5,5),
np.zeros((5, 5)),
np.zeros((9,8)) + 1,
np.random.randint(0, 2, (5, 9, 7)),
np.random.randint(0, 2, (10, 13, 11)),
np.random.randint(0, 2, (8, 7, 6, 5, 4)),
np.random.randint(0, 2, (11, 11), dtype=np.uint8),
np.random.randint(0, 2, (7, 7), dtype=np.uint8),

@pytest.mark.parametrize("input_shape, d_type", [
(np.eye(5,5), np.int16),
(np.zeros((5, 5)), np.int16),
(np.zeros((9,8)) + 1, np.int16),
([5, 9, 7], np.int16),
([10, 13, 11], np.int16),
([8, 7, 6, 5, 4], np.int16),
([11, 11], np.uint8),
([7, 7], np.uint8)
])
@pytest.mark.parametrize("keepdim", [
True,
Expand All @@ -68,8 +71,13 @@ def test_all_noparams(self, input_tensor, ie_device, precision, ir_version):
])
@pytest.mark.nightly
@pytest.mark.precommit
def test_all(self, input_tensor, keepdim, ie_device, precision, ir_version):
self.input_tensor = input_tensor
for dim in range(len(input_tensor.shape)):
self._test(aten_all(dim, keepdim), None, "aten::all",
def test_all(self, input_shape, d_type, keepdim, ie_device, precision, ir_version):
if type(input_shape) is list:
self.input_tensor = np.random.randint(0, 2, input_shape, dtype=d_type)
else:
self.input_tensor = input_shape
self._test(aten_all_noparam(), None, "aten::all",
ie_device, precision, ir_version, trace_model=True, freeze_model=False)
for dim in range(len(self.input_tensor.shape)):
self._test(aten_all(dim, keepdim), None, "aten::all",
ie_device, precision, ir_version, trace_model=True, freeze_model=False)
8 changes: 4 additions & 4 deletions tests/layer_tests/pytorch_tests/test_narrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def forward(self, input_tensor, dim: int, start, length: int):

return aten_narrow(), ref_net, "aten::narrow"

@pytest.mark.parametrize("input_tensor", [
np.random.randn(3, 3), np.random.randn(3, 4, 5)
@pytest.mark.parametrize("input_shape", [
[3, 3], [3, 4, 5]
])
@pytest.mark.parametrize("dim", [
np.array(0).astype(np.int32), np.array(1).astype(np.int32), np.array(-1).astype(np.int32)
Expand All @@ -37,8 +37,8 @@ def forward(self, input_tensor, dim: int, start, length: int):
])
@pytest.mark.nightly
@pytest.mark.precommit
def test_narrow(self, input_tensor, dim, start, length, ie_device, precision, ir_version):
self.input_tensor = input_tensor
def test_narrow(self, input_shape, dim, start, length, ie_device, precision, ir_version):
self.input_tensor = np.random.random_sample(input_shape).astype(np.float32)
self.dim = dim
self.start = start
self.length = length
Expand Down
16 changes: 8 additions & 8 deletions tests/layer_tests/pytorch_tests/test_remainder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@


@pytest.mark.parametrize(
"input_rhs",
(
np.random.randn(2, 5, 3, 4).astype(np.float32),
np.random.randn(1, 5, 3, 4).astype(np.float32),
np.random.randn(1).astype(np.float32),
),
"input_shape_rhs",
[
[2, 5, 3, 4],
[1, 5, 3, 4],
[1]
]
)
class TestRemainder(PytorchLayerTest):
def _prepare_input(self):
Expand All @@ -30,8 +30,8 @@ def forward(self, lhs, rhs):

@pytest.mark.nightly
@pytest.mark.precommit
def test_remainder(self, ie_device, precision, ir_version, input_rhs):
self.input_rhs = input_rhs
def test_remainder(self, ie_device, precision, ir_version, input_shape_rhs):
self.input_rhs = np.random.random_sample(input_shape_rhs).astype(np.float32)
self._test(*self.create_model(), ie_device, precision, ir_version)


Expand Down
8 changes: 5 additions & 3 deletions tests/layer_tests/pytorch_tests/test_roi_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def forward(self, input_tensor, rois):
return (torchvision_roi_align(output_size, spatial_scale, sampling_ratio, aligned),
ref_net, "torchvision::roi_align")

@pytest.mark.parametrize('input_tensor', (np.random.randn(4, 5, 6, 7).astype(np.float32),))
@pytest.mark.parametrize('input_shape', [
[4, 5, 6, 7],
])
@pytest.mark.parametrize('boxes', (np.array([[1, 2, 2, 3, 3]]).astype(np.float32),
np.array([[0, 1, 2, 5, 4],
[2, 1, 2, 5, 4],
Expand All @@ -50,9 +52,9 @@ def forward(self, input_tensor, rois):
@pytest.mark.parametrize('aligned', (True, False))
@pytest.mark.nightly
@pytest.mark.precommit
def test_roi_align(self, ie_device, precision, ir_version, input_tensor, boxes, output_size,
def test_roi_align(self, ie_device, precision, ir_version, input_shape, boxes, output_size,
spatial_scale, sampling_ratio, aligned):
self.input_tensor = input_tensor
self.input_tensor = np.random.random_sample(input_shape).astype(np.float32)
self.boxes = boxes
self._test(*self.create_model(output_size, spatial_scale, sampling_ratio, aligned),
ie_device, precision, ir_version, trace_model=True)
20 changes: 12 additions & 8 deletions tests/layer_tests/pytorch_tests/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def forward(self, input_tensor):
ref_net = None
return aten_sort(dim, descending, stable), ref_net, "aten::sort"

@pytest.mark.parametrize("input_tensor", [
np.random.rand(16),
np.random.rand(1, 4),
np.random.rand(4, 4),
np.random.rand(4, 4, 4),
@pytest.mark.parametrize("input_shape", [
[16],
[1, 4],
[4, 4],
[4, 4, 4],
np.array([1, 2, 4, 6, 5, 8, 7]),
np.array([6, 5, 4, 2, 3, 0, 1]),
np.array([1, 1, 1, 2, 1, 3, 1, 4, 2, 5, 1, 2, 4, 4, 0]),
Expand Down Expand Up @@ -78,9 +78,13 @@ def forward(self, input_tensor):
])
@pytest.mark.nightly
@pytest.mark.precommit
def test_sort(self, input_tensor, descending, stable, ie_device, precision, ir_version):
self.input_tensor = input_tensor
dims = len(input_tensor.shape)
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.random_sample(input_shape).astype(np.float32)
else:
self.input_tensor = input_shape
dims = len(self.input_tensor.shape)
for dim in range(-dims, dims):
self._test(*self.create_model(dim, descending, stable),
ie_device, precision, ir_version)
41 changes: 25 additions & 16 deletions tests/layer_tests/pytorch_tests/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create_model(self, dim):
class aten_stack(torch.nn.Module):
def __init__(self, dim):
super(aten_stack, self).__init__()
self.dim = dim
self.dim = dim

def forward(self, x, y):
inputs = [x, y]
Expand All @@ -27,18 +27,22 @@ def forward(self, x, y):

return aten_stack(dim), ref_net, "aten::stack"

@pytest.mark.parametrize("input_tensor", ([
[np.random.rand(1, 3, 3), np.random.rand(1, 3, 3)],
[np.random.rand(4, 4, 2), np.random.rand(4, 4, 2)],
[np.random.rand(8, 1, 1, 9), np.random.rand(8, 1, 1, 9)]
]))
@pytest.mark.parametrize("input_shape",
[
[1, 3, 3],
[4, 4, 2],
[8, 1, 1, 9]
])
@pytest.mark.parametrize("dim", ([
0, 1, 2,
]))
@pytest.mark.nightly
@pytest.mark.precommit
def test_stack2D(self, input_tensor, dim, ie_device, precision, ir_version):
self.input_tensors = input_tensor
def test_stack2D(self, input_shape, dim, ie_device, precision, ir_version):
self.input_tensors = [
np.random.random_sample(input_shape).astype(np.float32),
np.random.random_sample(input_shape).astype(np.float32),
]
self._test(*self.create_model(dim), ie_device, precision, ir_version)


Expand All @@ -52,7 +56,7 @@ def create_model(self, dim):
class aten_stack(torch.nn.Module):
def __init__(self, dim):
super(aten_stack, self).__init__()
self.dim = dim
self.dim = dim

def forward(self, x, y, z):
inputs = [x, y, z]
Expand All @@ -62,16 +66,21 @@ def forward(self, x, y, z):

return aten_stack(dim), ref_net, "aten::stack"

@pytest.mark.parametrize("input_tensor", ([
[np.random.rand(1, 3, 3), np.random.rand(1, 3, 3), np.random.rand(1, 3, 3)],
[np.random.rand(4, 4, 2), np.random.rand(4, 4, 2), np.random.rand(4, 4, 2)],
[np.random.rand(8, 1, 1, 9), np.random.rand(8, 1, 1, 9), np.random.rand(8, 1, 1, 9)]
]))
@pytest.mark.parametrize("input_shape",
[
[1, 3, 3],
[4, 4, 2],
[8, 1, 1, 9]
])
@pytest.mark.parametrize("dim", ([
0, 1, 2,
]))
@pytest.mark.nightly
@pytest.mark.precommit
def test_stack3D(self, input_tensor, dim, ie_device, precision, ir_version):
self.input_tensors = input_tensor
def test_stack3D(self, input_shape, dim, ie_device, precision, ir_version):
self.input_tensors = [
np.random.random_sample(input_shape).astype(np.float32),
np.random.random_sample(input_shape).astype(np.float32),
np.random.random_sample(input_shape).astype(np.float32)
]
self._test(*self.create_model(dim), ie_device, precision, ir_version)
Loading

0 comments on commit 471187c

Please sign in to comment.