paperbot · PL 论文追踪

全部论文 待读 收藏

P1 PyTorch 2: Faster Machine Learning Through Dynamic Python Bytecode Transformation and Graph Compilation

PyTorch 2:通过动态 Python 字节码变换与图编译加速机器学习
ASPLOS Proceedings of the 29th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 22024匹配度 6/10 · 论文属于 PL 与机器学习系统交叉的编译器工作,涉及动态字节码变换和计算图编译,与“PL→AI”中在 ML 系统中应用程序分析/编译有一定关联;但它不是静态分析、浮点程序分析或 LLM/Agent 交叉,也未直接面向 Agentic 程序,因此匹配度中等。引用 1395 inbox
Jason Ansel, Edward Yang, Horace He, Natalia Gimelshein, Animesh Jain, Michael Voznesensky, Bin Bao, Peter Bell, David Berard, Evgeni Burovski, Geeta Chauhan, Anjali Chourdia, Will Constable, Alban Desmaison, Zachary DeVito, Elias Ellison, Will Feng, Jiong Gong, Michael Gschwind, Brian Hirsh, Sherlock Huang, Kshiteej Kalambarkar, Laurent Kirsch, Michael Lazos, Mario Lezcano, Yanbo Liang, Jason Liang, Yinghai Lu, C. K. Luk, Bert Maher, Yunjie Pan, Christian Puhrsch, Matthias Reso, Mark Saroufim, Marcos Yukio Siraichi, Helen Suk, Shunting Zhang, Michael Suo, Phil Tillet, Xu Zhao, Eikan Wang, Keren Zhou, Richard Zou, Xiaodong Wang, Ajit Mathews, William Wen, Gregory Chanan, Peng Wu, Soumith Chintala
crossref: 2026-09-12dblp: 2026-09-12

AI 速览

一句话:PyTorch 2 的 torch.compile 借助动态字节码变换捕获计算图并编译,在真实模型上取得显著加速。

该论文介绍 PyTorch 2 中 torch.compile 功能的两个核心组件 TorchDynamo 与 TorchInductor。问题在于 eager 模式的 PyTorch 虽灵活却难以应用编译器优化。TorchDynamo 是一种 Python 级 JIT 编译器,在不牺牲 Python 灵活性的前提下,于执行前动态修改 Python 字节码,将 PyTorch 操作序列提取为 FX 图,再交由可扩展后端 JIT 编译。TorchInductor 是默认后端,将 PyTorch 程序翻译为面向 GPU 的 OpenAI Triton 和面向 CPU 的 C++。实验表明,TorchDynamo 比先前方法更稳健地捕获图且额外开销极小;在 NVIDIA A100 上对 180 多个真实模型,TorchInductor 实现推理 2.27 倍、训练 1.41 倍的几何平均加速,优于其他六个编译器。这为 eager 框架通过编译器应用优化提供了新途径。

问题
在 PyTorch 等 eager 模式框架中,如何在不牺牲 Python 灵活性的前提下捕获计算图并应用编译器优化,是长期难题。
方法
TorchDynamo 在运行时动态修改 Python 字节码,将 PyTorch 操作序列提取为 FX 图并交由可扩展后端 JIT 编译;TorchInductor 作为默认后端,将程序翻译为 GPU 的 OpenAI Triton 和 CPU 的 C++。
评估
在 NVIDIA A100 上对 180 多个真实模型进行评测,TorchDynamo 图捕获更稳健且开销极小,TorchInductor 取得推理几何平均 2.27 倍、训练 1.41 倍加速,并优于六个其他编译器。
原文摘要(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.

链接与引用

DOI 原文 · DBLP

BibTeX
@inproceedings{AnselYHGJVBBBBC24,
  title = {PyTorch 2: Faster Machine Learning Through Dynamic Python Bytecode Transformation and Graph Compilation},
  author = {Jason Ansel and Edward Yang and Horace He and Natalia Gimelshein and Animesh Jain and Michael Voznesensky and Bin Bao and Peter Bell and David Berard and Evgeni Burovski and Geeta Chauhan and Anjali Chourdia and Will Constable and Alban Desmaison and Zachary DeVito and Elias Ellison and Will Feng and Jiong Gong and Michael Gschwind and Brian Hirsh and Sherlock Huang and Kshiteej Kalambarkar and Laurent Kirsch and Michael Lazos and Mario Lezcano and Yanbo Liang and Jason Liang and Yinghai Lu and C. K. Luk and Bert Maher and Yunjie Pan and Christian Puhrsch and Matthias Reso and Mark Saroufim and Marcos Yukio Siraichi and Helen Suk and Shunting Zhang and Michael Suo and Phil Tillet and Xu Zhao and Eikan Wang and Keren Zhou and Richard Zou and Xiaodong Wang and Ajit Mathews and William Wen and Gregory Chanan and Peng Wu and Soumith Chintala},
  booktitle = {ASPLOS},
  year = {2024},
  doi = {10.1145/3620665.3640366}
}