@@ -211,7 +211,7 @@ def bypass_export_some_errors(
211211 patch_torch : bool = True ,
212212 patch_transformers : bool = False ,
213213 catch_constraints : bool = True ,
214- stop_if_static : bool = False ,
214+ stop_if_static : int = 0 ,
215215 verbose : int = 0 ,
216216 patch : bool = True ,
217217) -> Callable :
@@ -227,7 +227,9 @@ def bypass_export_some_errors(
227227 can be put to stop at that stage.
228228 :param stop_if_static: see example :ref:`l-plot-export-locale-issue`,
229229 to stop the export as soon as an issue is detected with dynamic shapes
230- and show a stack trace indicating the exact location of the issue
230+ and show a stack trace indicating the exact location of the issue,
231+ ``if stop_if_static > 1``, more methods are replace to catch more
232+ issues
231233 :param patch: if False, disable all patches except the registration of
232234 serialization function
233235 :param verbose: to show which patches is applied
@@ -375,17 +377,24 @@ def bypass_export_some_errors(
375377 )
376378
377379 if stop_if_static :
380+ from torch .fx .experimental .symbolic_shapes import ShapeEnv
381+ from .patches .patch_torch import patched_ShapeEnv
382+
378383 if verbose :
379384 print (
380385 "[bypass_export_some_errors] assert when a dynamic dimension turns static"
381386 )
382-
383- from torch .fx .experimental .symbolic_shapes import ShapeEnv
384- from .patches .patch_torch import patched_ShapeEnv
387+ print ("[bypass_export_some_errors] replaces ShapeEnv._set_replacement" )
385388
386389 f_shape_env__set_replacement = ShapeEnv ._set_replacement
387390 ShapeEnv ._set_replacement = patched_ShapeEnv ._set_replacement
388391
392+ if stop_if_static > 1 :
393+ if verbose :
394+ print ("[bypass_export_some_errors] replaces ShapeEnv._check_frozen" )
395+ f_shape_env__check_frozen = ShapeEnv ._check_frozen
396+ ShapeEnv ._check_frozen = patched_ShapeEnv ._check_frozen
397+
389398 ####################
390399 # patch transformers
391400 ####################
@@ -444,6 +453,10 @@ def bypass_export_some_errors(
444453 print ("[bypass_export_some_errors] restored ShapeEnv._set_replacement" )
445454
446455 ShapeEnv ._set_replacement = f_shape_env__set_replacement
456+ if stop_if_static > 1 :
457+ if verbose :
458+ print ("[bypass_export_some_errors] restored ShapeEnv._check_frozen" )
459+ ShapeEnv ._check_frozen = f_shape_env__check_frozen
447460
448461 if catch_constraints :
449462 # to catch or skip dynamic_shapes issues
0 commit comments