LLM Distillation: Engineering Practices for Hard and Soft Distillation

    This article compares hard and soft distillation for large language models from an engineering perspective. Hard distillation directly reuses teacher-model trajectories, while soft distillation uses the teacher model to generate, filter, and synthesize training data. The article analyzes their trade-offs in data cost, training objectives, risk control, pipeline design, evaluation, and governance, and recommends combining both strategies according to task risk, data economics, and evaluation maturity.

    LLM Distillation: Engineering Practices for Hard and Soft Distillation

    In practical engineering discussions, LLM distillation is often summarized into two approaches. One directly reuses trajectory data produced by a stronger teacher model. The other uses the teacher model to construct, filter, or synthesize training data, which is then used to train the student model. The former is often called “hard distillation”; the latter can be called “soft distillation” in this data-centric sense. The two are not simply a matter of one being better than the other. They correspond to different data costs, training objectives, and risk-control requirements. This article breaks down both routes from an engineering implementation perspective.

    1. Conceptual Boundaries: What Are “Trajectories” and “Distillation”?

    In the LLM context, a “trajectory” usually refers to the intermediate and final outputs produced by a model while completing a task. This includes the input prompt, reasoning steps, tool-call records, final answer, format structure, and so on. Distillation is the process of transferring the behavioral patterns, output distributions, or task capabilities demonstrated by a stronger teacher model to a smaller student model with lower inference cost.

    It is important to emphasize that distillation is not simply copying answers. From an engineering standpoint, the real concern is whether the student model can reliably reproduce the teacher model’s behavioral quality on the target task distribution while offering lower inference cost, better controllability, and easier maintenance. Therefore, whether hard or soft distillation is used, the work should revolve around three things: data quality, training objective, and the evaluation loop.

    2. Hard Distillation: Benefits and Risks of Reusing Trajectories Directly

    At its core, hard distillation directly applies trajectories. A typical approach is to collect input-output pairs from the teacher model on a set of tasks, use the inputs as conditions during student training, and use the teacher outputs as supervision signals for supervised fine-tuning or instruction tuning.

    2.1 Advantages of Hard Distillation

    First, the implementation path is short. As long as there is a stable ability to collect inputs and outputs, a training set can be built relatively quickly. Second, behavioral consistency can be strong. For tasks such as format following, fixed templates, and tool-call order, directly learning from trajectories often produces results quickly. Third, engineering complexity is low. On the data side, the main work is cleaning, deduplication, desensitization, and format conversion; on the training side, conventional supervised learning is the primary method.

    2.2 Risks of Hard Distillation

    The biggest risks of hard distillation are distribution shift and overfitting to trajectories. Teacher outputs may carry a particular style, verbose reasoning, or implicit assumptions. If the student model learns only the surface text, it can fail on unseen inputs. Second, directly applying trajectories may introduce incorrect answers, hallucinated content, or non-compliant statements. Without quality filtering, this amplifies noise. Third, if trajectories contain content subject to copyright, privacy, or licensing constraints, direct reuse creates compliance risk.

    2.3 Suitable Scenarios

    Hard distillation is better suited to scenarios with clear task boundaries, stable output formats, and verifiable teacher-trajectory quality. Examples include structured information extraction, fixed-format conversion, simple tool-calling workflows, and standard answer generation in domain question answering. For open-ended reasoning, complex planning, and high-risk decision-making, hard distillation should be used cautiously and combined with strict spot checks and evaluation.

    3. Soft Distillation: Using a Strong Model to Construct and Filter Data

    The core of soft distillation is not to copy trajectories directly. Instead, the teacher model acts as both a “data producer” and a “quality judge”: it first generates candidate data, which is then filtered through rules, model scoring, consistency checks, and manual spot checks to select high-quality samples for student training.

    3.1 Key Stages of Soft Distillation

    Soft distillation usually includes the following steps:

    1. Task distribution design: Define the task types, difficulty levels, input lengths, output formats, and refusal boundaries that the student model should cover.
    2. Candidate data construction: Use the teacher model to generate multiple answer versions, reasoning processes, or rewritten samples to increase data diversity.
    3. Quality filtering: Apply multi-stage filtering using rule checks, answer consistency, format checks, factuality verification, and model scoring.
    4. Deduplication and mixing: Remove near-duplicate samples and control the mix of tasks, difficulty levels, and styles to avoid training-set skew.
    5. Training and regression evaluation: Train the student model and validate results through offline evaluation and online canary testing.

    3.2 Advantages of Soft Distillation

    The advantage of soft distillation is that it is designable. Engineering teams can actively construct data around target capabilities instead of passively collecting trajectories. Data density can be improved through rejection sampling, multi-answer voting, difficulty stratification, and negative-sample construction. For complex reasoning tasks, soft distillation can also retain part of the reasoning process while filtering out low-quality paths, reducing noise.

    3.3 Challenges of Soft Distillation

    Soft distillation costs more. Candidate generation, scoring, and manual spot checks all require resources. Second, the teacher model’s preferences may be amplified indirectly. If the filtering criteria are one-dimensional, the student model may learn the scorer’s preferences rather than true capability. Third, synthetic data carries a risk of homogenization, which needs to be mitigated through diversity constraints and mixing with real data.

    4. An Implementable Data Pipeline Sketch

    The following pseudocode illustrates the difference between hard and soft distillation. The example expresses only the engineering logic and does not depend on a specific platform or API.

    1. # Hard distillation: collect teacher trajectories directly and clean them
    2. raw_traces = collect_teacher_traces(task_suite)
    3. clean_traces = []
    4. for item in raw_traces:
    5. if contains_sensitive(item): continue
    6. if not format_valid(item.output): continue
    7. if duplicate(item): continue
    8. clean_traces.append({
    9. "prompt": item.prompt,
    10. "response": item.output
    11. })
    12. train_student(clean_traces)
    13. # Soft distillation: construct candidates, filter, mix, and then train
    14. candidates = []
    15. for task in task_suite:
    16. for i in range(N):
    17. candidates.append(teacher_generate(task, temperature=variant(i)))
    18. scored = []
    19. for c in candidates:
    20. score = rule_check(c) * 0.4 + consistency_score(c) * 0.3 + factuality_score(c) * 0.3
    21. if score >= threshold:
    22. scored.append(c)
    23. selected = dedup_and_balance(scored, task_mix, difficulty_mix)
    24. selected = mix_with_real_data(selected, real_data, ratio=0.2)
    25. train_student(selected)

    The hard distillation pipeline is shorter, with emphasis on cleaning and compliance. The soft distillation pipeline is longer, with emphasis on candidate generation, scoring criteria, and data mixing. Both can run on general-purpose cloud resources—for example, using object storage to manage datasets, container platforms to run training jobs, and logging and monitoring services to track data quality and the training process. General-purpose capabilities from Baidu AI Cloud can be used to support this kind of infrastructure, but the specific architecture still needs to be designed according to the team’s actual requirements.

    5. Evaluation Loop: Do Not Look Only at Training Loss

    Distillation evaluation should cover multiple dimensions:

    • Task accuracy: accuracy, recall, and format compliance rate on target tasks.
    • Behavior consistency: differences from the teacher model in key behaviors such as refusal boundaries and tool-call order.
    • Robustness: performance on input perturbations, long text, multi-turn dialogue, and edge conditions.
    • Hallucination and safety: factual error rate, unsafe output rate, and sensitive-content trigger rate.
    • Cost and latency: student-model inference cost, time to first token, and throughput.
    • Data leakage and benchmark contamination: overlap between training and evaluation sets, and whether answers have leaked.

    We recommend building a closed loop of “offline evaluation set—regression testing—canary release—online monitoring.” Every change to the data pipeline should trigger regression evaluation to avoid capability regressions caused by adjustments to data mixing.

    6. Compliance and Governance Recommendations

    Regardless of whether hard or soft distillation is used, a data governance mechanism should be established: record data sources, generation methods, filtering rules, and version information; desensitize sensitive information; review content subject to licensing constraints; retain traceable identifiers for synthetic data; and isolate training and evaluation data. For high-risk scenarios, add manual spot checks and red-team testing to avoid passing the teacher model’s uncertainty directly to the student model.

    7. Conclusion

    Hard distillation and soft distillation are not mutually exclusive options. They are two data strategies in distillation engineering. Hard distillation is suitable for quickly reusing stable trajectories, while soft distillation is suitable for actively constructing high-quality data around target capabilities. Engineering teams should choose a combined approach based on task risk, data cost, and evaluation capability: use hard distillation to establish a baseline quickly, use soft distillation to supplement diversity and difficulty coverage, and then rely on a strict evaluation and governance loop to ensure that the result is deployable, maintainable, and traceable.