-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest_select.py
66 lines (47 loc) · 2.24 KB
/
test_select.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest
@pytest.mark.parametrize('input_dim', list(range(-3, 4)))
@pytest.mark.parametrize('input_index', list(range(-3, 4)))
class TestSelect(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(4, 4, 5, 5).astype(np.float32),)
def create_model(self, input_dim, input_index):
class aten_select(torch.nn.Module):
def __init__(self, input_dim, input_index) -> None:
super().__init__()
self.dim = input_dim
self.index = input_index
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"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_select(self, ie_device, precision, ir_version, input_dim, input_index):
self._test(*self.create_model(input_dim, input_index),
ie_device, precision, ir_version)
@pytest.mark.parametrize('input_dim', list(range(-3, 4)))
@pytest.mark.parametrize('input_index', list(range(-3, 4)))
class TestSelectCopy(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(4, 4, 5, 5).astype(np.float32),)
def create_model(self, input_dim, input_index):
class aten_select_copy(torch.nn.Module):
def __init__(self, input_dim, input_index) -> None:
super().__init__()
self.dim = input_dim
self.index = input_index
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"
@pytest.mark.precommit_fx_backend
def test_select_copy(self, ie_device, precision, ir_version, input_dim, input_index):
self._test(*self.create_model(input_dim, input_index),
ie_device, precision, ir_version)