arXiv:2412.19770cs.LG2024-12被引 7

用对话式AI自动翻译老旧Fortran代码为C++,提升准确率和编译成功率。

Fortran2CPP: Automating Fortran-to-C++ Translation using LLMs via Multi-Turn Dialogue and Dual-Agent Integration

  • 通过双代理对话机制生成1.17万条代码翻译反馈数据
  • 编译成功率提升92%,CodeBLEU分数提高3.31倍
  • 适合需要现代化高性能计算代码的科研与工程团队

将遗留的Fortran代码转换为C++是现代化高性能计算(HPC)应用的关键步骤。然而,高质量并行Fortran-to-C++数据集稀缺,且大语言模型缺乏领域专业知识,给自动化翻译带来挑战。本文提出Fortran2CPP,一种基于新型双代理问答机制的多轮对话数据集生成方法,通过迭代反馈-决策流程(包括代码翻译、编译、执行、单元测试与错误修复)构建了11.7k条对话数据。基于该数据集,我们微调多个开源大模型,在代码语法准确性和功能可靠性上显著提升:CodeBLEU得分最高提升3.31倍,编译成功率达92%。结果表明,基于对话的训练对复杂代码转换任务具有重要价值。相关数据集与模型已开源,可在公开GitHub仓库获取。

原文摘要 · Abstract (English)

Translating legacy Fortran code into C++ is a crucial step in modernizing high-performance computing (HPC) applications. However, the scarcity of high-quality, parallel Fortran-to-C++ datasets and the limited domain-specific expertise in large language models (LLMs) present significant challenges for automated translation. In this paper, we introduce Fortran2CPP, a multi-turn dialogue dataset generated by a novel LLM agent-based approach that integrates a dual-LLM Questioner-Solver module to enhance translation accuracy. Our dataset comprises 11.7k dialogues capturing iterative feedback-decision workflows including code translation, compilation, execution, unit testing, and error-fixing. Using this dataset, we fine-tune several open-weight LLMs and achieve up to a 3.31x improvement in CodeBLEU scores and a 92\% increase in compilation success rate, demonstrating enhanced syntactic accuracy and functional reliability. Our findings highlight the value of dialogue-based LLM training for complex code translation tasks. The dataset and model have been open-sourced and are available on our public GitHub repository\footnote{\url{https://github.com/HPC-Fortran2CPP/Fortran2Cpp}}.

代码翻译LLM应用HPC现代化

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