Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a1dbeb3

Browse files
committedMar 30, 2020
convtranspose2d dilation check performance 2
1 parent a6f8bce commit a1dbeb3

File tree

1 file changed

+255
-0
lines changed

1 file changed

+255
-0
lines changed
 
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"1.6.0a0+77b4e2d\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"import torch \n",
18+
"import time\n",
19+
"\n",
20+
"print(torch.__version__)\n",
21+
"\n",
22+
"warmup_iter_raw = 1000\n",
23+
"prof_iter_raw = 1000\n",
24+
"\n",
25+
"def test_convtranspose2d(bs, c, hw, ks, stride, pad, outpad, dilation):\n",
26+
" warmup_iter = warmup_iter_raw\n",
27+
" prof_iter = prof_iter_raw\n",
28+
" \n",
29+
" if c >= 256: \n",
30+
" warmup_iter //= 10 \n",
31+
" prof_iter //= 10 \n",
32+
" \n",
33+
" print(bs, c, hw, ks, stride, pad, outpad, dilation)\n",
34+
" x = torch.randn(bs, c, hw, hw, device='cuda', dtype=torch.half, requires_grad=True) \n",
35+
" conv = torch.nn.ConvTranspose2d(\n",
36+
" in_channels=c, \n",
37+
" out_channels=c, \n",
38+
" kernel_size=ks, \n",
39+
" stride=stride, \n",
40+
" padding=pad, \n",
41+
" output_padding=outpad, \n",
42+
" groups=c,\n",
43+
" bias=False, \n",
44+
" dilation=dilation\n",
45+
" ).half().cuda()\n",
46+
"\n",
47+
" y:torch.Tensor = conv(x)\n",
48+
" g = torch.ones_like(y)\n",
49+
"\n",
50+
" for warm_up in range(warmup_iter): \n",
51+
" y = conv(x)\n",
52+
" y.backward(g)\n",
53+
"\n",
54+
" torch.cuda.synchronize()\n",
55+
" ts = time.time() \n",
56+
"\n",
57+
" for it in range(prof_iter): \n",
58+
" y = conv(x)\n",
59+
"\n",
60+
" torch.cuda.synchronize()\n",
61+
" te = time.time()\n",
62+
"\n",
63+
" t_forward = (te-ts)/prof_iter\n",
64+
" print(f'forward {t_forward: .3e}')\n",
65+
"\n",
66+
" ts = time.time()\n",
67+
" torch.cuda.synchronize() \n",
68+
"\n",
69+
" for it in range(prof_iter): \n",
70+
" y.backward(g, retain_graph=True)\n",
71+
"\n",
72+
" torch.cuda.synchronize()\n",
73+
" te = time.time()\n",
74+
"\n",
75+
" t_backward = (te-ts)/prof_iter\n",
76+
" print(f'backward {t_backward: .3e}')\n",
77+
"\n",
78+
" print(f'total {t_forward + t_backward: .3e}')\n",
79+
" \n",
80+
" print()"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": 2,
86+
"metadata": {},
87+
"outputs": [],
88+
"source": [
89+
"def test(): \n",
90+
" print('bs c hw ks stride pad outpad dilation\\n')\n",
91+
" # def test_convtranspose2d(bs, c, hw, ks, stride, pad, outpad, dilation)\n",
92+
" \n",
93+
" test_convtranspose2d(32, 128, 7, 1, 2, 0, 0, 2)\n",
94+
" test_convtranspose2d(32, 128, 7, 1, 1, 0, 0, 2)\n",
95+
" test_convtranspose2d(8, 128, 14, 1, 1, 0, 0, 3)\n",
96+
" test_convtranspose2d(1, 128, 7, 1, 3, 0, 1, 2)\n",
97+
" \n",
98+
" test_convtranspose2d(32, 512, 7, 1, 3, 0, 2, 2)\n",
99+
" test_convtranspose2d(8, 512, 14, 3, 2, 1, 1, 1)\n",
100+
" test_convtranspose2d(32, 256, 7, 1, 3, 0, 1, 1)\n",
101+
" test_convtranspose2d(1, 512, 14, 3, 3, 1, 1, 1)"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": 15,
107+
"metadata": {
108+
"scrolled": false
109+
},
110+
"outputs": [
111+
{
112+
"name": "stdout",
113+
"output_type": "stream",
114+
"text": [
115+
"master\n",
116+
"bs c hw ks stride pad outpad dilation\n",
117+
"\n",
118+
"32 128 7 1 2 0 0 2\n",
119+
"forward 7.415e-05\n",
120+
"backward 2.432e-03\n",
121+
"total 2.506e-03\n",
122+
"\n",
123+
"32 128 7 1 1 0 0 2\n",
124+
"forward 7.270e-05\n",
125+
"backward 3.238e-03\n",
126+
"total 3.311e-03\n",
127+
"\n",
128+
"8 128 14 1 1 0 0 3\n",
129+
"forward 7.214e-05\n",
130+
"backward 3.232e-03\n",
131+
"total 3.304e-03\n",
132+
"\n",
133+
"1 128 7 1 3 0 1 2\n",
134+
"forward 7.211e-05\n",
135+
"backward 3.110e-03\n",
136+
"total 3.182e-03\n",
137+
"\n",
138+
"32 512 7 1 3 0 2 2\n",
139+
"forward 1.974e-01\n",
140+
"backward 3.896e-01\n",
141+
"total 5.870e-01\n",
142+
"\n",
143+
"8 512 14 3 2 1 1 1\n",
144+
"forward 8.204e-02\n",
145+
"backward 1.598e-01\n",
146+
"total 2.418e-01\n",
147+
"\n",
148+
"32 256 7 1 3 0 1 1\n",
149+
"forward 9.928e-02\n",
150+
"backward 1.947e-01\n",
151+
"total 2.940e-01\n",
152+
"\n",
153+
"1 512 14 3 3 1 1 1\n",
154+
"forward 3.833e-02\n",
155+
"backward 8.089e-02\n",
156+
"total 1.192e-01\n",
157+
"\n"
158+
]
159+
}
160+
],
161+
"source": [
162+
"print('master')\n",
163+
"test()"
164+
]
165+
},
166+
{
167+
"cell_type": "code",
168+
"execution_count": 3,
169+
"metadata": {},
170+
"outputs": [
171+
{
172+
"name": "stdout",
173+
"output_type": "stream",
174+
"text": [
175+
"without dilation check\n",
176+
"bs c hw ks stride pad outpad dilation\n",
177+
"\n",
178+
"32 128 7 1 2 0 0 2\n",
179+
"forward 9.304e-05\n",
180+
"backward 2.358e-03\n",
181+
"total 2.451e-03\n",
182+
"\n",
183+
"32 128 7 1 1 0 0 2\n",
184+
"forward 7.569e-05\n",
185+
"backward 3.104e-03\n",
186+
"total 3.180e-03\n",
187+
"\n",
188+
"8 128 14 1 1 0 0 3\n",
189+
"forward 7.390e-05\n",
190+
"backward 3.123e-03\n",
191+
"total 3.197e-03\n",
192+
"\n",
193+
"1 128 7 1 3 0 1 2\n",
194+
"forward 7.711e-05\n",
195+
"backward 2.982e-03\n",
196+
"total 3.059e-03\n",
197+
"\n",
198+
"32 512 7 1 3 0 2 2\n",
199+
"forward 2.085e-04\n",
200+
"backward 1.152e-02\n",
201+
"total 1.173e-02\n",
202+
"\n",
203+
"8 512 14 3 2 1 1 1\n",
204+
"forward 1.887e-04\n",
205+
"backward 1.424e-04\n",
206+
"total 3.311e-04\n",
207+
"\n",
208+
"32 256 7 1 3 0 1 1\n",
209+
"forward 1.264e-04\n",
210+
"backward 3.502e-03\n",
211+
"total 3.629e-03\n",
212+
"\n",
213+
"1 512 14 3 3 1 1 1\n",
214+
"forward 7.291e-05\n",
215+
"backward 1.455e-04\n",
216+
"total 2.184e-04\n",
217+
"\n"
218+
]
219+
}
220+
],
221+
"source": [
222+
"print('without dilation check')\n",
223+
"test()"
224+
]
225+
},
226+
{
227+
"cell_type": "code",
228+
"execution_count": null,
229+
"metadata": {},
230+
"outputs": [],
231+
"source": []
232+
}
233+
],
234+
"metadata": {
235+
"kernelspec": {
236+
"display_name": "Python 3.7.6 64-bit",
237+
"language": "python",
238+
"name": "python37664bitfce950e88ea94256bae6c6f663f53e68"
239+
},
240+
"language_info": {
241+
"codemirror_mode": {
242+
"name": "ipython",
243+
"version": 3
244+
},
245+
"file_extension": ".py",
246+
"mimetype": "text/x-python",
247+
"name": "python",
248+
"nbconvert_exporter": "python",
249+
"pygments_lexer": "ipython3",
250+
"version": "3.7.6"
251+
}
252+
},
253+
"nbformat": 4,
254+
"nbformat_minor": 2
255+
}

0 commit comments

Comments
 (0)
Please sign in to comment.