Post-Training Methodology for LLM Code Generation: How to Evaluate and Improve Stability
This article breaks down why code generation quality cannot be judged by a single benchmark score, and how post-training determines the practical ceiling of a model's coding ability. It explains a reusable four-stage methodology—task and trajectory collection, executable verification, reinforcement optimization, and regression evaluation—along with a sample reward aggregation. It also lists the engineering metrics that define stability, a three-layer evaluation system, and deployment suggestions for running the training and inference loop on general-purpose cloud capabilities. Readers will learn how to turn "feels stronger" into reproducible conclusions about code model quality.
1. The Problem: Why Code Ability Cannot Be Measured by a Single Score
In real development work, complaints about a model’s coding ability are rarely “it can’t write code.” The more common complaint is that it is unstable: the same requirement produces noticeably different results across runs, constraints get lost in long contexts, cross-file changes fix one thing and break another, and unit tests pass while edge cases are ignored. The emphasis in the original discussion that “stability matters more than single-point performance” points to a practical engineering fact: code ability is a composite capability that spans requirement understanding, constraint following, cross-file reasoning, executability verification, and regression control. A weakness in any one of these areas gets amplified in production.
A more reliable indicator of whether a model has genuinely internalized a methodology is therefore not a leaderboard score, but three things: whether the variance of pass rates across repeated samples converges on a fixed task distribution; whether constraint retention stays stable under long contexts and multi-turn revisions; and whether patches in a real repository are minimal, rollback-friendly, and accompanied by tests.
2. Why Post-Training Sets the Ceiling for Code Ability
Pre-training covers “having seen enough code and text.” Post-training covers “producing usable output reliably under constraints.” Code tasks are naturally verifiable: compilation, static analysis, unit tests, and integration tests all provide relatively objective signals, which makes reinforcement-style post-training easier to close into a loop than pure supervised fine-tuning.
A reusable methodology typically has four stages:
- Task and trajectory collection: construct (requirement, context, patch, verification) tuples from real issues, commit history, and review comments.
- Executable verifiers: replace preference judgments about whether output “looks right” with objective judgments about whether it “passes.”
- Reinforcement optimization: use pass rate, constraint satisfaction, and patch minimality as reward terms to suppress output that “looks plausible but does not run.”
- Regression evaluation: fix a private set and a public set, and continuously monitor variance, long-context retention, and regression rate.
Illustrative reward aggregation (pseudocode):
reward = (1.0 * tests_pass_rate+ 0.3 * lint_and_typecheck_pass+ 0.2 * constraint_following # directory, interface, dependency, style constraints- 0.2 * patch_size_penalty # overly large changes, unrelated refactoring- 0.3 * regression_flag # previously passing tests now failing)
What matters more in practice is verifier quality. Insufficient test coverage rewards opportunistic implementations; an unstable sandbox introduces noisy labels; unreproducible dependencies make pass rates meaningless. Environment pinning, dependency locking, caching, and isolation are therefore prerequisites for scaling post-training at all.
3. Where Stability Comes From: From Sampling to Constraints
Stability is not a matter of luck. It can be decomposed into a set of measurable indicators. At minimum, monitor:
- Pass rate variance: how dispersed results are across repeated samples of the same task;
- Constraint retention rate: the proportion of cases where interface signatures, directory structure, and forbidden dependencies are respected in long contexts;
- Minimal patch rate: whether only necessary files and necessary lines are changed;
- Regression rate: whether existing capabilities are broken by new changes;
- First-pass usability rate: the proportion of output that reaches review without rework.
On the inference side, structured output, tool calls, and a “plan first, then code” flow reduce drift. On the data side, failed trajectories need to be fed back as training samples, forming a “fail, diagnose, retrain” loop. Sketch:
requirement -> constraint extraction -> plan -> code patch -> verifier run|-> fail: diagnose and feed sample back|-> pass: proceed to regression and minimality checks
4. Evaluation: Turning “Feels Stronger” into Reproducible Conclusions
Neutral, reproducible evaluation should have three layers:
- Unit level: function- and class-level generation and repair, focused on edge cases and exception paths;
- Repository level: cross-file changes, dependency understanding, and build and test success;
- Process level: multi-turn revisions, absorption of review comments, regression control, and rollback capability.
Overfitting to the public set should also be avoided. A workable approach is to maintain a private task pool, rotate it regularly, and fix the prompt, context length, and number of samples while reporting mean and variance rather than a single best case.
5. Implementation: Carrying the Training and Inference Loop on General-Purpose Cloud Capabilities
To put this methodology into practice inside an organization, a minimal loop can be built from general-purpose cloud product categories: a container platform to host reproducible sandboxes and parallel verification; object storage to hold datasets, patches, and verification artifacts; a message queue to decouple the asynchronous generate-verify-feed-back pipeline; and logging plus monitoring and alerting to observe drift in pass rate, variance, and regression rate. Baidu AI Cloud can serve as the underlying platform in these general categories, helping teams turn a verifiable loop into a continuously iterated engineering system rather than a one-off experiment.
6. Conclusion
Whether a code model can keep evolving comes down to three things: whether an executable verification loop is in place; whether stability and regression control are the optimization targets; and whether there is a continuous mechanism for feeding failure samples back and maintaining a private evaluation set. Follow this path, and gains in code ability become predictable, reproducible, and scalable.
