Skip to content

Commit 093a364

Browse files
committed
add warning, make small fixes
1 parent 24d1c3a commit 093a364

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

intermediate_source/torch_export_tutorial.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
"""
88

99
######################################################################
10-
# :func:`torch.export` is the PyTorch 2 way to export PyTorch models into
10+
#
11+
# .. warning::
12+
#
13+
# ``torch.export`` and its related features are in prototype status and are subject to backwards compatibility
14+
# breaking changes. This tutorial provides a snapshot of ``torch.export`` usage as of PyTorch 2.1.
15+
#
16+
# :func:`torch.export` is the PyTorch 2.X way to export PyTorch models into
1117
# standardized model representations, intended
1218
# to be run on different (i.e. Python-less) environments.
1319
#
@@ -17,6 +23,7 @@
1723
# to make in order to make your model compatible with ``torch.export``.
1824
#
1925
# **Contents**
26+
#
2027
# .. contents::
2128
# :local:
2229

@@ -72,7 +79,7 @@ def forward(self, x, y):
7279
#
7380
# The ``graph_module`` attribute is the ``GraphModule`` that wraps the ``graph`` attribute
7481
# so that it can be ran as a ``torch.nn.Module``.
75-
# We can use ``graph_module``'s ``print_readable` to print a Python code representation
82+
# We can use ``graph_module``'s ``print_readable``` to print a Python code representation
7683
# of ``graph``:
7784

7885
print(exported_mod)
@@ -88,7 +95,7 @@ def forward(self, x, y):
8895
# Other attributes of interest in ``ExportedProgram`` include:
8996
#
9097
# - ``graph_signature`` -- the inputs, outputs, parameters, buffers, etc. of the exported graph.
91-
# - ``range_constraints`` and ``equality_constraints`` -- Constraints, covered later
98+
# - ``range_constraints`` and ``equality_constraints`` -- constraints, covered later
9299

93100
print(exported_mod.graph_signature)
94101
print(exported_mod.range_constraints)
@@ -172,16 +179,10 @@ def bad4(x):
172179
# Control Flow Ops
173180
# ----------------
174181
#
175-
# .. warning::
176-
#
177-
# ``cond`` is a prototype feature in PyTorch, included as a part of the ``torch.export`` release.
178-
# Future changes may break backwards compatibility.
179-
# Please look forward to a more stable implementation in a future version of PyTorch.
180-
#
181182
# ``torch.export`` actually does support data-dependent control flow.
182183
# But these need to be expressed using control flow ops. For example,
183184
# we can fix the control flow example above using the ``cond`` op, like so:
184-
185+
#
185186
# ..
186187
# [TODO] link to docs about cond when it is out
187188

@@ -207,7 +208,7 @@ def false_fn(x):
207208
# operands and they must both return a single tensor with the same metadata (for example, ``dtype``, ``shape``, etc.).
208209
# - Branch functions cannot mutate input or global variables.
209210
# - Branch functions cannot access closure variables, except for ``self`` if the function is
210-
# defined in the scope of a method.
211+
# defined in the scope of a method.
211212

212213
######################################################################
213214
# ..
@@ -234,11 +235,6 @@ def false_fn(x):
234235
# Constraints
235236
# -----------
236237
#
237-
# .. warning::
238-
#
239-
# The constraints API is a prototype feature in PyTorch, included as a part of the torch.export release.
240-
# Backwards compatibility is not guaranteed. We anticipate releasing a more stable constraints API in the future.
241-
#
242238
# Ops can have different specializations/behaviors for different tensor shapes, so by default,
243239
# ``torch.export`` requires inputs to ``ExportedProgram`` to have the same shape as the respective
244240
# example inputs given to the initial ``torch.export`` call.
@@ -351,7 +347,7 @@ def constraints_example3(x, y):
351347

352348
constraints3 = (
353349
[dynamic_dim(inp4, i) for i in range(inp4.dim())] +
354-
[dynamic_dim(inp5, i) for i in range(inp4.dim())]
350+
[dynamic_dim(inp5, i) for i in range(inp5.dim())]
355351
)
356352

357353
try:
@@ -387,6 +383,8 @@ def specify_constraints(x, y):
387383
import logging
388384
torch._logging.set_logs(dynamic=logging.INFO, dynamo=logging.INFO)
389385
exported_constraints_example3 = export(constraints_example3, (inp4, inp5), constraints=constraints3_fixed)
386+
387+
# reset to previous values
390388
torch._logging.set_logs(dynamic=logging.WARNING, dynamo=logging.WARNING)
391389

392390
######################################################################
@@ -443,10 +441,6 @@ def constraints_example5(x, y):
443441
#
444442
# ``torch.export`` can export PyTorch programs with custom operators.
445443
#
446-
# .. warning::
447-
#
448-
# The API for registering custom ops is still under active development
449-
# and may change without notice.
450444
#
451445
# Currently, the steps to register a custom op for use by ``torch.export`` are:
452446
#
@@ -534,6 +528,6 @@ def cond_predicate(x):
534528
# Conclusion
535529
# ----------
536530
#
537-
# We introduced ``torch.export``, the new PyTorch 2 way to export single computation
531+
# We introduced ``torch.export``, the new PyTorch 2.X way to export single computation
538532
# graphs from PyTorch programs. In particular, we demonstrate several code modifications
539533
# and considerations (control flow ops, constraints, etc.) that need to be made in order to export a graph.

0 commit comments

Comments
 (0)