Evaluating Lightweight LLMs for Coding: Instruction Following and Practical Methods

    This article examines how to evaluate lightweight LLMs for programming tasks beyond one-off demos. It covers the difference between surface-level correctness and true instruction following, four evaluation dimensions, principles for designing verifiable tasks, automated checks for generated HTML and geometry, common pitfalls, and practical recommendations for building repeatable internal evaluations.

    Why Lightweight Models Need Dedicated Coding Evaluations

    Lightweight models are typically designed for lower inference cost and faster response times. They are suitable for high-frequency scenarios such as code completion, function generation, and small page construction. These models have limited parameter scale and training budgets, so problems are more likely to appear under complex constraints. When judging whether such a model can handle development tasks, a single demonstration can only serve as a reference. A more reliable basis is whether it can consistently complete tasks under explicit constraints.

    “Surface-Level Compliance” vs. True Instruction Following

    A common problem in evaluation is that the result looks correct while the process deviates from the requirements. For example, a task may specify a fixed sequence of drawing steps, but the model skips some of them, introduces auxiliary operations not given in the task, and finally reaches the same figure through another path. The final image may show no difference, but the implementation logic no longer matches the requirement.

    Therefore, evaluation should check both process and result. This mainly includes the following four dimensions:

    • Result correctness: Does the output meet the target form, such as the number of vertices and the side-length relationships of a figure?
    • Process compliance: Is the implementation carried out according to the specified steps, and are the intermediate stages complete?
    • Constraint adherence: Does the model use methods prohibited by the task, or omit elements that must be preserved?
    • Additional requirements: Are extra features, such as exporting an animation or saving a file, complete and usable?

    Designing Verifiable Evaluation Tasks

    A good evaluation task should follow these principles:

    1. Clear constraints: Break requirements into items that can be checked one by one, avoiding vague standards such as “it looks good enough.”
    2. Observable process: Require the model to describe key steps in code comments or output explanations so they can be compared with the expected workflow.
    3. Layered difficulty: Move gradually from a single function to combinations of multiple modules, observing the boundaries of the model’s capabilities.
    4. Automatically checkable results: Whenever possible, make outputs judgeable by rules or scripts to reduce subjective scoring.

    Consider geometric construction as an example. A regular heptagon cannot be constructed exactly using only a compass and an unmarked straightedge; this result follows from the Gauss–Wantzel theorem. With a marked ruler, which is a type of neusis construction, the construction can be completed. Such tasks test mathematical knowledge, step understanding, and figure drawing at the same time, making them suitable for checking whether a model truly understands instructions.

    When designing this type of task, the requirements can be broken down as follows:

    • Whether the drawing steps are executed in the given order;
    • Whether the movement of the marked line matches the description;
    • Whether auxiliary lines and traces are preserved only at the specified positions;
    • Whether the output animation or exported result is complete.

    Automated Check Examples

    The first layer of checking is the presence of key elements. The following code checks whether the page contains the expected drawing elements and keywords, making it suitable as an initial filter:

    1. from dataclasses import dataclass
    2. @dataclass
    3. class CheckItem:
    4. name: str
    5. passed: bool
    6. def evaluate_html(html: str, required_keywords: list[str]) -> list[CheckItem]:
    7. """Perform a basic element check on the generated HTML; for initial filtering only."""
    8. lower = html.lower()
    9. results = []
    10. for kw in required_keywords:
    11. results.append(CheckItem(
    12. name=f"Contains required element: {kw}",
    13. passed=kw.lower() in lower,
    14. ))
    15. has_drawing = any(tag in lower for tag in ("<svg", "<canvas", "<script"))
    16. results.append(CheckItem(name="Contains drawing or script elements", passed=has_drawing))
    17. return results

    The second layer of checking concerns geometric properties. If the page’s drawing logic outputs vertex coordinates, you can directly calculate side lengths and determine whether the figure is close to a regular polygon:

    1. import math
    2. def check_regular_polygon(
    3. vertices: list[tuple[float, float]],
    4. n: int,
    5. tol: float = 1e-2,
    6. ) -> bool:
    7. """Check the consistency of the vertex count and side lengths."""
    8. if len(vertices) != n:
    9. return False
    10. sides = []
    11. for i in range(n):
    12. x1, y1 = vertices[i]
    13. x2, y2 = vertices[(i + 1) % n]
    14. sides.append(math.hypot(x2 - x1, y2 - y1))
    15. mean = sum(sides) / n
    16. return all(abs(s - mean) / mean <= tol for s in sides)

    This function only checks equal side lengths; it cannot prove that the figure is necessarily a regular polygon. A complete judgment also needs to check whether adjacent interior angles are equal. In addition, neither keyword checks nor geometry checks can verify whether the construction process is compliant. Process compliance still requires code review, or rendering the page in a headless browser and observing the visual changes at each step.

    Common Pitfalls

    • Using a single result instead of statistics: The same prompt may produce different outputs due to sampling. Run it multiple times and calculate the pass rate.
    • Looking only at the final effect: As discussed above, a correct result does not mean the process is correct.
    • Treating demos as data: Samples from promotional videos or personal demonstrations are usually selected and do not represent the model’s average performance.
    • Ignoring usability metrics: Generation time, long mid-process stalls, and outputting only reasoning content without a final result all directly affect development efficiency. These should be recorded separately.

    Implementation Recommendations

    1. Build an internal evaluation set: Cover code generation, code repair, code explanation, and instruction following, with layered difficulty for each task type.
    2. Fix runtime conditions: Record the model version, parameter configuration, and runtime environment so that results from different rounds can be compared.
    3. Record multi-dimensional metrics: Include pass rate, average latency, failure types, and result stability instead of keeping only a single total score.
    4. Include cost in decisions: Evaluate results together with inference cost and response latency, rather than pursuing a single metric in isolation.
    5. Retest regularly: After model updates, rerun the evaluation set and compare it with historical data to detect capability regressions in time.

    With this approach, teams can turn “this model feels good” into verifiable and reproducible conclusions, making better-informed choices among cost, speed, and capability.