LLM Inference Optimization & Serving · 3 of 5
Quantization & Distillation for Serving
How smaller numbers and smaller models can make inference cheaper and faster without losing the quality users notice.
Serving a model is where machine learning meets physics and accounting. Every request must move numbers through memory, multiply them fast enough, and return an answer before a user, workflow, or service-level agreement gets impatient. Quantization and distillation are two practical ways to reduce that work. Quantization makes the numbers smaller. Distillation makes the model smaller. Used well, they cut latency, raise throughput, and lower cost. Used carelessly, they quietly damage accuracy, safety, or reliability.
Serving is a resource problem
A trained model is mostly a large collection of numbers called weights. When a request arrives, the serving system combines the request with those weights to produce an output. That calculation is called inference.
Serving is different from training. Training changes the weights by learning from examples. Serving reuses fixed weights again and again. The main question is not how to learn, but how to answer many requests quickly, cheaply, and consistently.
Four limits usually matter. Memory limits how large a model can be loaded. Memory bandwidth limits how quickly weights can be read. Compute limits how many mathematical operations can be done per second. Network and scheduling overhead limit how efficiently requests reach the model and return to the caller.
Quantization and distillation attack these limits from different angles. Quantization reduces the size and cost of arithmetic. Distillation reduces the amount of model that must be run at all.
Quantization means using smaller numbers
Computers can store numbers with different levels of precision. A high-precision number can represent tiny differences; a low-precision number uses fewer bits and represents values more coarsely. Model weights are often stored as floating point 16-bit numbers, or FP16. Quantization may store them as integer 8-bit numbers, or INT8, or integer 4-bit numbers, or INT4.
The trade is simple in principle. Smaller numbers take less memory and move faster through memory bandwidth. Some processors can also multiply smaller numbers faster or in larger groups. The risk is that rounding a model's weights and intermediate values can change its answers.
A useful mental model is a ruler. Measuring a table with millimeters gives more detail than measuring with centimeters. If the task only needs centimeter accuracy, the smaller representation is enough. If the task depends on tiny differences, the coarse ruler causes errors.
Quantization is not one technique. Weight-only quantization changes the stored weights but may keep some calculations in higher precision. Activation quantization also reduces the temporary numbers produced while the model runs. Mixed-precision serving uses different precisions in different parts of the model because not every layer is equally sensitive.
How quantization is made safe enough to serve
The easiest path is post-training quantization. You start with a trained model, inspect representative examples, choose how to map high-precision values into lower-precision values, and then test the converted model. This is often fast and works well when the model has enough tolerance for rounding.
A stronger path is quantization-aware training. During additional training, the model is exposed to the effects of quantization so it can adjust. This usually costs more engineering time but can preserve quality when simple conversion loses too much.
Calibration is the step that decides the numeric ranges used during conversion. If the calibration data is too clean, too short, or too narrow, the quantized model may behave well in tests and badly in production. The calibration set should resemble real prompts, real images, real audio, or real tabular inputs, including hard cases.
Some parts of a model are more fragile than others. Embeddings, normalization layers, attention projections, and output heads can react differently to low precision. Many production systems therefore use mixed precision: aggressive quantization where it is safe, and higher precision where it protects quality.
- Use representative calibration data, not only benchmark examples.
- Measure task quality, not only model perplexity or loss.
- Check worst-case behavior, including rare classes and long inputs.
- Test on the same processor type used in production.
- Keep a reversible path back to the higher-precision model.
Distillation means teaching a smaller model
Distillation starts with a larger or stronger model, often called the teacher. A smaller model, called the student, is trained to imitate the teacher's behavior. The student may learn from the teacher's final answers, from ranked alternatives, from explanations, or from hidden intermediate signals if those are available.
This works because many serving workloads do not need the full generality of the largest model. A customer support classifier, code review assistant, document router, or retrieval answer checker may live in a narrower world. A smaller model can learn the shape of that world and serve it at lower cost.
Distillation is not compression in the same mechanical sense as zipping a file. The student is a different model with fewer parameters, a different architecture, or both. It must be trained, evaluated, deployed, and monitored as its own system.
For generative artificial intelligence, where models produce text, images, audio, or code, distillation can be subtle. A student may match the teacher on common prompts but fail on prompts that require deeper reasoning, long context, uncommon languages, or careful refusal behavior.
Quality is the budget you spend
Neither quantization nor distillation should be judged by model size alone. The real question is what quality you can afford to give up, if any, for the latency, throughput, and cost you gain.
Latency is the time a single request takes. Throughput is how many requests a system can handle in a period of time. Cost per request is the infrastructure and operations cost divided by useful work completed. Quality may mean accuracy, factuality, semantic similarity, user preference, policy compliance, or business outcome.
The hard part is that these metrics interact. A smaller model may allow larger batches, which increases throughput but can raise latency for individual users. A quantized model may run faster on a graphics processing unit, or GPU, but show little benefit on a central processing unit, or CPU, if the runtime does not use the right instructions.
Measure against a baseline that represents the current production choice. Keep the same prompts, data distribution, retrieval settings, decoding parameters, and safety filters where possible. If more than one thing changes at once, you may not know whether the win came from compression, caching, batching, routing, or a prompt change.
The real decision is not smaller or larger
Leaders and practitioners rarely choose between one giant model and one tiny model for every task. They choose a serving strategy. Some requests can go to a small distilled model. Some should go to a quantized general model. Some must be escalated to a larger model because the task is high value, ambiguous, risky, or outside the smaller model's strengths.
This is where architecture matters. A routing layer can classify requests by difficulty, customer tier, safety risk, language, document length, or confidence. Easy work stays cheap. Hard work gets more capable treatment. The goal is not to make every answer use the smallest model; the goal is to spend capability where it matters.
A practical decision also includes operational facts. Which hardware is already available? Which runtimes are approved? What service-level agreement, or SLA, must be met? Can the team monitor quality drift? Can the organization retrain or recalibrate when the workload changes? Whether teams work in Microsoft Foundry, open source toolchains, or another platform, these questions decide whether compression becomes a durable advantage.
For regulated or sensitive systems, include security and governance early. Access to models, evaluation data, and deployment pipelines should be controlled through identity and policy, for example with Microsoft Entra ID in Microsoft environments. Smaller models are not automatically safer models; they are still software artifacts that can leak, fail, or be misused.
Deployment patterns that work in practice
The safest pattern is staged rollout. First run the compressed model offline against historical data. Then run it in shadow mode, where it receives production traffic but its answers are not shown to users. Next send a small percentage of real traffic to it. Only then expand if quality, latency, and cost behave as expected.
Another useful pattern is fallback. If the small model has low confidence, sees an unfamiliar input, triggers a safety concern, or exceeds a time limit, the system can call a larger model or a human workflow. Fallback turns compression from an all-or-nothing bet into a managed policy.
Observability must include more than infrastructure metrics. Track latency percentiles, throughput, error rates, memory use, and cost. Also track task outcomes, user feedback, safety events, refusal rates, and distributions of input length or type. Compression can fail slowly when user behavior changes.
Finally, keep versioning strict. Record the teacher model, student model, quantization settings, calibration set, evaluation suite, runtime, hardware target, prompts, and safety filters. A serving model is not just a file; it is a reproducible bundle of choices.
- Prove value offline.
- Shadow production traffic.
- Canary a small percentage of users or requests.
- Expand only with monitored gates.
- Keep fallback and rollback ready.
Key takeaways
- Quantization makes model numbers smaller; distillation makes the model itself smaller.
- Lower precision can reduce memory, bandwidth, latency, and cost, but only when the serving stack supports it well.
- Distillation is a training project, not a file conversion, and the student model needs its own evaluation.
- Quality loss must be measured on real tasks, edge cases, and production-like hardware.
- The best serving architectures route requests by difficulty and risk instead of forcing one model to handle everything.
- Safe rollout requires baselines, shadow testing, canaries, monitoring, fallback, and rollback.
Glossary
- Inference
- The process of running a trained model on an input to produce an output.
- Quantization
- A technique that represents model numbers with lower precision to reduce memory use and sometimes speed up computation.
- Distillation
- A training method where a smaller student model learns to imitate a larger or stronger teacher model.
- Weights
- The learned numbers inside a model that determine how inputs are transformed into outputs.
- Activation
- A temporary value produced inside a model while it processes an input.
- Calibration
- The step of choosing numeric ranges for quantization using representative data.
- Latency
- The time it takes for one request to be processed and returned.
- Throughput
- The amount of work a serving system can complete in a given period of time.
- Fallback
- A policy that sends a request to a larger model, another service, or a human process when the primary model should not answer alone.