Evaluating and Optimizing Inference for Small and Medium-Sized Language Models: A Practical Guide
Leaderboard scores alone tell you little about how a language model will perform in production. This article explains how to evaluate small and medium-sized models (up to tens of billions of parameters) as a complete system of model, quantization, inference strategy, and hardware. It covers how to define comparable performance metrics, why low-bit quantization does not automatically mean low latency, how to expand quantization coverage while maintaining quality boundaries, when speculative decoding actually helps, the real resource costs of sparse-activation architectures, and how to build a reproducible optimization loop with proper baselines, profiling, and quality regression testing. Readers will come away with a practical framework for judging whether an inference deployment delivers real engineering value under limited hardware.
1. Don’t Judge a Model by Leaderboard Scores Alone
For language models with at most tens of billions of parameters, developers usually care about two questions: can the model complete complex tasks, and can it run at an acceptable speed on limited hardware?
These two questions cannot be separated. A model that excels on standard benchmarks may still fail in real applications because its reasoning process is too long, its context cache consumes too much memory, or its low-concurrency execution is inefficient. Conversely, a fast model that frequently produces wrong answers or requires multiple retries may not reduce overall task cost.
A more meaningful evaluation target is therefore not an isolated model score, but the complete system formed by the model, its quantization configuration, inference strategy, and hardware environment.
Evaluate at least four dimensions:
- Task quality: whether reasoning, code generation, information extraction, and instruction following are stable.
- Response experience: how long the wait is for the first output token, and whether subsequent output is smooth.
- Resource cost: how much GPU memory the weights, cache, and runtime buffers each consume.
- Task efficiency: how much time and how many tokens it takes to complete a correct task, and whether retries are needed.
Especially for models with long reasoning chains, final answer quality is often correlated with generation length. Spending more reasoning budget may improve some complex tasks, but it also increases waiting time. Evaluations should report both quality and latency together, rather than only showcasing the best answer.
2. Align Your Metrics Before Debating “Speed Gains”
In performance discussions, “throughput” is often used to describe different metrics, which leads to misjudgments.
2.1 Single-request output speed
This usually refers to the number of tokens generated per second during the decoding phase of a single request, mainly reflecting interactive fluency. Measurements should state whether input processing, model warm-up, and first-token wait time are included.
2.2 Service-level throughput
This refers to the total number of output tokens per second the system completes when multiple requests run concurrently. It approximates server-side resource utilization efficiency, but it does not directly represent any single user’s response experience.
2.3 First-token latency and end-to-end latency
First-token latency is mainly affected by input length, prefill computation, and queuing time; end-to-end latency also includes subsequent decoding, tool calls, and other business steps.
The same optimization may increase overall throughput while increasing per-request latency. For example, larger batches improve hardware utilization but may make individual requests wait longer. Therefore, local interactive scenarios and multi-user service scenarios should be benchmarked separately.
A comparable set of experiments should at minimum hold constant:
- Model weights and quantization configuration;
- Input length and output length;
- Concurrency level and actual batch sizes;
- Sampling method and stopping conditions;
- Reasoning budget;
- Whether speculative decoding is enabled;
- Hardware power draw, temperature, and operating state.
Without these premises, an isolated “tokens per second” figure cannot support a reliable conclusion.
3. Single-Request Decoding: Low-Bit Does Not Mean Low Latency
In single-request, autoregressive decoding, the model typically processes only one new position per step. The shape of the linear-layer computation differs significantly from the large-batch computation seen during training.
Abstracting the linear layer as:
Y = XW
where the input matrix is M × K and the weight matrix is K × N. In ordinary single-step decoding, M is usually very small; with speculative decoding, the verification phase can process multiple candidate positions at once, but it may still be far smaller than the sizes that high-throughput matrix kernels prefer.
This creates a common problem: general-purpose matrix computation kernels are designed for larger matrices. With small M, you may see underutilized thread blocks, excessive padding computation, and a high proportion of data movement and launch overhead.
3.1 Why 4-bit quantization can still be a bottleneck
4-bit weights reduce storage and weight-reading costs, but actual execution involves more than reading 4-bit data. It may also involve:
- Weight unpacking or format conversion;
- Reading grouped scaling coefficients;
- Activation quantization and scaling;
- Data layout adjustments;
- Accumulation of intermediate results;
- Output type conversion.
Whether these steps can be efficiently fused with the matrix computation determines the end-to-end benefit. If the low-bit kernel does not match the actual shapes, the theoretical bandwidth advantage may not materialize.
You also need to distinguish integer 4-bit quantization from floating-point 4-bit quantization. Their numerical representation, scaling methods, and hardware support differ; equal bit width does not imply equal accuracy or performance.
3.2 Optimize around real computation shapes
Low-concurrency optimization should prioritize:
- Tiling and thread organization designed for small
M; - Reducing unnecessary padding;
- Fusing scaling, conversion, and adjacent operations;
- Avoiding repeated reads of weights or intermediate data;
- Lowering launch overhead for many short computation tasks.
But do not benchmark only one matrix shape. A full model contains linear layers with varying input and output dimensions, and speculative verification lengths can also change dynamically. A faster microbenchmark does not guarantee a faster end-to-end inference pipeline.
3.3 Use bottleneck share to bound expected gains
Suppose a category of computation accounts for a fraction p of total time, and after optimization it gains an s-times speedup. The ideal overall speedup is:
Overall speedup = 1 / [(1 - p) + p / s]
For example, if that category accounts for half the total time, even halving its execution time yields only about a one-third overall improvement, not a doubling.
This estimate also excludes newly added data conversion and scheduling overhead. Therefore, analyze time breakdown first, then decide where to invest optimization effort.
4. Expanding Low-Bit Quantization Requires Quality Boundaries
Beyond the main feedforward layers, attention-related projections and other linear transformations can also occupy significant time. If these parts still run at higher precision, further reducing precision may cut weight-reading and computation costs.
However, “accuracy on a certain test set did not drop” only means no obvious degradation was observed within that test’s scope—it does not prove safety across all scenarios.
4.1 Quantization sensitivity varies across layers
Errors in some projection layers can alter subsequent attention distributions; modules with recurrent states or linear attention structures may accumulate errors as the sequence progresses. Long contexts, outlier magnitudes, and unusual input distributions can all amplify quantization effects.
A safer strategy is to proceed layer by layer:
- Start with linear layers that account for a large share of time and carry relatively manageable risk;
- Preserve sufficient precision for normalization, accumulation, and necessary state updates;
- Calibrate with representative data;
- Compare quality changes across different layer groups;
- Restore higher precision for sensitive layers.
The goal of mixed precision is not to push every module to the lowest bit width, but to find a better performance combination under quality constraints.
4.2 Quality acceptance should cover real workloads
Check all of the following:
- Mathematical and logical reasoning;
- Code generation and bug fixing;
- Long-text retrieval and multi-step information integration;
- Structured output formatting;
- Multi-turn conversation consistency;
- Correctness of tool-call parameters;
- Repeated output, abnormal termination, and unreasonable refusals.
For business-critical stability, also record variance across multiple runs rather than comparing single scores. Small average degradation can mask a clear failure on a critical task category.
5. Speculative Decoding: Optimize Effective Output, Not Just Draft Speed
Speculative decoding typically uses a lightweight draft mechanism to propose multiple candidate tokens, which the target model then verifies. Its value lies in using one verification pass to confirm multiple output positions, reducing the number of serial target-model steps.
However, it does not guarantee a speedup.
5.1 Three factors jointly determine the gain
Draft cost: the slower the draft stage, the higher the overhead.
Effective acceptance length: the more tokens actually confirmed per round, the more easily the verification cost is amortized.
Verification cost: longer verification lengths typically increase computation and may trigger different kernel execution strategies.
You can understand the effective output speed as:
Effective output speed ≈ confirmed tokens per round / total time per round
where total time includes draft generation, target-model verification, and scheduling overhead. This expression emphasizes that speeding up draft generation alone, or extending candidate length alone, does not necessarily improve the final result.
You should also distinguish speculatively sampled schemes with strict distribution-preserving properties from schemes using approximate acceptance rules. The former preserves the target sampling distribution when the relevant algorithmic conditions are met; the latter requires additional output quality validation. The two cannot be assumed equivalent.
5.2 Evaluate draft-model quantization jointly with acceptance length
Using lower precision for the draft model may reduce resource usage and speed up generation, but it may also shift the candidate distribution away from the target model’s, causing more candidates to be rejected.
Therefore, draft quantization should at minimum be measured jointly against:
- Draft-stage time;
- Average effective acceptance length per round;
- Verification-stage time;
- Final effective output speed;
- Quality and stability across different tasks.
If the target model’s own quantization configuration changes, the draft model’s compatibility should be re-evaluated. Whether retraining or adjustment is necessary, however, depends on the specific implementation, interface compatibility, and acceptance-rate changes—it cannot be generalized.
5.3 Candidate length should adapt dynamically
Simple continuation tasks are usually easy to predict, while complex reasoning or format-constrained tasks may diverge frequently. Fixing a very long candidate sequence tends to waste draft and verification computation.
In practice, candidate length can be adjusted based on recent acceptance rates, verification time, and task state. But adaptive strategies carry their own scheduling costs, so their benefit should be confirmed through end-to-end testing.
6. Sparse-Activation Architectures: Don’t Estimate Speed from Parameter Ratios
Sparse-activation models invoke only a subset of expert modules per token, which reduces some computation. But the full parameter set still needs to be stored or loaded on demand, so “fewer activated parameters” does not mean “smaller memory footprint.”
On local devices, such models may face:
- Total weight size exceeding available GPU memory;
- Scattered access patterns caused by expert routing;
- Unbalanced workloads across experts;
- Expert computation granularity being too small under small batches;
- Weight swapping in and out canceling out computational savings.
Cross-device execution may add communication and synchronization costs.
Whether a sparse model runs faster than a dense one depends on how expert weights are kept resident, memory bandwidth, routing overhead, and the execution implementation—speedups cannot be extrapolated simply from the number of activated parameters.
Likewise, having more total parameters does not guarantee a given capability level. Training data, training budget, architectural design, and optimization methods all affect the outcome.
7. Local Deployment Requires a Full Memory Budget
Determining whether a model can be deployed cannot rely on the weight file size alone.
If a model has P parameters with an average of b bits per parameter, the ideal weight storage is approximately:
Weight bytes ≈ P × b / 8
This is a baseline estimate that does not include scaling coefficients, metadata, unquantized modules, or runtime layout overhead.
Actual operation also needs room for:
- Attention key-value caches or other sequence state;
- Activations and temporary buffers;
- Computation workspaces;
- Draft weights and caches for speculative decoding;
- Additional memory from concurrent requests.
For architectures using key-value caches, cache requirements typically grow with sequence length and concurrency; state overhead for other architectures must be analyzed per implementation. “Able to load the weights” and “able to run long-context tasks stably” are therefore two different capabilities.
8. Build a Reproducible Optimization Loop
Recommended practice:
Step 1: Establish a baseline
Record quality, first-token latency, decoding speed, end-to-end latency, and peak memory. Test short inputs, long inputs, and various output lengths separately.
Step 2: Analyze the critical path
Separate prefill from decoding, and identify the time spent in matrix computation, attention, data movement, and scheduling. Profiling tools may change runtime overhead, so re-measure under normal execution after diagnosis.
Step 3: Change one thing at a time
First optimize hotspot kernels, then evaluate expanding low-bit coverage, and finally jointly tune the speculative decoding strategy. Change only one variable per round so gains can be attributed.
Step 4: Run quality regression in parallel
Performance improvements must be accepted together with task quality. For interactive systems, also check tail latency, formatting errors, and abnormal terminations.
Step 5: Verify sustained stability
Short tests cannot cover temperature, power, memory fragmentation, and long-run variance. The final configuration should pass sustained load testing, and a fallback plan should be kept.
Conclusion
The value of small and medium-sized language models is shifting from “fewer parameters but higher scores” to “reliably completing complex tasks under limited resources.” Effective inference optimization requires understanding computation shapes, quantization error, speculative acceptance rates, and memory constraints together.
The most reliable path is: first define task and experience targets, then locate the actual bottleneck, implement localized optimizations, and confirm gains through end-to-end performance and quality regression. Only by putting accuracy, waiting time, resource usage, and failure retries into the same evaluation table can you judge whether a deployment truly has engineering value.
