arXiv:2504.05424cs.SEcs.AI2025-04

将深度学习的即时执行代码自动转为图执行,提升性能且不影响准确率。

Speculative Automated Refactoring of Imperative Deep Learning Programs to Graph Execution

  • 通过静态分析判断哪些代码可转为图执行,支持智能重构。
  • 在19个项目中42.56%的函数可重构,平均提速2.16倍。
  • 适合希望优化性能又不愿改写代码的开发者使用。

效率对支撑日益增长的数据集至关重要,尤其在深度学习(DL)系统中。传统DL框架采用延迟执行风格,支持符号化、基于图的深度神经网络(DNN)计算,虽可扩展但易出错、难调试。为此,更直观的即时执行框架兴起,但牺牲了运行时性能。尽管混合方法试图兼顾两者,但使用需细致权衡。本文核心洞察是:尽管DL程序通常顺序执行,但将即时代码混合为图执行,类似于传统系统中并行化顺序代码。受此启发,我们提出一种自动化重构方法,帮助开发者判断哪些本应即时执行的函数可高效转为图执行。该方法引入针对Python的新型静态张量与副作用分析,因Python动态性可能导致分析不严谨,故采用推测性(基于关键词)分析处理复杂情况,并向开发者通报假设。实现上,作为PyDev Eclipse插件集成WALA Ariadne分析框架,在19个包含132 KLOC的DL项目上评估。结果显示,766个候选函数中有326个(42.56%)可重构,性能测试平均相对加速2.16倍,模型精度无显著差异。结果表明,该方法能有效挖掘即时代码的性能潜力。

原文摘要 · Abstract (English)

Efficiency is essential to support ever-growing datasets, especially for Deep Learning (DL) systems. DL frameworks have traditionally embraced deferred execution-style DL code -- supporting symbolic, graph-based Deep Neural Network (DNN) computation. While scalable, such development is error-prone, non-intuitive, and difficult to debug. Consequently, more natural, imperative DL frameworks encouraging eager execution have emerged but at the expense of run-time performance. Though hybrid approaches aim for the "best of both worlds," using them effectively requires subtle considerations. Our key insight is that, while DL programs typically execute sequentially, hybridizing imperative DL code resembles parallelizing sequential code in traditional systems. Inspired by this, we present an automated refactoring approach that assists developers in determining which otherwise eagerly-executed imperative DL functions could be effectively and efficiently executed as graphs. The approach features novel static imperative tensor and side-effect analyses for Python. Due to its inherent dynamism, analyzing Python may be unsound; however, the conservative approach leverages a speculative (keyword-based) analysis for resolving difficult cases that informs developers of any assumptions made. The approach is: (i) implemented as a plug-in to the PyDev Eclipse IDE that integrates the WALA Ariadne analysis framework and (ii) evaluated on nineteen DL projects consisting of 132 KLOC. The results show that 326 of 766 candidate functions (42.56%) were refactorable, and an average relative speedup of 2.16x on performance tests was observed with negligible differences in model accuracy. The results indicate that the approach is useful in optimizing imperative DL code to its full potential.

深度学习代码优化图执行自动化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。