-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathtest_conv_transposend.py
199 lines (173 loc) · 10.6 KB
/
test_conv_transposend.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import pytest
from pytorch_layer_test_class import PytorchLayerTest
class TestConvTranspose2D(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
return (np.random.randn(1, 3, 10, 10).astype(np.float32),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias, output_padding):
import torch
import torch.nn.functional as F
class aten_conv_transpose2d(torch.nn.Module):
def __init__(self):
super(aten_conv_transpose2d, self).__init__()
self.weight = torch.randn(weights_shape)
self.bias = None
if bias:
self.bias = torch.randn(groups)
self.strides = strides
self.pads = pads
self.dilations = dilations
self.groups = groups
self.output_padding = output_padding
def forward(self, x):
return F.conv_transpose2d(x, weight=self.weight, bias=self.bias, stride=self.strides, padding=self.pads, output_padding=self.output_padding, dilation=self.dilations, groups=self.groups)
ref_net = None
return aten_conv_transpose2d(), ref_net, "aten::conv_transpose2d"
@pytest.mark.parametrize("params",
[{'weights_shape': [3, 1, 1, 1], 'strides': [1, 1], 'pads': [0, 0],
'dilations': [2, 2], 'groups': 1, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [1, 1], 'pads': [
0, 0], 'dilations': [1, 1], 'groups': 3, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [1, 1], 'pads': [
1, 1], 'dilations': [1, 1], 'groups': 1, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [1, 1], 'pads': [
3, 1], 'dilations': [1, 1], 'groups': 1, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [1, 1], 'pads': [
1, 0], 'dilations': [1, 1], 'groups': 1, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [1, 1], 'pads': [
1, 0], 'dilations': [1, 1], 'groups': 3, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [1, 1], 'pads': [
1, 0], 'dilations': [2, 2], 'groups': 3, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [2, 1], 'pads': [
1, 0], 'dilations': [1, 1], 'groups': 1, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [2, 2], 'pads': [
0, 0], 'dilations': [1, 1], 'groups': 1, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [2, 2], 'pads': [
0, 0], 'dilations': [1, 1], 'groups': 1, 'output_padding': [0, 0]},
{'weights_shape': [3, 1, 1, 1], 'strides': [2, 2], 'pads': [
1, 1], 'dilations': [2, 2], 'groups': 1, 'output_padding': [1, 1]},
])
@pytest.mark.parametrize("bias", [True, False])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_conv_transpose2d(self, params, bias, ie_device, precision, ir_version):
self._test(*self.create_model(**params, bias=bias),
ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1)
class TestConvTranspose1D(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
return (np.random.randn(1, 3, 10).astype(np.float32),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias, output_padding):
import torch
import torch.nn.functional as F
class aten_conv_transpose1d(torch.nn.Module):
def __init__(self):
super(aten_conv_transpose1d, self).__init__()
self.weight = torch.randn(weights_shape)
self.bias = None
if bias:
self.bias = torch.randn(groups)
self.strides = strides
self.pads = pads
self.dilations = dilations
self.groups = groups
self.output_padding = output_padding
def forward(self, x):
return F.conv_transpose1d(
x,
weight=self.weight,
bias=self.bias,
stride=self.strides,
padding=self.pads,
output_padding=self.output_padding,
dilation=self.dilations,
groups=self.groups
)
ref_net = None
return aten_conv_transpose1d(), ref_net, "aten::conv_transpose1d"
@pytest.mark.parametrize("params",
[{'weights_shape': [3, 1, 1], 'strides': 1, 'pads': 0, 'dilations': 1, 'groups': 1, 'output_padding': 0},
{'weights_shape': [3, 1, 1], 'strides': 1, 'pads': 0,
'dilations': 1, 'groups': 3, 'output_padding': 0},
{'weights_shape': [3, 1, 1], 'strides': 1, 'pads': 1,
'dilations': 1, 'groups': 1, 'output_padding': 0},
{'weights_shape': [3, 1, 1], 'strides': 1, 'pads': 1,
'dilations': 1, 'groups': 3, 'output_padding': 0},
{'weights_shape': [3, 1, 1], 'strides': 1, 'pads': 3,
'dilations': 2, 'groups': 1, 'output_padding': 1},
{'weights_shape': [3, 1, 1], 'strides': 1, 'pads': 3,
'dilations': 2, 'groups': 3, 'output_padding': 1},
])
@pytest.mark.parametrize("bias", [True, False])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_conv_transpose1d(self, params, bias, ie_device, precision, ir_version):
self._test(*self.create_model(**params, bias=bias),
ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1)
class TestConvTranspose3D(PytorchLayerTest):
def _prepare_input(self):
import numpy as np
return (np.random.randn(1, 3, 10, 10, 4).astype(np.float32),)
def create_model(self, weights_shape, strides, pads, dilations, groups, bias, output_padding):
import torch
import torch.nn.functional as F
class aten_conv_transpose3d(torch.nn.Module):
def __init__(self):
super(aten_conv_transpose3d, self).__init__()
self.weight = torch.randn(weights_shape)
self.bias = None
if bias:
self.bias = torch.randn(groups)
self.strides = strides
self.pads = pads
self.dilations = dilations
self.groups = groups
self.output_padding = output_padding
def forward(self, x):
return F.conv_transpose3d(
x,
weight=self.weight,
bias=self.bias,
stride=self.strides,
padding=self.pads,
output_padding=self.output_padding,
dilation=self.dilations,
groups=self.groups
)
ref_net = None
return aten_conv_transpose3d(), ref_net, "aten::conv_transpose3d"
@pytest.mark.parametrize("params",
[{'weights_shape': [3, 1, 1, 1, 1], 'strides': [1, 1, 1], 'pads': [0, 0, 0],
'dilations': [2, 2, 2], 'groups': 1, 'output_padding': [0, 0, 0]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [1, 1, 1], 'pads': [
0, 0, 0], 'dilations': [1, 1, 1], 'groups': 3, 'output_padding': [0, 0, 0]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [1, 1, 1], 'pads': [
1, 1, 0], 'dilations': [1, 1, 2], 'groups': 1, 'output_padding': [0, 0, 1]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [1, 1, 2], 'pads': [
3, 1, 0], 'dilations': [4, 4, 4], 'groups': 1, 'output_padding': [1, 1, 1]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [1, 1, 1], 'pads': [
1, 0, 1], 'dilations': [1, 2, 1], 'groups': 1, 'output_padding': [0, 1, 0]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [1, 1, 1], 'pads': [
1, 0, 0], 'dilations': [1, 1, 2], 'groups': 3, 'output_padding': [0, 0, 0]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [1, 1, 1], 'pads': [
1, 0, 0], 'dilations': [2, 2, 1], 'groups': 3, 'output_padding': [0, 0, 0]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [2, 1, 2], 'pads': [
1, 0, 0], 'dilations': [3, 4, 2], 'groups': 1, 'output_padding': [2, 0, 0]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [2, 2, 2], 'pads': [
0, 0, 0], 'dilations': [1, 1, 1], 'groups': 1, 'output_padding': [0, 0, 0]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [2, 2, 2], 'pads': [
0, 0, 0], 'dilations': [1, 1, 1], 'groups': 1, 'output_padding': [0, 0, 0]},
{'weights_shape': [3, 1, 1, 1, 1], 'strides': [2, 2, 2], 'pads': [
1, 1, 2], 'dilations': [2, 2, 2], 'groups': 1, 'output_padding': [1, 1, 0]},
])
@pytest.mark.parametrize("bias", [True, False])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
def test_conv_transpose3d(self, params, bias, ie_device, precision, ir_version):
self._test(*self.create_model(**params, bias=bias),
ie_device, precision, ir_version, dynamic_shapes=params['groups'] == 1)