GraphMend: 用于修复PyTorch 2中图打破的代码转换
GraphMend: Code Transformations for Fixing Graph Breaks in PyTorch 2
AI总结:
GraphMend通过代码转换消除PyTorch 2中的图打破问题,提升编译效率和性能,减少延迟并提高吞吐量。
摘要:
本文提出了GRAPHMEND,一种高级编译技术,用于消除PyTorch 2程序中的FX图打破。尽管PyTorch 2引入了TorchDynamo和TorchInductor以实现即时图编译,但未解决的动态控制流和不支持的Python构造常导致模型分解为多个FX图。这些碎片迫使频繁回退到急躁模式,引入昂贵的CPU到GPU同步,并减少优化机会。GRAPHMEND通过在执行前分析和转换源代码来解决这一限制。基于Jaseci编译框架,GRAPHMEND引入了两种代码转换,以去除由动态控制流和Python副作用引起的图打破。这种设计使PyTorch的编译流水线能够捕获更大的、不间断的FX图,而无需开发人员手动重构。在八个Hugging Face模型上的评估显示,GRAPHMEND消除了由动态控制流和Python副作用引起的图打破,使6个模型的打破数量减少到0,另一个模型的打破数量从5减少到2。在NVIDIA RTX 3090和A40 GPU上,GRAPHMEND实现了高达75%的延迟减少和高达8%的端到端吞吐量提升。这些结果表明,高级代码转换是PyTorch动态JIT编译流水线的有效补充,显著提高了可用性和性能。
英文摘要:
This paper presents GraphMend, a compiler technique that automatically fixes FX graph breaks in PyTorch 2 programs. Although PyTorch 2 introduced TorchDynamo and TorchInductor to enable just-in-time graph compilation, certain code patterns still cause graph breaks that force execution to fall back to Python eager mode, introducing costly CPU-GPU synchronization and reducing optimization opportunities. Our investigation of 195 Hugging Face models reveals that 13.8% of models exhibit graph breaks. GraphMend automatically eliminates fixable breaks through source-level program analysis and transformations. It analyzes AST-level program structure to identify graph-break patterns and applies transformations only when their semantic preservation can be statically established. These transformations enable PyTorch to capture larger, uninterrupted FX graphs without manual refactoring by developers. We evaluate GraphMend on all 27 models found to exhibit graph breaks in our investigation. GraphMend eliminates 107 of 147 graph breaks (73%), fully fixing all breaks in 21 models. In our experiments on NVIDIA GPUs, GraphMend achieves up to 26x cold-start speedup, 5x on average, and up to 1.39x steady-state forward pass speedup. These results demonstrate that semantics-aware source-level analysis and transformation are effective complements to PyTorch's dynamic JIT compilation pipeline, substantially improving both usability and performance.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。