This paper presents GRAPHMEND, a high-level compiler technique that eliminates FX graph breaks in PyTorch 2 programs. Although PyTorch 2 introduced TorchDynamo and TorchInductor to enable just-in-time graph compilation, unresolved dynamic control flow and unsupported Python constructs often fragment models into multiple FX graphs. These fragments force frequent fallbacks to eager mode, introduce costly CPU-to-GPU synchronizations, and reduce optimization opportunities. GRAPHMEND addresses this limitation by analyzing and transforming source code before execution. Built on the Jaseci compilation framework, GRAPHMEND introduces two code transformations that remove graph breaks due to dynamic control flow and Python side effects. This design allows PyTorch's compilation pipeline to capture larger, uninterrupted FX graphs without requiring manual refactoring by developers. Evaluation across eight Hugging Face models shows that GRAPHMEND removes graph breaks due to dynamic control flow and Python side effects, reducing the break count to 0 in 6 models and reducing it from 5 to 2 in another model. On NVIDIA RTX 3090 and A40 GPUs, GRAPHMEND achieves up to 75% latency reductions and up to 8% higher end-to-end throughput. These results demonstrate that high-level code transformation is an effective complement to PyTorch's dynamic JIT compilation pipeline, substantially improving both usability and performance.


翻译:本文提出 GRAPHMEND,一种用于消除 PyTorch 2 程序中 FX 图中断的高级编译技术。尽管 PyTorch 2 引入了 TorchDynamo 和 TorchInductor 以支持即时图编译,但未解决的动态控制流及不支持的 Python 结构仍常将模型分割为多个 FX 图。这些片段迫使系统频繁回退至即时执行模式,引入昂贵的 CPU 至 GPU 同步开销,并减少优化机会。GRAPHMEND 通过在执行前分析并转换源代码来解决此限制。该技术基于 Jaseci 编译框架构建,引入了两种代码转换方法,以消除由动态控制流和 Python 副作用导致的图中断。此设计使得 PyTorch 的编译流水线能够捕获更大且连续的 FX 图,无需开发者手动重构代码。在八个 Hugging Face 模型上的评估表明,GRAPHMEND 成功消除了由动态控制流和 Python 副作用引起的图中断:在六个模型中将中断数降为 0,在另一个模型中将中断数从 5 降至 2。在 NVIDIA RTX 3090 和 A40 GPU 上,GRAPHMEND 实现了高达 75% 的延迟降低和高达 8% 的端到端吞吐量提升。这些结果表明,高级代码转换技术可有效补充 PyTorch 的动态即时编译流水线,显著提升其可用性与性能。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
图增强生成(GraphRAG)
专知会员服务
34+阅读 · 2025年1月4日
【IJCAI2024】Gradformer:具有指数衰减的图变换器
专知会员服务
17+阅读 · 2024年4月25日
Graph Transformer近期进展
专知会员服务
65+阅读 · 2023年1月5日
【Code】GraphSAGE 源码解析
AINLP
31+阅读 · 2020年6月22日
使用Python进行图像增强
AI研习社
17+阅读 · 2018年9月30日
教程 | PyTorch经验指南:技巧与陷阱
机器之心
16+阅读 · 2018年7月30日
实战 | 用Python做图像处理(二)
七月在线实验室
17+阅读 · 2018年5月25日
国家自然科学基金
0+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
0+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员