How to Choose a Small Model for Code Execution: Balancing Instruction Following and Speed

    When pairing a large model with a small model for coding tasks, selection should be driven by your own tasks and environment rather than generic rankings. This article explains the basic division of labor between large and small models, the limits of multimodal capabilities, the two key metrics that determine a small model's execution quality—instruction following and execution speed—how to write a clear task specification, and how to evaluate model combinations with controlled experiments. It also covers cost and reliability trade-offs and practical rollout recommendations.

    1. The Basic Division of Labor Between Large and Small Models

    For coding tasks, a common practice is to split the work into two layers. At the upper layer, a more capable large model handles requirement understanding, architecture design, and task decomposition, and produces a task specification document. At the lower layer, a smaller model follows that document to implement code item by item, add tests, and modify configurations.

    The small model’s advantages are low inference cost and fast response, making it well suited for large volumes of repetitive coding and rewriting work. The large model is responsible for judging whether the direction is correct. The quality of the handoff between the two layers directly determines the stability of the final output.

    When discussing “which small model is the best,” conclusions often lack comparability. The same model can perform very differently depending on the task description and execution environment. Therefore, model selection should be validated on your own tasks and in your own environment, rather than relying on generic leaderboards.

    2. The Boundaries of General-Purpose Capabilities

    Some models integrate multimodal features such as image understanding and image generation in addition to text capabilities. In scenarios like game prototyping or UI asset creation, these capabilities can reduce dependence on external tools.

    However, multimodal capabilities come with extra costs. If you need to call a separate image generation service, you must account for per-call billing or quota-based purchases. If you choose to deploy models locally, you take on GPU resources, model updates, and operational maintenance. Either way, you need to manage additional command-line tools and capability plugins, which increases overall system complexity.

    Therefore, when evaluating multimodal capabilities, consider three things at once: whether the capability itself meets your needs, whether the invocation chain is stable, and whether the long-term maintenance cost is acceptable.

    3. Two Metrics That Determine a Small Model’s Execution Quality

    3.1 Instruction Following

    During the execution phase, a small model’s tendency to “diverge” is usually a drawback. Execution requires implementing strictly according to the specification—not adding features on its own, modifying interfaces, or restructuring directories. A model that proactively “optimizes” things can push the code away from the design and create trouble for later integration.

    To evaluate instruction following, design test tasks with constraints and check the following:

    • Whether the output matches the specified file structure and naming conventions;
    • Whether only the files allowed by the task were modified;
    • Whether interface signatures and data formats match the specification document;
    • Whether prohibited dependencies or coding patterns were avoided.

    After each run, record the number of violations and compute a violation rate. This reflects problems better than simply checking whether the code runs.

    3.2 Execution Speed

    Execution speed affects iteration efficiency. The total time for a single task consists of three parts: model generation time, the number of retries after failures, and the waiting time for human intervention. A model that generates quickly but has a low first-pass rate may not be faster overall.

    You can measure this with the following metrics:

    • Average completion time per task;
    • First-pass rate, i.e., the proportion of tasks that pass tests without modification;
    • Average number of retries;
    • Throughput under concurrent workloads.

    4. How to Write the Task Specification

    The task description produced by the large model sets the ceiling for the small model’s performance. A complete specification should include: tech stack and versions, directory structure, module responsibilities, interface contracts, testing boundaries, acceptance criteria, and prohibitions. Below is a generic template:

    1. # Task: User Order Query API
    2. ## Tech Stack
    3. - Language: Python 3.11
    4. - Framework: FastAPI
    5. - Database access: parameterized queries only
    6. ## Directory Structure
    7. - app/api/orders.py: route definitions
    8. - app/services/order_service.py: business logic
    9. - tests/test_orders.py: unit tests
    10. ## Interface Contract
    11. - GET /orders/{order_id}
    12. - Response fields: order_id, status, amount, created_at
    13. - Return 404 when the order does not exist
    14. ## Testing Boundaries
    15. - Cover only three cases: successful query, order not found, invalid parameters
    16. - Do not modify the app/models directory
    17. ## Acceptance Criteria
    18. - All tests pass
    19. - No new third-party dependencies
    20. - Response structure matches the contract exactly
    21. ## Prohibitions
    22. - Do not add any caching mechanism
    23. - Do not change the paths or field names of existing endpoints

    The key to this template is clear boundaries. The small model should not have to decide “what to do”—only “how to do it.” The more specific the description, the smaller the execution deviation.

    5. How to Evaluate Model Combinations

    Selection should be done through controlled experiments, not subjective impressions. The recommended approach is:

    1. Prepare three to five representative tasks covering three scenario types: adding features, fixing bugs, and refactoring;
    2. Write the same specification document for each task;
    3. Execute the same tasks with different large/small model combinations;
    4. Record the results of each run and compute the metrics.

    Here is a simple statistics example:

    1. from dataclasses import dataclass
    2. @dataclass
    3. class RunResult:
    4. task_id: str
    5. passed_tests: bool
    6. violated_constraints: int
    7. elapsed_seconds: float
    8. def summarize(results: list[RunResult]) -> dict:
    9. total = len(results)
    10. if total == 0:
    11. raise ValueError("The results list must not be empty")
    12. pass_rate = sum(r.passed_tests for r in results) / total
    13. violation_rate = sum(r.violated_constraints > 0 for r in results) / total
    14. avg_time = sum(r.elapsed_seconds for r in results) / total
    15. return {
    16. "pass_rate": round(pass_rate, 3),
    17. "violation_rate": round(violation_rate, 3),
    18. "avg_time_seconds": round(avg_time, 2),
    19. }

    Once the statistics are in, look at pass rate, violation rate, and elapsed time together. All three metrics need to be judged jointly. For example, a combination with a slightly lower pass rate but a very low violation rate may be better suited for production than one with a high pass rate that frequently makes out-of-scope changes.

    6. Balancing Cost and Reliability

    Model cost includes three parts: API call fees, compute resources, and maintenance labor. Call fees are easy to calculate, but maintenance costs are often overlooked. Local deployment eliminates per-call charges, yet requires ongoing version upgrades, resource scheduling, and troubleshooting.

    In scenarios with high reliability requirements, keep a human review step and use automated tests as a merge gate. Treat the small model’s output as a draft that enters the main branch only after passing tests and code review.

    7. Practical Recommendations

    • Start with two or three large/small model combinations and run a small-scale comparison under the same task specifications;
    • Record the evaluation results as the team’s internal basis for selection;
    • Retest after model version updates, since behavior may change between versions;
    • Comparison conclusions apply only to the current task types and runtime environment; re-validate when migrating to new scenarios.

    There is no universal answer to model selection. The approach that actually works is to write task specifications clearly, measure results with unified metrics, and validate repeatedly in your own projects.