1
1
"""
2
- (beta) Using TORCH_LOGS python API with torch.compile
2
+ (beta) torch.compile๊ณผ ํจ๊ป TORCH_LOGS ํ์ด์ฌ API ์ฌ์ฉํ๊ธฐ
3
3
==========================================================================================
4
- **Author:** `Michael Lazos <https://github.com/mlazos>`_
4
+ **์ ์:** `Michael Lazos <https://github.com/mlazos>`_
5
+ **๋ฒ์ญ:** `์ฅํจ์ <https://github.com/hyoyoung>`_
5
6
"""
6
7
7
8
import logging
10
11
#
11
12
# This tutorial introduces the ``TORCH_LOGS`` environment variable, as well as the Python API, and
12
13
# demonstrates how to apply it to observe the phases of ``torch.compile``.
14
+ # ์ด ํํ ๋ฆฌ์ผ์์๋ ``TORCH_LOGS`` ํ๊ฒฝ ๋ณ์์ ํจ๊ป Python API๋ฅผ ์๊ฐํ๊ณ ,
15
+ # ์ด๋ฅผ ์ ์ฉํ์ฌ ``torch.compile``์ ๋จ๊ณ๋ฅผ ๊ด์ฐฐํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค.
13
16
#
14
17
# .. note::
15
18
#
16
- # This tutorial requires PyTorch 2.2.0 or later .
19
+ # ์ด ํํ ๋ฆฌ์ผ์๋ PyTorch 2.2.0 ์ด์ ๋ฒ์ ์ด ํ์ํฉ๋๋ค .
17
20
#
18
21
#
19
22
20
23
21
24
######################################################################
22
- # Setup
25
+ # ์ค์
23
26
# ~~~~~~~~~~~~~~~~~~~~~
24
27
# In this example, we'll set up a simple Python function which performs an elementwise
25
28
# add and observe the compilation process with ``TORCH_LOGS`` Python API.
29
+ # ์ด ์์ ์์๋ ์์๋ณ ๋ง์
์ ์ํํ๋ ๊ฐ๋จํ ํ์ด์ฌ ํจ์๋ฅผ ์ค์ ํ๊ณ
30
+ # ``TORCH_LOGS`` ํ์ด์ฌ API๋ฅผ ์ฌ์ฉํ์ฌ ์ปดํ์ผ ํ๋ก์ธ์ค๋ฅผ ๊ด์ฐฐํด ๋ณด๊ฒ ์ต๋๋ค.
26
31
#
27
32
# .. note::
28
33
#
29
- # There is also an environment variable ``TORCH_LOGS``, which can be used to
30
- # change logging settings at the command line. The equivalent environment
31
- # variable setting is shown for each example .
34
+ # ๋ช
๋ น์ค์์ ๋ก๊น
์ค์ ์ ๋ณ๊ฒฝํ๋ ๋ฐ ์ฌ์ฉํ ์ ์๋
35
+ # ํ๊ฒฝ ๋ณ์ ``TORCH_LOGS``๋ ์์ต๋๋ค. ๊ฐ ์์ ์ ํด๋นํ๋
36
+ # ํ๊ฒฝ ๋ณ์ ์ค์ ์ด ํ์๋์ด ์์ต๋๋ค .
32
37
33
38
import torch
34
39
35
- # exit cleanly if we are on a device that doesn't support torch.compile
40
+ # torch.compile์ ์ง์ํ์ง ์๋ ๊ธฐ๊ธฐ์ธ ๊ฒฝ์ฐ ์์ ํ ์ข
๋ฃํฉ๋๋ค.
36
41
if torch .cuda .get_device_capability () < (7 , 0 ):
37
42
print ("Skipping because torch.compile is not supported on this device." )
38
43
else :
@@ -45,52 +50,51 @@ def fn(x, y):
45
50
inputs = (torch .ones (2 , 2 , device = "cuda" ), torch .zeros (2 , 2 , device = "cuda" ))
46
51
47
52
48
- # print separator and reset dynamo
49
- # between each example
53
+ # ๊ฐ ์์ ์ฌ์ด์ ๊ตฌ๋ถ ๊ธฐํธ๋ฅผ ์ถ๋ ฅํ๊ณ dynamo๋ฅผ resetํฉ๋๋ค
50
54
def separator (name ):
51
55
print (f"==================={ name } =========================" )
52
56
torch ._dynamo .reset ()
53
57
54
58
55
59
separator ("Dynamo Tracing" )
56
- # View dynamo tracing
60
+ # dynamo tracing ๋ณด๊ธฐ
57
61
# TORCH_LOGS="+dynamo"
58
62
torch ._logging .set_logs (dynamo = logging .DEBUG )
59
63
fn (* inputs )
60
64
61
65
separator ("Traced Graph" )
62
- # View traced graph
66
+ # traced ๊ทธ๋ํ ๋ณด๊ธฐ
63
67
# TORCH_LOGS="graph"
64
68
torch ._logging .set_logs (graph = True )
65
69
fn (* inputs )
66
70
67
71
separator ("Fusion Decisions" )
68
- # View fusion decisions
72
+ # fusion decision ๋ณด๊ธฐ
69
73
# TORCH_LOGS="fusion"
70
74
torch ._logging .set_logs (fusion = True )
71
75
fn (* inputs )
72
76
73
77
separator ("Output Code" )
74
- # View output code generated by inductor
78
+ # inductor๊ฐ ์์ฑํ ๊ฒฐ๊ณผ ์ฝ๋ ๋ณด๊ธฐ
75
79
# TORCH_LOGS="output_code"
76
80
torch ._logging .set_logs (output_code = True )
77
81
fn (* inputs )
78
82
79
83
separator ("" )
80
84
81
85
######################################################################
82
- # Conclusion
86
+ # ๊ฒฐ๋ก
83
87
# ~~~~~~~~~~
84
88
#
85
- # In this tutorial we introduced the TORCH_LOGS environment variable and python API
86
- # by experimenting with a small number of the available logging options .
87
- # To view descriptions of all available options, run any python script
88
- # which imports torch and set TORCH_LOGS to "help".
89
+ # ์ด ํํ ๋ฆฌ์ผ์์๋ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ช ๊ฐ์ง ๋ก๊น
์ต์
์ ์คํํ์ฌ
90
+ # TORCH_LOGS ํ๊ฒฝ ๋ณ์์ Python API๋ฅผ ์๊ฐํ์ต๋๋ค .
91
+ # ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ ์ต์
์ ๋ํ ์ค๋ช
์ ๋ณด๋ ค๋ฉด
92
+ # ํ์ด์ฌ ์คํฌ๋ฆฝํธ์์ import torch๋ฅผ ์คํํ๊ณ TORCH_LOGS๋ฅผ "help"๋ก ์ค์ ํ์ธ์ .
89
93
#
90
- # Alternatively, you can view the `torch._logging documentation `_ to see
91
- # descriptions of all available logging options .
94
+ # ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก๋, `torch._logging ๋ฌธ์ `_ ๋ฅผ ๋ณด๋ฉด,
95
+ # ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ ๋ก๊น
์ต์
์ ๋ํ ์ค๋ช
์ ํ์ธํ ์ ์์ต๋๋ค .
92
96
#
93
- # For more information on torch.compile, see the `torch.compile tutorial`_ .
97
+ # torch.compile์ ๊ดํ ๋ ๋ง์ ์ ๋ณด๋, `torch.compile ํํ ๋ฆฌ์ผ`_๋ฅผ ๋ณด์ธ์ .
94
98
#
95
- # .. _torch._logging documentation : https://pytorch.org/docs/main/logging.html
96
- # .. _torch.compile tutorial : https://tutorials.pytorch.kr/intermediate/torch_compile_tutorial.html
99
+ # .. _torch._logging ๋ฌธ์ : https://pytorch.org/docs/main/logging.html
100
+ # .. _torch.compile ํํ ๋ฆฌ์ผ : https://tutorials.pytorch.kr/intermediate/torch_compile_tutorial.html
0 commit comments