Choosing Open-Source LLMs: A Scientific Guide to Evaluating Local Inference

    Selecting the right open-source LLM for local deployment requires more than subjective impressions of "good quality" or "fast speed." This guide breaks down the evaluation process into model architecture, local inference performance metrics, and task-specific output quality. It explains why you shouldn't rely solely on public leaderboards, how to build a custom evaluation set, the practical value of small models, and licensing considerations. Finally, it provides a step-by-step selection workflow to ensure your choice is backed by concrete data and compliant with your operational constraints.

    1. Why “Is This Model Good?” is Hard to Answer in One Sentence

    Open-source large language models are being released more frequently, and a single series often provides multiple sizes simultaneously, ranging from small models suitable for edge devices to large flagship models. Many discussions remain at the subjective level of “good results” or “fast speed” without specifying the test conditions. The same model can perform very differently depending on the context length, quantization precision, inference framework, and hardware.

    Therefore, evaluating a model should be broken down into three questions: what performance characteristics its architecture determines, how many resources it consumes when running locally, and what the output quality is for your specific tasks. Let’s expand on these in order.

    2. Model Architecture: Dense Models vs. Mixture of Experts (MoE)

    Common architectures currently fall into two categories.

    Dense Models: Every parameter participates in the computation to generate a single token. The larger the parameter count, the higher the per-step computational load. Quality is generally more stable, but the speed is also slower.

    Mixture of Experts (MoE): The model contains multiple “expert” sub-networks, and only a subset is activated for each token. The total number of parameters determines the storage space required for the weights, while the number of activated parameters determines the computational load per step.

    These two metrics need to be considered separately. Taking an MoE model with total parameters N and activated parameters A as an example:

    • VRAM or RAM must accommodate all weights, so the footprint is related to the total parameters N.
    • The decoding phase is often memory bandwidth limited on many devices. The amount of weights read per generated token is related to A.

    Assuming bandwidth is the bottleneck, the decoding speed can be roughly estimated as:

    1. Generation speed (tokens/s) ≈ Memory bandwidth (GB/s) ÷ Weight size read per token (GB)
    2. Weight size read per token ≈ Activated parameters × Bytes per parameter

    This formula only provides a theoretical upper limit. Actual speed is also affected by routing overhead, attention computation, KV cache reading, and the inference framework’s implementation. However, it illustrates a basic rule: the fewer the activated parameters in an MoE model, the faster the decoding speed usually is on the same hardware, while the storage footprint remains determined by the total parameters.

    3. Three Core Metrics for Local Inference

    When evaluating the local inference experience, it is recommended to pay attention to at least the following three metrics.

    3.1 Prefill Speed

    When processing an input prompt, the model needs to complete a parallel computation. The speed of this phase determines the user’s wait time for the first output token. Long document summarization, codebase Q&A, and multi-turn conversations all increase input length, which subsequently increases prefill time. When testing, you should report data across several typical input lengths rather than just providing a single number.

    3.2 Generation Speed (Decode)

    Generation speed refers to the number of tokens produced per second during the output phase. For conversational and agent scenarios, it directly impacts the fluency perceived by the user. Note that with long contexts, the KV cache grows larger, typically causing the generation speed to drop. Therefore, it should also be measured at multiple context lengths.

    3.3 Memory and VRAM Footprint

    The KV cache is one of the major overheads in long-context scenarios. Its size can be estimated using the following formula:

    1. KV cache bytes ≈ 2 × num_layers × num_kv_heads × head_dim × context_length × bytes_per_element

    By adding the model weight footprint to the KV cache footprint and reserving a certain buffer, you can determine whether a specific device can stably run the target configuration.

    3.4 Measurement Code Example

    Below is a framework-agnostic timing script. It assumes that generate is a streaming generation function that returns each token via an iterator:

    1. import time
    2. def measure(generate, prompt, max_new_tokens=256):
    3. start = time.perf_counter()
    4. first_token_time = None
    5. count = 0
    6. for _ in generate(prompt, max_new_tokens):
    7. if first_token_time is None:
    8. first_token_time = time.perf_counter()
    9. count += 1
    10. end = time.perf_counter()
    11. if first_token_time is None or count < 2:
    12. raise ValueError("Insufficient generated tokens to calculate speed")
    13. return {
    14. "Time to first token (s)": first_token_time - start,
    15. "Generation speed (tokens/s)": (count - 1) / (end - first_token_time),
    16. }

    When testing, fix and record the following conditions in your report: input length, output length, quantization method, batch size, inference framework version, hardware model, and driver version. Performing one or two warm-up runs before taking the median of multiple results can reduce random fluctuations.

    4. Quality Evaluation: Don’t Rely on a Single Leaderboard

    Public leaderboards provide a reference, but they have several limitations.

    1. Task distribution mismatch: Leaderboards mostly feature general Q&A, math, or coding problems, which may not be relevant to internal enterprise tasks like ticket classification, report extraction, or API calls.
    2. Non-significant score gaps: A few percentage points of difference might disappear under different question sampling and random seeds.
    3. Potential training data overlap: Once questions are public, models might have encountered similar content during training, inflating their scores.
    4. Subjective scoring bias: Longer answers and neater formatting often receive higher scores, even if they aren’t more accurate.

    A more reliable approach is to build your own evaluation set. It is recommended to cover the following categories of tasks, preparing dozens to hundreds of real samples for each:

    • Structured output: Require the model to return fields in a fixed JSON structure and check if the format is valid and the fields are complete.
    • Instruction following: Include constraints like word count limits, banned words, and output language.
    • Code generation and modification: Use unit tests to judge the results instead of manual grading.
    • Long-text comprehension: Extract key information from materials close to the target context length.
    • Tool calling and multi-step workflows: Check if parameters are correct and step sequences are logical.

    Structured output can be automatically verified programmatically. Here is a simple example:

    1. import json
    2. REQUIRED_FIELDS = {"name": str, "score": (int, float)}
    3. def is_valid(text: str) -> bool:
    4. try:
    5. data = json.loads(text)
    6. except json.JSONDecodeError:
    7. return False
    8. if not isinstance(data, dict):
    9. return False
    10. return all(
    11. key in data and isinstance(data[key], expected)
    12. for key, expected in REQUIRED_FIELDS.items()
    13. )

    Automated verification quantifies “whether the format is acceptable” into a pass rate. For semantic tasks, you can use double-blind human evaluation or have multiple models review each other, regularly sampling and reviewing the evaluation results themselves to ensure reliability.

    5. The Practical Value of Small Models

    Smaller-scale models have clear value in edge deployment and low-cost services. Their advantages are primarily reflected in the following areas:

    • Low memory footprint, allowing offline execution on laptops or mobile devices, reducing data exfiltration.
    • Short time-to-first-token, suitable for input completion, classification, and instant chat.
    • In tasks with fixed formats and clear goals, structured output quality can meet production needs after applying minor prompt constraints.

    The limitations of small models are also clear: complex reasoning, long-chain planning, and open-ended creation are usually weaker than in large models. In practice, a tiered strategy can be adopted, routing simple requests to a small model and complex requests to a large model. Routing rules can be based on task type, input length, or the small model’s confidence signals.

    6. License and Compliance Evaluation

    When selecting a model, you cannot look only at performance and speed. The model license determines whether commercial use, modification, redistribution, and deployment methods are compliant. Permissive open-source licenses typically allow commercial use while retaining attribution and notice obligations, but specific clauses still need to be checked line by line. Some models use custom licenses that may restrict user scale, specific industries, or the release of derivative models.

    It is recommended that legal or compliance personnel confirm the following matters during the project initiation phase: the original license text, commercial usage scope, whether data is transmitted back to a server, whether there are usage restrictions on model outputs, and whether the model source needs to be disclosed in the product.

    Combining the above, you can follow these steps for selection:

    1. Define constraints: List hardware limits, acceptable time-to-first-token, target throughput, data security requirements, and licensing restrictions.
    2. Initial screening: Exclude candidates that clearly exceed hardware capabilities based on total parameters, activated parameters, and quantized footprint.
    3. Measure performance: On target hardware and inference frameworks, measure prefill speed, generation speed, and memory footprint using typical input and output lengths.
    4. Evaluate quality: Use your custom evaluation set for automated testing, recording pass rates, error types, and failure samples.
    5. Comprehensive trade-off: Compare quality, speed, resource, and compliance results in a single table, and choose the solution that meets constraints with the highest cost-effectiveness.
    6. Canary validation: First run on low traffic or internal scenarios to observe performance under real request distributions before deciding whether to fully launch.

    By following this process, selection conclusions can be traced back to specific data, and the evaluation methodology can be quickly reused when a new batch of hardware or tasks is introduced.