Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

Commit 664c689

Browse files
committed
Naming
1 parent 6bd7193 commit 664c689

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

torchdynamo/config.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,16 @@
9999
"torch._decomp",
100100
}
101101

102+
# Debug Flag to try minifier at different stages. Possible values are {None, "aot", "dynamo"}
103+
# None - Minifier is switched off
104+
# dynamo - Runs minifier on the TorchDynamo produced graphs, if compilation fails
105+
# aot - Runs minifier on the Aot Autograd produced graphs, if compilation fails
106+
repro_after = os.environ.get("REPRO_AFTER", None)
102107
# Compiler compilation debug info
103-
# 0: Nothing printed out when compilation fails
104-
# 1: Dump the graph out to repro.py if compilation fails
105-
# 2: Dumps the graph out to minify_repro.py with a minifier if compilation fails
106-
# 3: Always dumps the last graph ran out to minify_repro.py, useful for segfaults/irrecoverable errors
107-
repro_level = int(os.environ.get("COMPILER_REPRO_LEVEL", 0))
108-
109-
# TorchDynamo produced Fx GraphModule compilation debug info
110-
# 0: Nothing printed out when compilation fails
111-
# 1: Dump the initial graph to repro.tar.gz
112-
# 2/3: Minifies and Dumps the minified repro to repro.tar.gz
113-
backend_repro_level = int(os.environ.get("BACKEND_REPRO_LEVEL", 0))
108+
# 1: Dumps the original graph out to repro.py/repro.tar.gz if compilation fails
109+
# 2: Either 1) Dumps the original graph out to minify_repro.py with a minifier if compilation fails
110+
# or 2) Minifies and dumps the minified graph to repro.py/repro.tar.gz if compilation fails
111+
repro_level = int(os.environ.get("REPRO_LEVEL", 2))
114112

115113
# Not all backends support scalars. Some calls on torch.Tensor (like .item()) return a scalar type.
116114
# When this flag is set to False, we introduce a graph break instead of capturing.

torchdynamo/debug_utils.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -310,25 +310,23 @@ def wrap_compiler_debug(compiler, compiler_name: str):
310310
@functools.wraps(compiler)
311311
def debug_wrapper(gm, example_inputs, **kwargs):
312312
orig_graph = copy.deepcopy(gm.graph)
313-
if config.repro_level == 3:
314-
dump_to_minify(
315-
fx.GraphModule(gm, orig_graph), example_inputs, compiler_name
316-
)
317-
318-
try:
319-
compiled_fn = compiler(gm, example_inputs, **kwargs)
320-
if config.repro_level > 0:
313+
assert config.repro_after in ("dynamo", "aot", None)
314+
if config.repro_after == "aot":
315+
try:
316+
compiled_fn = compiler(gm, example_inputs, **kwargs)
321317
compiled_fn(*example_inputs)
322-
except Exception as e:
323-
if config.repro_level == 1:
324-
dump_compiler_graph_state(
325-
fx.GraphModule(gm, orig_graph), example_inputs, compiler_name
326-
)
327-
elif config.repro_level == 2:
328-
dump_to_minify(
329-
fx.GraphModule(gm, orig_graph), example_inputs, compiler_name
330-
)
331-
raise e
318+
except Exception as e:
319+
if config.repro_level == 1:
320+
dump_compiler_graph_state(
321+
fx.GraphModule(gm, orig_graph), example_inputs, compiler_name
322+
)
323+
elif config.repro_level == 2:
324+
dump_to_minify(
325+
fx.GraphModule(gm, orig_graph), example_inputs, compiler_name
326+
)
327+
raise e
328+
else:
329+
compiled_fn = compiler(gm, example_inputs, **kwargs)
332330

333331
return compiled_fn
334332

@@ -517,11 +515,12 @@ def wrap_backend_debug(compiler_fn, compiler_name: str):
517515

518516
@functools.wraps(compiler_fn)
519517
def debug_wrapper(gm, example_inputs, **kwargs):
520-
compiled_gm = compiler_fn(gm, example_inputs, **kwargs)
521-
if config.backend_repro_level > 0:
518+
assert config.repro_after in ("dynamo", "aot", None)
519+
if config.repro_after == "dynamo":
522520
# Ensure that we fail when backend fails
523521
config.raise_on_backend_error = True
524522
try:
523+
compiled_gm = compiler_fn(gm, example_inputs, **kwargs)
525524
run_fwd_maybe_bwd(compiled_gm, clone_inputs(example_inputs))
526525
except Exception as exc:
527526
orig_failure = str(exc)
@@ -531,7 +530,7 @@ def debug_wrapper(gm, example_inputs, **kwargs):
531530
dump_state_fn = functools.partial(
532531
dump_backend_state, compiler_name=compiler_name
533532
)
534-
if config.backend_repro_level == 1:
533+
if config.repro_level == 1:
535534
dump_state_fn(
536535
fx.GraphModule(gm, copy.deepcopy(gm.graph)), example_inputs
537536
)
@@ -558,6 +557,8 @@ def debug_wrapper(gm, example_inputs, **kwargs):
558557
dump_state=dump_state_fn,
559558
)
560559
raise exc
560+
else:
561+
compiled_gm = compiler_fn(gm, example_inputs, **kwargs)
561562

562563
return compiled_gm
563564

0 commit comments

Comments
 (0)