KAIST's UTRL Trains a 4B Model to Beat GPT-4.1 at Writing Code Tests
UTRL trains a unit test generator and a code generator against each other, letting a 4B model outperform GPT-4.1 on test quality without human-written test labels.
ProTakeaways
- UTRL trains a unit test generator and code generator adversarially, no human-written tests required.
- Qwen3-4B trained with UTRL beats GPT-4.1 and GPT-4o on unit test quality across two benchmarks.
- Best-of-N code score on Qwen3-8B jumps 34%, from 0.430 to 0.578.
- Unit test fidelity hits 0.794 for UTRL-4B and 0.827 for UTRL-14B, matching GPT-4.1.
- Validity reward is critical: without it, over 50% of generated tests are invalid.
- Code, checkpoints, and eval sets are available on GitHub.
A team from KAIST AI and Microsoft Research has flipped the usual recipe for training code models on its head. Instead of teaching a small language model to write better code, they trained it to write better unit tests, using an adversarial reinforcement learning loop that needs zero human-written tests. The result is UTRL, an ICLR 2026 paper in which a 4-billion-parameter Qwen3 model produces unit tests that measurably beat GPT-4.1 and GPT-4o.
Why unit tests are the bottleneck nobody talks about
Unit tests sit at the center of almost everything happening in code LLMs right now. They enable reliable software development, quantitative evaluation of code, and test-time scaling or reinforcement learning with verifiable rewards in code generation. If your tests are weak, your benchmarks lie, your reward signal is noisy, and your best-of-N sampling picks the wrong candidate.
The problem is that writing good tests is genuinely hard. Traditional pipelines need labeled unit tests, but UTRL only requires a dataset of task instruction and code pairs, where a unit test generator learns to distinguish code produced by a code generator from the ground-truth solution, and the code generator learns to pass increasingly sophisticated tests. That asymmetry matters because collecting high-quality unit tests at scale is expensive while instruction and code pairs are not, and UTRL converts an instruction and code dataset into a training signal through two interlocking rewards.
A GAN, but for code correctness
The setup borrows the spirit of generative adversarial networks. The unit test generator is optimized to maximize a discrimination reward that encourages producing tests that can tell code generated by the code generator LLM apart from ground-truth code, while the code generator is optimized to produce code that passes all test cases. Through this adversarial training, the code generator progressively learns to produce solutions that are harder to distinguish from ground-truth, and the test generator in turn learns to write highly discriminative test cases that catch subtle faults in near-correct code, covering challenging edge cases.
Concretely, the training loop looks like this:
- Sample a programming instruction and its ground-truth code from the dataset.
- The code generator produces a candidate solution that is close to correct but not identical.
- The test generator writes a unit test for the instruction.
- Each test case is executed against the ground-truth code, and only the ones that pass are kept as functionally valid so invalid tests cannot contaminate the reward.
- The test generator gets rewarded when its surviving tests catch the code generator's solution while still passing the ground-truth.
- The code generator gets rewarded when its solutions pass the tests. Repeat.
Two rewards, and why the second one matters
The discrimination reward alone is not enough. A test generator can trivially game it by writing garbage. So UTRL adds a validity term that rewards functional correctness of test cases but clips the denominator at a threshold so the model cannot game the reward by emitting two or three trivial tests copied from the prompt.
The ablation is telling. The design of the validity term matters at least as much as the discrimination signal itself. Drop the validity reward entirely and the generator emits tests where more than 50% are functionally invalid; the discrimination reward stays high but the tests are unreliable as evaluators. In other words, without the validity gate the model learns to "catch bugs" by writing tests that fail on everything.
The numbers
Evaluation runs on 945 competitive programming tasks from TACO and 511 from LiveCodeBench-v2, measured on two axes: Best-of-N improvement (does using these tests as a selector actually pick better code?) and unit test fidelity (do these tests rank code solutions the same way the human-written ground-truth tests do?).
The headline results:
- Best-of-N code score on Qwen3-8B jumps from 0.430 to 0.578, a 34% relative gain, with code accuracy rising from 9.8% to 14.9%.
- Qwen3-4B trained via UTRL achieves a Spearman correlation of 0.741, the highest fidelity in the comparison, outperforming even GPT-4.1.
- UTRL-4B reaches 0.794 fidelity, and UTRL-14B reaches 0.827, matching or surpassing GPT-4.1.
- UTRL-4B unit tests beat GPT-4.1 and GPT-4o despite the model having only 4B parameters.
The co-trained code generator is a nice byproduct. It achieves 15.3% code accuracy, remarkably higher than the baselines and comparable to the 15.9% achieved by a code generator trained to maximize pass rate over ground-truth unit tests. In practical terms, adversarial RL against a peer test generator gets you almost the same coding gains as RL with real human-written tests, for free.
Where SFT falls apart
Supervised fine-tuning on labeled tests is the natural baseline, and it does not hold up. SFT on human-written unit tests reaches only 0.458 Best-of-N score, and SFT on teacher-distilled reasoning plus tests still lags behind, because RL generalizes where SFT memorizes. That mirrors a pattern seen across the code RL literature: signal from execution feedback beats signal from imitation, especially on out-of-distribution tasks.
UTRL is also related to but distinct from CURE, a co-evolution framework where coding and unit test generation capabilities improve through their interaction outcomes without ground-truth supervision. The UTRL authors report head-to-head gains under CURE's own training setup.
What is actually released
The official implementation is on GitHub, along with two Hugging Face checkpoints: dgjun32/UTRL-4B (the test generator) and UTRL-Codegen-4B (the co-trained coder). Inference is a standard transformers load:
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("dgjun32/UTRL-4B")
tokenizer = AutoTokenizer.from_pretrained("dgjun32/UTRL-4B")
The authors provide evaluation sets built on TACO and LiveCodeBench-v2 to measure best-of-N improvement and unit test fidelity, with training scripts based on verl to follow.
Where this fits, and where it does not
UTRL is a strong fit if you are:
- Building a code RL pipeline and want a cheaper source of verifiable rewards than paying humans to write tests.
- Running best-of-N sampling in production and want a smarter selector than a base LLM judge.
- Evaluating code models on domains where the ground-truth test suite is thin or missing.
The caveats are real, though. The training data is competitive programming, so tests are for self-contained algorithmic functions rather than real-world software with I/O, state, network calls, or complex mocks. The validity reward relies on being able to execute against a ground-truth solution, which means you still need reference code for training, just not reference tests. And the discrimination framing rewards edge-case sharpness, which is exactly what you want for grading LLM outputs but is not the same as coverage-driven testing that a QA engineer would write for a production service.
Still, the broader point is worth sitting with: for a whole class of code correctness problems, the right move may not be scaling up the coder at all. It may be training a better critic, and letting the two argue.