Skip to content
This repository was archived by the owner on May 24, 2021. It is now read-only.

Commit 8b52d15

Browse files
committed
Squashed commit of the following:
commit 08d38b3 Author: Alexander Wong <alex@udia.ca> Date: Thu Nov 26 10:48:46 2020 -0700 CircleCI badge to README.md commit 64a3f8d Author: Alexander Wong <alex@udia.ca> Date: Thu Nov 26 10:42:32 2020 -0700 Enforce requirements versions for test, reduced comparison strictness commit fdcf493 Author: Alexander Wong <alex@udia.ca> Date: Thu Nov 26 10:30:07 2020 -0700 Test references updated to be consistent on development machine - torch==1.7.0 - torchvision==0.8.1 - TITAN Xp (12180MiB, CUDA Version 11.0, Driver Version: 450.80.02) commit 654c87a Author: Alexander Wong <alex@udia.ca> Date: Thu Nov 26 09:45:42 2020 -0700 CircleCI test configuration update commit a8ecbff Author: Alexander Wong <alex@udia.ca> Date: Thu Nov 26 09:39:12 2020 -0700 Add .circleci/config.yml
1 parent 60c217a commit 8b52d15

File tree

4 files changed

+278
-91
lines changed

4 files changed

+278
-91
lines changed

.circleci/config.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 2.1
2+
3+
orbs:
4+
python: circleci/python@1.2.1
5+
6+
jobs:
7+
build-and-test:
8+
executor: python/default
9+
steps:
10+
- checkout
11+
- python/install-packages:
12+
pkg-manager: pip
13+
- python/install-packages:
14+
pip-dependency-file: requirements.txt
15+
pkg-manager: pip
16+
- run:
17+
command: python3 -m unittest discover
18+
name: Test
19+
20+
workflows:
21+
main:
22+
jobs:
23+
- build-and-test

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# torchprof
22

