Improving Coding Ability in Open-Source LLMs: Training Methods and Practical Deployment

    This article examines why coding capability has become a key benchmark for evaluating large language models, and how open-source models can be improved through post-training techniques. It contrasts parameter count with real inference cost, explains supervised fine-tuning, execution-based reinforcement learning, and preference optimization, and discusses the value and limits of terminal-based task evaluation. Practical considerations for model selection—multi-step reliability, cost control, and local deployment—are also addressed.

    Why Coding Ability Is Now a Core Evaluation Metric

    Developers are shifting from using large language models (LLMs) for Q&A to using them for execution. Code completion, bug fixing, script writing, and command-line troubleshooting all require models that can not only generate code but also make it run correctly. As a result, coding ability has become one of the most important dimensions for measuring the practical value of a general-purpose model.

    Two common approaches are used to evaluate coding ability. The first is static coding tasks: the model generates a function based on a problem description, and unit tests determine whether the result is correct. The second is interactive tasks: the model must read files, execute commands, observe outputs, and revise its steps in a controlled environment to achieve a final goal. The second type is much closer to real-world work and is considerably harder to game by memorizing training examples.

    For a development team deciding whether to adopt a model, three questions matter most: Can it reliably complete multi-step tasks? Can it control costs within a given budget? Can it be deployed locally or in a private environment? The rest of this article addresses these questions.

    Understanding Architecture Choices from a Parameter Perspective

    Total Parameters vs. Active Parameters

    A Mixture-of-Experts (MoE) architecture consists of multiple feed-forward sub-networks (experts) and a router. For every input token, the router selects only a small subset of experts to participate in computation. Therefore, the model’s total parameter count and the parameter count actually used in a single forward pass are not the same.

    Total parameters determine the model’s knowledge capacity and storage requirements, while active parameters determine the computational load per inference. The lower the ratio between these two numbers, the more room the model has to scale in total parameters while keeping per-inference compute pressure relatively manageable.

    Parameter Count Is Not Equivalent to Inference Cost

    A common misconception is to equate total parameter count directly with inference cost. In reality, inference cost depends on several additional factors:

    • Active parameters and compute precision
    • Context length: attention computation grows with sequence length
    • Batching strategy and key-value cache usage
    • Hardware memory bandwidth and parallelization strategy

    The code below demonstrates how to estimate the activation ratio as a preliminary comparison during model selection. The numbers are illustrative only and do not represent any specific model.

    1. def active_ratio(total_params_b: float, active_params_b: float) -> float:
    2. """Calculate the ratio of active parameters to total parameters, in billions."""
    3. if total_params_b <= 0 or active_params_b <= 0:
    4. raise ValueError("Parameter counts must be positive")
    5. if active_params_b > total_params_b:
    6. raise ValueError("Active parameters cannot exceed total parameters")
    7. return active_params_b / total_params_b
    8. # Example: assume a model with 300B total parameters and 20B active per token
    9. ratio = active_ratio(300, 20)
    10. print(f"Active ratio: {ratio:.2%}") # Output: Active ratio: 6.67%

    The activation ratio is only a reference metric. Two models with the same number of active parameters can show very different latency in long-context scenarios if their attention mechanisms differ.

    How Post-Training Improves Coding Ability

    Division of Labor Between Pretraining and Post-Training

    The pretraining phase teaches the model language patterns and broad general knowledge. The post-training phase uses instruction data, preference data, and reinforcement learning to steer the model toward specific tasks. When two versions share the same base model, differences in capability come mainly from post-training, which makes comparison results more directly attributable to the training method itself.

    Common Post-Training Methods

    • Supervised fine-tuning: Uses high-quality question-and-answer pairs to teach the model proper code style and reasoning formats.
    • Reinforcement learning based on execution results: The model generates code, runs it against tests, and receives a reward signal based on pass rate. This approach forces the model to focus on whether the result is correct, not just whether the text looks fluent.
    • Preference optimization: Aligns the model’s responses with developer habits, such as reducing redundant explanations and providing clearer change descriptions.
    • Data filtering and de-noising: Removes duplicate, erroneous, or task-irrelevant samples to improve the quality of the training signal.

    How to Interpret “Improved Ability at the Same Cost”

    When a report claims that coding ability improved while inference cost stayed the same, readers should first verify several conditions: Is the evaluation set public? Could the problems have appeared in the training data? Are the tool permissions in the evaluation environment identical to those used for the comparison model? Were results averaged over multiple runs? Only when these conditions are clear are the numbers truly comparable.

    What Terminal-Task Evaluation Means and Where It Falls Short

    Terminal-task evaluation requires the model to complete objectives in a command-line environment, such as installing dependencies, fixing configuration files, analyzing logs, or running tests. Its value lies in verifiability: after a script executes, you can check whether the program produced the expected output or whether a service started correctly.

    However, this type of evaluation has clear limitations:

    • The environment needs to be carefully isolated, which adds complexity to the evaluation setup.
    • The set of tasks is often narrow and may not reflect the full range of real development workflows.
    • Models trained on similar terminal sessions may appear more capable than they are in genuinely novel situations.
    • Results can vary depending on the exact tools, versions, and network access allowed in the test environment.

    When considering a model for production use, terminal-task scores should be treated as one signal among many, not as a definitive measure of real-world effectiveness. The three questions raised earlier—reliability, cost, and deployability—should guide the final decision.