Knowledge Distillation for Large Language Models: Principles and Data Pollution Governance Guide

    This guide explains how knowledge distillation transfers a teacher model's capabilities to a student model, covers white-box vs. black-box distillation, loss functions, and sequence-level distillation, and shows how undistilled synthetic data can lead to data pollution and model collapse. It also offers practical governance measures, including data lineage, a minimum share of real data, teacher output filtering, sampling diversity control, and a closed-loop evaluation process, along with common mistakes and debugging paths.

    When large models distill from synthetic data, and that synthetic data is then fed back into training sets, issues such as the model “misidentifying itself”, outputs converging, and expressions becoming formulaic are amplified. Knowledge distillation is the core technique for transferring a teacher model’s capabilities to a student model, but without data pollution governance, distillation can turn from a capability amplifier into a quality diluter. This guide covers white-box and black-box approaches, loss functions, sequence-level distillation, model self-devouring, and engineering governance.

    1. What Is Knowledge Distillation, and Why Does It Cause Data Pollution?

    Knowledge distillation was systematized by Hinton et al. (2015). Rather than simply copying answer labels, it uses the soft targets produced by the teacher model to convey relative confidences, class relationships, or a generation distribution. A hard label only tells you that the correct answer is A, whereas a soft label gives the relative probabilities of A, B, and C, which carries more structural information.

    For large models, distillation commonly takes two forms:

    1. Classification-style distillation: applies to classification heads, scorers, and reward models by aligning class logits.
    2. Sequence-level distillation: the teacher generates token sequences and the student learns them in an autoregressive way. This is common for instruction following, writing, and summarization.

    The example code below (PyTorch style) shows classification-style distillation. Inputs: student logits, teacher logits, and ground-truth labels. Output: a scalar loss. The teacher must be frozen; temperature T and weight alpha are hyperparameters.

    1. import torch
    2. import torch.nn.functional as F
    3. def distillation_loss(student_logits, teacher_logits, labels, temperature=4.0, alpha=0.7):
    4. # Temperature softening: T > 1 smooths the distribution and boosts the relative contribution of low-probability classes
    5. soft_teacher = F.softmax(teacher_logits / temperature, dim=-1)
    6. log_soft_student = F.log_softmax(student_logits / temperature, dim=-1)
    7. # KL divergence measures the gap between the student and teacher distributions; multiplied by T^2 to compensate for gradient scaling
    8. kl = F.kl_div(log_soft_student, soft_teacher, reduction='batchmean') * (temperature ** 2)
    9. # The student also learns from the hard cross-entropy of the ground-truth labels
    10. ce = F.cross_entropy(student_logits, labels)
    11. return alpha * kl + (1 - alpha) * ce

    Notes: T² compensates for the gradient magnitude after temperature scaling, and alpha controls the balance between the soft and hard targets. In sequence-level distillation with large models, replace “teacher logit alignment” with “token sequences sampled from the teacher” and have the student learn them with an autoregressive loss. However, low-quality, policy-violating, repetitive, or unverifiable samples must be filtered out.

    2. White-Box vs. Black-Box Distillation: Which Should You Choose?

    Distillation is commonly split into white-box and black-box types based on whether you can access internal teacher signals.

    • White-box distillation: requires forward access to the teacher, such as reading weights, hidden states, attention, or the full logits. Common approaches align teacher logits, hidden-layer representations, or attention distributions. This requires an open-source or deployable teacher. If the API returns logits/logprobs, you can also align the output distribution in a white-box fashion.
    • Black-box distillation: when you can only obtain the final text or limited output, you can only have the student fit the input-to-teacher-output mapping from sample pairs. The advantage is a low engineering barrier: you can reuse the capabilities of a strong publicly available model within the scope of authorization. The downside is that internal signals are hard to align, so results depend on sampling quality, coverage, and filtering.
    Dimension White-box distillation Black-box distillation
    Access required Forward access to the teacher for logits, hidden states, weights, etc. API calls or text output only
    Signals you can align Logits, hidden representations, attention, temperature-scaled distributions, etc. Input-output pairs, teacher text or sequences
    Typical practice Loss alignment, intermediate-layer distillation, distribution matching Collecting Q&A pairs, filtering, then fine-tuning the student
    Suitable scenarios Self-developed model compression, internal model iteration, controlled evaluation External APIs, transferring capabilities of publicly available strong models
    Main risks Tight coupling to the teacher’s structure, complex engineering and compliance Sampling bias, low-quality outputs, terms-of-service risk

    How to choose: if the teacher can be deployed and you need fine-grained capability inheritance, prefer white-box. If you can only call an API and your goal is to quickly fill in basic skills such as output formatting, black-box works, but compliance checks, deduplication and filtering, and evaluation-based acceptance are mandatory.

    Compliance note: before collecting teacher outputs for training, confirm the provider’s API terms of service, restrictions on output use, data retention policy, and the scope of commercial licensing. Never assume that “publicly available” means “free to distill”.

    3. Data Pollution and Model Self-Devouring: How the Risks Form

    Data pollution can be understood as follows: after different models, synthetic content, and crawled corpora enter the training set, they overwrite, dilute, or homogenize the original distribution. When multiple models all distill from the same batch of strong models, and those outputs flow back into public corpora, the training set becomes cross-contaminated. Model boundaries blur, leading to identity confusion and a convergence of tone.

    A more severe risk is model self-devouring (self-consuming training), where a model is trained at scale on data generated by the previous generation of models. Shumailov et al. (2024) introduced the concept of model collapse: errors and biases can accumulate across generations, causing the tails of the distribution to disappear, variance to shrink, and low-frequency expressions to decline. Some studies argue that continuously adding real data can mitigate collapse, though the effect depends on the quality and coverage of that real data. Note that model collapse is mainly a risk demonstrated through theoretical analysis and controlled experiments. In real product iteration, a drop in output naturalness is also influenced by the data mix, training objectives, post-training strategies, alignment methods, and evaluation choices. Model self-devouring may be one cause, but it is not the only explanation.

    A practical warning sign: if the share of synthetic data keeps rising while long-tail expressions, diversity metrics, and real-task performance all decline, suspect data quality pollution first.

    4. Controlling the Ratio and Quality of Synthetic Data

    To make distillation deliver gains, you need data governance, not just “a stronger teacher”.

    1. Establish data lineage
      For each sample, record its source, generating model, generation time, prompt, filtering rules, and human review status. Track the share of real human-written and synthetic data by batch.

    2. Set a minimum share of real data
      Define a minimum share of high-quality real data for each training version, e.g., no less than 40%. For abilities such as writing, reasoning, and long-tail knowledge, you can raise the share of real samples further. If the synthetic share exceeds the threshold, trigger human review or roll back.

    3. Filter teacher outputs
      For black-box distillation samples, run correctness checks, rule-based deduplication, semantic deduplication, low-quality filtering, and safety review. Prioritize samples that are diverse, verifiable, and naturally expressed.

    4. Control sampling temperature and diversity
      If the teacher samples at too high a temperature, outputs can become repetitive, formulaic, or distorted. Too low a temperature can make expressions monotonous. Sample in buckets by topic, difficulty, style, and length, and monitor distinct-n, self-BLEU, and the share of long-tail words.

    5. Close the evaluation loop
      Use an evaluation set that is independent and held out from training. Track downstream benchmark scores, human preference, the share of long-tail expressions, diversity metrics, and the identity confusion rate. If these metrics drop, identify the newly added data batch and isolate it.

    5. Common Mistakes and How to Debug Them

    • Overlap between the evaluation set and the training data. This shows up as inflated offline scores and degraded online performance. To debug it, run near-duplicate detection between the two sets using hashes, embedding similarity, and manual spot checks.
    • Fine-tuning only on teacher outputs, with no real-data anchor. This shows up as solid format imitation but degraded factuality and long-tail abilities. To debug it, raise the share of real data, add more high-quality human-written samples, and add fact-checking.
    • Teacher sampling temperature too high or filtering insufficient. This shows up as homogeneous, repetitive, and semantically drifting synthetic data. To debug it, lower the sampling temperature, add deduplication and diversity constraints, sample in buckets, and compare evaluation results across different temperatures.

    6. Platform Engineering Support

    Distillation and data governance typically form an I/O-heavy, orchestration-heavy pipeline: object storage holds raw corpora and teacher outputs; message queues decouple collection, cleaning, labeling, and training; container platforms elastically schedule distributed jobs; and logging and monitoring track data distribution drift, abnormal training metrics, and evaluation regressions. Enterprises can combine components at the required scale using general capabilities from platforms such as Baidu AI Cloud to build a traceable, auditable data governance loop.

    7. Conclusion

    Knowledge distillation for large models is not just about “calling a stronger model to generate data”; it is a systems engineering effort. White-box distillation suits controllable teachers and fine-grained alignment, while black-box distillation suits API-based scenarios but requires compliance checks and filtering. Synthetic data can expand scale, but it must be backed by real-data anchors, quality filtering, diversity constraints, and a closed-loop evaluation process. The ceiling of distillation performance depends largely on the quality of your data governance.