Abstract
Traditional Large Language Model (LLM) training for code translation relies on static code pairs, which often fail to capture the iterative reasoning and debugging required for complex tasks, especially in low-resource domains like Fortran and CUDA. We present a dual-LLM "Questioner-Solver" pipeline that generates high-quality training data by recording multi-turn dialogues of the translation and debugging process. Fine-tuning on these reasoning traces allows mid-sized open-source models (7B-13B) to significantly outperform massive proprietary systems, achieving up to a 56% absolute boost in functional correctness.
Introduction
While LLMs excel at translating popular languages like Python or Java, they struggle with "low-resource" domains—specifically legacy languages (Fortran) and specialized high-performance computing (HPC) frameworks (CUDA). The core issue is two-fold: first, a scarcity of high-quality parallel code for training; and second, the "black box" nature of traditional supervised learning. Traditional training teaches the model what the answer is, but not how to reach it. In reality, code translation is an iterative process of compiling, analyzing errors, and fixing them. Models trained only on static pairs often lack the reasoning skills to recover when they encounter syntax or runtime errors.
The Questioner-Solver Framework
To address these limitations, we introduce an automated pipeline featuring a dual-LLM Questioner–Solver architecture. This framework moves beyond simple source-target pairs by capturing the entire dialogue history of a translation task.
- The Questioner: Acts as the architect and critic. It analyzes the current state, incorporates external feedback (such as compiler errors and runtime logs), and formulates targeted instructions.
- The Solver: Acts as the implementer. It generates the code, writes unit tests, and applies repairs based on the Questioner’s prompts.
As shown in the pipeline above, the process follows a rigorous flow: preprocessing, unit test generation for the source language, initial translation, and iterative refinement using compiler and runtime feedback. The final "Duo-Test Verification" ensures the source and target code produce identical outputs. By recording this entire history—including initial failures and subsequent fixes—we create a dataset of "reasoning traces."
Datasets and Training
The study focuses on two critical HPC translation tasks: Fortran2CPP (3.64k dialogues, 14.1k Question-Solution pairs) and CPP2CUDA (3.93k dialogues, 12.7k QS pairs). These datasets are unique because they provide the intermediate failures and debugging steps that lead to a correct solution. We found that decomposing dialogues into fine-grained QS-Pairs is highly effective for mastering complex syntax, while the full Dialogue trace helps maintain long-term semantic consistency.
Experimental Results
The improvements from fine-tuning on dialogue data were dramatic across all metrics. On the challenging C++-to-CUDA task, CodeLlama-13B’s unit test success rate soared from 12.5% to 68.8%. For Fortran-to-C++, success rates improved from 42.3% to 74.1%.
As illustrated in the success rate charts, models trained on dialogue and QS-pair data consistently outperform those trained on original data or simple code pairs. Notably, a dialogue-tuned Qwen2.5-7B model achieved a 93.18% compilation success rate on C++-to-CUDA, surpassing massive proprietary systems like Gemini 2.5 Flash (79.17%) and LLaMA 4 Scout (78.98%). Furthermore, these models demonstrated superior "recoverability," successfully resolving issues in subsequent debug rounds rather than repeating previous mistakes.
Conclusion and Future Work
This research demonstrates that for complex code translation, the process is as valuable as the product. Training models on the reasoning traces of debugging allows smaller, open-source models to achieve state-of-the-art performance in specialized domains.
Future work will focus on expanding the pipeline to more languages and incorporating complex performance-profiling tools into the feedback loop. We also aim to explore "round-aware" curriculum learning to train models on progressively more difficult debugging scenarios, further enhancing their ability to handle massive, multi-file industrial codebases.
Summary updated