You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# This spits out quite a handful, even with this simple toy model. But looking through the logs we can see the lines relevant
426
432
# to what we described above; e.g. the allocation of symbols:
427
433
@@ -435,6 +441,7 @@ def forward(
435
441
I1210 16:20:19.734000 3417744 torch/fx/experimental/symbolic_shapes.py:4404] [1/0] create_symbol s5 = 32 for L['z'].size()[0] [2, int_oo] (_dynamo/variables/builder.py:2841 in <lambda>), for more info run with TORCHDYNAMO_EXTENDED_DEBUG_CREATE_SYMBOL="s5" or to suppress this message run with TORCHDYNAMO_EXTENDED_ADVICE="0"
I1210 16:20:19.775000 3417744 torch/fx/experimental/symbolic_shapes.py:6234] [1/0] runtime_assert Eq(s2*s3, s5) [guard added] x3 = x2 + z # [32] # dynamic_shapes_tutorial.py:19 in forward (_subclasses/fake_impls.py:845 in infer_size), for more info run with TORCHDYNAMO_EXTENDED_DEBUG_GUARD_ADDED="Eq(s2*s3, s5)"
# Each of these statements emits an additional guard, and the exported program shows the changes; ``s0`` is eliminated in favor of ``s2 + 2``,
504
515
# and ``s2`` now contains lower and upper bounds, reflected in ``range_constraints``.
505
516
#
506
517
# For the if/else condition, you might ask why the True branch was taken, and why it wasn't the ``w.shape[0] != x.shape[0] + 2`` guard that
507
-
# got emitted from tracing. The answer is export is guided by the sample inputs provided by tracing, and specializes on the branches taken.
508
-
# If different sample input shapes were provided that fail the if condition, export would trace and emit guards corresponding to the else branch.
509
-
# Additionally, you might ask why we traced only the if branch, and if it's possible to maintain control-flow in your program and keep both branches
518
+
# got emitted from tracing. The answer is that export is guided by the sample inputs provided by tracing, and specializes on the branches taken.
519
+
# If different sample input shapes were provided that fail the ``if`` condition, export would trace and emit guards corresponding to the ``else`` branch.
520
+
# Additionally, you might ask why we traced only the ``if`` branch, and if it's possible to maintain control-flow in your program and keep both branches
510
521
# alive. For that, refer to rewriting your model code following the ``Control Flow Ops`` section above.
511
522
#
512
523
# 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.
@@ -524,6 +535,7 @@ def forward(self, w, x, y, z):
# 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
528
540
# 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
529
541
# dimensions are automatically figured out underneath export. The dynamic shapes subsystem essentially acts as a "discovery" process, summarizing these guards
@@ -541,6 +553,7 @@ def forward(self, w, x, y, z):
# This style of dynamic shapes allows the user to specify what symbols are allocated for input dimensions, min/max bounds on those symbols, and places restrictions on the
545
558
# dynamic behavior of the ExportedProgram produced; ConstraintViolation errors will be raised if model tracing emits guards that conflict with the relations or static/dynamic
546
559
# specifications given. For example, in the above specification, the following is asserted:
@@ -556,6 +569,7 @@ def forward(self, w, x, y, z):
556
569
"x": (4*dx, None) # x.shape[0] has range [16, 2048], and is divisible by 4.
# 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.
560
574
# That would lead to ConstraintViolation errors and export suggested fixes - see for example with this model & specification, where the model inherently requires equality between
561
575
# dimensions 0 of ``x`` and ``y``, and requires dimension 1 to be static.
# The expectation with suggested fixes is that the user can interactively copy-paste the changes into their dynamic shapes specification, and successfully export afterwards.
579
594
#
580
595
# Lastly, there's couple nice-to-knows about the options for specification:
0 commit comments