Knowledge Distillation in Practice: Optimizing Small Model Inference and Evaluating Refusal Behavior

    As enterprises adopt large language models, high inference costs and latency often drive teams toward knowledge distillation. This article outlines a reproducible engineering workflow for distilling the reasoning capabilities of large models into a smaller 9B student model. It covers generating and filtering high-quality chain-of-thought (CoT) data, configuring supervised fine-tuning (SFT) and reinforcement learning (RL), evaluating over-refusal behavior, measuring inference efficiency, and managing deployment and operations. By balancing accuracy, cost, and safety boundaries, teams can effectively deploy smaller, efficient models ready for production.

    In the deployment of large models, inference cost and response latency are two of the most common challenges enterprises face. Models with hundreds of billions of parameters offer strong reasoning capabilities but are expensive to deploy. Consequently, many teams turn to knowledge distillation to transfer the reasoning capabilities of large models into smaller student models. Using a 9B-level open-source base model as an example, this article outlines a reproducible engineering workflow covering data, training, evaluation, and safety governance.

    1. How to Generate High-Quality Chain-of-Thought Data?

    The key to distillation is teaching the small model the reasoning process, not just having it memorize the answers. Teams typically use large models to generate chain-of-thought (CoT) data with step-by-step breakdowns for math and science problems. During generation, sampling parameters should be fixed and versions recorded for reproducibility.

    After data generation, three layers of filtering are required:

    • Answer Validation: For questions with standard answers, compare the final results and discard samples with incorrect derivations.
    • Deduplication and Format Checking: Remove near-duplicate questions and ensure reasoning steps are complete and output formats are valid.
    • Contamination Detection: Training data must not overlap with evaluation sets. This can be checked using n-gram matching or semantic similarity.

    2. How to Configure SFT and Reinforcement Learning?

    Taking a 9B student model as an example, supervised fine-tuning (SFT) can use the LoRA method, training only low-rank adapters on the attention projection layers to reduce VRAM usage. A common starting point is a learning rate between 1e-5 and 2e-5, training for 2 to 3 epochs while monitoring loss and accuracy on a validation set. If overfitting occurs, prioritize reducing epochs or increasing data diversity rather than blindly increasing the learning rate.

    After SFT, a round of lightweight reinforcement learning (RL) can be added. For math tasks, rewards are easy to define: correct answers score points, and format errors deduct points. Using verifiable rewards reduces the bias introduced by reward models. If the team decides to exclude coding data, this trade-off should be documented, as it will alter the model’s performance on code tasks.

    3. How to Evaluate Refusal Behavior?

    Over-refusal occurs when a model rejects harmless questions that it should normally answer. The first step in governing this issue is measurement, rather than directly altering the model’s internal structure. Teams can build two evaluation sets:

    • One set consists of normal but sensitive-worded science questions to measure the over-refusal rate.
    • The other set contains harmful intent requests to measure the compliance rate with harmful content.

    Looking only at the first metric makes it easy to tune the model to lose its safety boundaries, so both metrics must be reported simultaneously.

    Refusal behavior is influenced by multiple factors, including training data, system prompts, safety policy classifiers, and internal model representations; it cannot be simplified to a switch on a single neuron or layer. Any adjustments to safety behavior must undergo safety evaluation, red teaming, and manual review, with approval records retained. This article does not discuss specific methods for bypassing safety alignment.

    Safer practices include: improving training data with reviewed boundary samples so the model learns to distinguish between “seemingly sensitive but safe to answer” and “genuinely risky” requests; adding an input-side classifier for risk grading; and retaining a manual review channel for high-risk categories.

    4. How to Measure Inference Efficiency and Accuracy?

    For efficiency metrics, it is recommended to use “average token consumption per correct answer,” calculated as the total output tokens divided by the number of correct answers. When comparing models before and after distillation, use the same test set, identical decoding parameters, and the same hardware, and report confidence intervals. For test sets of a few hundred questions, the bootstrap method can be used to estimate the fluctuation range of accuracy and determine if differences are statistically significant.

    A reduction in tokens does not equal an improvement in quality. If the model skips critical derivations to shorten output, accuracy will drop. Therefore, efficiency metrics must be viewed alongside accuracy.

    5. What to Focus on for Deployment and Operations?

    Once the model is online, three types of infrastructure capabilities are critical:

    • Object Storage: Saves training data, version snapshots, and evaluation results for traceability.
    • Container Platform: Manages the elastic scheduling of GPU resources; training tasks should release resources promptly upon completion to reduce idle costs.
    • Monitoring and Alerting System: Tracks changes in token consumption, response latency, accuracy, and refusal rate, triggering alerts when metrics deviate from the baseline.

    6. Frequently Asked Questions

    How to choose a base model for knowledge distillation of small models?
    Prioritize open-source models whose pre-training data is similar to the target task, with licenses permitting commercial use and strong community support. Under the same parameter scale, compare the benchmark scores of different models rather than just looking at the parameter count.

    How to evaluate the refusal rate?
    Build separate sets for normal sensitive questions and harmful requests, measuring the over-refusal rate and harmful compliance rate, which must be reported simultaneously. Re-run the evaluation after any change to the model or system prompt.

    How to reduce inference token cost?
    Start from three aspects: compress redundant expressions in the chain of thought, control the maximum output length, and enable batching and caching on the server side. Cost reduction effects must be verified under the premise that accuracy does not drop.

    The reasoning capabilities of small models can be significantly improved through distillation, but the results depend on verifiable data and evaluation. Teams should manage accuracy, inference cost, and safety boundaries within the same evaluation table. An improvement in any single metric is not sufficient to prove that the model is ready for production.