Skip to content

Commit

Permalink
fixed random
Browse files Browse the repository at this point in the history
  • Loading branch information
mryzhov committed Oct 23, 2023
1 parent d2a1aea commit 8a4f20b
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 45 deletions.
9 changes: 6 additions & 3 deletions tests/layer_tests/pytorch_tests/test_adaptive_avg_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def forward(self, input_shape):
@pytest.mark.precommit_ts_backend
@pytest.mark.precommit_fx_backend
def test_adaptive_avg_pool3d(self, ie_device, precision, ir_version, input_shape, output_size):
self.input_tensor = np.random.random_sample(input_shape).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
self._test(*self.create_model(output_size), ie_device, precision, ir_version)


Expand Down Expand Up @@ -64,7 +65,8 @@ def forward(self, input_tensor):
@pytest.mark.precommit_ts_backend
@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.random_sample(input_shape).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
self._test(*self.create_model(output_size), ie_device, precision, ir_version)


Expand Down Expand Up @@ -94,7 +96,8 @@ def forward(self, input_tensor):
@pytest.mark.precommit_ts_backend
@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.random_sample(input_shape).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
self._test(*self.create_model(output_size), ie_device, precision, ir_version)


9 changes: 6 additions & 3 deletions tests/layer_tests/pytorch_tests/test_adaptive_max_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def forward(self, input_tensor):
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
reason='Ticket - 122715')
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)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version)


Expand Down Expand Up @@ -97,7 +98,8 @@ def forward(self, input_tensor):
@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.random_sample(input_shape).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version)


Expand Down Expand Up @@ -144,5 +146,6 @@ def forward(self, input_tensor):
@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.random_sample(input_shape).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
self._test(*self.create_model(output_size, return_indices), ie_device, precision, ir_version)
3 changes: 2 additions & 1 deletion tests/layer_tests/pytorch_tests/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def forward2(self, lhs, rhs):
@pytest.mark.precommit_fx_backend
@pytest.mark.parametrize("op_type", ["add", "add_"])
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)
rng = np.random.default_rng(seed=13)
self.input_rhs = rng.standard_normal(size=input_shape_rhs).astype(np.float32)
self._test(*self.create_model(alpha, op_type), ie_device, precision, ir_version)


Expand Down
24 changes: 12 additions & 12 deletions tests/layer_tests/pytorch_tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def _prepare_input(self):
return (self.input_tensor,)

@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),
(np.eye(5,5), np.int64),
(np.zeros((5, 5)), np.int64),
(np.zeros((9,8)) + 1, np.int64),
([5, 9, 7], np.int64),
([10, 13, 11], np.int64),
([8, 7, 6, 5, 4], np.int64),
([11, 11], np.uint8),
([7, 7], np.uint8)
])
Expand All @@ -57,12 +57,12 @@ def test_all_noparams(self, input_shape, d_type, ie_device, precision, ir_versio
ie_device, precision, ir_version, trace_model=True, freeze_model=False)

@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),
(np.eye(5,5), np.int64),
(np.zeros((5, 5)), np.int64),
(np.zeros((9,8)) + 1, np.int64),
([5, 9, 7], np.int64),
([10, 13, 11], np.int64),
([8, 7, 6, 5, 4], np.int64),
([11, 11], np.uint8),
([7, 7], np.uint8)
])
Expand Down
3 changes: 2 additions & 1 deletion tests/layer_tests/pytorch_tests/test_argsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def forward(self, input_tensor):
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.random_sample(input_shape).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
else:
self.input_tensor = input_shape
dims = len(self.input_tensor.shape)
Expand Down
6 changes: 4 additions & 2 deletions tests/layer_tests/pytorch_tests/test_floor_divide.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ def forward(self, input_tensor, other_tensor):
reason='Ticket - 122715')
def test_floor_divide(self, input_tensor, other_tensor, ie_device, precision, ir_version):
if type(input_tensor) is list:
self.input_tensor = np.random.random_sample(input_tensor).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=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)
rng = np.random.default_rng(seed=14)
self.other_tensor = rng.standard_normal(size=other_tensor).astype(np.float32)
else:
self.other_tensor = other_tensor
self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True)
Expand Down
9 changes: 6 additions & 3 deletions tests/layer_tests/pytorch_tests/test_index_put_.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ 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 = np.random.random_sample(input_data["input_shape"]).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=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 @@ -107,7 +108,8 @@ 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 = np.random.random_sample(input_data["input_shape"]).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=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 @@ -158,7 +160,8 @@ def forward(self, input_tensor, values, indices_0, indices_1):
@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.random_sample(input_data["input_shape"]).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_data["input_shape"]).astype(np.float32)
self.values = input_data["values"]
for i in range(len(indices)):
if type(indices[i]) is list:
Expand Down
6 changes: 4 additions & 2 deletions tests/layer_tests/pytorch_tests/test_len.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ 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 = np.random.random_sample(input_tensor).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=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 = np.random.random_sample(input_tensor).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_tensor).astype(np.float32)
self._test(*self.create_model_int_list(),
ie_device, precision, ir_version)

