Evaluating Local LLM Inference Performance and SQL Generation: A Practical Methodology

    This article presents a practical methodology for evaluating locally deployed large language models across two independent tracks: inference performance and structured query generation capability. It explains why a single aggregate score is misleading, how to measure prefill and decode phases separately, and how to trace bottlenecks across batching limits, token budgets, and GPU memory. On the capability side, it breaks down failure modes in natural-language-to-SQL tasks, showing that most losses come from output contract violations rather than flawed reasoning, and lists fixes ordered by cost-effectiveness. It closes with token cost implications for capacity planning and three actionable engineering conclusions.

    1. Why “Production Release” Benchmarks Often Lead to Skewed Conclusions

    Once a large language model reaches its production release stage, many teams’ first instinct is to run their own test script and report a single aggregate score. The problem is that an aggregate score blends two fundamentally different capabilities: system throughput and latency characteristics, which are determined by the inference framework’s scheduling strategy, GPU memory capacity, and batching parameters; and model semantics and instruction-following ability, which are determined by training data and alignment strategy. Mixing the two yields conclusions that can guide neither deployment scaling nor prompt optimization.

    A more rigorous approach splits evaluation into two independent tracks: the performance track focuses on how many tokens can be produced per unit of time, how long the first token takes, and how throughput degrades as concurrency rises; the capability track focuses on whether all constraints of structured output are satisfied under strict grading. This article uses a hands-on local test of a production release of an open-source large model as source material and abstracts a general methodology from it. All specific numbers are provided only as order-of-magnitude references and do not represent any performance commitment for a particular product or service.

    2. Performance Track: Split Inference into Two Phases

    Autoregressive inference naturally divides into two phases whose bottlenecks are completely different, so they must be measured separately.

    The prefill phase is compute-intensive: it processes all input tokens in parallel in a single pass, so throughput is usually high, but it drops as concurrency rises because multiple long requests block each other for compute resources. The decode phase is memory-access-intensive: it generates tokens one at a time, so single-concurrency speed is stable, but as concurrency increases, throughput declines noticeably due to GPU memory bandwidth and KV cache capacity limits.

    A minimal viable metric set looks like this:

    Metric Meaning Typical Observation
    Prefill peak, single concurrency Maximum prefill throughput with short inputs Hundreds of tok/s for 4k inputs
    Prefill length decay Throughput change from 2k to 32k Minimal decay with reasonable scheduling
    Prefill concurrency decay Drop relative to single concurrency at 2/4/6 concurrency Roughly -30% to -45% / -50% / -63%
    Decode, single concurrency Per-token generation speed Around 20-30 tok/s, fairly stable
    Decode concurrency range Generation speed range under multiple concurrent requests Drops to single digits with long prompts and high concurrency
    TTFT Time to first token Rises linearly with input length, deteriorates sharply under high concurrency

    One key finding from the test deserves emphasis: with a 32k input at 6 concurrency, time to first token can exceed three times the single-concurrency figure, and most of that time is spent queuing rather than computing. This kind of misjudgment — “the model looks slow when it is actually the scheduler that is slow” — is the most common trap in performance evaluation.

    3. Locating Bottlenecks: The Triple Constraint of Queuing, Batching, and GPU Memory

    When locating bottlenecks, investigate in the following order.

    1. Check the batching limit first. If the framework’s maximum number of concurrent sequences is set to 2, then the third and subsequent requests can only wait, and long prefill requests also block each other, showing up as averaged-out throughput and linearly worsening time to first token. This is a “configuration bottleneck” and does not require switching models.
    2. Then check the batched token budget. A maximum batched token count that is too small prevents long inputs from being merged into efficient batches; one that is too large may trigger GPU memory overflow or preemption, causing jitter instead.
    3. Finally check GPU memory utilization and KV cache levels. When memory utilization is already near 0.9 and the KV cache is nearly full, raising concurrency only produces queuing and swapping, not real throughput gains.

    The corresponding tuning logic can be expressed in pseudocode:

    1. # Illustrates tuning approach only, not a specific framework API
    2. config = {
    3. "max_num_seqs": 8, # raised from 2 to relieve queuing
    4. "max_num_batched_tokens": 8192, # adjusted in tandem with memory levels
    5. "gpu_memory_utilization": 0.88, # reserve room for fragmentation and activations
    6. "enable_chunked_prefill": True, # interleave long prefill with decode to reduce TTFT jitter
    7. }

    Keep in mind that tuning is a trade-off, not a monotonic improvement. Raising the concurrency limit squeezes KV cache space, which may trigger more frequent swapping in long-context scenarios; enabling chunked prefill smooths time to first token but slightly reduces peak pure-prefill throughput. An evaluation report must state the parameter combination clearly, otherwise the data is not reproducible.

    4. Capability Track: Dual-Track Grading for Structured Query Generation

    For capability evaluation, consider a task like natural language to structured query. It combines three layers of difficulty — tool calling, multi-step reasoning, and strict output formatting — which makes it good material for testing instruction-following ability.

    The grading results from one test showed a clear polarized distribution: everything passed at trivial difficulty, only some passed at easy, medium and hard were almost entirely failures, and the overall pass rate was just over thirty percent. But when numeric precision was relaxed to 1e-6, the pass rate jumped to over eighty percent. This huge gap shows that the main cause of lost points is not an inability to solve the problem, but a refusal to follow the format.

    Breaking the failures down further:

    • Format failures (the largest share): the prompt asked for two decimal places, the model omitted the rounding function, and since the official grading requires the first line of the result string to match strictly, the outcome was “logic correct, format wrong”.
    • Definition failures: the prompt specified a particular business channel definition, the model chose a different one on its own, causing deviation in the share values.
    • Structural failures: complex queries combining multi-table joins with discount logic returned wrong column names; queries using window functions for year-over-year or period-over-period comparison returned zero rows with mismatched column names.

    The tool-calling loop itself is healthy: the model can autonomously complete the full cycle of “generate query → engine executes → validate result → pass grading”, and it can mostly write complex multi-table joins and window functions correctly (such as lagged values, row numbering, and cumulative share). This shows that the execution loop is not the bottleneck; adherence to the output contract is.

    The corresponding optimizations, ordered by cost-effectiveness:

    1. Explicitly reinforce the output contract in the system prompt, writing precision, column names, and row count requirements as hard constraints;
    2. Provide a few examples for window function problems to reduce structural errors;
    3. Add a “self-check and rewrite” step so the model verifies formatting against the prompt item by item before submitting;
    4. On the evaluation side, keep both strict and lenient grading: the strict score reflects production readiness, the lenient score reflects true reasoning ability.

    An illustrative prompt snippet:

    1. Output contract (all must be satisfied):
    2. 1. Numeric columns must keep the decimal places specified in the task;
    3. 2. Result column names and order must match the task description exactly;
    4. 3. Do not return extra columns; self-check each item before submitting.

    5. Token Cost and Engineering Implications

    Another value of capability evaluation is exposing the cost structure. Simple tasks can be completed in an average of two steps and a few thousand tokens; hard tasks average six or more steps, with individual samples reaching a dozen-plus steps and consuming tens of thousands of tokens. This means capacity planning before launch cannot be based on average token counts alone; it must be modeled by difficulty tier, with retry and timeout budgets reserved for multi-step tool calls.

    Three conclusions that can be put into practice:

    • Performance and capability must be evaluated and reported separately, so a single aggregate score does not mask two distinct classes of problems;
    • Latency degradation under high concurrency should first be suspected to come from scheduling configuration and memory levels, not the model itself;
    • For structured output scenarios, the pass-rate bottleneck is usually the format contract, and the payoff from prompts and self-check mechanisms far exceeds that of switching models.

    To reproduce the evaluation above in an enterprise environment, you can use a container platform to host the inference service, object storage to hold evaluation datasets and results, a message queue to smooth out multi-step tasks, and logging and monitoring with alerting to track latency and throughput metrics. Baidu AI Cloud’s relevant general-purpose product categories can serve as a reference for infrastructure selection.