← Latest papers
💻 computer science

Reward-Free Code Alignment from Pretrained or Fine-Tuned LLM: Unpacking the Trade-offs for Code Generation

This empirical study investigates the trade-offs of applying reward-free alignment techniques (DPO and BoNBoN) to both pretrained and instruction-tuned LLMs for code generation, revealing that while aligning pretrained models yields larger relative improvements, starting from instruction-tuned models generally preserves higher absolute accuracy despite offering smaller gains or potential degradation.

Original authors: Gias Uddin, Sanjeepan Sivapiran

Published 2026-06-30
📖 5 min read🧠 Deep dive

Original authors: Gias Uddin, Sanjeepan Sivapiran

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 brilliant, raw talent who knows how to write code but hasn't learned the "rules of the road" yet. They might write a program that works, but it could be messy, insecure, or hard for others to read. This is what a Pretrained Large Language Model (LLM) is like: smart, but unpolished.

Now, imagine you have a Fine-Tuned LLM. This is that same talent, but they've already gone to a coding bootcamp. They know how to follow instructions and write clean code, but they might be a bit rigid or stuck in their ways.

The paper asks a big question: How do we teach these AI models to be "better" coders? Specifically, should we train them to follow safety and quality rules before they go to bootcamp (starting from raw talent), or after they've already learned to code (starting from the bootcamp graduate)?

The researchers call this process "Alignment." It's like teaching a model to prefer a "good" answer over a "bad" one, not just for text, but for code.

The Two Training Paths

The study compared two different training routes using two specific teaching methods (called DPO and BoNBoN):

  1. The "Raw Talent" Path (Pretrained-to-Aligned): You take the raw, untrained model and teach it the rules of coding and safety first.

    • The Analogy: Taking a raw, untrained artist and teaching them the rules of perspective and color theory before they ever try to paint a masterpiece.
    • The Result: These models showed huge improvements in their "soft skills" (like code readability, style, and security). They learned the rules very well because their minds were flexible. However, they started from a very low baseline, so even with big improvements, they weren't always the best at actually solving the hardest coding puzzles compared to the bootcamp graduates.
  2. The "Bootcamp Graduate" Path (Fine-Tuned-to-Aligned): You take the model that already knows how to code and then teach it the rules of safety and style.

    • The Analogy: Taking a professional chef who already cooks great meals and trying to teach them new hygiene rules.
    • The Result: These models were already very good at solving problems. When they were aligned, they didn't improve much because they were already near the top. In fact, sometimes the training backfired, and they actually got worse at solving problems (a phenomenon called "catastrophic forgetting," like a student forgetting how to add numbers because they were too focused on learning new grammar).

The Two Types of "Better"

The researchers looked at two different kinds of code quality:

  • Functional Requirements (The "Does it work?" test): Does the code actually run? Does it solve the math problem?
    • Finding: This is hard to fix with alignment. Sometimes it gets better, sometimes it gets worse. It's like trying to teach a runner to run faster by changing their shoes; sometimes it helps, sometimes it trips them up.
  • Non-Functional Requirements (The "Is it a good code?" test): Is the code secure? Is it easy to read? Does it follow style guides?
    • Finding: This is where alignment shines! Models improved consistently here. It's like teaching a writer to use better grammar and punctuation; almost every model got better at this, regardless of whether they started as raw talent or a bootcamp grad.

The Big Trade-Off: Flexibility vs. Stability

The paper uses a concept called the "Stability-Plasticity Dilemma" to explain what happened:

  • Raw Models (High Plasticity): They are like clay. They can be molded easily into a new shape (learning new rules quickly), but they might lose their original shape (forgetting how to code) if you push too hard. They showed the biggest percentage jumps in quality.
  • Fine-Tuned Models (High Stability): They are like hardened stone. They hold their shape well (they keep their coding skills), but they are hard to mold (hard to teach new rules without breaking them). They started higher and stayed high, but didn't improve much.

What Should Practitioners Do? (The 9 Recommendations)

Based on their experiments with five different AI models, the authors give nine pieces of advice:

  1. Pick your path based on your goal: If you want the biggest relative improvement (making a bad model much better), start with the raw model. If you need a model that is already reliable and just needs a little polish, start with the fine-tuned one.
  2. Focus on "Soft Skills" first: Teaching a model to write secure, readable code (Non-Functional) is safer and more successful than trying to force it to solve harder math problems (Functional).
  3. Choose the right model: Specialized coding models (like CodeLlama or DeepSeek) learn better than general chat models. Bigger models (7B parameters or more) are generally better than tiny ones.
  4. Don't guess the teaching method: Different models like different teachers. Some models (like Llama) learn best with one method (DPO), while others (like DeepSeek) prefer the other (BoNBoN). You have to test them.
  5. Watch for warning signs: If a model starts getting worse during the early "practice" phase (Supervised Fine-Tuning), stop! It's a strong sign that the full training will fail.
  6. Check all dimensions: Don't just check if the code runs; check if it's readable and secure. Sometimes a model gets better at one thing but worse at another.

The Bottom Line

If you want to make an AI coder safer and more professional, alignment works best when you start with a raw model and teach it the rules from scratch. However, if you already have a smart, fine-tuned coder, be very careful when trying to "align" it, because you might accidentally break its ability to solve problems.

The paper concludes that while alignment is a powerful tool, it's not a magic wand. It requires careful selection of the starting model, the teaching method, and the specific goals (safety vs. problem-solving) to avoid making things worse.

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 →