TL;DR
While large language models (LLMs) can learn to improve their coding skills via reinforcement learning (RL) in a high-resource language like Python, these gains completely fail to transfer to lower-resource languages like Go or Ruby. To fix this, the authors introduce Parallel-SFT, a method that trains models on functionally equivalent code across multiple languages during the supervised fine-tuning stage. This simple alignment step restructures the model's latent space to focus on what the code does rather than how it's written, enabling seamless zero-shot cross-language transfer during subsequent RL.
What Problem Does This Paper Address?
When humans learn a new algorithm in Python, they can easily implement it in C++ or Java because the underlying logic is universal. Ideally, LLMs should do the same. However, the authors discover that when a model undergoes Reinforcement Learning (RL) to optimize code generation in a specific "source" programming language (PL), the performance gains are strictly locked to that language. When evaluated on a different "target" language, the performance flatlines or even degrades—a phenomenon known as negative transfer.
The root cause lies in how LLMs are pretrained. Unlike natural language data, which features abundant "incidental bilingualism" (e.g., Wikipedia articles discussing the same topic in different languages), code repositories are almost exclusively monolingual and highly domain-specialized (e.g., C for systems programming, JavaScript for web development). This lack of overlapping context causes the LLM to build fragmented, syntax-heavy representation spaces for different programming languages, preventing algorithmic improvements learned in one language from propagating to others.
Methods
To bridge this gap, the authors propose Parallel-SFT, a post-training strategy designed to align the representation spaces of different programming languages before RL training begins.
The method consists of two main phases:
- Parallel Data Construction: The authors took Python coding problems and used a powerful teacher model (Llama-4-Maverick 400B) to translate the solutions into seven other languages (C, C++, Java, C#, JavaScript, Bash, Lua). Crucially, they executed these translated programs against rigorous test suites to ensure absolute functional equivalence.
- Supervised Fine-Tuning (SFT): They fine-tuned Llama-3.1-8B on these "parallel programs"—forcing the model to map the exact same natural language problem description to multiple syntactically distinct but functionally identical code implementations.
Following Parallel-SFT, the model undergoes standard RL training (using the GRPO algorithm) on a single, high-resource source language (like C++ or Python) and is evaluated zero-shot on unseen target languages.
Datasets
- SFT Training: Built by translating Python solutions from the APPS and CodeContests datasets into parallel multi-PL equivalents. This was mixed into a modified version of the Tulu 3 SFT mixture (replacing its original coding instances with the new parallel dataset).
- RL & Evaluation:
- CodeForces: Used for the code generation task.
- CodeForces Submissions: A dataset of human code submissions used for the code validation task (predicting whether a given piece of code correctly solves a problem).
Key Insights and Ideas
- The "Semantic Hub" in Middle Layers: Probing the model's internal representations revealed that Parallel-SFT induces an inverted U-shape in representation similarity across the model's layers. The initial and final layers remain specialized in language-specific syntax, but the middle layers act as a language-independent "semantic hub" that reasons about program functionality.
- Functionality-Centric Latent Space: By training on parallel code, the model learns to cluster programs based on what they achieve rather than their surface-level syntax tokens. This tight clustering allows policy improvements discovered during RL in Python to naturally map over to Go or Ruby in the latent space.
Key Results
The authors evaluated Parallel-SFT against a monolingual baseline and a standard multi-PL baseline (which saw all languages but not as parallel pairs solving the same problem).
- Outperforming the Oracle: In code generation, when performing RL on Python, the Parallel-SFT model didn't just beat the baselines on unseen target languages (Go, PHP, Ruby)—it actually outperformed the oracle model that was trained directly on those target languages.
- Robust Practical Transfer: In code validation (a task where the input code is highly language-dependent), Parallel-SFT consistently yielded the highest zero-shot accuracy gains across the board throughout the RL training timeline.
Limitations and Future Work
While Parallel-SFT shows remarkable transfer capabilities, the authors note several areas for expansion:
- Scale and Complexity: Due to compute constraints, experiments were restricted to non-reasoning 8B models. Testing this approach on larger reasoning models (like o1-style architectures) or complex coding agents remains an open question.
- Hyperparameter Optimization: The exploration did not exhaustively tune SFT data formatting, mixing ratios, or curriculum learning schedules, which could yield further performance boosts.
- Typological Similarities: Future iterations could explicitly leverage structural similarities between specific programming languages to optimize the transfer pathways.
Summary updated