Skip to content

Commit 31fad3d

Browse files
authored
[translation] recipes_source/torch_export_aoti_python.py ๋ฒˆ์—ญ (#1136)
1 parent 3e2b652 commit 31fad3d

1 file changed

Lines changed: 76 additions & 81 deletions

File tree

โ€Žrecipes_source/torch_export_aoti_python.pyโ€Ž

Lines changed: 76 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,70 @@
22

33
"""
44
.. meta::
5-
:description: An end-to-end example of how to use AOTInductor for Python runtime.
5+
:description: Python ๋Ÿฐํƒ€์ž„์—์„œ AOTInductor๋ฅผ ์‚ฌ์šฉํ•˜๋Š” end-to-end ์˜ˆ์ œ
66
:keywords: torch.export, AOTInductor, torch._inductor.aoti_compile_and_package, aot_compile, torch._export.aoti_load_package
77
8-
``torch.export`` AOTInductor Tutorial for Python runtime (Beta)
9-
===============================================================
10-
**Author:** Ankith Gunapal, Bin Bao, Angela Yi
8+
(Beta) Python ๋Ÿฐํƒ€์ž„์„ ์œ„ํ•œ ``torch.export`` AOTInductor ํŠœํ† ๋ฆฌ์–ผ
9+
==================================================================
10+
**์ €์ž:** Ankith Gunapal, Bin Bao, Angela Yi
11+
**๋ฒˆ์—ญ:** `๊น€์ •์—ฐ <https://github.com/jykimai>`_
1112
"""
1213

1314
######################################################################
1415
#
1516
# .. warning::
1617
#
17-
# ``torch._inductor.aoti_compile_and_package`` and
18-
# ``torch._inductor.aoti_load_package`` are in Beta status and are subject
19-
# to backwards compatibility breaking changes. This tutorial provides an
20-
# example of how to use these APIs for model deployment using Python
21-
# runtime.
18+
# ``torch._inductor.aoti_compile_and_package`` ์™€
19+
# ``torch._inductor.aoti_load_package`` ๋Š” Beta ์ƒํƒœ์ด๋ฉฐ, ํ•˜์œ„ ํ˜ธํ™˜์„ฑ์„ ๊นจ๋Š”
20+
# ๋ณ€๊ฒฝ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ํŠœํ† ๋ฆฌ์–ผ์€ Python ๋Ÿฐํƒ€์ž„์„ ์‚ฌ์šฉํ•œ
21+
# ๋ชจ๋ธ ๋ฐฐํฌ์— ์ด๋Ÿฌํ•œ API๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์˜ˆ์ œ๋กœ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
2222
#
23-
# It has been shown `previously
24-
# <https://pytorch.org/docs/stable/torch.compiler_aot_inductor.html#>`__ how
25-
# AOTInductor can be used to do Ahead-of-Time compilation of PyTorch exported
26-
# models by creating an artifact that can be run in a non-Python environment.
27-
# In this tutorial, you will learn an end-to-end example of how to use
28-
# AOTInductor for Python runtime.
23+
# `์ด์ „ ๋ฌธ์„œ <https://pytorch.org/docs/stable/torch.compiler_aot_inductor.html#>`__ ์—์„œ
24+
# AOTInductor๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ PyTorch๋กœ ๋‚ด๋ณด๋‚ธ(exported) ๋ชจ๋ธ์„ ์‚ฌ์ „ ์ปดํŒŒ์ผ(Ahead-of-Time compilation)ํ•˜๊ณ ,
25+
# Python์ด ์•„๋‹Œ ํ™˜๊ฒฝ์—์„œ๋„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์‚ฐ์ถœ๋ฌผ(artifact)์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค.
26+
# ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” Python ๋Ÿฐํƒ€์ž„์—์„œ AOTInductor๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์—”๋“œ ํˆฌ ์—”๋“œ ์˜ˆ์ œ๋กœ ์•Œ์•„๋ด…๋‹ˆ๋‹ค.
2927
#
30-
# **Contents**
28+
# **๋ชฉ์ฐจ**
3129
#
3230
# .. contents::
3331
# :local:
3432

3533
######################################################################
36-
# Prerequisites
34+
# ์ „์ œ์กฐ๊ฑด
3735
# -------------
38-
# * PyTorch 2.6 or later
39-
# * Basic understanding of ``torch.export`` and AOTInductor
40-
# * Complete the `AOTInductor: Ahead-Of-Time Compilation for Torch.Export-ed Models <https://pytorch.org/docs/stable/torch.compiler_aot_inductor.html#>`_ tutorial
36+
# * PyTorch 2.6 ์ด์ƒ
37+
# * ``torch.export`` ์™€ AOTInductor์— ๋Œ€ํ•œ ๊ธฐ๋ณธ์ ์ธ ์ดํ•ด
38+
# * `AOTInductor: Torch.Export๋กœ ๋‚ด๋ณด๋‚ธ ๋ชจ๋ธ์˜ ์‚ฌ์ „ ์ปดํŒŒ์ผ(Ahead-of-Time Compilation) <https://pytorch.org/docs/stable/torch.compiler_aot_inductor.html#>`_ ํŠœํ† ๋ฆฌ์–ผ ์™„๋ฃŒ
4139

4240
######################################################################
43-
# What you will learn
41+
# ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ ๋ฐฐ์šธ ๋‚ด์šฉ
4442
# ----------------------
45-
# * How to use AOTInductor for Python runtime.
46-
# * How to use :func:`torch._inductor.aoti_compile_and_package` along with :func:`torch.export.export` to generate a compiled artifact
47-
# * How to load and run the artifact in a Python runtime using :func:`torch._export.aot_load`.
48-
# * When to you use AOTInductor with a Python runtime
43+
# * Python ๋Ÿฐํƒ€์ž„์—์„œ AOTInductor๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•
44+
# * :func:`torch._inductor.aoti_compile_and_package` ์™€ :func:`torch.export.export` ๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํŒŒ์ผ๋œ ์‚ฐ์ถœ๋ฌผ(artifact)์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•
45+
# * :func:`torch._export.aot_load` ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Python ๋Ÿฐํƒ€์ž„์—์„œ ์‚ฐ์ถœ๋ฌผ์„ ๋ถˆ๋Ÿฌ์˜ค๊ณ  ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•
46+
# * Python ๋Ÿฐํƒ€์ž„๊ณผ ํ•จ๊ป˜ AOTInductor๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ
4947

5048
######################################################################
51-
# Model Compilation
49+
# ๋ชจ๋ธ ์ปดํŒŒ์ผ
5250
# -----------------
5351
#
54-
# We will use the TorchVision pretrained ``ResNet18`` model as an example.
52+
# ์˜ˆ์‹œ๋กœ TorchVision์˜ ์‚ฌ์ „ ํ•™์Šต๋œ ``ResNet18`` ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
5553
#
56-
# The first step is to export the model to a graph representation using
57-
# :func:`torch.export.export`. To learn more about using this function, you can
58-
# check out the `docs <https://pytorch.org/docs/main/export.html>`_ or the
59-
# `tutorial <https://tutorials.pytorch.kr/intermediate/torch_export_tutorial.html>`_.
54+
# ์ฒซ ๋ฒˆ์งธ ๋‹จ๊ณ„๋Š” :func:`torch.export.export` ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋ธ์„ ๊ทธ๋ž˜ํ”„ ํ‘œํ˜„์œผ๋กœ
55+
# ๋‚ด๋ณด๋‚ด๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด ํ•จ์ˆ˜์— ๋Œ€ํ•ด ๋” ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด
56+
# `๋ฌธ์„œ <https://pytorch.org/docs/main/export.html>`_ ๋‚˜
57+
# `ํŠœํ† ๋ฆฌ์–ผ <https://tutorials.pytorch.kr/intermediate/torch_export_tutorial.html>`_ ์„ ์ฐธ๊ณ ํ•˜์„ธ์š”.
6058
#
61-
# Once we have exported the PyTorch model and obtained an ``ExportedProgram``,
62-
# we can apply :func:`torch._inductor.aoti_compile_and_package` to AOTInductor
63-
# to compile the program to a specified device, and save the generated contents
64-
# into a ".pt2" artifact.
59+
# PyTorch ๋ชจ๋ธ์„ ๋‚ด๋ณด๋‚ด์–ด ``ExportedProgram`` ์„ ์–ป์€ ํ›„์—๋Š”,
60+
# :func:`torch._inductor.aoti_compile_and_package` ๋ฅผ AOTInductor์— ์ ์šฉํ•˜์—ฌ
61+
# ์ง€์ •๋œ ๋””๋ฐ”์ด์Šค์— ๋งž์ถฐ ํ”„๋กœ๊ทธ๋žจ์„ ์ปดํŒŒ์ผํ•˜๊ณ , ์ƒ์„ฑ๋œ ๋‚ด์šฉ์„ ".pt2" ์‚ฐ์ถœ๋ฌผ๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
6562
#
6663
# .. note::
6764
#
68-
# This API supports the same available options that :func:`torch.compile`
69-
# has, such as ``mode`` and ``max_autotune`` (for those who want to enable
70-
# CUDA graphs and leverage Triton based matrix multiplications and
71-
# convolutions)
65+
# ์ด API๋Š” :func:`torch.compile` ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์˜ต์…˜๊ณผ ๋™์ผํ•œ ์˜ต์…˜์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
66+
# ์˜ˆ๋ฅผ ๋“ค์–ด ``mode`` ์™€ ``max_autotune`` ๊ฐ™์€ ์˜ต์…˜์ด ์žˆ์œผ๋ฉฐ,
67+
# ์ด๋Š” CUDA ๊ทธ๋ž˜ํ”„๋ฅผ ํ™œ์„ฑํ™”ํ•˜๊ณ  Triton ๊ธฐ๋ฐ˜์˜ ํ–‰๋ ฌ ๊ณฑ์…ˆ๊ณผ ํ•ฉ์„ฑ๊ณฑ(convolution)์„
68+
# ํ™œ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
7269

7370
import os
7471
import torch
@@ -101,15 +98,14 @@
10198
)
10299