Expand Down
3 changes: 2 additions & 1 deletion tests/layer_tests/pytorch_tests/test_narrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def forward(self, input_tensor, dim: int, start, length: int):
@pytest.mark.nightly
@pytest.mark.precommit
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)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
self.dim = dim
self.start = start
self.length = length
Expand Down
3 changes: 2 additions & 1 deletion tests/layer_tests/pytorch_tests/test_remainder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def forward(self, lhs, rhs):
@pytest.mark.nightly
@pytest.mark.precommit
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)
rng = np.random.default_rng(seed=13)
self.input_rhs = rng.standard_normal(size=input_shape_rhs).astype(np.float32)
self._test(*self.create_model(), ie_device, precision, ir_version)


Expand Down
3 changes: 2 additions & 1 deletion tests/layer_tests/pytorch_tests/test_roi_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def forward(self, input_tensor, rois):
@pytest.mark.precommit
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.random_sample(input_shape).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=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)
11 changes: 9 additions & 2 deletions tests/layer_tests/pytorch_tests/test_rsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ def forward(self, x, y:int, alpha: float):
@pytest.mark.precommit
def test_rsub(self, ie_device, precision, ir_version, input_data):
self.input_data = []
seed = 13
rng = np.random.default_rng(seed=13)
for input in input_data:
if type(input) is list:
self.input_data.append(np.random.random_sample(input).astype(np.float32))
rng = np.random.default_rng(seed)
self.input_data.append(rng.standard_normal(input).astype(np.float32))
seed += 1
else:
self.input_data.append(input)
self._test(*self.create_model(second_type="float"), ie_device, precision, ir_version)
Expand All @@ -57,9 +61,12 @@ def test_rsub(self, ie_device, precision, ir_version, input_data):
@pytest.mark.precommit
def test_rsub(self, ie_device, precision, ir_version, input_data):
self.input_data = []
seed = 13
for input in input_data:
if type(input) is list:
self.input_data.append(np.random.random_sample(input).astype(np.float32))
rng = np.random.default_rng(seed)
self.input_data.append(rng.standard_normal(input).astype(np.float32))
seed += 1
else:
self.input_data.append(input)
self._test(*self.create_model(second_type="int"), ie_device, precision, ir_version)
Expand Down
3 changes: 2 additions & 1 deletion tests/layer_tests/pytorch_tests/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def forward(self, input_tensor):
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)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
else:
self.input_tensor = input_shape
dims = len(self.input_tensor.shape)
Expand Down
15 changes: 10 additions & 5 deletions tests/layer_tests/pytorch_tests/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def forward(self, x, y):
@pytest.mark.nightly
@pytest.mark.precommit
def test_stack2D(self, input_shape, dim, ie_device, precision, ir_version):
rng_1 = np.random.default_rng(seed=1)
rng_2 = np.random.default_rng(seed=2)
self.input_tensors = [
np.random.random_sample(input_shape).astype(np.float32),
np.random.random_sample(input_shape).astype(np.float32),
rng_1.standard_normal(input_shape).astype(np.float32),
rng_2.standard_normal(input_shape).astype(np.float32),
]
self._test(*self.create_model(dim), ie_device, precision, ir_version)

