Before You Start
- Required knowledge
- Classification, softmax, quantization concepts, and knowledge distillation.
- Libraries used
- NumPy
- Dataset and source
- Synthetic 256-dimensional examples and teacher logits across 12 classes.
- Expected output
- Fake-int8 and student-distillation experiments with quality comparisons; no production LLM weights are loaded.
Lesson Videos
LLMs in Production — Theory & Concepts
Read this before attempting the exercises. This lab is about the production question: once you already have a strong model, how do you make it cheaper and faster without damaging quality too much?
1. What This Lab Is Actually About
This notebook does not train a real large language model.
Instead, it uses a toy classifier as a stand-in for an LLM output head so that you can study two very common production ideas:
- ●quantization: keep the same model, but store weights in lower precision
- ●distillation: train a smaller student to imitate a stronger teacher
Those are two different compression strategies.
2. Why “Production” Changes the Goal
In research, you usually ask:
How do I get the best possible quality?
In production, you ask:
What quality can I afford at my latency and cost budget?
That means every deployment decision becomes a tradeoff among:
- ●accuracy / quality
- ●memory footprint
- ●throughput
- ●latency
- ●serving cost

A model that is slightly worse but much cheaper may be the better production choice.
3. Quantization
Quantization means storing model parameters in a cheaper numeric format.
Examples in practice:
- ●FP32 -> FP16
- ●FP16 -> INT8
- ●FP16 -> 4-bit weight formats
The important point is:
quantization does not change the model architecture
it changes how weights are represented
Why teams do it:
- ●lower memory usage
- ●faster loading
- ●higher batch sizes at serving time
- ●better hardware utilization
Risk:
- ●too much quantization can hurt quality or numerical stability
4. What the Quantization Section in This Lab Shows
The lab uses fake symmetric int8 quantization:

- ●find one scale for the weight tensor
- ●round weights into the int8 range
- ●dequantize back to float for inference
- ●compare memory and quality
This is a simplified version of post-training quantization.
It is not a full production quantization stack, but it teaches the correct intuition:
same model
smaller weight representation
usually small quality drop if done carefully
5. Distillation
Distillation means training a student model to imitate a stronger teacher model.
Instead of learning only from hard labels, the student also learns from teacher outputs.
That matters because teacher logits or probabilities contain richer information such as:
- ●which wrong answers were still plausible
- ●which classes were close competitors
- ●how confident the teacher was
The core idea is:
teacher -> soft supervision -> smaller student
6. What the Distillation Section in This Lab Shows
The student in this notebook is deliberately smaller.
In this toy setup, the student only uses a narrower input representation. That stands in for real production choices such as:
- ●fewer layers
- ●smaller hidden size
- ●fewer attention heads
- ●a compressed backbone
The student then fits teacher logits with a simple regression-style objective.
So the lesson is:
distillation changes the model itself
quantization keeps the model but changes the number format
7. Quantization vs Distillation
Quantization
- ●keeps architecture unchanged
- ●usually easier to apply after training
- ●often preserves quality well
- ●mainly reduces memory / improves serving efficiency
Distillation
- ●creates a smaller new model
- ●can reduce both compute and memory
- ●usually needs an extra training step
- ●may lose more quality, but can give much larger runtime savings
A good production engineer should know when each tool is appropriate.
8. What to Measure in Production
For compression decisions, strong teams measure more than one metric.
Useful dimensions include:
- ●task accuracy / evaluation quality
- ●model size in memory
- ●latency
- ●throughput
- ●cost per request
- ●quality drop relative to the teacher
If you only report accuracy, you are missing the production picture.
9. What a Strong Interview Answer Sounds Like
Quantization reduces the cost of an existing model by storing weights more cheaply.
Distillation trains a smaller student to imitate a stronger teacher.
Quantization is often the easiest way to cut memory with small quality loss.
Distillation can reduce compute more aggressively, but requires retraining and usually gives a larger tradeoff.
In production, choose based on latency, memory, throughput, and acceptable quality loss.
That is the real lesson of this lab.
Now you're ready to attempt the exercises. Switch to the Exercise tab and start coding!
Ready to practice?
LLMs in Production — Student Lab
Offline lab: study two common production optimization ideas using a toy classifier that stands in for an LLM head.
In this lab you will:
- ●build a synthetic teacher model
- ●quantize the teacher weights with fake int8
- ●distill the teacher into a smaller student model
- ●compare quality, memory, and tradeoffs
Run the tasks in order. Later sections depend on the teacher logits created earlier.
0 — Synthetic dataset + teacher model
Create a sparse synthetic dataset and a stronger teacher model. The teacher logits act as the high-quality baseline that later sections will compress.
1 — Quantization (fake int8)
Quantize the teacher weights to int8, dequantize them back for inference, and compare memory versus quality. This is a toy stand-in for production post-training quantization.
2 — Distillation (smaller student matches teacher logits)
Fit a smaller student model to the teacher logits. In this toy lab, the student only uses the first d_student input dimensions, which stands in for a smaller hidden width or a narrower network.