42digest首页
LLM生成代码的动态稳定性

Dynamic Stability of LLM-Generated Code

Prateek Rajput, Abdoul Aziz Bonkoungou, Yewei Song, Abdoul Kader Kabore, Iyiola E. Olatunji, Jacques Klein, Tegewende Bissyande

arXiv
2025年11月7日

目前对代码生成的LLM的评价强调了功能的正确性,忽视了功能上正确的解决方案在算法复杂性方面可能有很大差异的事实。 例如,(O(n^2))与(O(n log n))排序算法可能会产生类似的输出,但在生产中产生截然不同的性能成本。 这种差异揭示了当前评估方法的一个关键限制:它们未能捕捉到正确解决方案之间的行为和性能多样性。 为了解决这个问题,我们引入了一个用于评估生成代码的动态稳定性的原则框架。 我们提出了来自opcode分布的两个指标:静态 Canonical Trace Divergence (SCTD),它捕获了生成解决方案的算法结构多样性,以及动态 Canonical Trace Divergence (DCTD),它量化运行时行为方差。 它们的比例,行为表达因子(BEF),作为诊断信号:当BEF≪1和BEF≫1时,它表示关键的运行时不稳定,当BEF≪1时,功能冗余。 BigOBench和CodeContests的经验结果表明,最先进的LLM即使在功能正确的输出中也表现出显著的算法差异。 值得注意的是,提高采样温度提高了pass@1速率,但降低了稳定性,揭示了一种未被认可的权衡:在不同的输出空间中寻找正确的解决方案引入了正确性和行为一致性之间的“不稳定性惩罚”。 我们的研究结果要求代码生成中的稳定性感知目标,以及具有无症状测试用例的新基准,以实现强大的真实世界LLM评估。

Current evaluations of LLMs for code generation emphasize functional correctness, overlooking the fact that functionally correct solutions can differ significantly in algorithmic complexity. For instance, an (O(n^2)) versus (O(n log n)) sorting algorithm may yield similar output but incur vastly different performance costs in production. This discrepancy reveals a critical limitation in current evaluation methods: they fail to capture the behavioral and performance diversity among correct soluti...