103100
######################################################################
104-
# The result of :func:`aoti_compile_and_package` is an artifact "resnet18.pt2"
105-
# which can be loaded and executed in Python and C++.
101+
# :func:`aoti_compile_and_package` ์˜ ๊ฒฐ๊ณผ๋กœ "resnet18.pt2" ์‚ฐ์ถœ๋ฌผ์ด ์ƒ์„ฑ๋˜๋ฉฐ,
102+
# Python๊ณผ C++ ํ™˜๊ฒฝ ๋ชจ๋‘์—์„œ ๋ถˆ๋Ÿฌ์™€ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
106103
#
107-
# The artifact itself contains a bunch of AOTInductor generated code, such as
108-
# a generated C++ runner file, a shared library compiled from the C++ file, and
109-
# CUDA binary files, aka cubin files, if optimizing for CUDA.
104+
# ์‚ฐ์ถœ๋ฌผ ์ž์ฒด์—๋Š” AOTInductor๊ฐ€ ์ƒ์„ฑํ•œ ๋‹ค์–‘ํ•œ ์ฝ”๋“œ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
105+
# ์˜ˆ๋ฅผ ๋“ค์–ด ์ƒ์„ฑ๋œ C++ ๋Ÿฌ๋„ˆ ํŒŒ์ผ, C++ ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ์ปดํŒŒ์ผ๋œ ๊ณต์œ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ,
106+
# ๊ทธ๋ฆฌ๊ณ  CUDA์— ์ตœ์ ํ™”ํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” CUDA ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ(cubin ํŒŒ์ผ)์ด ํ•จ๊ป˜ ๋“ค์–ด ์žˆ์Šต๋‹ˆ๋‹ค.
110107
#
111-
# Structure-wise, the artifact is a structured ``.zip`` file, with the following
112-
# specification:
108+
# ๊ตฌ์กฐ ์ธก๋ฉด์—์„œ ์‚ฐ์ถœ๋ฌผ์€ ๊ตฌ์กฐํ™”๋œ ``.zip`` ํŒŒ์ผ์ด๋ฉฐ, ์•„๋ž˜์™€ ๊ฐ™์€ ์‚ฌ์–‘์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
113109
#
114110
# .. code::
115111
# .
@@ -118,18 +114,22 @@
118114
# โ”œโ”€โ”€ data
119115
# โ”‚ โ”œโ”€โ”€ aotinductor
120116
# โ”‚ โ”‚ โ””โ”€โ”€ model
121-
# โ”‚ โ”‚ โ”œโ”€โ”€ xxx.cpp # AOTInductor generated cpp file
122-
# โ”‚ โ”‚ โ”œโ”€โ”€ xxx.so # AOTInductor generated shared library
123-
# โ”‚ โ”‚ โ”œโ”€โ”€ xxx.cubin # Cubin files (if running on CUDA)
124-
# โ”‚ โ”‚ โ””โ”€โ”€ xxx_metadata.json # Additional metadata to save
117+
# โ”‚ โ”‚ โ”œโ”€โ”€ xxx.cpp # AOTInductor๊ฐ€ ์ƒ์„ฑํ•œ cpp ํŒŒ์ผ
118+
# โ”‚ โ”‚ โ”œโ”€โ”€ xxx.so # AOTInductor๊ฐ€ ์ƒ์„ฑํ•œ ๊ณต์œ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
119+
# โ”‚ โ”‚ โ”œโ”€โ”€ xxx.cubin # Cubin ํŒŒ์ผ (CUDA์—์„œ ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ)
120+
# โ”‚ โ”‚ โ””โ”€โ”€ xxx_metadata.json # ์ €์žฅํ•  ์ถ”๊ฐ€ ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ
125121
# โ”‚ โ”œโ”€โ”€ weights
126122
# โ”‚ โ”‚ โ””โ”€โ”€ TBD
127123
# โ”‚ โ””โ”€โ”€ constants
128124
# โ”‚ โ””โ”€โ”€ TBD
129125
# โ””โ”€โ”€ extra
130126
# โ””โ”€โ”€ metadata.json
131127
#
132-
# We can use the following command to inspect the artifact contents:
128+
# ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฐ์ถœ๋ฌผ์˜ ๋‚ด์šฉ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
129+
#
130+
# .. code:: bash
131+
#
132+
# $ unzip -l resnet18.pt2
133133
#
134134
# .. code:: bash
135135
#
@@ -163,10 +163,10 @@
163163

