Back to News Feed
Hugging Face Blog22d ago

Making Knowledge Distillation Cheap Enough to Run at Scale

Knowledge distillation—the process of training a compact "student" model to mirror the performance of a massive "teacher" model—has long been a cornerstone of machine learning. However, the recent explosion of open-source Large Language Models (LLMs) like Qwen, GLM, Kimi, and various GPT-based variants has thrust this technique back into the spotlight. As these models grow in complexity, the challenge of deploying them becomes increasingly daunting. For instance, the Kimi-K3 model, boasting 2.8 trillion parameters, requires roughly 3TB of VRAM just to load.

To bridge the gap between massive performance and practical deployment, researchers are increasingly turning to compression. Companies like Nvidia, with its Nemotron 3 Puzzle 75B, and Multiverse Computing, with its Hypernova 60B, have demonstrated that high-quality compressed models are not just possible, but essential. Yet, the distillation process itself remains a significant bottleneck. It is typically the most expensive phase of the pipeline, requiring both the teacher and student to reside in memory simultaneously while generating probability distributions across the entire vocabulary for every token. This usually necessitates hundreds of GPUs and complex tensor-parallelism strategies.

A new paper, Efficient Knowledge Distillation for LLMs: Offline Top-K Logits and a Fused Chunked KL Loss, introduces a paradigm shift. By implementing two critical systems changes—caching the teacher’s top-K logits and utilizing a memory-efficient KL-divergence loss—the researchers have effectively democratized large-scale distillation. These advancements allow for long-context training on a single GPU, turning what was once a massive infrastructure hurdle into a practical, iterative experiment.

The High Cost of Traditional Distillation

The standard approach to distillation, known as online distillation, relies on the Kullback-Leibler (KL) divergence loss. In this setup, the teacher and student models are loaded concurrently. At every training step, the teacher performs a full forward pass to generate an output distribution, which the student then attempts to emulate.

While this method is highly expressive because it leverages the full teacher distribution, it is prohibitively resource-intensive. Because the teacher’s behavior remains static throughout the training run, recomputing its output at every step is redundant and wasteful. Furthermore, the memory requirements are staggering.

Consider a model like gpt-oss-120b, which features a vocabulary of 201,088 tokens. If we train at a sequence length of 32K with a batch size of 4, the teacher-probability tensor alone occupies roughly 50GB of VRAM in bfloat16 precision. When you factor in gradients, model weights, activations, and optimizer states, a single training iteration can peak at approximately 250GB of VRAM. This exceeds the capacity of even the most powerful hardware, such as the H200 or B200 GPUs.

The research team’s new approach reformulates the KL loss to process data in chunks, effectively eliminating the massive memory spikes that plague traditional methods. Where dense KL loss might peak at 250GB, the fused chunked loss maintains a significantly lower memory footprint, peaking at around 128GB.

Two Systems Changes: A New Blueprint

The researchers propose two primary innovations to solve the memory crisis:

1. Offline Distillation

Instead of forcing the teacher to reside in memory during the student’s training, the team computes the teacher’s output once. They cache the top-100 most likely tokens for every position and train the student against this static cache. Because the teacher is never needed again once the cache is generated, the same data can be reused across numerous experiments and ablations, saving massive amounts of compute time.

2. Fused, Chunked KL Loss

The standard KL loss is computationally expensive because it constructs a massive grid—one row per vocabulary entry and one column per sequence position—to measure the discrepancy between the teacher and student. For a 100K+ vocabulary and long sequences, this grid is enormous. The team compared three methods of computing this loss:

  • Dense KL: The textbook approach that builds the full grid. While useful as a correctness baseline, it is memory-intensive, holding the full vocabulary-by-sequence grid in memory twice.
  • Forward-chunked KL: This method keeps the teacher sparse, using only the cached top-100 logits. It computes the loss in smaller slices, which is faster but still limited by the student’s own logit grid, which is computed in full.
  • Fused Chunked KL: The team’s primary contribution. This method fuses the model’s output projection directly into the loss computation. It never creates the full student logit grid. Instead, it processes one chunk of the sequence at a time, projects hidden states to logits, folds the result into the running loss, and discards the chunk before moving to the next.

By recomputing the projection during the backward pass, the team ensures that peak memory grows linearly with sequence length rather than spiking with the full vocabulary-by-sequence size.

Practical Impact and Scaling

The efficiency gains are substantial. In benchmarks using a single H200 GPU with Llama 3.1 8B Instruct as the teacher and a 3.2B Llama model as the student, all four methods reached near-identical training loss. This confirms that offline distillation against cached top-100 logits is essentially lossless compared to online distillation.

"At 32K tokens, peak memory falls from 85.2 GiB with the dense loss to 5.45 GiB with the fully chunked version, a 15.6× reduction."

The advantages become even more pronounced as context length increases. At 256K tokens, the fully chunked loss requires only 11.6 GiB of memory, compared to 134.2 GiB for the next-best chunked variant, and it performs roughly 3.3× faster per iteration.

When distilling a GPT-OSS 20B model at a 32,768-token context, the memory savings allowed the researchers to reduce their infrastructure from four GPU nodes down to just one. The step time plummeted from 57 seconds to 12.23 seconds—a 5× speedup—while throughput per GPU increased from 74.2 to 345.7 TFLOP/s.

The Resulting Student

The efficiency of this offline setup enabled a large-scale distillation campaign that would have otherwise been financially or technically unfeasible. The resulting 3.2B parameter student model, distilled from the Llama 3.1 8B Instruct, retains the vast majority of the teacher’s accuracy on benchmarks like BoolQ and HellaSwag. Even on MMLU, the student remains within nine points of its much larger predecessor, despite having less than half the parameter count.

This work represents a significant step forward in Multiverse Computing’s mission to make model distillation and "healing" practical at scale. By moving away from monolithic, memory-heavy training recipes, teams can now iterate faster and experiment more freely.

For those looking to implement these techniques, the researchers have open-sourced their chunked-loss implementation on GitHub. Whether you are looking to optimize your own distillation pipeline or simply want to understand the closed-form gradient behind the fused chunked loss, the full paper provides a comprehensive roadmap for the future of efficient LLM training.

Key Takeaways

  • Memory Efficiency: The fused chunked KL loss allows memory usage to scale linearly with sequence length, avoiding the massive spikes associated with traditional dense KL loss.
  • Cost Reduction: By caching teacher logits offline, researchers can reuse data across multiple training runs, drastically reducing the compute overhead.
  • Scalability: The method enables long-context training on significantly smaller hardware footprints, turning multi-node requirements into single-GPU tasks.
  • Performance: The approach is mathematically equivalent to standard online distillation, ensuring that student model quality remains high without the traditional resource tax.