PyTorch 2.x 의 가장 큰 단일 feature
torch.compile(model) 이 너 model 을 optimized fused kernel 로 JIT-compile 하는 한 줄 변환. 전형적 speedup: CUDA 1.5–3x, transformer-shaped model 에 자주 더. 놀라운 부분: compiled region 밖에선 eager-mode 디버깅 가능성 유지.
실제로 일어나는 일
- TorchDynamo 가 너 forward 의 Python bytecode 가로채서 op 를 FX graph 에 capture.
- AOTAutograd 가 backward op 포함하게 graph rewrite.
- TorchInductor 가 graph 를 optimized Triton/CUDA kernel (CPU 면 C++) 로 lowering.
graph 가 첫 호출에 lazy 짓기. 너 코드가 Dynamo 가 capture 못 하는 거 (data-dependent control flow, forward 안 custom Python 객체) 하면 그 section 위 eager 로 graceful fallback — 'graph break'. compile 이 outright fail X; speedup 만 좀 잃음.
세 mode
- default — compile 시간과 speedup 의 좋은 균형.
mode="reduce-overhead"— kernel launch 사이 Python overhead 최소화. 작은 model 또는 작은 batch size 에 best.mode="max-autotune"— max 속도 위 kernel variant 철저 탐색. 컴파일 느림 (가끔 분), 실행 가장 빠름.
graph 깨는 거
- tensor 값에 data-dependent control flow (
if x.sum() > 0) — Python int / config 면 보통 OK. - untraced 라이브러리 호출 (forward 안 일부 OpenCV / PIL op).
- Python attribute 통한 tensor 값 mutating.
- 일부 custom autograd Function (PyTorch 2.x 에 개선 중).