inference/research
verifiedhigh · 0.85updated 2026-10-04

torch.compile / TorchInductor

compiler-framework

Fields

id
compilers/torch-compile-torchinductor
Repo
pytorch/pytorch
Language
Python
License
BSD-3-Clause
First release
2022
Category
compiler-framework
Target backends
cudarocmcpu-avx2cpu-avx512
Input languages
pytorch
Output artifacts
triton-irptxamdgcnc
Compilation strategy
jit
Autotuning
yes
Production ready
yes
Production evidence
vLLM uses torch.compile for some model pathsPyTorch 2.x makes torch.compile the default recommended path for performanceUsed in production by Meta for some models
Strengths
Seamless PyTorch integration: just add torch.compile() to existing codeAutomatic fusion: fuses elementwise and reduction operations automaticallyTriton backend: generates Triton kernels for GPU, combining Inductor's fusion with Triton's performanceAutotuning: autoheuristic and autotune modes search over configurationsActive development: part of PyTorch core, regular improvements
Weaknesses
Graph breaks: when Dynamo cannot trace a function, it falls back to eager mode, causing performance cliffsRecompilation storms: each new shape or Python value can trigger recompilation, leading to long warmup timesDebugging difficulty: errors in generated code are hard to trace back to sourceNot all PyTorch operations are supported: unsupported ops cause graph breaksCompile time: first compilation can take 30+ seconds for complex modelsDynamic shapes: handling dynamic shapes requires careful configuration to avoid excessive recompilations
Learning curve
moderate
Compile time (s)
30
notes
torch.compile is PyTorch's recommended path for improving model performance. It consists of TorchDynamo (a Python bytecode tracer that captures the computation graph) and TorchInductor (a compiler that generates optimized code, primarily Triton kernels for GPU). The main failure modes are: (1) Graph breaks: when Dynamo encounters an operation it cannot trace (e.g., data-dependent control flow, unsupported Python constructs), it breaks the graph and falls back to eager mode for that segment. This can cause significant performance degradation. (2) Recompilation storms: Dynamo specializes on Python values (e.g., integer arguments), so each new value triggers recompilation. For inference with varying batch sizes, this can lead to dozens of recompilations. The recompile_limit (default 8) and accumulated_recompile_limit (default 256) control when compilation fails. (3) Dynamic shapes: by default, Dynamo specializes on tensor shapes, so each new shape triggers recompilation. The automatic_dynamic_shapes config can help, but it is not enabled by default. For production inference, torch.compile is most effective when the workload has fixed shapes (e.g., fixed batch size, fixed sequence length). For variable-length workloads, the recompilation overhead can dominate.

Notes

torch.compile is PyTorch's recommended path for improving model performance. It consists of TorchDynamo (a Python bytecode tracer that captures the computation graph) and TorchInductor (a compiler that generates optimized code, primarily Triton kernels for GPU). The main failure modes are: (1) Graph breaks: when Dynamo encounters an operation it cannot trace (e.g., data-dependent control flow, unsupported Python constructs), it breaks the graph and falls back to eager mode for that segment. This can cause significant performance degradation. (2) Recompilation storms: Dynamo specializes on Python values (e.g., integer arguments), so each new value triggers recompilation. For inference with varying batch sizes, this can lead to dozens of recompilations. The recompile_limit (default 8) and accumulated_recompile_limit (default 256) control when compilation fails. (3) Dynamic shapes: by default, Dynamo specializes on tensor shapes, so each new shape triggers recompilation. The automatic_dynamic_shapes config can help, but it is not enabled by default. For production inference, torch.compile is most effective when the workload has fixed shapes (e.g., fixed batch size, fixed sequence length). For variable-length workloads, the recompilation overhead can dominate.

Cross-references

This record references no other records — it is a leaf. It is cited by 1.