Skip to content

Commit

Permalink
rest of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mryzhov committed Oct 20, 2023
1 parent 471187c commit 16de29d
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 119 deletions.
44 changes: 24 additions & 20 deletions tests/layer_tests/pytorch_tests/test_argsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ def __init__(self, dim, descending, stable) -> None:

def forward(self, input_tensor):
if self.stable is not None:
return torch.argsort(input_tensor,
dim = self.dim,
descending = self.descending,
return torch.argsort(input_tensor,
dim = self.dim,
descending = self.descending,
stable = self.stable
)
else:
return torch.argsort(input_tensor,
dim = self.dim,
return torch.argsort(input_tensor,
dim = self.dim,
descending = self.descending
)
)
ref_net = None

return aten_argsort(dim, descending, stable), ref_net, "aten::argsort"

@pytest.mark.parametrize("tensor_stable_pair", [
(np.random.rand(1, 4), False),
(np.random.rand(4, 4), False),
(np.random.rand(4, 4, 4), False),
([1, 4], False),
([4, 4], False),
([4, 4, 4], False),
(np.array([1, 2, 4, 6, 5, 8, 7]), False),
(np.array([6, 5, 4, 2, 3, 0, 1]), False),
(np.array([1, 1, 1, 2, 1, 3, 1, 4, 2, 5, 1, 2, 4, 4, 0]), True),
Expand All @@ -49,20 +49,20 @@ def forward(self, input_tensor):
(np.array([[9, 8, 8], [8, 7, 7], [7, 5, 6],
[8, 8, 9], [7, 7, 8], [6, 5, 7],
[8, 9, 8], [7, 8, 7], [5, 6, 7]]), True),
(np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
[[5, 2, 4], [4, 9, 0], [7, 7, 9]],
(np.array([[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
[[5, 2, 4], [4, 9, 0], [7, 7, 9]],
[[5, 2, 4], [4, 9, 0], [7, 7, 9]]]), True),
(np.array([[[3, 2, 2], [1, 2, 1], [3, 2, 2]],
[[1, 2, 1], [4, 3, 4], [3, 2, 2]],
(np.array([[[3, 2, 2], [1, 2, 1], [3, 2, 2]],
[[1, 2, 1], [4, 3, 4], [3, 2, 2]],
[[3, 2, 2], [1, 2, 1], [7, 9, 9]]]), True),
(np.array([[[2, 1, 3], [3, 2, 1], [1, 2, 3]],
[[2, 0, 2], [1, 2, 1], [3, 2, 8]],
(np.array([[[2, 1, 3], [3, 2, 1], [1, 2, 3]],
[[2, 0, 2], [1, 2, 1], [3, 2, 8]],
[[3, 2, 2], [3, 2, 1], [1, 2, 3]],
[[2, 1, 3], [3, 2, 1], [1, 2, 3]],
[[2, 0, 2], [1, 2, 1], [3, 2, 8]],
[[2, 1, 3], [3, 2, 1], [1, 2, 3]],
[[2, 0, 2], [1, 2, 1], [3, 2, 8]],
[[3, 2, 2], [3, 2, 1], [1, 2, 3]],
[[2, 1, 3], [3, 2, 1], [1, 2, 3]],
[[2, 0, 2], [1, 2, 1], [3, 2, 8]],
[[2, 1, 3], [3, 2, 1], [1, 2, 3]],
[[2, 0, 2], [1, 2, 1], [3, 2, 8]],
[[3, 2, 2], [3, 2, 1], [1, 2, 3]]]), True)
])
@pytest.mark.parametrize("descending", [
Expand All @@ -72,7 +72,11 @@ def forward(self, input_tensor):
@pytest.mark.nightly
@pytest.mark.precommit
def test_argsort(self, tensor_stable_pair, descending, ie_device, precision, ir_version):
self.input_tensor, stable = tensor_stable_pair
input_shape, stable = tensor_stable_pair
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):
stable_values = [True] if stable else [True, False, None]
Expand Down
58 changes: 32 additions & 26 deletions tests/layer_tests/pytorch_tests/test_floor_divide.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,45 @@ def forward(self, input_tensor, other_tensor):

return aten_floor_divide(), ref_net, "aten::floor_divide"

@pytest.mark.parametrize('input_tensor', ([
np.random.randn(5).astype(np.float32),
np.random.randn(5, 5, 1).astype(np.float32),
np.random.randn(1, 1, 5, 5).astype(np.float32),
]))
@pytest.mark.parametrize('other_tensor', ([
np.array([[0.5]]).astype(np.float32),
np.random.randn(5).astype(np.float32),
np.random.randn(5, 1).astype(np.float32),
np.random.randn(1, 5).astype(np.float32),
]))
@pytest.mark.parametrize('input_tensor',
[
[5], [5, 5, 1], [1, 1, 5, 5]
])
@pytest.mark.parametrize('other_tensor',
[
np.array([[0.5]]).astype(np.float32), [5], [5, 1], [1, 5]
])
@pytest.mark.nightly
@pytest.mark.precommit
def test_floor_divide(self, input_tensor, other_tensor, ie_device, precision, ir_version):
self.input_tensor = input_tensor
self.other_tensor = other_tensor
if type(input_tensor) is list:
self.input_tensor = np.random.random_sample(input_tensor).astype(np.float32)
else:
self.input_tensor = input_tensor
if type(other_tensor) is list:
self.other_tensor = np.random.random_sample(other_tensor).astype(np.float32)
else:
self.other_tensor = other_tensor
self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True)

@pytest.mark.parametrize('input_tensor', ([
np.random.randint(low=0, high=10, size=5).astype(np.float32),
np.random.randint(low=1, high=10, size=(5, 5, 1)).astype(np.float32),
np.random.randint(low=1, high=10, size=(1, 1, 5, 5)).astype(np.float32),
]))
@pytest.mark.parametrize('other_tensor', ([
np.array([[2]]).astype(np.float32),
np.random.randint(low=1, high=10, size=5).astype(np.float32),
np.random.randint(low=1, high=10, size=(5, 1)).astype(np.float32),
np.random.randint(low=1, high=10, size=(1, 5)).astype(np.float32),
]))
@pytest.mark.parametrize('input_tensor',
[
[5], [5, 5, 1], [1, 1, 5, 5]
])
@pytest.mark.parametrize('other_tensor',
[
np.array([[2]]).astype(np.float32), [5], [5, 1], [1, 5],
])
@pytest.mark.nightly
@pytest.mark.precommit
def test_floor_divide_int(self, input_tensor, other_tensor, ie_device, precision, ir_version):
self.input_tensor = input_tensor
self.other_tensor = other_tensor
if type(input_tensor) is list:
self.input_tensor = np.random.randint(low=0, high=10, size=input_tensor).astype(np.float32)
else:
self.input_tensor = input_tensor
if type(other_tensor) is list:
self.other_tensor = np.random.randint(low=0, high=10, size=other_tensor).astype(np.float32)
else:
self.other_tensor = other_tensor
self.create_model = self.create_model_int
self._test(*self.create_model(), ie_device, precision, ir_version)
33 changes: 18 additions & 15 deletions tests/layer_tests/pytorch_tests/test_index_put_.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def forward(self, input_tensor, values):
"input_data",
(
{
"input_tensor": np.random.randn(5).astype(np.float32),
"input_shape": [5],
"values": np.array(11).astype(np.float32)},
{
"input_tensor": np.random.randn(3, 3).astype(np.float32),
"input_shape": [3, 3],
"values": np.array([10, 11, 12]).astype(np.float32),
},
),
Expand All @@ -54,7 +54,7 @@ def forward(self, input_tensor, values):
@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 = input_data["input_tensor"]
self.input_tensor = np.random.random_sample(input_data["input_shape"]).astype(np.float32)
self.values = input_data["values"]
self._test(*self.create_model(indices, accumulate), ie_device, precision, ir_version)

Expand Down Expand Up @@ -83,11 +83,11 @@ def forward(self, input_tensor, values):
"input_data",
(
{
"input_tensor": np.random.randn(3, 3).astype(np.float32),
"input_shape": [3, 3],
"values": np.array(12).astype(np.float32)
},
{
"input_tensor": np.random.randn(3, 3, 3).astype(np.float32),
"input_shape": [3, 3, 3],
"values": np.array([10, 11, 12]).astype(np.float32),
},
),
Expand All @@ -107,7 +107,7 @@ def forward(self, input_tensor, values):
@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 = input_data["input_tensor"]
self.input_tensor = np.random.random_sample(input_data["input_shape"]).astype(np.float32)
self.values = input_data["values"]
self._test(*self.create_model(indices, accumulate), ie_device, precision, ir_version)

Expand Down Expand Up @@ -135,39 +135,42 @@ def forward(self, input_tensor, values, indices_0, indices_1):
"input_data",
(
{
"input_tensor": np.random.randn(3).astype(np.float32),
"input_shape": [3],
"values": np.array(11).astype(np.float32),
},
{
"input_tensor": np.random.randn(3, 3).astype(np.float32),
"input_shape": [3, 3],
"values": np.array([10, 11, 12]).astype(np.float32),
},
),
)
@pytest.mark.parametrize(
"indices",
(
(np.random.randint(low=0, high=2, size=(1,)), np.random.randint(low=0, high=2, size=(1,))),
(np.random.randint(low=0, high=2, size=(2,)), np.random.randint(low=0, high=2, size=(2,))),
(np.array([0, 1, 0]), np.array([1, 1, 0])),
(np.ones(shape=(3,)), np.ones(shape=(3,))),
(np.ones(shape=(3,)), np.zeros(shape=(3,))),
[[1, ], [1, ]],
[[2, ], [2, ]],
[np.array([0, 1, 0]), np.array([1, 1, 0])],
[np.ones(shape=(3,)), np.ones(shape=(3,))],
[np.ones(shape=(3,)), np.zeros(shape=(3,))],
),
)
@pytest.mark.parametrize("accumulate", (False, True))
@pytest.mark.nightly
@pytest.mark.precommit
def test_nonzero_index_put_(self, ie_device, precision, ir_version, input_data, indices, accumulate):
self.input_tensor = input_data["input_tensor"]
self.input_tensor = np.random.random_sample(input_data["input_shape"]).astype(np.float32)
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])
self.indices_0 = indices[0]
self.indices_1 = indices[1]
self._test(*self.create_model(accumulate), ie_device, precision, ir_version, trace_model=True)

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))

def create_model(self):
class aten_index_put_mask(torch.nn.Module):
def forward(self, x, y):
Expand Down
10 changes: 6 additions & 4 deletions tests/layer_tests/pytorch_tests/test_len.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from pytorch_layer_test_class import PytorchLayerTest


@pytest.mark.parametrize('input_tensor', (np.random.randn(2, 1, 3), np.random.randn(3, 7),
np.random.randn(1, 1, 4, 4)))
@pytest.mark.parametrize('input_tensor',
[
[2, 1, 3], [3, 7], [1, 1, 4, 4]
])
class TestLen(PytorchLayerTest):

def _prepare_input(self):
Expand Down Expand Up @@ -40,13 +42,13 @@ def forward(self, input_tensor):
@pytest.mark.nightly
@pytest.mark.precommit
def test_len(self, ie_device, precision, ir_version, input_tensor):
self.input_tensor = input_tensor
self.input_tensor = np.random.random_sample(input_tensor).astype(np.float32)
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 = input_tensor
self.input_tensor = np.random.random_sample(input_tensor).astype(np.float32)
self._test(*self.create_model_int_list(),
ie_device, precision, ir_version)

Expand Down
6 changes: 4 additions & 2 deletions tests/layer_tests/pytorch_tests/test_repeat_interleave.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
{'repeats': 2, 'dim': 2},
{'repeats': [2, 3], 'dim': 1},
{'repeats': [3, 2, 1], 'dim': 3},
{'repeats': [3, 2, 1], 'dim': 3},
{'repeats': 2, 'dim': None},
{'repeats': [random.randint(1, 5) for _ in range(36)], 'dim': None}))
{'repeats': [36], 'dim': None}))
class TestRepeatInterleaveConstRepeats(PytorchLayerTest):