164164

165165
######################################################################
166-
# Model Inference in Python
166+
# Python์—์„œ์˜ ๋ชจ๋ธ ์ถ”๋ก 
167167
# -------------------------
168168
#
169-
# To load and run the artifact in Python, we can use :func:`torch._inductor.aoti_load_package`.
169+
# Python์—์„œ ์‚ฐ์ถœ๋ฌผ์„ ๋ถˆ๋Ÿฌ์™€ ์‹คํ–‰ํ•˜๋ ค๋ฉด :func:`torch._inductor.aoti_load_package` ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
170170
#
171171

172172
import os
@@ -183,33 +183,30 @@
183183

184184

185185
######################################################################
186-
# When to use AOTInductor with a Python Runtime
186+
# Python ๋Ÿฐํƒ€์ž„๊ณผ ํ•จ๊ป˜ AOTInductor๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ
187187
# ---------------------------------------------
188188
#
189-
# There are mainly two reasons why one would use AOTInductor with a Python Runtime:
189+
# Python ๋Ÿฐํƒ€์ž„๊ณผ ํ•จ๊ป˜ AOTInductor๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ฃผ๋œ ์ด์œ ๋Š” ํฌ๊ฒŒ ๋‘ ๊ฐ€์ง€์ž…๋‹ˆ๋‹ค.
190190
#
191-
# - ``torch._inductor.aoti_compile_and_package`` generates a singular
192-
# serialized artifact. This is useful for model versioning for deployments
193-
# and tracking model performance over time.
194-
# - With :func:`torch.compile` being a JIT compiler, there is a warmup
195-
# cost associated with the first compilation. Your deployment needs to
196-
# account for the compilation time taken for the first inference. With
197-
# AOTInductor, the compilation is done ahead of time using
198-
# ``torch.export.export`` and ``torch._inductor.aoti_compile_and_package``.
199-
# At deployment time, after loading the model, running inference does not
200-
# have any additional cost.
191+
# - ``torch._inductor.aoti_compile_and_package`` ๋Š” ํ•˜๋‚˜์˜ ์ง๋ ฌํ™”๋œ ์‚ฐ์ถœ๋ฌผ์„
192+
# ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ๋ฐฐํฌ ์‹œ ๋ชจ๋ธ ๋ฒ„์ „ ๊ด€๋ฆฌ์™€ ์‹œ๊ฐ„์— ๋”ฐ๋ฅธ ๋ชจ๋ธ ์„ฑ๋Šฅ ์ถ”์ ์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.
193+
# - :func:`torch.compile` ์€ JIT ์ปดํŒŒ์ผ๋Ÿฌ์ด๋ฏ€๋กœ ์ฒซ ์ปดํŒŒ์ผ ์‹œ ์›Œ๋ฐ์—… ๋น„์šฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
194+
# ๋”ฐ๋ผ์„œ ๋ฐฐํฌ ์‹œ ์ฒซ ์ถ”๋ก ์— ๊ฑธ๋ฆฌ๋Š” ์ปดํŒŒ์ผ ์‹œ๊ฐ„์„ ๊ณ ๋ คํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
195+
# ๋ฐ˜๋ฉด AOTInductor๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ``torch.export.export`` ์™€
196+
# ``torch._inductor.aoti_compile_and_package`` ๋ฅผ ํ†ตํ•ด ์ปดํŒŒ์ผ์ด ๋ฏธ๋ฆฌ ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค.
197+
# ๋ฐฐํฌ ์‹œ์ ์—๋Š” ๋ชจ๋ธ์„ ๋ถˆ๋Ÿฌ์˜จ ํ›„ ์ถ”๋ก ์„ ์‹คํ–‰ํ•  ๋•Œ ์ถ”๊ฐ€ ๋น„์šฉ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
201198
#
202199
#
203-
# The section below shows the speedup achieved with AOTInductor for first inference
200+
# ์•„๋ž˜ ์„น์…˜์—์„œ๋Š” AOTInductor๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ ์ฒซ ์ถ”๋ก ์—์„œ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์†๋„ ํ–ฅ์ƒ์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
204201
#
205-
# We define a utility function ``timed`` to measure the time taken for inference
202+
# ์ถ”๋ก ์— ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์„ ์ธก์ •ํ•˜๊ธฐ ์œ„ํ•ด ``timed`` ๋ผ๋Š” ์œ ํ‹ธ๋ฆฌํ‹ฐ ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
206203
#
207204

