How torch.compile Actually Works Torch.compile is not a traditional compiler but a system that intercepts Python bytecode at runtime, extracts compilable regions through a multi-stage pipeline, and stitches them back with eager Python fallbacks, with boundaries determining speedup. The pipeline consists of four stages: TorchDynamo for graph capture, AOTAutograd for ahead-of-time backward tracing, Inductor for fusion and delegation, and fallback for unsupported operations. How torch.compile Actually Works Most PyTorch users think torch.compile is a compiler. It is not — at least not in the way gcc or nvcc is a compiler. It is a system that intercepts Python bytecode at runtime, extracts the parts it can handle, compiles those parts through a multi-stage pipeline, and stitches the compiled regions back together with eager Python fallbacks for everything it cannot handle. The interesting engineering is not in the compilation itself. It is in the boundaries — where the compiler gives up and hands control back to Python. Those boundaries determine whether you get a 2x speedup or no speedup at all. This post walks through the four stages of the torch.compile pipeline: how Dynamo captures a graph from live Python, how AOTAutograd traces the backward pass ahead of time, how Inductor decides what to fuse and what to delegate to cuBLAS, and where the whole thing falls apart. The Pipeline php graph LR PY "Python bytecode" -- DY "TorchDynamo