Expand Down Expand Up @@ -78,9 +80,12 @@ def forward(self, x, y, z):
@pytest.mark.nightly
@pytest.mark.precommit
def test_stack3D(self, input_shape, dim, ie_device, precision, ir_version):
rng_1 = np.random.default_rng(seed=1)
rng_2 = np.random.default_rng(seed=2)
rng_3 = np.random.default_rng(seed=3)
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)
rng_1.standard_normal(input_shape).astype(np.float32),
rng_2.standard_normal(input_shape).astype(np.float32),
rng_3.standard_normal(input_shape).astype(np.float32)
]
self._test(*self.create_model(dim), ie_device, precision, ir_version)
5 changes: 4 additions & 1 deletion tests/layer_tests/pytorch_tests/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ def _forward_inplace(self, x, y, alpha: float):
@pytest.mark.precommit
def test_sub(self, ie_device, precision, ir_version, input_shapes, inplace):
self.input_data = []
seed = 13
for input_shape in input_shapes:
self.input_data.append(np.random.random_sample(input_shape).astype(np.float32))
rng = np.random.default_rng(seed)
self.input_data.append(rng.standard_normal(input_shape).astype(np.float32))
seed += 1
self._test(*self.create_model(inplace), ie_device, precision, ir_version)


Expand Down
3 changes: 2 additions & 1 deletion tests/layer_tests/pytorch_tests/test_topk.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ def forward(self, input_tensor):
@pytest.mark.precommit
@pytest.mark.skipif(os.getenv("GITHUB_ACTIONS") == 'true', reason="Ticket - 115085")
def test_topK(self, input_shape, k, dim, largest, sort, ie_device, precision, ir_version):
self.input_tensor = np.random.random_sample(input_shape).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
self._test(*self.create_model(k, dim, largest, sort), ie_device, precision, ir_version)
3 changes: 2 additions & 1 deletion tests/layer_tests/pytorch_tests/test_unfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def forward(self, input_tensor):
@pytest.mark.nightly
@pytest.mark.precommit
def test_unfold(self, ie_device, precision, ir_version, dimension, size, step, input_shape):
self.input_tensor = np.random.random_sample(input_shape).astype(np.float32)
rng = np.random.default_rng(seed=13)
self.input_tensor = rng.standard_normal(size=input_shape).astype(np.float32)
self._test(*self.create_model(dimension, size, step),
ie_device, precision, ir_version)
20 changes: 16 additions & 4 deletions tests/layer_tests/pytorch_tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ def forward(self, input_tensor, dim1: int, dim2: int):
@pytest.mark.precommit
def test_view_list_construct(self, ie_device, precision, ir_version, input_shapes):
self.input_data = []
seed = 13
for input_shape in input_shapes:
if type(input_shape) is list:
self.input_data.append(np.random.random_sample(input_shape).astype(np.float32))
rng = np.random.default_rng(seed)
self.input_data.append(rng.standard_normal(input_shape).astype(np.float32))
seed += 1
else:
self.input_data.append(input_shape)
self._test(*self.create_model(), ie_device, precision, ir_version)
Expand Down Expand Up @@ -68,9 +71,12 @@ def forward(self, input_tensor, dtype):
@pytest.mark.precommit
def test_view_dtype(self, ie_device, precision, ir_version, input_shapes):
self.input_data = []
seed = 13
for input_shape in input_shapes:
if type(input_shape) is list:
self.input_data.append(np.random.random_sample(input_shape).astype(np.float32))
rng = np.random.default_rng(seed)
self.input_data.append(rng.standard_normal(input_shape).astype(np.float32))
seed += 1
else:
self.input_data.append(input_shape)
self._test(*self.create_model(), ie_device, precision, ir_version)
Expand Down Expand Up @@ -101,9 +107,12 @@ def forward(self, input_tensor, input_size):
@pytest.mark.precommit
def test_view_size(self, ie_device, precision, ir_version, input_shapes):
self.input_data = []
seed = 13
for input_shape in input_shapes:
if type(input_shape) is list:
self.input_data.append(np.random.random_sample(input_shape).astype(np.float32))
rng = np.random.default_rng(seed)
self.input_data.append(rng.standard_normal(input_shape).astype(np.float32))
seed += 1
else:
self.input_data.append(input_shape)
self._test(*self.create_model(), ie_device, precision, ir_version)
Expand Down Expand Up @@ -144,9 +153,12 @@ def forward(self, input_tensor):
@pytest.mark.precommit
def test_view(self, ie_device, precision, ir_version, input_shapes):
self.input_data = []
seed = 13
for input_shape in input_shapes:
if type(input_shape) is list:
self.input_data.append(np.random.random_sample(input_shape).astype(np.float32))
rng = np.random.default_rng(seed)
self.input_data.append(rng.standard_normal(input_shape).astype(np.float32))
seed += 1
else:
self.input_data.append(input_shape)
self._test(*self.create_model(), ie_device, precision, ir_version)

0 comments on commit 8a4f20b

Please sign in to comment.