PyTorch 2: Faster Machine Learning Through Dynamic Python Bytecode Transformation and Graph Compilation
Authors:
- Jason AnselJAJason Ansel
- Edward YangEYEdward Yang
- Horace HeHHHorace He
- Natalia GimelsheinNGNatalia Gimelshein
- Animesh JainAJAnimesh Jain
- Michael VoznesenskyMVMichael Voznesensky
- Bin BaoBBBin Bao
- Peter BellPBPeter Bell
- David BerardDBDavid Berard
- Evgeni BurovskiEBEvgeni Burovski
- Geeta ChauhanGCGeeta Chauhan
- Anjali ChourdiaACAnjali Chourdia
Top Cited Papers
Open Access
- 27 April 2024
- conference paper
- Published by Association for Computing Machinery (ACM)
- p. 929-947
Abstract
This paper introduces two extensions to the popular PyTorch machine learning framework, TorchDynamo and TorchInductor, which implement the torch.compile feature released in PyTorch 2. TorchDynamo is a Python-level just-in-time (JIT) compiler that enables graph compilation in PyTorch programs without sacrificing the flexibility of Python. It achieves this by dynamically modifying Python bytecode before execution and extracting sequences of PyTorch operations into an FX graph, which is then JIT compiled using one of many extensible backends. TorchInductor is the default compiler backend for TorchDynamo, which translates PyTorch programs into OpenAI's Triton for GPUs and C++ for CPUs. Results show that TorchDynamo is able to capture graphs more robustly than prior approaches while adding minimal overhead, and TorchInductor is able to provide a 2.27× inference and 1.41× training geometric mean speedup on an NVIDIA A100 GPU across 180+ real-world models, which outperforms six other compilers. These extensions provide a new way to apply optimizations through compilers in eager mode frameworks like PyTorch.Keywords
This publication has 20 references indexed in Scilit:
- MLIR: Scaling Compiler Infrastructure for Domain Specific Computation2021
- UNIT: Unifying Tensorized Instruction Compilation2021
- Array programming with NumPyNature, 2020
- Tiramisu: A Polyhedral Compiler for Expressing Fast and Portable Code2019
- In-Datacenter Performance Analysis of a Tensor Processing Unit2017
- CNTK2016
- Caffe2014
- OpenTuner2014
- Halide2013
- Note on a Method for Calculating Corrected Sums of Squares and ProductsTechnometrics, 1962