学习 PyTorch 到 JAX 翻译中的 Bug 上下文
Learning Bug Context for PyTorch-to-JAX Translation with LLMs
AI总结:
针对 LLM 在 PyTorch 到 JAX 代码翻译中易出错的问题,构建 T2J 基准(含 bug 及修复),通过上下文学习使弱 LLM 翻译质量提升达 20%。
摘要:
大型语言模型(LLMs)在常用编程语言之间的代码翻译上表现出色。然而,对于领域特定代码,翻译的可靠性会大大降低,因为其正确性依赖于框架特定的 API 和执行语义。一个例子是将深度学习代码从 PyTorch 翻译到 JAX,LLM 的输出常常包含细微的 bug 或非惯用用法,导致无法执行或行为改变。先前的研究表明,从 LLM 生成的代码中精心策划的 bug 修复数据有助于提高代码生成质量,但此类资源对于 PyTorch 到 JAX 的翻译仍然有限。在这项工作中,我们引入了 T2J,这是一个包含 LLM 翻译 bug 及其开发者编写修复的基准,专门针对 PyTorch 到 JAX 的代码。我们从 TorchLeet 数据集中的 20 个内核开始,使用弱 LLM gpt-4o-mini 将其翻译成 JAX,并聘请软件开发人员调试和修复生成的 JAX 实现。然后,我们利用 T2J 通过上下文学习来改进弱 LLM gpt-4o-mini 的 PyTorch 到 JAX 翻译。我们的评估表明,使用 T2J 使我们提出的指标 T2J-CodeTrans-Score 提升了高达 20%。
英文摘要:
Large language models (LLMs) have shown strong performance on code translation between widely used programming languages. However, translation becomes much less reliable for domain-specific code, where correctness depends on framework-specific APIs and execution semantics. One example is translating deep-learning code from PyTorch to JAX, where LLM outputs often contain subtle bugs or non-idiomatic usage that prevents execution or changes behavior. Prior work suggests that curated bug-fix data from LLM-generated code can help improve code generation quality, but such resources are still limited for PyTorch-to-JAX translation. In this work, we introduce T2J, a benchmark of LLM translation bugs paired with developer-written fixes for PyTorch-to-JAX code. We start from 20 kernels in the TorchLeet dataset, translate them to JAX using the weak LLM gpt-4o-mini, and hire software developers to debug and repair the generated JAX implementations. We then use T2J to improve PyTorch-to-JAX translation for the weak LLM gpt-4o-mini via in-context learning. Our evaluation shows that using T2J yields up to 20% improvement of our proposed metric T2J-CodeTrans-Score.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。