Shaf Lab

Model compression

Making a model smaller and cheaper to run while keeping as much quality as possible.

Model compression is the family of techniques that make a model smaller, faster, or cheaper to run while keeping as much of its quality as possible. The two you will meet most often are quantization, which stores the same model's numbers with fewer bits, and knowledge distillation, which trains a smaller model to imitate a larger one. Pruning, which removes weights or whole structures that contribute little, is a third approach.

The motivation is mostly memory. A model's weights must fit in accelerator memory, and generating each token requires reading essentially all of them. A 7-billion-parameter model stored at 16 bits needs about 14 GB just for weights; at 4 bits it needs about a quarter of that. Smaller models fit on cheaper hardware, serve more users per machine, and run on laptops and phones.

Every compression method trades quality for efficiency, and the trade is uneven. Losses often show up first on harder tasks, such as multi-step reasoning, long context, or less common languages, while easy benchmarks look unchanged. Evaluate a compressed model on your own task data, not on a single headline score.

The techniques combine. A common path is to distill a large model into a smaller one, fine-tune it for the task, and quantize the result for deployment. Each step should be measured, because small losses compound.

Quantization

Storing a model's weights, and sometimes activations, with fewer bits to cut memory and speed up inference.

Quantization stores a model's numbers with fewer bits, such as 8 or 4 instead of 16 or 32. Each group of weights is mapped onto a small set of levels with a scale factor, so a 4-bit model needs roughly a quarter of the memory of a 16-bit one. Because generating each token means reading nearly all the weights, smaller weights often mean faster generation as well as cheaper hardware.

Methods differ in what they compress and how. Weight-only quantization is the most common for running models locally; quantizing activations too can speed up computation on supporting hardware. Some methods calibrate on sample data so that the most important weights keep more precision. Quality loss is usually small at 8 bits and varies by model and task at 4 bits and below, so measure on your own evaluation data before you ship.

Knowledge distillation

Training a smaller student model to imitate a larger teacher model's outputs.

Knowledge distillation trains a smaller student model to imitate a larger teacher. In the classic form, the student learns from the teacher's full probability distribution over possible outputs, not just its top answer. Those soft targets carry more information than a single correct label, because they reveal which wrong answers the teacher considers nearly right.

With language models, distillation often means generating a large set of teacher responses and fine-tuning the student on them, which needs only the teacher's text rather than its internal probabilities. Distilled models can come surprisingly close to their teachers on the tasks covered by the training data, but tend to fall behind on tasks the data did not cover. Check a provider's terms before training on its model's outputs.