208205
import time
209206
def timed(fn):
210-
# Returns the result of running `fn()` and the time it took for `fn()` to run,
211-
# in seconds. We use CUDA events and synchronization for accurate
212-
# measurement on CUDA enabled devices.
207+
# `fn()` ์„ ์‹คํ–‰ํ•œ ๊ฒฐ๊ณผ์™€ `fn()` ์˜ ์‹คํ–‰ ์‹œ๊ฐ„(์ดˆ)์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
208+
# CUDA๋ฅผ ์ง€์›ํ•˜๋Š” ๋””๋ฐ”์ด์Šค์—์„œ ์ •ํ™•ํ•˜๊ฒŒ ์ธก์ •ํ•˜๊ธฐ ์œ„ํ•ด
209+
# CUDA ์ด๋ฒคํŠธ์™€ ๋™๊ธฐํ™”๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
213210
if torch.cuda.is_available():
214211
start = torch.cuda.Event(enable_timing=True)
215212
end = torch.cuda.Event(enable_timing=True)
@@ -224,7 +221,7 @@ def timed(fn):
224221
else:
225222
end = time.time()
226223

227-
# Measure time taken to execute the function in miliseconds
224+
# ํ•จ์ˆ˜ ์‹คํ–‰์— ๊ฑธ๋ฆฐ ์‹œ๊ฐ„์„ ๋ฐ€๋ฆฌ์ดˆ ๋‹จ์œ„๋กœ ์ธก์ •ํ•ฉ๋‹ˆ๋‹ค.
228225
if torch.cuda.is_available():
229226
duration = start.elapsed_time(end)
230227
else:
@@ -234,7 +231,7 @@ def timed(fn):
234231

