Distilling Model Trajectories: Hard and Soft Distillation in Practice

    This article offers a systematic engineering perspective on trajectory distillation for large language models, comparing two data production approaches: hard distillation (directly reusing teacher-generated trajectories) and soft distillation (using the teacher model to sample, score, filter, rewrite, and construct high-quality training data). It discusses the trade-offs, risks, and mixed strategies, and outlines a practical data pipeline with key control points, training and evaluation methods, and pseudocode examples. The goal is to help teams decide how to produce training data, control quality, and assess benefits and risks when using a stronger teacher model to improve a student model on specific tasks.

    1. Defining Trajectory Distillation

    A “trajectory” refers to the serialized record produced during a complete model interaction, including user inputs, model outputs, visible step-by-step reasoning, tool invocation records, and final answers. The core idea of trajectory distillation is to convert the teacher model’s problem-solving processes and results across many tasks into supervised signals that the student model can learn from.

    From a data production perspective, trajectory distillation can be divided into two categories:

    • Hard distillation: Directly reusing the teacher model’s complete trajectories, applying basic cleaning, and using them for supervised fine-tuning.
    • Soft distillation: Instead of treating teacher trajectories as fixed answers, the teacher model is used to generate candidates, filter high-quality samples, rewrite errors, produce process labels or preference data, and then synthesize a training set.

    It is important to note that “soft distillation” does not necessarily refer to soft-label distillation at the loss-function level. Rather, it is a “softening” of the data production approach: the teacher changes from an “answer provider” into a “data generator, scorer, and filter.” Hard and soft distillation are not mutually exclusive; in practice, a hybrid approach of “hard distillation for the baseline, soft distillation for refinement” is common.

    2. Hard Distillation: Benefits and Boundaries of Reusing Trajectories

    Hard distillation has the advantages of a short pipeline, low cost, and simple implementation. A typical flow is: prepare a set of task prompts, call the teacher model to generate complete trajectories, apply safety and quality filtering, deduplicate, and then perform supervised fine-tuning. For tasks with clear format requirements, well-defined answer boundaries, and relatively stable task distributions, hard distillation can quickly establish a baseline.

    However, the limitations of hard distillation are also obvious. First, teacher outputs are not ground truth; errors will enter the training set along with the trajectories. Second, the teacher’s expression style, step granularity, and refusal strategies may be over-imitated by the student, leading to a lack of generalization. Third, directly reusing complete trajectories may introduce privacy, copyright, and compliance risks. Fourth, when long-tail task coverage is insufficient, the student is prone to degradation on out-of-distribution inputs.

    Therefore, the key to hard distillation is not “whether to distill,” but “what to distill, what to filter, and how much to keep.” It is recommended to at least set up safety filtering, format validation, answer verifiability checks, approximate deduplication, and domain ratio control. For tasks that can be automatically verified, trajectories that pass rule-based or execution-result checks should be prioritized. For open-ended generation tasks, add manual spot checks or a secondary teacher review.

    3. Soft Distillation: Using the Teacher to Construct and Filter Data

    Soft distillation is closer to “data engineering” than to “answer copying.” Common practices include: sampling multiple candidate trajectories for the same prompt; using a scorer to evaluate dimensions such as correctness, format consistency, safety, information density, and diversity; selecting high-scoring yet diverse samples; rewriting low-quality trajectories for error correction; generating difficulty-level labels for complex tasks; and constructing positive and negative sample pairs for preference optimization.

    The advantages of soft distillation lie in controllable quality and designable coverage. Through candidate sampling and filtering, the impact of a single generation error can be reduced; through diversity constraints, over-homogenization of the training set can be avoided; through rewriting and desensitization, compliance can be improved. However, soft distillation is more costly and introduces scorer bias: if the scoring criteria favor a certain expression style, the student will inherit that bias. Therefore, the scorer needs calibration, and the filtering threshold should be tuned on a small validation set, with a human review channel retained.

    A practical soft-distillation principle can be summarized as “three checks and three keeps”: check safety, check correctness, check format; keep high quality, keep diversity, keep interpretable labels. For open-ended tasks that cannot be automatically verified, lower the weight of automatic filtering and increase sampling evaluation and version comparison.

    4. Comparison and Hybrid Strategy of Hard and Soft Distillation

    Dimension Hard Distillation Soft Distillation
    Data production approach Directly reuse teacher trajectories Sample, score, filter, rewrite, then synthesize
    Cost Lower Higher
    Quality control Relies on post-filtering Pre-filtering and multi-candidate selection
    Main risks Error propagation, style overfitting, compliance risks Scorer bias, homogenization, complex pipeline
    Suitable scenarios Well-defined formats, verifiable tasks, quick baseline Complex reasoning, open-ended tasks, high-quality data construction

    In practice, a phased hybrid strategy is recommended. In the first phase, use hard distillation to quickly establish a runnable baseline, confirming the student model’s fit with the task format and basic capabilities. In the second phase, introduce soft distillation for difficult samples, long-tail samples, and high-value domain samples through multi-candidate selection and rewriting. In the third phase, apply data ratio control and curriculum learning, mixing easy samples, hard samples, safety samples, and format samples in appropriate proportions to avoid a single source dominating training.

    5. Key Control Points in the Data Pipeline

    An auditable trajectory distillation pipeline should include at least the following stages:

    1. Prompt pool construction: Cover real business distribution, edge cases, safety refusal scenarios, and format-constrained scenarios.
    2. Candidate generation: Hard distillation can use deterministic decoding to reduce randomness; soft distillation can use diverse sampling to expand the candidate space.
    3. Safety and compliance filtering: Remove privacy information, sensitive content, unauthorized data, and clearly violating outputs.
    4. Correctness and format validation: For verifiable tasks, use rule-based or execution-result checks; for open-ended tasks, use a scorer plus manual spot checks.
    5. Deduplication and diversity control: Perform exact deduplication, approximate deduplication, and cluster sampling to prevent the training set from being dominated by a few templates.
    6. Proportion and version management: Record data source, generation parameters, filtering rules, and version numbers to ensure reproducibility and rollback capability.

    In terms of engineering infrastructure, teams can use object storage for sample and version management, container platforms to orchestrate sampling, filtering, and training tasks, and logging and monitoring services to track data drift and training anomalies. These are generic categories; the actual implementation should be aligned with the team’s existing infrastructure.

    6. Training and Evaluation Methods

    On the training side, hard distillation typically uses supervised fine-tuning. Soft distillation can combine rejection sampling fine-tuning, process supervision, or preference optimization. Regardless of the method, a validation set and a test set should be kept independent to avoid evaluation leakage. Evaluation should not focus only on average accuracy, but also on format adherence rate, tool invocation success rate, long-context stability, safety refusal rate, and out-of-distribution robustness.

    It is recommended to establish a gray-release path: “offline evaluation → small-traffic comparison → full rollout.” In the offline stage, perform per-task metrics and manual spot checks. In the small-traffic stage, observe real user feedback and failure cases. In the full rollout stage, continuously monitor data drift and model degradation. For style changes introduced by distillation, confirm through controlled experiments that the gains come from capability improvement rather than expressive preference.

    7. Pseudocode Example

    The following pseudocode outlines the flow without binding to a specific framework or interface:

    1. # Hard distillation baseline
    2. def build_hard_set(prompts, teacher, safety_check, quality_check):
    3. samples = []
    4. for p in prompts:
    5. y = teacher.generate(p, decoding="deterministic")
    6. if safety_check(p, y) and quality_check(p, y):
    7. samples.append({ "prompt": p, "response": y, "source": "teacher_trace" })
    8. return dedup_and_balance(samples)
    9. # Soft distillation pipeline
    10. def build_soft_set(prompts, teacher, scorer, rewriter):
    11. samples = []
    12. for p in prompts:
    13. candidates = teacher.sample(p, n=8, decoding="diverse")
    14. scored = []
    15. for c in candidates:
    16. s = scorer(p, c) # correctness, format, safety, difficulty, etc.
    17. d = diversity_score(c, samples)
    18. scored.append((c, s, d))
    19. chosen = select_top(scored, quality_weight=0.7, diversity_weight=0.3)
    20. for c in chosen:
    21. r = rewriter(p, c) # error correction, desensitization, format unification
    22. if safety_check(p, r):
    23. samples.append({ "prompt": p, "response": r, "source": "synthetic_filtered" })
    24. return dedup_and_balance(samples)
    25. # Training and evaluation
    26. def distill_train(student, train_set, val_set):
    27. student.fit_supervised(train_set)
    28. metrics = evaluate(student, val_set,
    29. tasks=["accuracy", "format", "safety", "robustness"])
    30. return student, metrics

    8. Conclusion

    Hard and soft distillation are not simply “low-level vs. high-level” approaches; they represent two data production strategies with different cost structures and risk profiles. Hard distillation is suitable for quickly establishing baselines, while soft distillation is better suited for building high-quality datasets. The former needs to focus on controlling error propagation and compliance risks; the latter needs to focus on controlling scorer bias and homogenization. Engineering teams should treat trajectory distillation as an auditable data pipeline, balancing quality, cost, and risk through phased hybrid strategies, rigorous filtering, version management, and gray-scale evaluation.