← Latest papers
🤖 machine learning

Learning Bug Context for PyTorch-to-JAX Translation with LLMs

This paper introduces T2J, a benchmark of PyTorch-to-JAX translation bugs paired with developer fixes, which is used to demonstrate that in-context learning with this dataset can improve the code translation quality of weak LLMs by up to 20%.

Original authors: Hung Phan, Son Vu, Tuan Dinh, Nesreen Ahmed, Ali Payani, Ali Jannesari

Published 2026-06-23
📖 4 min read☕ Coffee break read

Original authors: Hung Phan, Son Vu, Tuan Dinh, Nesreen Ahmed, Ali Payani, Ali Jannesari

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a master chef who is famous for cooking delicious meals in French (PyTorch, a popular coding language for AI). You want to hire a translator to convert these recipes into Japanese (JAX, another coding language for AI) so a different kitchen can cook them.

You hire a very smart, but slightly inexperienced sous-chef (an AI called gpt-4o-mini) to do the translation. The problem? The sous-chef knows the words, but doesn't quite understand the kitchen rules of the new language. They might translate "simmer for 10 minutes" as "boil for 10 seconds," or use a knife that doesn't exist in the new kitchen. The result is a recipe that looks okay on paper but fails when you try to cook it.

This paper, titled "Learning Bug Context for PyTorch-to-JAX Translation with LLMs," introduces a new system called T2J to fix this problem. Here is how it works, broken down into simple steps:

1. The Problem: The "Smart but Clumsy" Translator

The authors found that when AI tries to translate code between these two specific deep-learning languages, it often makes subtle, tricky mistakes.

  • The Analogy: It's like translating a recipe that says "add a pinch of salt" but the translator writes "add a cup of salt" because they didn't understand the specific context of the dish.
  • The Result: The code doesn't run, or it produces the wrong results. Previous attempts to fix this by just asking the AI to "try again" didn't work well, especially with smaller, cheaper AI models.

2. The Solution: The "Bug Fixing Library" (T2J)

Instead of just asking the AI to translate blindly, the authors built a library of mistakes and their fixes.

  • How they built it: They took 20 simple coding problems, asked the "clumsy" AI to translate them, and then hired real human software developers to act as editors. These humans found the errors, fixed them, and wrote down exactly what was wrong and how they fixed it.
  • The Collection: This resulted in a "Bug-Solution Library" containing over 160 pairs of "Here is the mistake" and "Here is the fix."

3. The Magic Trick: "Show, Don't Just Tell"

This is the core of their new method. When the AI needs to translate a new piece of code, they don't just say, "Translate this."

  • The Old Way: "Translate this PyTorch code to JAX." (The AI guesses and often fails).
  • The T2J Way: "Translate this PyTorch code to JAX. By the way, here are 5 examples of mistakes other people made on similar tasks and how they fixed them."
  • The Analogy: It's like giving the sous-chef a cheat sheet right before they start cooking: "Remember, last time you tried to chop onions, you used the wrong knife. Here is the right knife. Also, don't forget to peel the garlic first."

4. The Results: Faster and Better

The authors tested this new method and found:

  • Better Quality: The translated code was much more accurate. They created a new scoring system (like a taste test) called the T2J CodeTrans Score, and the new method improved the score by up to 20%.
  • Less Editing Needed: Because the AI made fewer mistakes to begin with, the human editors had to do about half the work to fix the code compared to the old method.
  • Faster Execution: The code that was generated ran about 2.5 times faster than the code generated by the standard method.

5. What They Didn't Do (The Boundaries)

It is important to note what this paper didn't do:

  • They did not test this on "Open Source" AI models (the free ones) because they didn't have the budget to hire enough humans to fix the code for those models.
  • They did not apply this to medical or clinical uses. They strictly focused on translating code between two specific AI frameworks.
  • They did not invent a new AI model; they just taught an existing one (gpt-4o-mini) how to learn from its past mistakes using a "cheat sheet."

Summary

Think of T2J as a training manual for a translator. Instead of hoping the translator gets it right on the first try, you give them a book of "Common Mistakes and How to Avoid Them" right before they start working. This simple trick made the translation process significantly more reliable, cheaper (less human editing needed), and faster.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →