Skip to content

Commit a321092

Browse files
authored
recipes_source/torch_logs.py ๋ฒˆ์—ญ (#963)
* translate beginner_source/torchtext_custom_dataset_tutorial.py
1 parent 5fc8a7d commit a321092

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

โ€Žbeginner_source/torchtext_custom_dataset_tutorial.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
* ๋ฌธ์žฅ์— ๋ณ€ํ™˜ ์ ์šฉํ•˜๊ธฐ
2727
* ๋ฒ„ํ‚ท ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ
2828
29-
๋‹ค์Œ ์˜์–ด์—์„œ ๋…์ผ์–ด ๋ฒˆ์—ญ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋ธ์„ ํ›ˆ๋ จํ•˜๊ธฐ ์œ„ํ•ด ๋ฐ์ดํ„ฐ์…‹์„ ์ค€๋น„ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
29+
30+
์˜์–ด์—์„œ ๋…์ผ์–ด ๋ฒˆ์—ญ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋ชจ๋ธ์„ ํ›ˆ๋ จํ•˜๊ธฐ ์œ„ํ•ด ๋ฐ์ดํ„ฐ์…‹์„ ์ค€๋น„ํ•ด์•ผ ํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
3031
`Tatoeba Project <https://tatoeba.org/en>`_๊ฐ€ ์ œ๊ณตํ•˜๋Š” ํƒญ์œผ๋กœ ๊ตฌ๋ถ„๋œ ๋…์ผ์–ด-์˜์–ด ๋ฌธ์žฅ ์Œ์„ ์‚ฌ์šฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
3132
์ด ๋ฐ์ดํ„ฐ๋Š” `๋‹ค์šด๋กœ๋“œ ๋งํฌ <https://www.manythings.org/anki/deu-eng.zip>`__ ์—์„œ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
3233
@@ -83,7 +84,7 @@
8384
# ์œ„์˜ ์ฝ”๋“œ ๋ธ”๋ก์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค
8485
#
8586
# 1. 2๋ฒˆ์งธ ์ค„์—์„œ ํŒŒ์ผ ์ด๋ฆ„์˜ ๋ฐ˜๋ณต๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค
86-
# 2. 3๋ฒˆ์งธ ์ค„์—์„œ ํ•ด๋‹น ๋ฐ˜๋ณต๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด `FileOpener`์— ์ „๋‹ฌํ•˜๊ณ ,
87+
# 2. 3๋ฒˆ์งธ ์ค„์—์„œ ํ•ด๋‹น ๋ฐ˜๋ณต๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด๋ฅผ `FileOpener`์— ์ „๋‹ฌํ•˜๊ณ ,
8788
# ํŒŒ์ผ์„ ์ฝ๊ธฐ ๋ชจ๋“œ๋กœ ์—ด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
8889
# 3. 4๋ฒˆ์งธ ์ค„์—์„œ ํ•ด๋‹น ํŒŒ์ผ์„ ํŒŒ์‹ฑํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.
8990
# ํ•ด๋‹น ํ•จ์ˆ˜๋Š” ํƒญ์œผ๋กœ ๊ตฌ๋ถ„๋œ ํŒŒ์ผ์˜ ๊ฐ๊ฐ ์ค„(row)์ด ์žˆ๋Š” ๋ฐ˜๋ณต ๊ฐ€๋Šฅํ•œ ํŠœํ”Œ ๊ฐ์ฒด๋ฅผ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค.
@@ -330,7 +331,7 @@ def separateSourceTarget(sequence_pairs):
330331
# %%
331332
# ์ด์ œ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค
332333
#
333-
# ํŽ˜๋”ฉ
334+
# ํŒจ๋”ฉ
334335
# -------
335336
# ์•ž์„œ ์„ค๋ช…ํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ์–ดํœ˜๋ฅผ ๊ตฌ์ถ•ํ•  ๋•Œ, ๋ฐฐ์น˜์—์„œ ๋ชจ๋“  ์‹œํ€€์Šค๋ฅผ ๋™์ผํ•œ ๊ธธ์ด๋กœ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด
336337
# ์งง์€ ๋ฌธ์žฅ์€ ํŒจ๋”ฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ํŒจ๋”ฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

โ€Žrecipes_source/torch_logs.py

+28-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
2-
(beta) Using TORCH_LOGS python API with torch.compile
2+
(beta) torch.compile๊ณผ ํ•จ๊ป˜ TORCH_LOGS ํŒŒ์ด์ฌ API ์‚ฌ์šฉํ•˜๊ธฐ
33
==========================================================================================
4-
**Author:** `Michael Lazos <https://github.com/mlazos>`_
4+
**์ €์ž:** `Michael Lazos <https://github.com/mlazos>`_
5+
**๋ฒˆ์—ญ:** `์žฅํšจ์˜ <https://github.com/hyoyoung>`_
56
"""
67

78
import logging
@@ -10,29 +11,33 @@
1011
#
1112
# This tutorial introduces the ``TORCH_LOGS`` environment variable, as well as the Python API, and
1213
# demonstrates how to apply it to observe the phases of ``torch.compile``.
14+
# ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ``TORCH_LOGS`` ํ™˜๊ฒฝ ๋ณ€์ˆ˜์™€ ํ•จ๊ป˜ Python API๋ฅผ ์†Œ๊ฐœํ•˜๊ณ ,
15+
# ์ด๋ฅผ ์ ์šฉํ•˜์—ฌ ``torch.compile``์˜ ๋‹จ๊ณ„๋ฅผ ๊ด€์ฐฐํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
1316
#
1417
# .. note::
1518
#
16-
# This tutorial requires PyTorch 2.2.0 or later.
19+
# ์ด ํŠœํ† ๋ฆฌ์–ผ์—๋Š” PyTorch 2.2.0 ์ด์ƒ ๋ฒ„์ „์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
1720
#
1821
#
1922

2023

2124
######################################################################
22-
# Setup
25+
# ์„ค์ •
2326
# ~~~~~~~~~~~~~~~~~~~~~
2427
# In this example, we'll set up a simple Python function which performs an elementwise
2528
# add and observe the compilation process with ``TORCH_LOGS`` Python API.
29+
# ์ด ์˜ˆ์ œ์—์„œ๋Š” ์š”์†Œ๋ณ„ ๋ง์…ˆ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฐ„๋‹จํ•œ ํŒŒ์ด์ฌ ํ•จ์ˆ˜๋ฅผ ์„ค์ •ํ•˜๊ณ 
30+
# ``TORCH_LOGS`` ํŒŒ์ด์ฌ API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํŒŒ์ผ ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ด€์ฐฐํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
2631
#
2732
# .. note::
2833
#
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+
# ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •์ด ํ‘œ์‹œ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
3237

3338
import torch
3439

35-
# exit cleanly if we are on a device that doesn't support torch.compile
40+
# torch.compile์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๊ธฐ๊ธฐ์ธ ๊ฒฝ์šฐ ์™„์ „ํžˆ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.
3641
if torch.cuda.get_device_capability() < (7, 0):
3742
print("Skipping because torch.compile is not supported on this device.")
3843
else:
@@ -45,52 +50,51 @@ def fn(x, y):
4550
inputs = (torch.ones(2, 2, device="cuda"), torch.zeros(2, 2, device="cuda"))
4651

4752

48-
# print separator and reset dynamo
49-
# between each example
53+
# ๊ฐ ์˜ˆ์ œ ์‚ฌ์ด์˜ ๊ตฌ๋ถ„ ๊ธฐํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  dynamo๋ฅผ resetํ•ฉ๋‹ˆ๋‹ค
5054
def separator(name):
5155
print(f"==================={name}=========================")
5256
torch._dynamo.reset()
5357

5458

5559
separator("Dynamo Tracing")
56-
# View dynamo tracing
60+
# dynamo tracing ๋ณด๊ธฐ
5761
# TORCH_LOGS="+dynamo"
5862
torch._logging.set_logs(dynamo=logging.DEBUG)
5963
fn(*inputs)
6064

6165
separator("Traced Graph")
62-
# View traced graph
66+
# traced ๊ทธ๋ž˜ํ”„ ๋ณด๊ธฐ
6367
# TORCH_LOGS="graph"
6468
torch._logging.set_logs(graph=True)
6569
fn(*inputs)
6670

6771
separator("Fusion Decisions")
68-
# View fusion decisions
72+
# fusion decision ๋ณด๊ธฐ
6973
# TORCH_LOGS="fusion"
7074
torch._logging.set_logs(fusion=True)
7175
fn(*inputs)
7276

7377
separator("Output Code")
74-
# View output code generated by inductor
78+
# inductor๊ฐ€ ์ƒ์„ฑํ•œ ๊ฒฐ๊ณผ ์ฝ”๋“œ ๋ณด๊ธฐ
7579
# TORCH_LOGS="output_code"
7680
torch._logging.set_logs(output_code=True)
7781
fn(*inputs)
7882

7983
separator("")
8084

8185
######################################################################
82-
# Conclusion
86+
# ๊ฒฐ๋ก 
8387
# ~~~~~~~~~~
8488
#
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"๋กœ ์„ค์ •ํ•˜์„ธ์š”.
8993
#
90-
# Alternatively, you can view the `torch._logging documentation`_ to see
91-
# descriptions of all available logging options.
94+
# ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ๋Š”, `torch._logging ๋ฌธ์„œ`_ ๋ฅผ ๋ณด๋ฉด,
95+
# ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๋กœ๊น… ์˜ต์…˜์— ๋Œ€ํ•œ ์„ค๋ช…์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
9296
#
93-
# For more information on torch.compile, see the `torch.compile tutorial`_.
97+
# torch.compile์— ๊ด€ํ•œ ๋” ๋งŽ์€ ์ •๋ณด๋Š”, `torch.compile ํŠœํ† ๋ฆฌ์–ผ`_๋ฅผ ๋ณด์„ธ์š”.
9498
#
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

Comments
ย (0)