Demystifying the Silence of Correctness Bugs in PyTorch Compiler
作者: Meiziniu Li, Dongze Li, Jianmeng Liu, Shing-Chi Cheung
分类: cs.SE, cs.AI
发布日期: 2026-04-09
💡 一句话要点
针对PyTorch编译器正确性Bug,提出基于LLM变异的检测方法AlignGuard
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: PyTorch编译器 正确性Bug LLM变异 模糊测试 深度学习 测试用例生成 AI可靠性
📋 核心要点
- PyTorch编译器中的正确性Bug会导致模型输出错误且难以发现,严重影响LLM应用的可靠性,但缺乏系统性研究。
- AlignGuard利用LLM进行测试用例变异,并结合从错误特征分析中提取的知识,专门针对PyTorch编译器的正确性Bug进行检测。
- AlignGuard成功检测到23个新的正确性Bug,其中超过一半被PyTorch开发团队标记为高优先级,验证了该方法的有效性。
📝 摘要(中文)
PyTorch编译器(torch.compile)是深度学习模型(包括LLM)性能优化的关键工具。然而,torch.compile容易出现正确性错误,导致编译后的模型输出错误,且不会触发异常、崩溃或警告。这些错误严重威胁下游LLM应用的可靠性。PyTorch社区数据显示,19.2%的高优先级问题是由torch.compile错误导致的编译模型输出错误,是第二常见的错误类别(仅次于程序崩溃的19.57%)。本文首次对torch.compile中的正确性错误进行了实证研究,分析了它们的特征,并评估了现有模糊测试器检测这些错误的效果。基于研究结果,我们提出了一种名为AlignGuard的概念验证测试技术,专门用于检测torch.compile中的正确性错误。AlignGuard结合了从实证研究中提取的错误特征,应用基于LLM的测试用例变异来检测正确性错误。AlignGuard已成功检测到torch.compile中的23个新正确性错误,这些错误均已得到PyTorch开发团队的确认或修复,其中超过一半(14/23)甚至被标记为高优先级错误,突显了该技术的实用性。
🔬 方法详解
问题定义:论文旨在解决PyTorch编译器(torch.compile)中存在的正确性Bug问题。这些Bug会导致编译后的深度学习模型产生错误的输出,而且不会触发任何异常、崩溃或警告,使得检测和修复变得非常困难。现有方法,如通用模糊测试器,在检测此类Bug上的效果不佳。
核心思路:论文的核心思路是通过深入分析PyTorch编译器中正确性Bug的特征,并利用这些特征来指导测试用例的生成和变异。具体而言,论文利用大型语言模型(LLM)来对现有的测试用例进行变异,从而更有可能触发正确性Bug。
技术框架:AlignGuard的整体框架包括以下几个主要步骤:1) 收集现有的PyTorch测试用例;2) 使用LLM对这些测试用例进行变异,生成新的测试用例;3) 使用torch.compile编译原始测试用例和变异后的测试用例;4) 比较原始测试用例和变异后测试用例的输出结果,如果结果不一致,则可能发现了新的正确性Bug;5) 将发现的Bug报告给PyTorch开发团队进行确认和修复。
关键创新:AlignGuard的关键创新在于它结合了错误特征分析和LLM驱动的测试用例变异。通过分析已知的正确性Bug,论文提取出了一些关键的特征,例如涉及特定算子或数据类型的计算。然后,AlignGuard利用LLM来生成符合这些特征的测试用例,从而更有可能触发新的Bug。与传统的模糊测试方法相比,AlignGuard更加有针对性,效率更高。
关键设计:AlignGuard的关键设计包括:1) 使用LLM进行测试用例变异的具体策略,例如如何选择合适的LLM,如何设计提示语,以及如何控制变异的强度;2) 如何比较原始测试用例和变异后测试用例的输出结果,例如使用哪些指标来衡量输出结果的差异;3) 如何对发现的Bug进行优先级排序,以便PyTorch开发团队能够优先处理最严重的Bug。
🖼️ 关键图片
📊 实验亮点
AlignGuard成功检测到PyTorch编译器中23个新的正确性Bug,所有Bug均已得到PyTorch开发团队的确认或修复。其中超过一半(14/23)的Bug被标记为高优先级,表明AlignGuard能够有效地发现严重影响系统稳定性的问题。这些结果验证了基于LLM变异的测试方法在检测编译器正确性Bug方面的有效性。
🎯 应用场景
该研究成果可应用于提升深度学习编译器的可靠性和安全性,尤其是在对正确性要求极高的LLM应用领域。通过更有效地检测和修复编译器中的正确性Bug,可以减少模型部署后出现意外错误的风险,提高AI系统的整体质量和可信度。该方法也可推广到其他深度学习框架的编译器测试中。
📄 摘要(原文)
Performance optimization of AI infrastructure is key to the fast adoption of large language models (LLMs). The PyTorch compiler (torch.compile), a core optimization tool for deep learning (DL) models (including LLMs), has received due attention. However, torch.compile is prone to correctness bugs, which cause incorrect outputs of compiled DL models without triggering exceptions, crashes, or warnings. These bugs pose a serious threat to the reliability of downstream LLM applications. Data from the PyTorch community shows that 19.2% of high-priority issues are incorrect outputs of compiled DL models induced by torch.compile bugs, the second-most-common bug category (only behind program crashes at 19.57%). However, no systematic study has been conducted to specifically characterize and thereby detect these bugs. In this paper, we present the first empirical study of the correctness bugs in torch.compile, examine their characteristics, and assess the effectiveness of existing fuzzers in detecting them. Based on our findings, we propose a proof-of-concept testing technique named AlignGuard, tailored specifically for detecting correctness bugs in torch.compile. AlignGuard incorporates bug characteristics distilled from our empirical study, applying LLM-based test mutation to existing test cases for correctness bug detection. At the time of writing, AlignGuard has successfully detected 23 new correctness bugs in recent torch.compile. All these bugs have been confirmed or fixed by the PyTorch development team, and over half (14/23) of them are even marked as high-priority bugs, underscoring the usefulness of our technique.