Reading preferences
Concept

Compression and Inference Trade-offs

Compare quantisation, distillation, caching, and context limits.

generative ai, quantisation, distillation, inference

Save resources deliberately

Quantisation represents values using fewer bits under a chosen scheme; scales, metadata and kernels add overhead. Distillation trains a smaller student using a teacher's outputs or behaviour. Either can reduce resource use, but the quality change varies with model, workload and implementation.

A context budget

Suppose a service allows 100 tokens for input plus output: 20 for instructions, 50 for retrieved context and 30 for a response.

  1. The input consumes 70 tokens.
  2. The remaining 30 fit the planned response in this simplified budget.
  3. Adding a 20-token passage requires removing context or shortening the response. Check whether the removed material contains essential evidence.

See the reasoning

Allocate a context budget

Account for instructions, retrieved text, and output. This is a prepared demonstration, not live code execution.

Allocate input

Illustrative 100-token total
  1. Instructions20 tokensCurrent focus
  2. Retrieved text50 tokens
  3. Output30 tokens reserved

The input uses 70 tokens.

Performance and correctness

A KV cache reuses attention keys and values during autoregressive decoding, trading memory for less repeated work. Batching, hardware and serving implementation affect actual throughput and latency. Test compressed models on representative tasks and failure slices, including long-context cases. A smaller model or shorter context is not automatically faster, cheaper or adequate for every workload.

Reflect on the concept

Four fixed questions to reinforce the reasoning. Answers are not saved or scored.

1. What does quantisation generally change?
2. What is model distillation?
3. Why cache attention keys and values during decoding?
4. What should context truncation consider?

References and further reading