Small Model Distillation and Local Inference: A Practical Guide
This guide explains how to distill large models into smaller student models and run them locally. It covers why data quality matters more than data volume, how to build and filter training data, multi-objective training strategies, evaluation across multiple dimensions, quantitative estimates for quantization and VRAM usage, context engineering for AI agents, and when to choose local inference versus cloud compute. It also includes a checklist of common pitfalls to help teams deploy stable local inference on consumer-grade hardware.
1. Why Small Models and Local Inference Are Relevant Again
Model development over the past two years shows a clear trend: scaling parameters is delivering diminishing returns, while gains from better inference data, training strategies, and deployment engineering are increasing. For most developers and small teams, the real pain points are not access to the largest model, but three things: data cannot leave the internal network, invocation costs are unpredictable, and response latency is unstable.
Against this backdrop, distilling a large model into a small model and running that small model locally has become a pragmatic path. The core assumption is that the value of a large model lies not only in how many facts it memorizes, but in the relatively stable reasoning workflow it has formed. That workflow can be partially reproduced in a student model with an order of magnitude fewer parameters.
It is worth emphasizing that distillation is not synonymous with compression. Quantization, pruning, and low-rank decomposition are forms of compression, with the goal of keeping the original model’s output distribution as unchanged as possible. Distillation is capability transfer: the goal is for the student model to approximate the teacher model’s behavior on the target task, and with well-chosen data and training strategies, even outperform the original on certain narrow tasks. The observation that distilled versions are more stable on structured reasoning, tool calling, and front-end code generation essentially shows that when training data is highly focused and high quality, a student model can outperform the teacher’s average performance on a general distribution within a specific distribution.
2. The Key to Distillation: Data Quality Matters Far More Than Data Scale
A counterintuitive but repeatedly validated observation is that a few thousand carefully constructed examples often beat hundreds of thousands of noisy ones. There are three reasons.
First, the student model has limited capacity, and that capacity must be spent on correct patterns. A 9B-class model cannot simultaneously hold massive styles and conflicting problem-solving habits. The messier the data, the more likely the student learns surface phrasing rather than the reasoning skeleton.
Second, long-chain reasoning data carries a denser supervision signal. A sample containing a complete derivation actually provides four types of supervision at once: problem decomposition, intermediate conclusions, self-verification, and final expression. With only a final answer, the student has to guess the intermediate path.
Third, high-quality data is naturally transferable. When training samples span multiple domains but share the same reasoning paradigm (clarify constraints first, then break down sub-problems, then verify boundaries), the student learns a reusable reasoning engine rather than domain-specific catchphrases.
A practical data construction workflow looks like this:
- Task layering: split the target scenarios into structured reasoning, code generation, tool-call argument construction, and long-document summarization, so the data distribution is not dominated by a single task.
- Teacher generation plus filtering: sample multiple answers to the same question, then apply three filters: consistency voting, executable verification (for example, whether code passes tests), and format validation.
- Deduplication and removal of style fingerprints: strip highly similar templated openings and closings to prevent the student from learning meaningless filler.
- Difficulty mix: keep roughly 30% of hard samples that require multi-step reasoning even for the teacher, otherwise the student will only handle easy problems.
- Hold out a clean evaluation set: the evaluation set must never share a source with the training data, or the scores are untrustworthy.
An illustrative, field-neutral data entry structure:
{"task_type": "structured_reasoning","prompt": "Given constraints and inputs, produce a result that satisfies them","reasoning_trace": "1) Clarify constraints 2) Break down sub-problems 3) Solve each one 4) Verify boundaries","final_answer": "structured result","verifiable": true}
3. Training Strategy: Teach the Process, Not Just the Conclusion
A common mistake in distillation is aligning only the final output. A more effective approach is multi-objective supervision:
- Output alignment: the student’s output should match the teacher’s output at the semantic level as closely as possible.
- Process alignment: apply supervision or consistency constraints to the student’s intermediate steps to suppress skipping steps and guessing answers.
- Format and parseability constraints: for scenarios consumed by programs (function arguments, structured fields), a format error should count as a wrong answer.
- Hard-sample weighting: increase the weight of low-pass-rate samples, but set a cap to prevent overfitting.
Two engineering details also matter during training. First, the learning rate and batch size must match the data scale. With only a few thousand examples, too large a learning rate will quickly destroy existing capabilities, causing catastrophic forgetting where the model learns the new task but loses general ability. In practice, a smaller learning rate, fewer training epochs, and a general-capability regression test are commonly used. Second, capability regression is mandatory: run the same general test set before and after training to confirm there is no clear degradation.
4. Evaluation: Do Not Look at a Single Overall Score
Evaluation design determines how trustworthy the conclusions are. Cover at least four dimensions:
- In-distribution accuracy: whether the target task was actually learned.
- Out-of-distribution transfer: whether it still holds after changing domains or phrasing. This is the criterion for whether distillation learned an engine.
- Tool-call correctness: whether arguments are parseable, whether the correct capability was called, and whether the model can self-correct on failure.
- Stability and consistency: whether repeated samples of the same question are consistent. Excessive variance is nearly unusable in production.
Inference cost metrics should also be reported: time to first token, tokens generated per second, and peak VRAM usage. Without these metrics, whether a model can run locally is only a guess.
5. Local Deployment: Quantitative Estimates for Quantization, VRAM, and Throughput
The feasibility of local deployment is mainly determined by VRAM capacity. A rough but practical estimate is that weight memory is approximately the parameter count multiplied by bytes per parameter. For a 9B model, half precision needs about 18GB for weights, 8-bit about 9GB, and 4-bit about 4.5–5GB. Adding KV cache and runtime overhead, actual usage typically rises by 20%–40%. KV cache is roughly proportional to context length and concurrency, so long-context scenarios need more headroom.
Selection guidance:
- 8GB VRAM devices: prioritize 4-bit quantization with moderate context, suitable for single-user interaction.
- 12–16GB VRAM devices: can run 4-bit with a larger context, suitable for code and document scenarios.
- 24GB and above: 8-bit is an option, with less precision loss.
- Unified memory architecture devices: memory bandwidth is the main bottleneck, so choose moderate quantization and control concurrency.
Quantization causes precision loss, so always compare before and after on a real business dataset rather than relying only on general leaderboards. If you use an inference runtime, enable continuous batching, KV cache reuse, and prefix caching. These optimizations often improve throughput more than moving to a larger VRAM card.
6. Context Engineering and Tool Calling: Can Small Models Handle Agents
The biggest weakness of small models in agent scenarios is not knowledge volume but long-range consistency. Mitigations include breaking complex tasks into short steps, giving only the necessary context at each step, passing state between steps via structured intermediate artifacts, truncating and summarizing tool return values, and setting failure retries and fallback strategies. In practice, a small model with good context engineering and tool constraints can approach a large model’s completion rate on multi-step tasks while reducing cost by an order of magnitude.
7. How to Choose: The Boundary Between Local Inference and Cloud Compute
Local inference fits scenarios that are data-sensitive, need to run offline, have stable long-term invocation volume, have controllable tail-latency requirements, and have a relatively fixed task distribution. Cloud compute fits scenarios with bursty tasks, a need for very large context, a need for the strongest general capability, or a desire to avoid operations. A more robust engineering approach is a hybrid architecture: route sensitive and high-frequency requests to a local small model, route complex and low-frequency requests to the cloud, and have a gateway handle authentication, rate limiting, logging, and monitoring alerts.
Building a complete production pipeline typically also involves object storage for training and evaluation datasets, a message queue for asynchronous task decoupling, a container platform to host inference services, and logging and monitoring services for observability. These general cloud product categories can serve as deployment support; specific selection should be evaluated against your own compliance and cost constraints. On Baidu AI Cloud, for example, these general capabilities can be combined as needed.
8. Common Pitfalls Checklist
- The evaluation set shares a source with the training data, producing inflated scores.
- Aligning only answers and not the process, so the student learns to guess conclusions.
- Scaling data to the hundreds-of-thousands level with high noise, which actually degrades student capability.
- Skipping business-dataset regression after quantization, only to find structured output broken after launch.
- Ignoring KV cache and concurrency, causing VRAM overflow under long context.
- Too many training epochs, causing general-capability degradation.
- No fallback mechanism, so the whole chain breaks when a tool call fails.
9. Conclusion
The value of a small-parameter model is not to replace the strongest model, but to deploy reasoning capability at a controllable cost into environments constrained by data and compute. The three factors that determine success, in order, are: high-quality long-chain reasoning data, evaluation centered on process and verifiability, and a quantized deployment plan based on VRAM and throughput budgets. Following the framework in this article, teams can obtain stable, usable local inference on consumer-grade devices and leave a clear evolution path for a future hybrid architecture.
