-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest_repeat.py
86 lines (62 loc) · 2.81 KB
/
test_repeat.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import pytest
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),)
def create_model(self, repeats):
import torch
class aten_repeat(torch.nn.Module):
def __init__(self, repeats):
super(aten_repeat, self).__init__()
self.repeats = repeats
def forward(self, x):
return x.repeat(self.repeats)
ref_net = None
return aten_repeat(repeats), ref_net, "aten::repeat"
@pytest.mark.parametrize("repeats", [(4, 3), (1, 1), (1, 2, 3), (1, 2, 2, 3)])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_repeat(self, repeats, ie_device, precision, ir_version):
self._test(*self.create_model(repeats), ie_device, precision, ir_version)
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),)
def create_model(self):
import torch
class aten_repeat(torch.nn.Module):
def forward(self, x, y):
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"]
@pytest.mark.parametrize("repeats", [(4, 3), (1, 1), (1, 3, 3), (1, 2, 2, 3)])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_repeat(self, repeats, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision, ir_version,
kwargs_to_prepare_input={"repeats_shape": repeats})
class TestRepeatFromFlanT5(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
return (np.random.randn(1, 15).astype(np.float32),)
def create_model(self):
import torch
from transformers.modeling_utils import ModuleUtilsMixin
class aten_repeat(torch.nn.Module):
def forward(self, x):
return ModuleUtilsMixin.create_extended_attention_mask_for_decoder(x.size(), x)
return aten_repeat(), None, "aten::repeat"
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
def test_repeat_t5(self, ie_device, precision, ir_version):
self._test(*self.create_model(), ie_device, precision, ir_version, trace_model=True, use_convert_model=True)