Skip to content

Commit b720e32

Browse files
authored
Update torch_export_tutorial.py
1 parent 82efe6b commit b720e32

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

intermediate_source/torch_export_tutorial.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ def forward(
342342
######################################################################
343343
# Basic concepts: symbols and guards
344344
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
345-
346-
######################################################################
345+
#
347346
# To enable dynamism, ``export()`` provides a ``dynamic_shapes`` argument. The easiest way to work with
348347
# dynamic shapes is using ``Dim.AUTO`` and looking at the program that's returned. Dynamic behavior is specified
349348
# at a input dimension-level; for each input we can specify a tuple of values:
@@ -527,7 +526,7 @@ def forward(self, w, x, y, z):
527526
######################################################################
528527
# 0/1 specialization
529528
# ^^^^^^^^^^^^^^^^^^
530-
529+
#
531530
# Since we're talking about guards and specializations, it's a good time to talk about the 0/1 specialization issue we brought up earlier.
532531
# The bottom line is that export will specialize on sample input dimensions with value 0 or 1, because these shapes have trace-time properties that
533532
# don't generalize to other shapes. For example, size 1 tensors can broadcast while other sizes fail; and size 0 ... . This just means that you should
@@ -546,8 +545,7 @@ def forward(self, w, x, y, z):
546545
######################################################################
547546
# Named Dims
548547
# ^^^^^^^^^^
549-
550-
######################################################################
548+
#
551549
# So far we've only been talking about 3 ways to specify dynamic shapes: ``Dim.AUTO``, ``Dim.DYNAMIC``, and ``Dim.STATIC``. The attraction of these is the
552550
# low-friction user experience; all the guards emitted during model tracing are adhered to, and dynamic behavior like min/max ranges, relations, and static/dynamic
553551
# dimensions are automatically figured out underneath export. The dynamic shapes subsystem essentially acts as a "discovery" process, summarizing these guards
@@ -585,8 +583,7 @@ def forward(self, w, x, y, z):
585583
######################################################################
586584
# Constraint violations, suggested fixes
587585
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
588-
589-
######################################################################
586+
#
590587
# One common issue with this specification style (before ``Dim.AUTO`` was introduced), is that the specification would often be mismatched with what was produced by model tracing.
591588
# That would lead to ``ConstraintViolation`` errors and export suggested fixes - see for example with this model & specification, where the model inherently requires equality between
592589
# dimensions 0 of ``x`` and ``y``, and requires dimension 1 to be static.

0 commit comments

Comments
 (0)