How to Systematically Evaluate the Code Generation Capabilities of Open-Source LLMs
A single coding task is not enough to judge an open-source language model. This guide presents a reproducible evaluation method based on functional correctness, runtime reliability, context usage, instruction following, and engineering fit. It also explains how to build a private benchmark from historical commits, measure sampling stability, classify failures, detect behavioral differences between models, and integrate evaluations into CI and observability workflows.
1. Why a Single Trial Is Not Enough
Using a function from your own work to test a model is the lowest-cost validation method. However, a sample size of one creates three serious problems. First, it cannot distinguish between “the task was easy” and “the model is capable.” Second, it does not reveal whether a failure came from misunderstanding the requirements, choosing the wrong algorithm, or making a syntax-level mistake. Third, the result is difficult to reproduce: a different day or a slightly different prompt may produce a completely different outcome.
The problem is compounded by the fact that the first impression of a model often reflects alignment and response style rather than capability. For example, when asked to implement numerical root finding, one model may start with a basic bisection or Newton iteration and then add examples and boundary-condition notes. Another may immediately provide an executable entry point, command-line argument parsing, and exception handling.
The first approach is more tutorial-oriented, while the second is more engineering-oriented. Neither is inherently better; they simply reflect different styles. Mistaking stylistic differences for capability differences is one of the most common sources of evaluation bias.
2. Five Dimensions for Measuring “Usability”
Functional correctness
Do not judge whether the code looks elegant. Judge only whether its output satisfies the requirements. For each task, prepare three categories of test cases:
- Normal inputs
- Boundary inputs, such as empty collections, single-element inputs, and extreme values
- Invalid inputs
Use assertions rather than visual inspection whenever possible.
Runability
Can the code run successfully in a clean environment on the first attempt? Does it introduce undeclared dependencies or call APIs that do not exist? This dimension is particularly effective at exposing hallucinated dependencies and interfaces.
Context utilization
This is a key indicator of whether the model actually understands the material provided in the prompt. Include explicit constraints such as the language version, dependency restrictions, team conventions, and deployment environment. Then check whether the generated output follows them.
If the model consistently ignores constraints already included in the context, its ability to extract and apply relevant information from long prompts may be limited.
Instruction following
This includes formatting requirements, such as “output code only” or “include type annotations,” as well as length limits and prohibited elements. Poor instruction following can cause downstream automation pipelines to fail even when the generated code is functionally correct.
Engineering fit
Evaluate naming, error handling, logging, testability, and whether the code can be cleanly split into modules. This dimension determines whether the output is merely suitable for a demonstration or ready to be integrated into a codebase.
3. Building a Minimal Private Evaluation Set
Avoid relying on tasks from public leaderboards. They are likely to have appeared in training data already. Instead, construct tasks from historical commits in your own repository.
Select 30 to 50 merged commits, remove the implementations, and retain only the requirement descriptions and tests. Ask the model to recreate the implementation, then compare the result against the original implementation and the existing tests. The resulting evaluation set naturally reflects your technology stack and is less likely to introduce benchmark contamination.
# Example: a minimal local evaluation harness for side-by-side comparisoncases = load_cases("cases/*.json") # Each case includes a prompt, tests, and constraintsdef run(model, case, n=3):results = []for _ in range(n): # Sample multiple times to measure stabilitycode = model.generate(case.prompt, **case.constraints)results.append(pass_rate(code, case.tests))return {"case": case.id,"mean": sum(results) / n,"variance": variance(results), # High variance suggests poor automation reliability}report = [run(m, c) for m in models for c in cases]
Three details are especially important:
- Sample multiple times and measure variance. A single successful result may be a matter of luck.
- Tests must be based on real assertions from your codebase, not test cases generated by the model itself.
- Record failure categories, such as requirement misunderstanding, syntax errors, hallucinated interfaces, and constraint violations. These labels are more actionable than an overall score.
4. How to Determine Whether a Model Is More Than a Simple Request Relay
The community often speculates that one model is merely forwarding requests to another provider. Rather than debating the claim, use observable behavior to evaluate it.
Create a set of highly uncommon boundary tasks with unique answers, then compare output distributions and failure patterns. Sample the same prompt multiple times and observe whether stylistic variation remains stable. Measure information retention as the context becomes longer, and compare how consistently the models follow specific formatting constraints.
Independently trained models should display coherent and stable characteristics across these dimensions. However, this type of analysis can provide only directional evidence. It should not be presented as definitive proof.
5. Integrating Evaluation into the Engineering Workflow
Evaluation should not be a one-time exercise. Place the evaluation set in continuous integration and run regression checks whenever prompts or model versions change.
Collect each request and response, execution time, and failure reason through logging and monitoring systems. This creates an observable feedback loop. Deploy model services through a container platform to support gradual rollouts and rollback. Store evaluation data and code artifacts in object storage to maintain traceability.
If you use relevant general-purpose capabilities from Baidu AI Cloud, you can combine them according to the categories above without being tied to a specific interface design.
6. Practical Checklist
- Build the evaluation set from private historical commits to reduce benchmark contamination.
- Cover normal, boundary, and invalid inputs for every task, and use assertions for evaluation.
- Sample multiple times and track both the mean and variance.
- Label every failure; use the overall score primarily for ranking.
- Record stylistic differences separately from capability differences.
- Integrate evaluation into continuous integration and observability systems to maintain a long-term baseline.
With this process, half a day is enough to produce a reproducible, comparable, and regression-friendly assessment—rather than relying on a vague impression that a model “seems good.”
