LLM Distillation: Trajectory Imitation vs. Synthetic Data Training

    This article examines two common approaches to knowledge distillation for large language models, especially in agent and code-generation scenarios: trajectory imitation and synthetic-data distillation. It compares their engineering trade-offs, outlines a synthetic-data workflow, and covers quality evaluation, compliance boundaries, and practical recommendations.

    1. Background

    Knowledge distillation (KD) uses a stronger teacher model to guide the training of a smaller or less capable student model. Its core goal is to reproduce the stronger model’s performance on specific tasks at lower inference cost.

    In agent and code-generation scenarios, the teacher model produces more than final answers. Its outputs also include multi-step reasoning, tool calls, and error-correction processes. These complete process records are called “trajectories.” Because trajectories contain more information than a single answer, they are a common source of distillation data.

    As model outputs are increasingly used for training, distinguishing legitimate capability learning from data acquisition that violates terms of service has become a serious industry issue. The following sections break down two common practices from a technical perspective and explain their engineering trade-offs.

    2. Two Common Approaches

    2.1 Trajectory-Imitation Distillation

    This approach directly collects complete input-output records from a teacher model across a batch of tasks and uses them as supervision data for the student model, which learns to fit those outputs token by token.

    Its advantages are simple implementation, fast data acquisition, and almost no additional design. Its limitations are also clear:

    • Data quality depends entirely on teacher outputs, so teacher errors are learned by the student.
    • Formats and styles in the trajectories are tightly coupled to the original scenario, limiting generalization.
    • Most model service terms do not allow bulk collection of outputs to train other models, creating explicit authorization risk.

    2.2 Synthetic-Data Distillation

    In this approach, a strong model generates prompts, solutions, and intermediate steps according to a pre-designed task distribution. Low-quality samples are then filtered out through rule-based validation, execution-based verification, and manual spot checks. The filtered data is used to train the student model.

    Its advantages are mainly in three areas:

    • The data distribution can be controlled to actively cover edge cases in target scenarios.
    • Objective validation signals such as unit tests and execution results make correctness more reliable than directly reusing outputs.
    • The filtered dataset can become a team-owned data asset that is easy to reuse and audit.

    Its costs also need to be considered: at large generation scale, calls to the strong model can be expensive; synthetic data can suffer from insufficient diversity, so task distribution must be controlled deliberately; and this approach must still comply with model service terms.

    2.3 Comparison of the Two Approaches

    Dimension Trajectory imitation Synthetic data
    Implementation cost Low Medium to high
    Data controllability Low; depends on source outputs High; can be designed by distribution
    Correctness assurance Depends on source output quality Can be improved through validation
    Compliance risk Higher Depends on terms and use

    3. Engineering Workflow Breakdown

    A complete synthetic-data distillation project usually includes the following five stages.

    1. Define the task distribution and evaluation set. First specify which task types, difficulty levels, and formats the target capability should cover, and reserve an evaluation set that is strictly isolated from training data.
    2. Generate candidate data. Generate samples in batches according to task specifications, and record each sample’s task category, generation parameters, and version information for later traceability.
    3. Filter for quality. Run format validation, deduplication, execution validation (such as running unit tests), and model scoring in sequence. Any sample that fails any stage should be removed.
    4. Train the student model. Usually start with supervised fine-tuning (SFT), and introduce methods such as preference optimization if performance is insufficient.
    5. Compare against a baseline. Compare the distilled student model with the original undistilled small model on the same evaluation set to confirm that improvements come from the target capability rather than random fluctuation.

    The following schematic code shows the core structure of generation and filtering. Here teacher is a placeholder for the teacher model call interface; the actual implementation depends on the service the team uses.

    1. def build_synthetic_dataset(task_specs, teacher, validators, dedup_fn):
    2. """Generate samples according to task specifications and return a deduplicated training set after multi-stage validation.
    3. task_specs: List of task specifications, each containing name, prompt_template, slots, and temperature
    4. teacher: Teacher model interface that must provide a generate(prompt, temperature) method
    5. validators: List of validation functions; each function receives a sample and returns bool
    6. dedup_fn: Deduplication function that receives a list of samples and returns a deduplicated list
    7. """
    8. candidates = []
    9. for spec in task_specs:
    10. prompt = spec["prompt_template"].format(**spec["slots"])
    11. response = teacher.generate(prompt, temperature=spec.get("temperature", 0.7))
    12. candidates.append({
    13. "task": spec["name"],
    14. "prompt": prompt,
    15. "response": response,
    16. })
    17. passed = [s for s in candidates if all(check(s) for check in validators)]
    18. return dedup_fn(passed)

    Three points in the code are worth noting. First, task specifications are separated from generation logic, making it easy to adjust the task distribution without changing the main workflow. Second, validation functions are injected as a list, so teams can add or remove rules by scenario. Third, each sample retains a task category field, allowing later evaluation to calculate pass rates by category and identify weak areas.

    4. Key Quality Evaluation Points

    Data quality directly determines the upper bound of distillation, and evaluation should run throughout the entire workflow.

    • Evaluation set isolation: Evaluation samples must not appear in training data and should not be produced by the same batch of generation parameters; otherwise metrics will be inflated.
    • Dimension-specific metrics: Break the overall score into sub-metrics such as accuracy, format compliance rate, and tool-call success rate to see where capability improvements occur.
    • Distribution shift checks: Compare the distribution of training data with real business requests to detect overly uniform tasks or imbalanced difficulty.
    • Mode collapse detection: Observe whether the student model gives identical or highly similar answers across many inputs, a typical signal of insufficient diversity.

    5. Compliance and Authorization Boundaries

    The choice of technical approach must match authorization conditions. The following recommendations should be confirmed jointly by legal and technical teams.

    • Read and comply with the model service provider’s terms of use, clarifying whether outputs may be used to train other models and whether commercial use is allowed.
    • Distinguish between two types of behavior: using one’s own data and methods to improve model capability, and bulk copying another model’s outputs as training data. The former is routine R&D; the latter requires separate authorization evaluation.
    • Establish data lineage records that state the source, generating model, license status, and generation time of each training data batch for audit purposes.
    • When user privacy data or copyrighted content is involved, complete an independent assessment before collection.
    • Set up internal approval processes for data procurement and model use to prevent individual developers from making bulk calls to external services without authorization.

    6. Practical Recommendations

    • Focus most effort on task distribution design and validator development. Validators determine the lower bound of data quality, while task distribution determines the scope of capability coverage.
    • Start with a small-scale pilot, validate the workflow and metrics, and then expand generation scale.
    • Write data source, license status, and version number into the metadata of each data batch to reduce later rework.
    • Prioritize public datasets, proprietary business data, and clearly authorized data as primary sources, with synthetic data as a supplement.

    With this approach, teams can achieve a controllable balance among performance, cost, and compliance, and turn distillation into a reproducible, auditable engineering workflow.