Skip to content

Commit 4e12325

Browse files
committed
[FlagGems Operator Development Competition] Optimize conv_transpose2d forward
1 parent 2b083bd commit 4e12325

5 files changed

Lines changed: 1783 additions & 0 deletions

File tree

benchmark/test_conv_transpose2d.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import pytest
2+
import torch
3+
4+
import flag_gems
5+
from benchmark.attri_util import FLOAT_DTYPES
6+
from benchmark.performance_utils import GenericBenchmark
7+
8+
9+
class ConvTranspose2DBenchmark(GenericBenchmark):
10+
def set_more_shapes(self):
11+
return [
12+
(16, 32, 24, 24, 24, 3, 3, 1, 1, 0, 2, 1),
13+
(16, 32, 24, 24, 24, 3, 3, 2, 1, 1, 2, 1),
14+
(32, 64, 64, 64, 32, 3, 3, 2, 1, 1, 1, 1),
15+
(32, 64, 128, 128, 32, 5, 5, 2, 2, 1, 1, 1),
16+
(4, 32, 128, 128, 32, 5, 5, 3, 2, 0, 1, 1),
17+
(16, 32, 24, 24, 24, 3, 3, 3, 1, 0, 2, 1),
18+
(16, 32, 24, 24, 24, 3, 3, 4, 1, 0, 2, 1),
19+
(8, 32, 32, 32, 32, 3, 3, 4, 1, 0, 1, 1),
20+
(4, 32, 32, 32, 32, 3, 3, 8, 1, 0, 1, 1),
21+
]
22+
23+
24+
def _input_fn(shape, dtype, device):
25+
(
26+
batch,
27+
input_c,
28+
input_h,
29+
input_w,
30+
out_c,
31+
kernel_h,
32+
kernel_w,
33+
stride,
34+
padding,
35+
output_padding,
36+
groups,
37+
dilation,
38+
) = shape
39+
input_shape = (batch, input_c, input_h, input_w)
40+
weight_shape = (input_c, out_c // groups, kernel_h, kernel_w)
41+
input = torch.randn(size=input_shape, device=device, dtype=dtype)
42+
weight = torch.randn(size=weight_shape, device=device, dtype=dtype)
43+
44+
yield {
45+
"input": input,
46+
"weight": weight,
47+
"bias": None,
48+
"stride": stride,
49+
"padding": padding,
50+
"output_padding": output_padding,
51+
"groups": groups,
52+
"dilation": dilation,
53+
},
54+
55+
56+
@pytest.mark.conv_transpose2d
57+
def test_conv_transpose2d():
58+
def gems_conv_transpose2d(**kwargs):
59+
with torch.no_grad():
60+
return flag_gems.conv_transpose2d(**kwargs)
61+
62+
torch.backends.cudnn.allow_tf32 = False
63+
bench = ConvTranspose2DBenchmark(
64+
input_fn=_input_fn,
65+
op_name="conv_transpose2d",
66+
torch_op=torch.nn.functional.conv_transpose2d,
67+
dtypes=FLOAT_DTYPES,
68+
)
69+
bench.set_gems(gems_conv_transpose2d)
70+
bench.run()

src/flag_gems/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def torch_ge(v):
140140
("conv1d.padding", conv1d),
141141
("conv2d", conv2d),
142142
("conv2d.padding", conv2d),
143+
("conv_transpose2d.input", conv_transpose2d),
143144
("conv3d", conv3d),
144145
("conv3d.padding", conv3d),
145146
(

src/flag_gems/ops/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
from flag_gems.ops.conv2d import conv2d
8181
from flag_gems.ops.conv3d import conv3d
8282
from flag_gems.ops.conv_depthwise2d import _conv_depthwise2d
83+
from flag_gems.ops.conv_transpose2d import conv_transpose2d
8384
from flag_gems.ops.copy import copy, copy_
8485
from flag_gems.ops.copysign import copysign, copysign_out
8586
from flag_gems.ops.cos import cos, cos_
@@ -427,6 +428,7 @@
427428
"conv1d",
428429
"conv2d",
429430
"conv3d",
431+
"conv_transpose2d",
430432
"copy",
431433
"copy_",
432434
"copysign",

0 commit comments

Comments
 (0)