33
[![PyPI version](https://badge.fury.io/py/torchprof.svg)](https://pypi.org/project/torchprof/)
4+
[![CircleCI](https://circleci.com/gh/awwong1/torchprof.svg?style=svg)](https://circleci.com/gh/awwong1/torchprof)
45

56
A minimal dependency library for layer-by-layer profiling of Pytorch models.
67

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
torch>=1.1.0
2-
torchvision>=0.3.0
1+
torch==1.7.0
2+
torchvision==0.8.1

tests/test_profile.py

Lines changed: 252 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -34,97 +34,254 @@ class TestProfile(unittest.TestCase):
3434
]
3535

3636
alexnet_cpu_ops = [
37-
None,
38-
None,
39-
(
40-
"conv2d",
41-
"convolution",
42-
"_convolution",
43-
"contiguous",
44-
"contiguous",
45-
"contiguous",
46-
"mkldnn_convolution",
47-
),
48-
("relu_",),
49-
("max_pool2d", "max_pool2d_with_indices"),
50-
(
51-
"conv2d",
52-
"convolution",
53-
"_convolution",
54-
"contiguous",
55-
"contiguous",
56-
"contiguous",
57-
"mkldnn_convolution",
58-
),
59-
("relu_",),
60-
("max_pool2d", "max_pool2d_with_indices"),
61-
(
62-
"conv2d",
63-
"convolution",
64-
"_convolution",
65-
"contiguous",
66-
"contiguous",
67-
"contiguous",
68-
"mkldnn_convolution",
69-
),
70-
("relu_",),
71-
(
72-
"conv2d",
73-
"convolution",
74-
"_convolution",
75-
"contiguous",
76-
"contiguous",
77-
"contiguous",
78-
"mkldnn_convolution",
79-
),
80-
("relu_",),
81-
(
82-
"conv2d",
83-
"convolution",
84-
"_convolution",
85-
"contiguous",
86-
"contiguous",
87-
"contiguous",
88-
"mkldnn_convolution",
89-
),
90-
("relu_",),
91-
("max_pool2d", "max_pool2d_with_indices"),
92-
("adaptive_avg_pool2d", "_adaptive_avg_pool2d"),
93-
None,
94-
("dropout", "empty_like", "empty", "bernoulli_", "div_", "mul"),
95-
("unsigned short", "addmm"),
96-
("relu_",),
97-
("dropout", "empty_like", "empty", "bernoulli_", "div_", "mul"),
98-
("unsigned short", "addmm"),
99-
("relu_",),
100-
("unsigned short", "addmm"),
37+
None, # 0
38+
None, # 1
39+
(
40+
"aten::conv2d",
41+
"aten::convolution",
42+
"aten::_convolution",
43+
"aten::contiguous",
44+
"aten::contiguous",
45+
"aten::contiguous",
46+
"aten::mkldnn_convolution",
47+
"aten::as_strided_",
48+
), # 2
49+
("aten::relu_", "aten::threshold_"), # 3
50+
(
51+
"aten::max_pool2d",
52+
"aten::max_pool2d_with_indices",
53+
"aten::contiguous",
54+
), # 4
55+
(
56+
"aten::conv2d",
57+
"aten::convolution",
58+
"aten::_convolution",
59+
"aten::contiguous",
60+
"aten::contiguous",
61+
"aten::contiguous",
62+
"aten::mkldnn_convolution",
63+
"aten::as_strided_",
64+
), # 5
65+
("aten::relu_", "aten::threshold_"), # 6
66+
(
67+
"aten::max_pool2d",
68+
"aten::max_pool2d_with_indices",
69+
"aten::contiguous",
70+
), # 7
71+
(
72+
"aten::conv2d",
73+
"aten::convolution",
74+
"aten::_convolution",
75+
"aten::contiguous",
76+
"aten::contiguous",
77+
"aten::contiguous",
78+
"aten::mkldnn_convolution",
79+
"aten::as_strided_",
80+
), # 8
81+
("aten::relu_", "aten::threshold_"), # 9
82+
(
83+
"aten::conv2d",
84+
"aten::convolution",
85+
"aten::_convolution",
86+
"aten::contiguous",
87+
"aten::contiguous",
88+
"aten::contiguous",
89+
"aten::mkldnn_convolution",
90+
"aten::as_strided_",
91+
), # 10
92+
("aten::relu_", "aten::threshold_"), # 11
93+
(
94+
"aten::conv2d",
95+
"aten::convolution",
96+
"aten::_convolution",
97+
"aten::contiguous",
98+
"aten::contiguous",
99+
"aten::contiguous",
100+
"aten::mkldnn_convolution",
101+
"aten::as_strided_",
102+
), # 12
103+
("aten::relu_", "aten::threshold_"), # 13
104+
(
105+
"aten::max_pool2d",
106+
"aten::max_pool2d_with_indices",
107+
"aten::contiguous",
108+
), # 14
109+
(
110+
"aten::adaptive_avg_pool2d",
111+
"aten::_adaptive_avg_pool2d",
112+
), # 15
113+
None, # 16
114+
(
115+
"aten::dropout",
116+
"aten::empty_like",
117+
"aten::bernoulli_",
118+
"aten::div_",
119+
"aten::to",
120+
"aten::empty_strided",
121+
"aten::mul",
122+
), # 17
123+
(
124+
"aten::t",
125+
"aten::transpose",
126+
"aten::as_strided",
127+
"aten::addmm",
128+
"aten::expand",
129+
"aten::as_strided",
130+
), # 18
131+
("aten::relu_", "aten::threshold_"), # 19
132+
(
133+
"aten::dropout",
134+
"aten::empty_like",
135+
"aten::bernoulli_",
136+
"aten::div_",
137+
"aten::to",
138+
"aten::empty_strided",
139+
"aten::mul",
140+
), # 20
141+
(
142+
"aten::t",
143+
"aten::transpose",
144+
"aten::as_strided",
145+
"aten::addmm",
146+
"aten::expand",
147+
"aten::as_strided",
148+
), # 21
149+
("aten::relu_", "aten::threshold_"), # 22
150+
(
151+
"aten::t",
152+
"aten::transpose",
153+
"aten::as_strided",
154+
"aten::addmm",
155+
"aten::expand",
156+
"aten::as_strided",
157+
), # 23
101158
]
102159

103160
alexnet_gpu_ops = (
104-
None,
105-
None,
106-
("conv2d", "convolution", "_convolution", "contiguous", "cudnn_convolution"),
107-
("relu_",),
108-
("max_pool2d", "max_pool2d_with_indices"),
109-
("conv2d", "convolution", "_convolution", "contiguous", "cudnn_convolution"),
110-
("relu_",),
111-
("max_pool2d", "max_pool2d_with_indices"),
112-
("conv2d", "convolution", "_convolution", "contiguous", "cudnn_convolution"),
113-
("relu_",),
114-
("conv2d", "convolution", "_convolution", "contiguous", "cudnn_convolution"),
115-
("relu_",),
116-
("conv2d", "convolution", "_convolution", "contiguous", "cudnn_convolution"),
117-
("relu_",),
118-
("max_pool2d", "max_pool2d_with_indices"),
119-
("adaptive_avg_pool2d", "_adaptive_avg_pool2d"),
120-
None,
121-
("dropout", "_fused_dropout"),
122-
("unsigned short", "addmm"),
123-
("relu_",),
124-
("dropout", "_fused_dropout"),
125-
("unsigned short", "addmm"),
126-
("relu_",),
127-
("unsigned short", "addmm"),
161+
None, # 0
162+
None, # 1
163+
(
164+
"aten::conv2d",
165+
"aten::convolution",
166+
"aten::_convolution",
167+
"aten::contiguous",
168+
"aten::cudnn_convolution",
169+
"aten::contiguous",
170+
"aten::contiguous",
171+
"aten::reshape",
172+
"aten::view",
173+
"aten::add_",
174+
), # 2
175+
("aten::relu_", "aten::threshold_"), # 3
176+
(
177+
"aten::max_pool2d",
178+
"aten::max_pool2d_with_indices",
179+
"aten::contiguous",
180+
), # 4
181+
(
182+
"aten::conv2d",
183+
"aten::convolution",
184+
"aten::_convolution",
185+
"aten::contiguous",
186+
"aten::cudnn_convolution",
187+
"aten::contiguous",
188+
"aten::contiguous",
189+
"aten::reshape",
190+
"aten::view",
191+
"aten::add_",
192+
), # 5
193+
("aten::relu_", "aten::threshold_"), # 6
194+
(
195+
"aten::max_pool2d",
196+
"aten::max_pool2d_with_indices",
197+
"aten::contiguous",
198+
), # 7
199+
(
200+
"aten::conv2d",
201+
"aten::convolution",
202+
"aten::_convolution",
203+
"aten::contiguous",
204+
"aten::cudnn_convolution",
205+
"aten::contiguous",
206+
"aten::contiguous",
207+
"aten::reshape",
208+
"aten::view",
209+
"aten::add_",
210+
), # 8
211+
("aten::relu_", "aten::threshold_"), # 9
212+
(
213+
"aten::conv2d",
214+
"aten::convolution",
215+
"aten::_convolution",
216+
"aten::contiguous",
217+
"aten::cudnn_convolution",
218+
"aten::contiguous",
219+
"aten::contiguous",
220+
"aten::reshape",
221+
"aten::view",
222+
"aten::add_",
223+
), # 10
224+
("aten::relu_", "aten::threshold_"), # 11
225+
(
226+
"aten::conv2d",
227+
"aten::convolution",
228+
"aten::_convolution",
229+
"aten::contiguous",
230+
"aten::cudnn_convolution",
231+
"aten::contiguous",
232+
"aten::contiguous",
233+
"aten::reshape",
234+
"aten::view",
235+
"aten::add_",
236+
), # 12
237+
("aten::relu_", "aten::threshold_"), # 13
238+
(
239+
"aten::max_pool2d",
240+
"aten::max_pool2d_with_indices",
241+
"aten::contiguous",
242+
), # 14
243+
(
244+
"aten::adaptive_avg_pool2d",
245+
"aten::_adaptive_avg_pool2d",
246+
"aten::contiguous",
247+
), # 15
248+
None, # 16
249+
(
250+
"aten::dropout",
251+
"aten::_fused_dropout",
252+
"aten::empty_like",
253+
), # 17
254+
(
255+
"aten::t",
256+
"aten::transpose",
257+
"aten::as_strided",
258+
"aten::addmm",
259+
"aten::expand",
260+
"aten::as_strided",
261+
), # 18
262+
("aten::relu_", "aten::threshold_"), # 19
263+
(
264+
"aten::dropout",
265+
"aten::_fused_dropout",
266+
"aten::empty_like",
267+
), # 20
268+
(
269+
"aten::t",
270+
"aten::transpose",
271+
"aten::as_strided",
272+
"aten::addmm",
273+
"aten::expand",
274+
"aten::as_strided",
275+
), # 21
276+
("aten::relu_", "aten::threshold_"), # 22
277+
(
278+
"aten::t",
279+
"aten::transpose",
280+
"aten::as_strided",
281+
"aten::addmm",
282+
"aten::expand",
283+
"aten::as_strided",
284+
), # 23
128285
)
129286

130287
def test_cpu_profile_structure(self):
@@ -155,7 +312,13 @@ def _profile_structure(self, model, x, use_cuda=False, alexnet_ops=[]):
155312
self.assertEqual(len(event_lists), 1)
156313
event_names = tuple(e.name for e in event_lists[0])
157314
# profiler returned order is not deterministic
158-
self.assertEqual(sorted(event_names), sorted(alexnet_ops[layer_idx]))
315+
try:
316+
self.assertTrue(
317+
all(event_name in event_names for event_name in alexnet_ops[layer_idx]),
318+
f"Layer {layer_idx} received {event_names}, old {alexnet_ops[layer_idx]}",
319+
)
320+
except IndexError:
321+
self.assertTrue(False, f"Layer {layer_idx} received {event_names}")
159322
else:
160323
# non leaf nodes should not have event_list values
161324
self.assertEqual(len(event_lists), 0)

0 commit comments

Comments
 (0)