Bridging Functional Correctness and Runtime Efficiency Gaps in LLM-Based Code Translation
Summary
SwiftTrans is a novel code translation framework designed to improve both functional correctness and runtime efficiency in large language model (LLM)-generated code. A preliminary study revealed that LLM-translated programs frequently exhibit slower execution times compared to human-written code, a problem not solvable by prompt engineering alone. SwiftTrans addresses this through a two-stage process: Multi-Perspective Exploration, where MpTranslator uses parallel in-context learning (ICL) to generate diverse translation candidates, and Difference-Aware Selection, where DiffSelector identifies the optimal candidate by explicitly comparing differences. The framework incorporates Hierarchical Guidance for MpTranslator and Ordinal Guidance for DiffSelector to enhance LLM adaptation. Evaluated on extended CodeNet and F2SBench, plus a new SwiftBench, SwiftTrans consistently demonstrated improvements in both metrics.
Key takeaway
For Machine Learning Engineers developing LLM-based code translation systems, you should prioritize runtime efficiency alongside functional correctness. Your current prompt engineering efforts may not adequately address performance bottlenecks in translated code. Consider integrating multi-stage frameworks like SwiftTrans, which generate diverse candidates and use explicit difference comparisons to select optimal, more efficient translations, thereby enhancing overall program quality.
Key insights
LLM-translated code often lacks runtime efficiency; SwiftTrans improves both correctness and speed through multi-perspective exploration and difference-aware selection.
Principles
- Runtime efficiency is critical for program quality.
- Diverse candidate generation improves translation.
- Explicitly comparing differences aids optimal selection.
Method
SwiftTrans employs Multi-Perspective Exploration via parallel in-context learning for diverse candidates, followed by Difference-Aware Selection to pick the optimal translation by comparing differences, guided hierarchically and ordinally.
In practice
- Extend benchmarks to include runtime metrics.
- Use parallel ICL for diverse code translations.
- Implement explicit difference comparison for selection.
Topics
- LLM Code Translation
- Runtime Efficiency
- SwiftTrans Framework
- In-Context Learning
- Code Benchmarking
- Program Optimization
Best for: AI Engineer, Research Scientist, AI Scientist, Machine Learning Engineer, NLP Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Computation and Language.