def _prepare_input(self):
Expand All @@ -39,6 +38,9 @@ def forward(self, input_tensor):
@pytest.mark.precommit
def test_repeat_interleave_const_repeats(self, ie_device, precision, ir_version, input_data):
repeats = input_data['repeats']
if type(repeats) is list and len(repeats) == 1:
repeats = np.random.randint(low=1, high=6, size=repeats[0], dtype='uint8')

dim = input_data['dim']
self._test(*self.create_model_const_repeat(repeats, dim),
ie_device, precision, ir_version)
Expand Down
26 changes: 16 additions & 10 deletions tests/layer_tests/pytorch_tests/test_rsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,30 @@ def forward(self, x, y:int, alpha: float):

return model(), ref_net, "aten::rsub"

@pytest.mark.parametrize('input_data', [(np.random.randn(2, 3, 4).astype(np.float32),
np.array(5).astype(np.float32),
np.random.randn(1)),])

@pytest.mark.parametrize('input_data',
[
[2, 3, 4], np.array(5).astype(np.float32), [1]
])
@pytest.mark.nightly
@pytest.mark.precommit
def test_rsub(self, ie_device, precision, ir_version, input_data):
self.input_data = input_data
if type(input_data) is list:
self.input_data = np.random.random_sample(input_data).astype(np.float32)
else:
self.input_data = input_data
self._test(*self.create_model(second_type="float"), ie_device, precision, ir_version)

@pytest.mark.parametrize('input_data', [(np.random.randn(2, 3, 4).astype(np.float32),
np.array(5).astype(int),
np.random.randn(1)),])

@pytest.mark.parametrize('input_data',
[
[2, 3, 4], np.array(5).astype(int), [1]
])
@pytest.mark.nightly
@pytest.mark.precommit
def test_rsub(self, ie_device, precision, ir_version, input_data):
self.input_data = input_data
if type(input_data) is list:
self.input_data = np.random.random_sample(input_data)
else:
self.input_data = input_data
self._test(*self.create_model(second_type="int"), ie_device, precision, ir_version)


Expand Down
Loading

0 comments on commit 16de29d

Please sign in to comment.