Microsoft's SemRep Lets a 32B Model Beat 405B Coders on Real Code Edits
A two-stage training recipe teaches code models to first rewrite programs into semantically equivalent variants, then optimize them, beating much larger baselines.
ProTakeaways
- SemRep trains code LLMs in two RL stages: first generate semantically equivalent rewrites, then apply instruction-specific edits.
- 32B QwQ-based SemRep matches GPT o4-mini and beats 405B Qwen3-Coder on EditBench Pass@1.
- Beats Kevin-32B on KernelBench by 43.1% in Correctness best@16 with a 1.1x speedup gain.
- Plugged into OpenEvolve, it beats 685B DeepSeek models on MST and circle packing.
- Cross-hardware transfer from L40S to H200 improves average speedup by 10.6% over baseline.
- Semantics equivalence is test-based, so low test coverage can bias what the model learns to preserve.
A team from the University of Chicago, UIUC, Columbia, and Microsoft has released SemRep, a code transformation framework that separates "understanding what the code does" from "changing it to do something new." The result is a 32B model that matches GPT o4-mini on real-world code edits, beats a 405B coder on the same benchmark, and finds GPU kernel optimizations that 685B reasoning models miss.
The core trick is deceptively simple: before asking a model to optimize or edit code, train it to generate semantically equivalent rewrites of that code. Those rewrites become an explicit, verifiable intermediate representation that guides the actual edit.
Why implicit semantics keep breaking code edits
Most LLM code editors treat transformation as one end-to-end task. The model reads source code plus an instruction like "make this run in parallel" and directly emits the new version. Existing approaches leave the representation needed for semantic reasoning implicit in model weights, or rely on rigid compiler-level abstractions.
That works until the model has to simultaneously preserve behavior and change behavior in a single generation. The paper shows a clean failure mode on EditBench: given a function that calls several LLM APIs sequentially and returns results in input order, a direct transformation swaps in asyncio.as_completed to parallelize the calls. The code runs faster, but results now come back in completion order, silently breaking the contract that the i-th output matches the i-th input model.
Classical compiler-style representations, like abstract syntax trees or data-flow graphs, would catch this. They are expensive to build on the fly, and code LLMs are pretrained on source rather than on IRs, so those rigid structures do not always help the model reason.
Rewrites as the intermediate representation
SemRep's answer is to make the intermediate representation just be more source code, specifically, a semantically equivalent version of the input. The framework decomposes editing into a transition from source, through one or more semantics-preserving rewrites, to the target program, where each intermediate step is verifiable against a set of tests.
Two programs are considered equivalent if they produce identical outputs on a test set. That gives the training loop a cheap, executable reward signal, and it means the intermediate representation stays human-readable and directly usable by the same LLM that generates it.

Inside the training pipeline
SemRep splits training into two RL stages, both using GRPO (Group Relative Policy Optimization, the RL algorithm from DeepSeekMath) with verifiable rewards from test execution:
- Generative code representation learning. The model is trained to produce semantically equivalent variants of the input program. The reward combines a compilability indicator with an equivalence indicator over a semantics test set, encouraging diverse rewrites (different loop structures, API choices) rather than trivial copies.
- Instruction-specific transformation. The model is then finetuned to apply the actual edit. The reward now combines compilability, semantic preservation of the parts that should not change, and a separate test set that verifies the new behavior requested by the instruction.
The total training budget is fixed to match the finetuning-only baseline, so the mid-training does not smuggle in extra compute. At inference, the model alternates between generating equivalent rewrites and applying instruction-specific edits, keeping a beam of the best candidates ranked by test execution.
The numbers on EditBench and KernelBench
The team evaluated on two benchmarks: EditBench for real-world repo-level instructed edits, and KernelBench for optimizing PyTorch models with custom CUDA kernels. Base models are Qwen2.5-Coder-7B and QwQ-32B.
On EditBench, SemRep with QwQ-32B hits 57.41% Pass@1, matching GPT o4-mini and beating both Qwen3-Coder (405B) and GLM-4.6 (355B) at 55.56%. On KernelBench, it beats Kevin-32B, the previous RL-finetuned state of the art, by 43.1% in Correctness best@16 with a 1.1x Speedup improvement.
Two other results matter more than the headline scores:
- Robustness to code perturbations. When EditBench inputs are rewritten with docstring changes, syntactic rewrites, and format changes, SemRep degrades less than the baselines and holds 88.89% consistency, a 6.7% improvement over a plainly finetuned QwQ-32B.
- Cross-hardware generalization. Trained on L40S GPUs and tested on unseen H200s, SemRep outperforms the finetuned QwQ-32B baseline by 10.6% in average speedup while maintaining 61.4% higher correctness. Low-level CUDA optimizations usually overfit hard to specific hardware, so this transfer is nontrivial.
Evolutionary search, unlocked
Because SemRep is explicitly trained to produce diverse equivalent programs, it slots naturally into evolutionary coding agents. The team plugged it into OpenEvolve, an open-source AlphaEvolve-style framework, and ran it against DeepSeek-V3-Chat and DeepSeek-V3-Reasoner (both 685B parameters) on two problems.
On a minimum spanning tree task from AlgoTune, SemRep reached a 7.28x speedup by discovering an iterative Union-Find with path compression, outperforming both DeepSeek variants by 25.95% at step 14. The other models kept implementing Union-Find recursively and missed the win.
On the n=26 circle packing problem studied in AlphaEvolve, SemRep reached 2.4737 (about 93.88% of AlphaEvolve's state-of-the-art 2.6358). Its trajectory temporarily got worse along the way: it abandoned a grid layout for a ring-based one that hurt performance, then used that ring initialization plus simulated annealing to find a better final packing. That willingness to explore semantic rewrites that briefly lose ground is exactly what pure exploit-driven agents cannot do.
Where this actually helps
SemRep targets code transformation tasks where correctness has to be preserved while some new property, performance, feature, or refactor, is introduced. Good fits:
- GPU kernel optimization where correctness against a reference implementation is checkable and speedup is the reward.
- Repo-level performance work, like the SWE-Perf case where SemRep first refactored an Astropy fixed-width parser to hoist repeated
process_linescalls, then optimized the column-width computation into a single pass. - Instruction-driven edits where a semantics-preserving refactor first exposes the change (e.g. extracting a helper function before parallelizing it).
The catch
The whole approach leans on tests. Equivalence is defined over a fixed set of inputs, so if tests have low coverage, the model can learn to preserve semantics only on the covered slice of behavior. There is no soundness guarantee; symbolic execution or stronger equivalence oracles would be the natural next step.
The authors also flag reward hacking: the model could game the equivalence reward by returning trivial rewrites like renamed variables or added comments. They reject exact duplicates and note that determining which classes of semantics-preserving transformations are most useful for training remains open.
The paper does not appear to link a public code release yet, though the base models (QwQ-32B, Qwen2.5-Coder-7B), the training framework (verl), and the evaluation harnesses (KernelBench, EditBench, OpenEvolve) are all open source, so reproducing the recipe is straightforward for anyone with a few L40S-class GPUs.