-
Notifications
You must be signed in to change notification settings - Fork 258
/
Copy pathtensorboard_profiler_tutorial.py
521 lines (476 loc) ยท 24.6 KB
/
tensorboard_profiler_tutorial.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
"""
ํ
์๋ณด๋๋ฅผ ์ด์ฉํ ํ์ดํ ์น ํ๋กํ์ผ๋ฌ
========================================
**๋ฒ์ญ**: `์๋์ฐ <https://github.com/dnd-qodqks>`__
์ด ํํ ๋ฆฌ์ผ์์๋ ํ์ดํ ์น(PyTorch) ํ๋กํ์ผ๋ฌ(profiler)์ ํจ๊ป ํ
์๋ณด๋(TensorBoard) ํ๋ฌ๊ทธ์ธ(plugin)์ ์ฌ์ฉํ์ฌ
๋ชจ๋ธ์ ์ฑ๋ฅ ๋ณ๋ชฉ ํ์์ ํ์งํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ ์ค๋๋ค.
์๊ฐ
------------
ํ์ดํ ์น(PyTorch) 1.8๋ถํฐ GPU์์ CUDA ์ปค๋(kernel) ์คํ ๋ฟ๋ง ์๋๋ผ
CPU ์์
์ ๊ธฐ๋กํ ์ ์๋ ์
๋ฐ์ดํธ๋ ํ๋กํ์ผ๋ฌ API๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
ํ๋กํ์ผ๋ฌ๋ ํ
์๋ณด๋ ํ๋ฌ๊ทธ์ธ์์ ์ด๋ฐ ์ ๋ณด๋ฅผ ์๊ฐํํ๊ณ
์ฑ๋ฅ ๋ณ๋ชฉ ํ์์ ๋ํ ๋ถ์์ ์ ๊ณตํ ์ ์์ต๋๋ค.
์ด ํํ ๋ฆฌ์ผ์์๋ ๊ฐ๋จํ Resnet ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ
ํ
์๋ณด๋ ํ๋ฌ๊ทธ์ธ์ ํ์ฉํ ๋ชจ๋ธ ์ฑ๋ฅ ๋ถ์ ๋ฐฉ๋ฒ์ ๋ณด์ฌ๋๋ฆฌ๊ฒ ์ต๋๋ค.
์ค๋น
-----
์๋ ๋ช
๋ น์ด๋ฅผ ์คํํ์ฌ ``torch``์ ``torchvision``์ ์ค์นํฉ๋๋ค:
.. code-block::
pip install torch torchvision
"""
######################################################################
# ๊ณผ์
# -----
#
# 1. ๋ฐ์ดํฐ ๋ฐ ๋ชจ๋ธ ์ค๋น
# 2. ํ๋กํ์ผ๋ฌ๋ฅผ ์ฌ์ฉํ์ฌ ์คํ ์ด๋ฒคํธ(execution events) ๊ธฐ๋ก
# 3. ํ๋กํ์ผ๋ฌ ์คํ
# 4. ํ
์๋ณด๋๋ฅผ ์ฌ์ฉํ์ฌ ๊ฒฐ๊ณผ ํ์ธ ๋ฐ ๋ชจ๋ธ ์ฑ๋ฅ ๋ถ์
# 5. ํ๋กํ์ผ๋ฌ์ ๋์์ผ๋ก ์ฑ๋ฅ ๊ฐ์
# 6. ๋ค๋ฅธ ๊ณ ๊ธ ๊ธฐ๋ฅ์ผ๋ก ์ฑ๋ฅ ๋ถ์
# 7. ์ถ๊ฐ ์ฐ์ต: AMD GPU์์ PyTorch ํ๋กํ์ผ๋ง
#
# 1. ๋ฐ์ดํฐ ๋ฐ ๋ชจ๋ธ ์ค๋น
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# ๋จผ์ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ชจ๋ ๋ถ๋ฌ์ต๋๋ค:
#
import torch
import torch.nn
import torch.optim
import torch.profiler
import torch.utils.data
import torchvision.datasets
import torchvision.models
import torchvision.transforms as T
######################################################################
# ์ดํ ์
๋ ฅ ๋ฐ์ดํฐ๋ฅผ ์ค๋นํฉ๋๋ค. ์ด ํํ ๋ฆฌ์ผ์ ๊ฒฝ์ฐ CIFAR10 ๋ฐ์ดํฐ์
์ ์ฌ์ฉํฉ๋๋ค.
# ์ํ๋ ํ์์ผ๋ก ๋ณํํ๊ณ ``DataLoader``๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ ๋ฐฐ์น(batch)๋ฅผ ๋ก๋ํฉ๋๋ค.
transform = T.Compose(
[T.Resize(224),
T.ToTensor(),
T.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
train_set = torchvision.datasets.CIFAR10(root='./data', train=True, download=True, transform=transform)
train_loader = torch.utils.data.DataLoader(train_set, batch_size=32, shuffle=True)
######################################################################
# ๊ทธ๋ฐ ๋ค์ Resnet ๋ชจ๋ธ, ์์ค ํจ์ ๋ฐ ์ตํฐ๋ง์ด์ ๊ฐ์ฒด๋ฅผ ์์ฑํฉ๋๋ค.
# GPU์์ ์คํํ๊ธฐ ์ํด ๋ชจ๋ธ ๋ฐ ์์ค์ GPU ์ฅ์น๋ก ์ด๋ํฉ๋๋ค.
device = torch.device("cuda:0")
model = torchvision.models.resnet18(weights='IMAGENET1K_V1').cuda(device)
criterion = torch.nn.CrossEntropyLoss().cuda(device)
optimizer = torch.optim.SGD(model.parameters(), lr=0.001, momentum=0.9)
model.train()
######################################################################
# ๊ฐ ์
๋ ฅ ๋ฐ์ดํฐ ๋ฐฐ์น์ ๋ํ ํ์ต ๋จ๊ณ๋ฅผ ์ ์ํฉ๋๋ค.
def train(data):
inputs, labels = data[0].to(device=device), data[1].to(device=device)
outputs = model(inputs)
loss = criterion(outputs, labels)
optimizer.zero_grad()
loss.backward()
optimizer.step()
######################################################################
# 2. ํ๋กํ์ผ๋ฌ๋ฅผ ์ฌ์ฉํ์ฌ ์คํ ์ด๋ฒคํธ ๊ธฐ๋ก
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# ํ๋กํ์ผ๋ฌ๋ ์ปจํ
์คํธ(context) ๊ด๋ฆฌ์๋ฅผ ํตํด ํ์ฑํ๋๊ณ ๋ช ๊ฐ์ง ๋งค๊ฐ๋ณ์๋ฅผ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ,
# ๊ฐ์ฅ ์ ์ฉํ ๊ฒ์ ์๋์ ๊ฐ์ต๋๋ค:
#
# - ``schedule`` - step (int)์ ๋จ์ผ ๋งค๊ฐ๋ณ์๋ก ๋ฐ์๋ค์ด๊ณ ,
# ๊ฐ ๋จ๊ณ์์ ์ํํ ํ๋กํ์ผ๋ฌ ์์
์ ๋ฐํํ๋ ํธ์ถ ๊ฐ๋ฅํ ํจ์์
๋๋ค.
#
# ์ด ์์์์๋ ``wait=1, warmup=1, active=3, repeat=1`` ๋ก ์ค์ ๋์ด ์์ผ๋ฉฐ,
# ํ๋กํ์ผ๋ฌ๋ ์ฒซ ๋ฒ์งธ ๋จ๊ณ/๋ฐ๋ณต(step/iteration)์ ๊ฑด๋๋๋๋ค.
# ๋ ๋ฒ์งธ๋ถํฐ ์๋ฐ์
(warming up)์ ์์ํ๋ฉด,
# ๋ค์ ์ธ ๋ฒ์ ๋ฐ๋ณต์ ๊ธฐ๋กํ๊ณ ,
# ๊ทธ ํ ์ถ์ (trace)์ ์ฌ์ฉํ ์ ์๊ฒ ๋๊ณ on_trace_ready (์ค์ ๋ ๊ฒฝ์ฐ)๊ฐ ํธ์ถ๋ฉ๋๋ค.
# ์ ์ฒด์ ์ผ๋ก ์ด ์ฃผ๊ธฐ๊ฐ ํ ๋ฒ ๋ฐ๋ณต๋ฉ๋๋ค. ํ
์๋ณด๋ ํ๋ฌ๊ทธ์ธ์์ ๊ฐ ์ฃผ๊ธฐ๋ "span"์ด๋ผ๊ณ ํฉ๋๋ค.
#
# ``wait`` ๋จ๊ณ์ธ ๋์ ํ๋กํ์ผ๋ฌ๋ ๋นํ์ฑํ๋ฉ๋๋ค.
# ``warmup`` ๋จ๊ณ์ธ ๋์์ ํ๋กํ์ผ๋ฌ๊ฐ ์ถ์ (tracing)์ ์์ํ์ง๋ง ๊ฒฐ๊ณผ๋ ๋ฌด์๋ฉ๋๋ค.
# ์ด๋ ํ๋กํ์ผ๋ง ๊ณผ๋ถํ(overhead)๋ฅผ ์ค์ด๊ธฐ ์ํจ์
๋๋ค.
# ํ๋กํ์ผ๋ง์ ์์ํ ๋ ๊ณผ๋ถํ๋ ํฌ๊ณ ํ๋กํ์ผ๋ง ๊ฒฐ๊ณผ์ ์๊ณก์ ๊ฐ์ ธ์ค๊ธฐ ์ฝ์ต๋๋ค.
# ``active`` ๋จ๊ณ์์ ํ๋กํ์ผ๋ฌ๊ฐ ์๋ํ๋ฉฐ ์ด๋ฒคํธ๋ฅผ ๊ธฐ๋กํฉ๋๋ค.
# - ``on_trace_ready`` - ๊ฐ ์ฃผ๊ธฐ ๋ง์ง๋ง์ ํธ์ถ๋๋ ํจ์์
๋๋ค;
# ์ด ์์์์๋ ``torch.profiler.tensorboard_trace_handler``๋ฅผ ์ฌ์ฉํ์ฌ ํ
์๋ณด๋์ ๊ฒฐ๊ณผ ํ์ผ์ ์์ฑํฉ๋๋ค.
# ํ๋กํ์ผ๋ง ํ ๊ฒฐ๊ณผ ํ์ผ์ ``./log/resnet18`` ๋๋ ํ ๋ฆฌ์ ์ ์ฅ๋ฉ๋๋ค.
# ํ
์๋ณด๋์์ ํ๋กํ์ผ(profile)์ ๋ถ์ํ๋ ค๋ฉด ์ด ๋๋ ํ ๋ฆฌ๋ฅผ ``logdir`` ๋งค๊ฐ๋ณ์๋ก ์ง์ ํด์ผ ํฉ๋๋ค.
# - ``record_shapes`` - ์ฐ์ฐ์ ์
๋ ฅ์ shape์ ๊ธฐ๋กํ ์ง ์ฌ๋ถ๋ฅผ ๋ํ๋
๋๋ค.
# - ``profile_memory`` - Track tensor memory ํ ๋น/ํ ๋น ํด์ ์ฌ๋ถ๋ฅผ ๋ํ๋
๋๋ค. ์ฃผ์, 1.10 ์ด์ ๋ฒ์ ์ ํ์ดํ ์น๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ
# ํ๋กํ์ผ๋ง ์๊ฐ์ด ๊ธธ๋ค๋ฉด ์ด ๊ธฐ๋ฅ์ ๋นํ์ฑํํ๊ฑฐ๋ ์ ๋ฒ์ ์ผ๋ก ์
๊ทธ๋ ์ด๋ํด ์ฃผ์ธ์.
# - ``with_stack`` - ops์ ๋ํ ์์ค ์ ๋ณด(ํ์ผ ๋ฐ ๋ผ์ธ ๋ฒํธ)๋ฅผ ๊ธฐ๋ก ์ฌ๋ถ๋ฅผ ๋ํ๋
๋๋ค.
# ๋ง์ฝ VS Code์์ ํ
์๋ณด๋๋ฅผ ์คํํ๋ ๊ฒฝ์ฐ (`์ฐธ๊ณ <https://code.visualstudio.com/docs/datascience/pytorch-support#_tensorboard-integration>`__),
# ์คํ ํ๋ ์(stack frame)์ ํด๋ฆญํ๋ฉด ํน์ ์ฝ๋ ๋ผ์ธ์ผ๋ก ์ด๋ํฉ๋๋ค.
with torch.profiler.profile(
schedule=torch.profiler.schedule(wait=1, warmup=1, active=3, repeat=1),
on_trace_ready=torch.profiler.tensorboard_trace_handler('./log/resnet18'),
record_shapes=True,
profile_memory=True,
with_stack=True
) as prof:
for step, batch_data in enumerate(train_loader):
prof.step() # ๊ฐ ๋จ๊ณ์์ ํธ์ถํ์ฌ ํ๋กํ์ผ๋ฌ์๊ฒ ๋จ๊ณ์ ๊ฒฝ๊ณ๋ฅผ ์๋ ค์ผ ํฉ๋๋ค.
if step >= 1 + 1 + 3:
break
train(batch_data)
######################################################################
#
# ๋ํ, ๋ค์์ non-context ๊ด๋ฆฌ์(manager)๋ ์์(start)/์ ์ง(stop) ๊ธฐ๋ฅ๋ ์ง์๋ฉ๋๋ค.
prof = torch.profiler.profile(
schedule=torch.profiler.schedule(wait=1, warmup=1, active=3, repeat=1),
on_trace_ready=torch.profiler.tensorboard_trace_handler('./log/resnet18'),
record_shapes=True,
with_stack=True)
prof.start()
for step, batch_data in enumerate(train_loader):
prof.step()
if step >= 1 + 1 + 3:
break
train(batch_data)
prof.stop()
######################################################################
#
# 3. ํ๋กํ์ผ๋ฌ ์คํ
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# ์ ์ฝ๋๋ฅผ ์คํํฉ๋๋ค. ํ๋กํ์ผ๋ง ๊ฒฐ๊ณผ๋ ``./log/resnet18`` ๋๋ ํ ๋ฆฌ์ ์ ์ฅ๋ฉ๋๋ค.
######################################################################
#
# 4. ํ
์๋ณด๋๋ฅผ ์ฌ์ฉํ์ฌ ๊ฒฐ๊ณผ ํ์ธ ๋ฐ ๋ชจ๋ธ ์ฑ๋ฅ ๋ถ์
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# .. note::
# ํ
์๋ณด๋ ํ๋ฌ๊ทธ์ธ(Tensorboard Plugin) ์ง์์ด ์ค๋จ๋์์ผ๋ฏ๋ก, ์๋ ๊ธฐ๋ฅ๋ค ์ค ์ผ๋ถ๋
# ์ด์ ์ฒ๋ผ ๋์ํ์ง ์์ ์ ์์ต๋๋ค. ์ด์ ๋ํ ๋์์ผ๋ก `HTA <https://github.com/pytorch/kineto/tree/main#holistic-trace-analysis>`_
# ๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
#
# ํ์ดํ ์น ํ๋กํ์ผ๋ฌ ํ
์๋ณด๋ ํ๋ฌ๊ทธ์ธ์ ์ค์นํฉ๋๋ค.
#
# .. code-block::
#
# pip install torch_tb_profiler
#
######################################################################
#
# ํ
์๋ณด๋๋ฅผ ์คํํฉ๋๋ค.
#
# .. code-block::
#
# tensorboard --logdir=./log
#
######################################################################
#
# ๊ตฌ๊ธ ํฌ๋กฌ(Google Chrome) ๋ธ๋ผ์ฐ์ ๋๋ ๋ง์ดํฌ๋ก์ํํธ ์ฃ์ง(Microsoft Edge) ๋ธ๋ผ์ฐ์ ์์ ํ
์๋ณด๋ ํ๋กํ์ผ(profile) URL์ ์ ์ํฉ๋๋ค. (**Safari ๋ธ๋ผ์ฐ์ ๋ ์ง์ํ์ง ์์ต๋๋ค.**)
#
# .. code-block::
#
# http://localhost:6006/#pytorch_profiler
#
######################################################################
#
# ์๋์ ๊ฐ์ด ํ๋กํ์ผ๋ฌ ํ๋ฌ๊ทธ์ธ ํ์ด์ง๋ฅผ ๋ณผ ์ ์์ต๋๋ค.
#
# - ๊ฐ์(Overview)
# .. image:: ../../_static/img/profiler_overview1.png
# :scale: 25 %
#
# ๊ฐ์ ํ์ด์ง์๋ ๋ชจ๋ธ ์ฑ๋ฅ์ ๋ํ ๋๋ต์ ์ธ ์์ฝ์ด ํ์๋ฉ๋๋ค.
#
# "GPU ์์ฝ(GPU Summary)" ํจ๋์๋ GPU ๊ตฌ์ฑ, GPU ์ฌ์ฉ๋ ๋ฐ Tensor ์ฝ์ด ์ฌ์ฉ๋์ด ํ์๋ฉ๋๋ค.
# ์ด ์์ ์์๋ GPU ์ฌ์ฉ๋์ด ๋ฎ์ต๋๋ค.
# ์ด๋ฌํ ์ธก์ ์งํ(metrics)์ ๋ํ ์์ธํ ๋ด์ฉ์ `์ฌ๊ธฐ <https://github.com/pytorch/kineto/blob/main/tb_plugin/docs/gpu_utilization.md>`__ ์์ ํ์ธํด์ฃผ์ธ์.
#
# "๋จ๊ณ ์๊ฐ ์ธ๋ถํ(Step Time Breakdown)"๋ ๊ฐ ๋จ๊ณ์์ ์ํ๋ ์๊ฐ์ ๋ถํฌ๋ฅผ ๋ณด์ฌ์ค๋๋ค.
# ์ด ์์ ์์๋ ``DataLoader`` ๊ณผ๋ถํ๊ฐ ์๋นํ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
#
# ํ๋จ์ "์ฑ๋ฅ ๊ถ์ฅ์ฌํญ(Performance Recommendation)"์ ํ๋กํ์ผ๋ง ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ
# ๋ฐ์ ๊ฐ๋ฅํ ๋ณ๋ชฉ ํ์์ ์๋์ผ๋ก ๊ฐ์กฐํ๊ณ ,
# ์คํ ๊ฐ๋ฅํ ์ต์ ํ ์ ์์ ์ ๊ณตํฉ๋๋ค.
#
# ์ผ์ชฝ "๋ณด๊ธฐ(Views)" ๋๋กญ๋ค์ด(dropdown) ๋ชฉ๋ก์์ ๋ณด๊ธฐ ํ์ด์ง๋ฅผ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค.
#
# .. image:: ../../_static/img/profiler_views_list.png
# :alt:
#
#
# - ์ฐ์ฐ ๋ณด๊ธฐ(Operator view)
# ์ฐ์ฐ ๋ณด๊ธฐ๋ ํธ์คํธ ๋๋ ์ฅ์น์์ ์คํ๋๋
# ๋ชจ๋ ํ์ดํ ์น ์ฐ์ฐ์์ ์ฑ๋ฅ์ ํ์ํฉ๋๋ค.
#
# .. image:: ../../_static/img/profiler_operator_view.png
# :scale: 25 %
#
# "์
ํ(Self)" ๊ธฐ๊ฐ์๋ ํ์ ์ฐ์ฐ์ ์๊ฐ์ด ํฌํจ๋์ง ์์ต๋๋ค.
# "์ ์ฒด(Total)" ๊ธฐ๊ฐ์๋ ํ์ ์ฐ์ฐ์ ์๊ฐ์ด ํฌํจ๋ฉ๋๋ค.
#
# - ํธ์ถ ์คํ ๋ณด๊ธฐ(View call stack)
# ์ฐ์ฐ์์ ``View Callstack``๋ฅผ ํด๋ฆญํ๋ฉด, ์ด๋ฆ์ ๊ฐ์ง๋ง ์๋ก ๋ค๋ฅธ ์ฐ์ฐ์๊ฐ ํ์๋ฉ๋๋ค.
# ํ์ ํ
์ด๋ธ์ ``View Callstack``๋ฅผ ํด๋ฆญํ๋ฉด, ํธ์ถ ์คํ ํ๋ ์(call stack frames)์ด ํ์๋ฉ๋๋ค.
#
# .. image:: ../../_static/img/profiler_callstack.png
# :scale: 25 %
#
# VS Code ๋ด๋ถ์์ ํ
์๋ณด๋๊ฐ ์คํ๋๋ ๊ฒฝ์ฐ
# (`์คํ ๊ฐ์ด๋ <https://devblogs.microsoft.com/python/python-in-visual-studio-code-february-2021-release/#tensorboard-integration>`__),
# ํธ์ถ ์คํ ํ๋ ์(call stack frame)์ ํด๋ฆญํ๋ฉด ํน์ ์ฝ๋ ๋ผ์ธ์ผ๋ก ์ด๋ํฉ๋๋ค.
#
# .. image:: ../../_static/img/profiler_vscode.png
# :scale: 25 %
#
# - ์ปค๋ ๋ณด๊ธฐ(Kernel view)
# GPU ์ปค๋ ๋ณด๊ธฐ(GPU kernel view)๋ ๋ชจ๋ ์ปค๋(kernel)์ด GPU์ ์๋นํ ์๊ฐ์ ๋ณด์ฌ์ค๋๋ค.
#
# .. image:: ../../_static/img/profiler_kernel_view.png
# :scale: 25 %
#
# ์ฌ์ฉ๋ Tensor ์ฝ์ด:
# ์ด ์ปค๋(kernel)์ด tensor ์ฝ์ด๋ฅผ ์ฌ์ฉํ๋์ง ์ฌ๋ถ๋ฃฐ ๋ํ๋
๋๋ค.
#
# SM๋น ํ๊ท ๋ธ๋ญ ์:
# SM๋น ๋ธ๋ญ ์ = ์ปค๋(kernel)์ ๋ธ๋ญ / GPU์ SM ์.
# ์ด ์์น๊ฐ 1๋ณด๋ค ์์ผ๋ฉด GPU ๋ฉํฐํ๋ก์ธ์๊ฐ ์์ ํ ์ฌ์ฉ๋์ง ์์์ ๋ํ๋
๋๋ค.
# "SM๋น ํ๊ท ๋ธ๋ญ ์(Mean Blocks per SM)"๋ ์ด ์ปค๋ ์ด๋ฆ์ ๋ชจ๋ ์คํ์ ๋ํ ๊ฐ์ค ํ๊ท ์ด๊ณ , ๊ฐ ์คํ ๊ธฐ๊ฐ์ ๊ฐ์ค์น๋ก ์ฌ์ฉํ์์ต๋๋ค.
#
# ํ๊ท ์์ ๋ฌ์ฑ ์ ์ ์จ(Mean Est. Achieved Occupancy):
# ์์ ๋ฌ์ฑ ์ ์ ์จ(Est. Achieved Occupancy)์ ์ด์ ํดํ(column's tooltip)์ ์ ์๋์ด ์์ต๋๋ค.
# ๋ฉ๋ชจ๋ฆฌ ๋์ญํญ ๊ฒฝ๊ณ ์ปค๋๊ณผ ๊ฐ์ ๋๋ถ๋ถ์ ๊ฒฝ์ฐ, ๋์์๋ก ์ข์ต๋๋ค.
# "ํ๊ท ์์ ๋ฌ์ฑ ์ ์ ์จ(Mean Est. Achieved Occupancy)"์ ์ปค๋ ์ด๋ฆ์ ๋ชจ๋ ์คํ์ ๋ํ ๊ฐ์ค ํ๊ท ์ด๋ฉฐ,
# ๊ฐ ์คํ์ ์ง์ ์๊ฐ์ ๊ฐ์ค์น๋ก ์ฌ์ฉํฉ๋๋ค.
#
# - ์ถ์ ๋ณด๊ธฐ(Trace view)
# ์ถ์ ๋ณด๊ธฐ๋ ํ๋กํ์ผ๋ ์ฐ์ฐ์์ GPU ์ปค๋์ ํ์๋ผ์ธ์ ๋ณด์ฌ์ค๋๋ค.
# ์๋์ ๊ฐ์ด ์ ํํ์ฌ ์ธ๋ถ ์ ๋ณด๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
#
# .. image:: ../../_static/img/profiler_trace_view1.png
# :scale: 25 %
#
# ์ค๋ฅธ์ชฝ ๋๊ตฌ ๋ชจ์์ ์ฌ์ฉํ์ฌ ๊ทธ๋ํ๋ฅผ ์ด๋ํ๊ณ ํ๋/์ถ์ํ ์ ์์ต๋๋ค.
# ๋ํ ํค๋ณด๋๋ฅผ ์ฌ์ฉํ์ฌ ํ์๋ผ์ธ ์์์ ํ๋/์ด๋ํ ์ ์์ต๋๋ค.
# 'w'๋ฐ 's' ํค๋ ๋ง์ฐ์ค ์ค์ฌ์ผ๋ก ํ๋๋๋ฉฐ,
# 'a'์ 'd' ํค๋ ํ์๋ผ์ธ์ ์ข์ฐ๋ก ์ด๋ํฉ๋๋ค.
# ์ฝ์ ์ ์๋ ํํ์ด ๋ณด์ผ ๋๊น์ง ์ด ํค๋ฅผ ์ฌ๋ฌ ๋ฒ ๋๋ฅผ ์ ์์ต๋๋ค.
#
# ์ญ๋ฐฉํฅ ์ฐ์ฐ์(backward operator)์ "Incoming Flow" ํ๋๊ฐ "forward correspond to backward" ๊ฐ์ธ ๊ฒฝ์ฐ,
# ํ
์คํธ๋ฅผ ํด๋ฆญํ์ฌ ์์๋๋ ์ ์ง ์ฐ์ฐ์(forward operator)๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.
#
# .. image:: ../../_static/img/profiler_trace_view_fwd_bwd.png
# :scale: 25 %
#
# ์ด ์์์์๋ ``enumerate(DataLoader)``๋ก ์ ๋์ฌ๊ฐ ๋ถ์ ์ด๋ฒคํธ์ ๋ง์ ์๊ฐ์ด ์์๋๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
# ๊ทธ๋ฆฌ๊ณ ๋๋ถ๋ถ์ ๊ธฐ๊ฐ ๋์ GPU๋ ์ฌ๋ ์ํ์
๋๋ค.
# ์ด ๊ธฐ๋ฅ์ ํธ์คํธ ์ธก์์ ๋ฐ์ดํฐ๋ฅผ ๋ก๋ํ๊ณ ๋ฐ์ดํฐ๋ฅผ ๋ณํํ๋ ๊ธฐ๋ฅ์ด๊ธฐ ๋๋ฌธ์,
# GPU ๋ฆฌ์์ค๊ฐ ๋ญ๋น๋ฉ๋๋ค.
######################################################################
#
# 5. ํ๋กํ์ผ๋ฌ์ ๋์์ผ๋ก ์ฑ๋ฅ ๊ฐ์
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# "๊ฐ์(Overview)" ํ์ด์ง ํ๋จ์ "์ฑ๋ฅ ์ถ์ฒ(Performance Recommendation)" ์ ์์ ๋ณ๋ชฉ ํ์์ด " ``DataLoader``์์ ์์ํฉ๋๋ค.
# ํ์ดํ ์น ``DataLoader``๋ ๊ธฐ๋ณธ์ ์ผ๋ก ๋จ์ผ ํ๋ก์ธ์ค๋ฅผ ์ฌ์ฉํฉ๋๋ค.
# ์ฌ์ฉ์๋ ๋งค๊ฐ๋ณ์ ``num_workers``๋ฅผ ์ค์ ํ์ฌ ๋ค์ค ํ๋ก์ธ์ค ๋ฐ์ดํฐ ๋ก๋๋ฅผ ํ์ฑํํ ์ ์์ต๋๋ค.
# ์์ธํ ๋ด์ฉ์ `์ฌ๊ธฐ <https://pytorch.org/docs/stable/data.html#single-and-multi-process-data-loading>`__ ์ ์์ต๋๋ค.
#
# ์ด ์์์์ "์ฑ๋ฅ ๊ถ์ฅ์ฌํญ(Performance Recommendation)"์ ๋ฐ๋ผ ์๋์ ๊ฐ์ด ``num_workers``๋ฅผ ์ค์ ํ๊ณ ,
# ``./log/resnet18_4workers``์ ๊ฐ์ ๋ค๋ฅธ ์ด๋ฆ์ ``tensorboard_trace_handler``๋ก ์ ๋ฌํ ํ ๋ค์ ์คํํฉ๋๋ค.
#
# .. code-block::
#
# train_loader = torch.utils.data.DataLoader(train_set, batch_size=32, shuffle=True, num_workers=4)
#
######################################################################
#
# ๊ทธ๋ฐ ๋ค์ ์ผ์ชฝ "์คํ(Runs)" ๋๋กญ๋ค์ด(dropdown) ๋ชฉ๋ก์์ ์ต๊ทผ ํ๋กํ์ผ๋ ์คํ์ ์ ํํฉ๋๋ค.
#
# .. image:: ../../_static/img/profiler_overview2.png
# :scale: 25 %
#
# ์์ ๋ณด๊ธฐ(view)์์ ์ด์ ์คํ์ธ 132ms์ ๋นํด ๋จ๊ณ(step) ์๊ฐ์ด ์ฝ 76ms๋ก ๊ฐ์ํ๊ณ ,
# ``DataLoader``์ ์๊ฐ ๊ฐ์๊ฐ ์ฃผ๋ก ๊ธฐ์ฌํ๋ค๋ ๊ฒ์ ์ ์ ์์ต๋๋ค.
#
# .. image:: ../../_static/img/profiler_trace_view2.png
# :scale: 25 %
#
# ์์ ๋ณด๊ธฐ(view)์์ ``enumerate(DataLoader)``์ ๋ฐํ์์ด ๊ฐ์ํ๊ณ ,
# GPU ํ์ฉ๋๊ฐ ์ฆ๊ฐํ๋ ๊ฒ์ ์ ์ ์์ต๋๋ค.
######################################################################
#
# 6. ๋ค๋ฅธ ๊ณ ๊ธ ๊ธฐ๋ฅ์ผ๋ก ์ฑ๋ฅ ๋ถ์
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# - ๋ฉ๋ชจ๋ฆฌ ๋ณด๊ธฐ(Memory view)
# ๋ฉ๋ชจ๋ฆฌ ํ๋กํ์ผ์ ์ค์ ํ๋ ค๋ฉด ``torch.profiler.profile`` ์ธ์์์ ``profile_memory``๋ฅผ ``True``๋ก ์ค์ ํด์ผ ํฉ๋๋ค.
#
# Azure์ ๊ธฐ์กด ์์ ๋ฅผ ์ฌ์ฉํด ๋ณผ ์ ์์ต๋๋ค.
#
# .. code-block::
#
# pip install azure-storage-blob
# tensorboard --logdir=https://torchtbprofiler.blob.core.windows.net/torchtbprofiler/demo/memory_demo_1_10
#
# ํ๋กํ์ผ๋ฌ๋ ํ๋กํ์ผ๋ง ์ค์ ๋ชจ๋ ๋ฉ๋ชจ๋ฆฌ ํ ๋น/ํด์ ์ด๋ฒคํธ์ ํ ๋น์์ ๋ด๋ถ ์ํ๋ฅผ ๊ธฐ๋กํฉ๋๋ค.
# ๋ฉ๋ชจ๋ฆฌ ๋ณด๊ธฐ(memory view)๋ ๋ค์๊ณผ ๊ฐ์ด ์ธ ๊ฐ์ง ์์๋ก ๊ตฌ์ฑ๋ฉ๋๋ค.
#
# .. image:: ../../_static/img/profiler_memory_view.png
# :scale: 25 %
#
# ๊ตฌ์ฑ ์์๋ ๊ฐ๊ฐ ๋ฉ๋ชจ๋ฆฌ ๊ณก์ ๊ทธ๋ํ, ๋ฉ๋ชจ๋ฆฌ ์ด๋ฒคํธ ํ
์ด๋ธ ๋ฐ ๋ฉ๋ชจ๋ฆฌ ํต๊ณ ํ
์ด๋ธ์
๋๋ค.
#
# ๋ฉ๋ชจ๋ฆฌ ์ ํ์ "์ฅ์น(Device)" ์ ํ ์์์์ ์ ํํ ์ ์์ต๋๋ค.
# ์๋ฅผ ๋ค๋ฉด, ๋ค์ ํ์์ "GPU0"์ GPU 0์์์ ๊ฐ ์ฐ์ฐ์์ ๋ฉ๋ก๋ฆฌ ์ฌ์ฉ๋๋ง ๋ณด์ฌ์ฃผ๊ณ , CPU ๋๋ ๋ค๋ฅธ GPU๋ฅผ ํฌํจํ์ง ์๋๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค.
#
# ๋ฉ๋ชจ๋ฆฌ ๊ณก์ ์ ๋ฉ๋ชจ๋ฆฌ ์๋น์ ์ถ์ธ๋ฅผ ๋ณด์ฌ์ค๋๋ค. "Allocated" ๊ณก์ ์ ์ค์ ์ฌ์ฉ ์ค์ธ ์ด ๋ฉ๋ชจ๋ฆฌ,
# ์๋ฅผ ๋ค๋ฉด tensor๋ฅผ ๋ณด์ฌ์ค๋๋ค. ํ์ดํ ์น์์ ์บ์ฑ ๋ฉ์ปค๋์ฆ(caching mechanism)์ CUDA ํ ๋น๊ธฐ ๋ฐ ์ผ๋ถ ๋ค๋ฅธ ํ ๋น๊ธฐ์ ์ฌ์ฉ๋ฉ๋๋ค.
# "Reserved" ๊ณก์ ์ ํ ๋น์์ ์ํด ์์ฝ๋ ์ด ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๋ณด์ฌ์ค๋๋ค. ๊ทธ๋ํ๋ฅผ ์ขํด๋ฆญํ๊ณ ๋์ด์
# ์ํ๋ ๋ฒ์์ ์ด๋ฒคํธ๋ฅผ ์ ํํ ์ ์์ต๋๋ค:
#
# .. image:: ../../_static/img/profiler_memory_curve_selecting.png
# :scale: 25 %
#
# ์ ํํ ํ์๋ ์ธ ๊ฐ์ง ๊ตฌ์ฑ ์์๊ฐ ์ ํ๋ ๋ฒ์์ ๋ง๊ฒ ์
๋ฐ์ดํธ๋์ด
# ์์ธํ ์ ๋ณด๋ฅผ ์ป์ ์ ์์ต๋๋ค. ์ด ํ๋ก์ธ์ค๋ฅผ ๋ฐ๋ณตํ๋ฉด, ๋งค์ฐ ์ธ๋ถํ๋ ์ธ๋ถ ์ ๋ณด๋ฅผ ํ๋ํ ์ ์์ต๋๋ค. ๊ทธ๋ํ๋ฅผ ์ฐํด๋ฆญํ๋ฉด
# ๊ทธ๋ํ๊ฐ ์ด๊ธฐ ์ํ๋ก ์ฌ์ค์ ๋ฉ๋๋ค.
#
# .. image:: ../../_static/img/profiler_memory_curve_single.png
# :scale: 25 %
#
# ๋ฉ๋ชจ๋ฆฌ ์ด๋ฒคํธ ํ
์ด๋ธ์์ ํ ๋น ๋ฐ ํด์ ์ด๋ฒคํธ๋ ํ๋์ ํญ๋ชฉ์ผ๋ก ์์ผ๋ก ๊ตฌ์ฑ๋ฉ๋๋ค. "operator" ์ด์๋
# ํ ๋น์ ๋ฐ์์ํค๋ ์ฆ์ ATen ์ฐ์ฐ์๊ฐ ํ์๋ฉ๋๋ค. ํ์ดํ ์น์์ ATen ์ฐ์ฐ์๋ ์ผ๋ฐ์ ์ผ๋ก
# ``aten::empty``๋ฅผ ์ฌ์ฉํ์ฌ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ ๋นํฉ๋๋ค. ์๋ฅผ ๋ค์ด, ``aten::ones``์ ``aten::empty`` ๋ค์์
# ``aten::fill_``๋ก ๊ตฌํ๋ฉ๋๋ค. ์ฐ์ฐ์ ์ด๋ฆ๋ง ``aten::empty``๋ก ํ์ํด๋ ๋ณ ๋์์ด ๋์ง ์์ต๋๋ค. ์ด ํน์ํ ๊ฒฝ์ฐ์๋
# ``aten::ones (aten::empty)``๋ก ํ์๋ฉ๋๋ค. "ํ ๋น ์๊ฐ(Allocation Time)", "ํด์ ์๊ฐ(Release Time)" ๋ฐ "๊ธฐ๊ฐ(Duration)"์
# ์ด๋ฒคํธ๊ฐ ์๊ฐ ๋ฒ์๋ฅผ ๋ฒ์ด๋๋ ๊ฒฝ์ฐ ์ด์ ๋ฐ์ดํฐ๊ฐ ๋๋ฝ๋ ์ ์์ต๋๋ค.
#
# ๋ฉ๋ชจ๋ฆฌ ํต๊ณ ํ
์ด๋ธ์์, "ํฌ๊ธฐ ์ฆ๊ฐ(Size Increase)" ์ด์ ๋ชจ๋ ํ ๋น ํฌ๊ธฐ๋ฅผ ํฉ์ฐํ๊ณ ๋ชจ๋ ๋ฉ๋ชจ๋ฆฌ ๋ฆด๋ฆฌ์ค(release)
# ํฌ๊ธฐ๋ฅผ ๋บ ๊ฐ, ์ฆ, ์ด ์ฐ์ฐ์ ์ดํ์ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ์ ์ฆ๊ฐ ๊ฐ์
๋๋ค. "์์ฒด ํฌ๊ธฐ ์ฆ๊ฐ(Self Size Increase)" ์ด์
# "ํฌ๊ธฐ ์ฆ๊ฐ(Size Increase)"์ ์ ์ฌ ํ์ง๋ง, ํ์ ์ฐ์ฐ์์ ํ ๋น์ ๊ณ์ฐํ์ง ์์ต๋๋ค. ATen ์ฐ์ฐ์์ ๊ตฌํ ์ธ๋ถ ์ฌํญ๊ณผ
# ๊ด๋ จํ์ฌ, ์ผ๋ถ ์ฐ์ฐ์๋ ๋ค๋ฅธ ์ฐ์ฐ์๋ฅผ ํธ์ถํ ์ ์์ผ๋ฏ๋ก, ๋ฉ๋ชจ๋ฆฌ ํ ๋น์ ์ฝ ์คํ์ ๋ชจ๋ ์์ค์์
# ๋ฐ์ํ ์ ์์ต๋๋ค. ์ฆ, "์์ฒด ํฌ๊ธฐ ์ฆ๊ฐ(Self Size Increase)"๋ ํ์ฌ ์์ค์ ์ฝ ์คํ์์ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ์ฆ๊ฐ๋ง์ ๊ณ์ฐํฉ๋๋ค.
# ๋ง์ง๋ง์ผ๋ก, "ํ ๋น ํฌ๊ธฐ(Allocation Size)" ์ด์ ๋ฉ๋ชจ๋ฆฌ ๋ฆด๋ฆฌ์ค๋ฅผ ๊ณ ๋ คํ์ง ์๊ณ ๋ชจ๋ ํ ๋น์ ํฉ์ฐํฉ๋๋ค.
#
# - ๋ถ์ฐ ๋ณด๊ธฐ(Distributed view)
# ์ด์ ํ๋ฌ๊ทธ์ธ์ NCCL/GLOO๋ฅผ ๋ฐฑ์๋๋ก ์ฌ์ฉํ๋ DDP ํ๋กํ์ผ๋ง์ ๋ํ ๋ถ์ฐ ๋ณด๊ธฐ๋ฅผ ์ง์ํฉ๋๋ค.
#
# Azure์ ๊ธฐ์กด ์์ ๋ฅผ ์ฌ์ฉํด ๋ณผ ์ ์์ต๋๋ค:
#
# .. code-block::
#
# pip install azure-storage-blob
# tensorboard --logdir=https://torchtbprofiler.blob.core.windows.net/torchtbprofiler/demo/distributed_bert
#
# .. image:: ../../_static/img/profiler_distributed_view.png
# :scale: 25 %
#
# "์ปดํจํ
/์ปค๋ฎค๋์ผ์ด์
๊ฐ์(Computation/Communication Overview)"์๋ ์ปดํจํ
/์ปค๋ฎค๋์ผ์ด์
๋น์จ๊ณผ ์ค๋ณต ์ ๋๊ฐ ํ์๋ฉ๋๋ค.
# ์ด ๋ณด๊ธฐ์์, ์ฌ์ฉ์๋ ์์
์ ๊ฐ์ ๋ก๋ ๋ฐธ๋ฐ์ฑ ๋ฌธ์ ๋ฅผ ํ์
ํ ์ ์์ต๋๋ค.
# ์๋ฅผ ๋ค์ด, ํ ์์
์์ ์ฐ์ฐ + ์ค๋ณต ์๊ฐ์ด ๋ค๋ฅธ ์์
์๋ณด๋ค ํจ์ฌ ํฐ ๊ฒฝ์ฐ,
# ๋ก๋ ๋ฐธ๋ฐ์ฑ์ ๋ฌธ์ ๊ฐ ์๊ฑฐ๋ ์ด ์์
์๊ฐ ๋์ค์(straggler)์ผ ์ ์์ต๋๋ค.
#
# "๋๊ธฐํ/์ปค๋ฎค๋์ผ์ด์
๊ฐ์(Synchronizing/Communication Overview)"๋ ํต์ ์ ํจ์จ์ฑ์ ๋ณด์ฌ์ค๋๋ค.
# "๋ฐ์ดํฐ ๊ตํ ์๊ฐ(Data Transfer Time)"์ ์ค์ ๋ฐ์ดํฐ๋ฅผ ๊ตํํ๋ ์๊ฐ์
๋๋ค.
# "๋๊ธฐํ ์๊ฐ(Synchronizing Time)"์ ๋ค๋ฅธ ์์
์์ ๋๊ธฐ ๋ฐ ๋๊ธฐํํ๋ ์๊ฐ์
๋๋ค.
#
# ํ ์์
์์ "๋๊ธฐํ ์๊ฐ"์ด ๋ค๋ฅธ ์์
์ ๋ณด๋ค ํจ์ฌ ์งง๋ค๋ฉดโ,
# ์ด ์์
์๋ ๋ค๋ฅธ ์์
์๋ณด๋ค ๋ ๋ง์ ๊ณ์ฐ ์์
๋์ ๊ฐ์ง ์ ์๋ ๋์ค์(straggler)์ผ ์ ์์ต๋๋คโ.
#
# "์ปค๋ฎค๋์ผ์ด์
์์
ํต๊ณ(Communication Operations Stats)"๋ ๊ฐ ์์
์์ ๋ชจ๋ ํต์ ์์
์ ๋ํ ์ธ๋ถ ํต๊ณ๋ฅผ ์์ฝํฉ๋๋ค.
######################################################################
#
# 7. ์ถ๊ฐ ์ฐ์ต: AMD GPU์์ PyTorch ํ๋กํ์ผ๋ง
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#
# The AMD ROCm Platform is an open-source software stack designed for GPU computation, consisting of drivers, development tools, and APIs.
# We can run the above mentioned steps on AMD GPUs. In this section, we will use Docker to install the ROCm base development image
# before installing PyTorch.
######################################################################
#
# For the purpose of example, let's create a directory called ``profiler_tutorial``, and save the code in **Step 1** as ``test_cifar10.py`` in this directory.
#
# .. code-block::
#
# mkdir ~/profiler_tutorial
# cd profiler_tutorial
# vi test_cifar10.py
######################################################################
#
# At the time of this writing, the Stable(``2.1.1``) Linux version of PyTorch on ROCm Platform is `ROCm 5.6 <https://pytorch.org/get-started/locally/>`_.
#
#
# - Obtain a base Docker image with the correct user-space ROCm version installed from `Docker Hub <https://hub.docker.com/repository/docker/rocm/dev-ubuntu-20.04>`_.
#
# It is ``rocm/dev-ubuntu-20.04:5.6``.
#
# - Start the ROCm base Docker container:
#
#
# .. code-block::
#
# docker run -it --network=host --device=/dev/kfd --device=/dev/dri --group-add=video --ipc=host --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --shm-size 8G -v ~/profiler_tutorial:/profiler_tutorial rocm/dev-ubuntu-20.04:5.6
#
#
# - Inside the container, install any dependencies needed for installing the wheels package.
#
# .. code-block::
#
# sudo apt update
# sudo apt install libjpeg-dev python3-dev -y
# pip3 install wheel setuptools
# sudo apt install python-is-python3
#
#
# - Install the wheels:
#
# .. code-block::
#
# pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.6
#
#
# - Install the ``torch_tb_profiler``, and then, run the Python file ``test_cifar10.py``:
#
# .. code-block::
#
# pip install torch_tb_profiler
# cd /profiler_tutorial
# python test_cifar10.py
#
#
# Now, we have all the data needed to view in TensorBoard:
#
# .. code-block::
#
# tensorboard --logdir=./log
#
# Choose different views as described in **Step 4**. For example, below is the **Operator** View:
#
# .. image:: ../../_static/img/profiler_rocm_tensorboard_operartor_view.png
# :scale: 25 %
######################################################################
#
# At the time this section is written, **Trace** view does not work and it displays nothing. You can work around by typing ``chrome://tracing`` in your Chrome Browser.
#
#
# - Copy the ``trace.json`` file under ``~/profiler_tutorial/log/resnet18`` directory to the Windows.
# You may need to copy the file by using ``scp`` if the file is located in a remote location.
#
# - Click **Load** button to load the trace JSON file from the ``chrome://tracing`` page in the browser.
#
# .. image:: ../../_static/img/profiler_rocm_chrome_trace_view.png
# :scale: 25 %
######################################################################
#
# As mentioned previously, you can move the graph and zoom in and out.
# You can also use keyboard to zoom and move around inside the timeline.
# The ``w`` and ``s`` keys zoom in centered around the mouse,
# and the ``a`` and ``d`` keys move the timeline left and right.
# You can hit these keys multiple times until you see a readable representation.
######################################################################
#
# ๋ ์์๋ณด๊ธฐ
# --------------
#
# ํ์ต์ ๊ณ์ํ๋ ค๋ฉด ๋ค์ ๋ฌธ์๋ฅผ ์ฐธ์กฐํ์๊ณ ,
# `์ฌ๊ธฐ <https://github.com/pytorch/kineto/issues>`__ ์์ ์์ ๋กญ๊ฒ ์ด์๋ฅผ ์ด์ด๋ณด์ธ์.
#
# - `PyTorch TensorBoard Profiler Github <https://github.com/pytorch/kineto/tree/master/tb_plugin>`_
# - `torch.profiler API <https://pytorch.org/docs/master/profiler.html>`_
# - `HTA <https://github.com/pytorch/kineto/tree/main#holistic-trace-analysis>`_