Skip to content

Commit 3ad5180

Browse files
committed
fix issues
1 parent 63d3f93 commit 3ad5180

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

_doc/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
"within_subsection_order": "ExampleTitleSortKey",
153153
# errors
154154
"abort_on_example_error": True,
155-
"expected_failing_examples": ["examples/plot_export_locate_issue.py"],
156155
# recommendation
157156
"recommender": {"enable": True, "n_examples": 3, "min_df": 3, "max_df": 0.9},
158157
# ignore capture for matplotib axes

_doc/examples/plot_export_locate_issue.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
Find and fix an export issue due to dynamic shapes
66
==================================================
77
8+
LLMs must be exported with dynamic shapes and it is common that
9+
a static dimension turns into a static ones. The error message from
10+
:epkg:`pytorch` tells the user to define ``TORCH_LOGS="+dynamic"``
11+
but it shows a very long list of messages where we need
12+
to find the string ``range_refined_to_singleton`` and that
13+
does not really indicates where it comes from. The example
14+
shows how to tweak pytorch to get that information until
15+
it gets better.
816
917
A model with an export issue
1018
============================
@@ -15,6 +23,7 @@
1523
it is difficult to find deep inside a big model.
1624
"""
1725

26+
import traceback
1827
import torch
1928
from onnx_diagnostic.torch_export_patches import bypass_export_some_errors
2029

@@ -69,10 +78,17 @@ def forward(self, x: torch.Tensor, ys: list[torch.Tensor]):
6978
# Stop when a dynamic dimension turns static
7079
# ==========================================
7180
#
72-
#
81+
# We use :func:`bypass_export_some_errors
82+
# <onnx_diagnostic.torch_export_patches.bypass_export_some_errors>`
83+
# to replace torch implementation by a new one raising the exception
84+
# mentioned in previous section.
7385

7486
with bypass_export_some_errors(stop_if_static=True, verbose=1):
75-
torch.export.export(model, inputs, dynamic_shapes=dyn_shapes)
87+
try:
88+
torch.export.export(model, inputs, dynamic_shapes=dyn_shapes)
89+
except AssertionError:
90+
print("-- It failed as excepted. Let's print the stack trace.")
91+
print(traceback.format_exc())
7692

7793
# The stack trace is quite long but the first line referring to this example
7894
# is the following one. It points out the line turing a dynamic dimension into

onnx_diagnostic/torch_export_patches/onnx_export_errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def bypass_export_some_errors(
210210
the environment variable ``SKIP_SOLVE_CONSTRAINTS=0``
211211
can be put to stop at that stage.
212212
:param stop_if_static: see example :ref:`l-plot-export-locale-issue`,
213-
to stop the export as soon as an issue is detected with dyanmic shapes
213+
to stop the export as soon as an issue is detected with dynamic shapes
214214
and show a stack trace indicating the exact location of the issue
215215
:param patch: if False, disable all patches except the registration of
216216
serialization function
@@ -361,7 +361,7 @@ def bypass_export_some_errors(
361361
if stop_if_static:
362362
if verbose:
363363
print(
364-
"[bypass_export_some_errors] assert when a dynamic dimnension turns static"
364+
"[bypass_export_some_errors] assert when a dynamic dimension turns static"
365365
)
366366

367367
from torch.fx.experimental.symbolic_shapes import ShapeEnv

0 commit comments

Comments
 (0)