235232

236233
######################################################################
237-
# Lets measure the time for first inference using AOTInductor
234+
# AOTInductor๋ฅผ ์‚ฌ์šฉํ•œ ์ฒซ ์ถ”๋ก  ์‹œ๊ฐ„์„ ์ธก์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
238235

239236
torch._dynamo.reset()
240237

@@ -247,7 +244,7 @@ def timed(fn):
247244

248245

249246
######################################################################
250-
# Lets measure the time for first inference using ``torch.compile``
247+
# ``torch.compile`` ์„ ์‚ฌ์šฉํ•œ ์ฒซ ์ถ”๋ก  ์‹œ๊ฐ„์„ ์ธก์ •ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
251248

252249
torch._dynamo.reset()
253250

@@ -262,15 +259,13 @@ def timed(fn):
262259
print(f"Time taken for first inference for torch.compile is {time_taken:.2f} ms")
263260

264261
######################################################################
265-
# We see that there is a drastic speedup in first inference time using AOTInductor compared
266-
# to ``torch.compile``
262+
# AOTInductor๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ``torch.compile`` ์— ๋น„ํ•ด ์ฒซ ์ถ”๋ก  ์‹œ๊ฐ„์ด ํฌ๊ฒŒ ๋‹จ์ถ•๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
267263

268264
######################################################################
269-
# Conclusion
265+
# ๊ฒฐ๋ก 
270266
# ----------
271267
#
272-
# In this recipe, we have learned how to effectively use the AOTInductor for Python runtime by
273-
# compiling and loading a pretrained ``ResNet18`` model. This process
274-
# demonstrates the practical application of generating a compiled artifact and
275-
# running it within a Python environment. We also looked at the advantage of using
276-
# AOTInductor in model deployments, with regards to speed up in first inference time.
268+
# ์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ์‚ฌ์ „ ํ•™์Šต๋œ ``ResNet18`` ๋ชจ๋ธ์„ ์ปดํŒŒ์ผํ•˜๊ณ  ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ๋ฒ•์„ ํ†ตํ•ด
269+
# Python ๋Ÿฐํƒ€์ž„์—์„œ AOTInductor๋ฅผ ํšจ๊ณผ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค.
270+
# ์ด ๊ณผ์ •์€ ์ปดํŒŒ์ผ๋œ ์‚ฐ์ถœ๋ฌผ์„ ์ƒ์„ฑํ•˜๊ณ  Python ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ํ•˜๋Š” ์‹ค์šฉ์ ์ธ ํ™œ์šฉ ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
271+
# ๋˜ํ•œ ์ฒซ ์ถ”๋ก  ์‹œ๊ฐ„ ๋‹จ์ถ•์ด๋ผ๋Š” ์ธก๋ฉด์—์„œ ๋ชจ๋ธ ๋ฐฐํฌ์— AOTInductor๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ์˜ ์žฅ์ ๋„ ํ•จ๊ป˜ ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

0 commit comments

Comments
ย (0)