Why there is no pytorch AOT graph tracer for both graph operations and bytecode

I see there are many options for model graph tracing including torch.export(), torch.compile() for jit execution and torch.compile.aot_compile().

  • torch.export(): Full AOT graph tracer but does not work with graph breaks.
  • torch.compile(): Jit compiler works with graph breaks gives the controls to python interpreter for executing graph break bytecode at runtime.
  • torch.compile.aot_compile(): AOT compilation on a torch.compile function raise error on graph break.

I am curious why there is not a single AOT tracer which inlcudes both graph operation and graph break bytecode.

Graph breaks and AOT compilation live at different layers, which is why one tracer cannot cover both. Dynamo and AOTInductor lower ATen operators, not Python bytecode; a break exists exactly where the semantics cannot be expressed as ATen ops - data-dependent control flow, arbitrary Python calls, or side effects the tracer cannot prove safe. AOTInductor emits a Python-free artifact, so at runtime there is no interpreter left to execute the resumed bytecode, and aot_compile raises rather than silently changing what the program means. In practice the fix is usually to remove the break instead of compiling it: move the offending region behind a torch.library custom op or a tensor-only formulation so export sees a single graph. torch._dynamo.explain(fn)(*sample_inputs) prints the break reasons and the resulting graph count, which shows whether the break is removable. What is the construct that actually breaks your trace - a data-dependent if, a Python-level call, or an unsupported op?