Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Pruning | Removing parts of a trained model — single weights, attention heads, FFN channels or whole layers — that contribute little. |
| Structured / unstructured | Structured pruning removes whole units, so the remaining matrices are simply smaller. Unstructured pruning zeroes scattered single weights, leaving the matrix shape unchanged. |
| 2:4 sparsity | A pattern where exactly 2 of every 4 consecutive weights are zero. NVIDIA tensor cores since Ampere can skip the zeros. |
| Distillation | Training a small “student” model to imitate a large “teacher” model’s outputs. |
| Logits | The raw scores a model gives every vocabulary token before softmax. Distilling on logits passes on far more information than distilling on the chosen words. |
| NAS (neural architecture search) | Automatically trying many model shapes and keeping the one that best trades quality against speed. |
| Cascade | Sending each request to a small model first and only escalating hard ones to a large model (21.k). |
1. What is it?#
Three ways to make the model itself cheaper, rather than making the same model run faster:
PRUNING remove weights, heads, channels or layers that contribute little
DISTILLATION train a small model to imitate a large one
ARCHITECTURE design (or choose) the model for inference efficiency from the startThese are model-changing techniques, not serving techniques. They cost training compute and evaluation effort, and they change what the model is. But their payoff can be the largest of all: a model half the size is roughly twice as cheap to serve, permanently, and it still benefits from every serving optimization in this module.
Facts checked on 12 November 2026.
2. Why does it matter?#
PROBLEM All the serving optimizations in this module together give maybe
5–10×. Sometimes that is not enough.
WHY You are still running a model sized for broad benchmark scores,
not for your task.
OPTIMIZE Make the model smaller in a way that keeps the capability YOU need.
TRADE-OFFS
✓ 2–10×, compounding with every serving optimization
✗ needs training compute and expertise
✗ needs task-specific evaluation to know what you lost
✗ you now own a model variant (retraining, provenance, separate rollout)
WHEN TO USE High volume, a specific task, serving optimizations already done.
WHEN NOT TO Low volume, general-purpose use, no evaluation harness, or before
the cheap serving wins.Model vendors now do this routinely: many 2025–2026 “small” open models are pruned and distilled from a larger sibling rather than trained from scratch.
3. Simple analogy#
Serving optimizations tune the engine. This chooses a smaller car.
A better tune gets you 15% more efficiency. A car half the weight gets you far more — but it carries less, and you had to buy a different car.
The right question is what are you actually carrying? Many deployments use a general-purpose model for a narrow task. A small model fine-tuned or distilled for that task often matches a much larger general model on it, at a fraction of the cost.
4. Tiny example: one task, two model sizes#
Task: extract 12 fields from support emails. 50M requests per month.
70B general model, FP8, on H100s
~1.0 s of GPU time per request at your batch → 50M × 1.0 s = 13,900 GPU-hours
8B student distilled on 200k teacher outputs for this task
~0.12 s per request → 50M × 0.12 s = 1,670 GPU-hours
At ~$2.5 per H100-hour: ~$34,700 vs ~$4,200 per month
Quality on held-out production emails: 97% vs 96% field accuracy (your eval decides)
Quality on general chat: much worse — and irrelevant for this service.The numbers are illustrative; the shape is typical. The saving is permanent, and the price is owning the student: an evaluation set, a retraining pipeline, and a model to version.
5. Technical explanation#
Distillation — usually the highest-value option#
Teacher (large) produces outputs → student (small) trains to match them.
Response distillation: train on the teacher's generated text
(easy, common; works through an API)
Logit distillation: train on the teacher's full output distribution
(more information per token, better results;
needs the teacher's logits and the same tokenizer)Why it beats training the small model on raw text: the teacher’s distribution says not just which token is right but how plausible every alternative is. The student learns the shape of the teacher’s beliefs, not only its top answer.
Practical guidance:
- Use real production prompts as the distillation set. It is the right distribution by construction (mind privacy and consent rules for user data).
- Filter the teacher’s outputs for quality.
- Evaluate on held-out production traffic, not public benchmarks.
Pruning#
UNSTRUCTURED: zero individual small weights (e.g. SparseGPT, Wanda)
✓ best quality per parameter removed
✗ scattered zeros give NO speedup with dense GPU kernels
→ storage savings only, for inference on GPUs
SEMI-STRUCTURED (2:4): exactly 2 of every 4 consecutive weights are zero
✓ sparse tensor cores (Ampere and later) skip the zeros: up to 2× matmul
throughput in theory, much less end to end
✗ needs fine-tuning to recover quality; the cost is real
✗ does not combine easily with 4-bit formats
→ [EMERGING] for years; limited adoption in LLM serving
STRUCTURED: remove whole units
- attention heads
- FFN channels (intermediate dimensions)
- embedding channels (hidden size)
- LAYERS (depth pruning)
✓ real speedup with ordinary dense kernels
✓ composes with quantization and everything else
✗ quality loss, mostly recoverable with distillationDepth pruning works better than you would expect. Gromov et al. (2024) removed large fractions of the deeper layers of open models (Llama-2-70B among them) with little loss on knowledge benchmarks after a short “healing” fine-tune — though reasoning tasks degrade faster than recall. Which layers are redundant varies by model; measure layer importance rather than assuming.
Prune, then distill: the 2024–2026 recipe#
1. Score the importance of heads, channels and layers on a small calibration set.
2. Prune to the target size (width usually beats depth for quality).
3. Distill from the ORIGINAL model into the pruned one, on a modest token budget.NVIDIA’s Minitron approach (2024) showed this reaches quality comparable to training the small model from scratch for a small fraction of the training tokens. It is now standard practice:
- Llama-3.1-Minitron 4B came from Llama-3.1-8B this way.
- Nemotron-Nano-9B-v2 (2025) was pruned and distilled from a 12B hybrid Mamba-Transformer to fit 128k-token inference on a single 22 GiB A10G.
- Puzzle (NVIDIA’s distillation-based NAS) searched per-layer variants — dropping attention in some layers, shrinking FFNs in others — to build Llama-Nemotron Super 49B and Ultra 253B from Llama-3.x 70B and 405B. Ultra also uses FFN Fusion (running consecutive FFN layers in parallel), reported at 1.71× lower latency than the 405B parent.
6. Under the hood: architecture choices that set serving cost#
If you are training or choosing a model, these decisions fix its serving cost permanently:
DECISION INFERENCE IMPACT
GQA / MQA vs MHA 4–8× less KV cache. The biggest single lever (12.g).
MLA a further ~7× over GQA in DeepSeek's design (12.g).
Sparse attention (DSA) far less KV read per step at long context; same memory.
Hybrid linear attention fixed state in most layers; large savings at long context,
harder prefix caching (12.g, 17.i).
Sliding windows caps KV in windowed layers at W tokens.
Cross-layer KV sharing ~2× less KV [EMERGING] (13.i).
MoE large total, small active parameters → cheap compute,
expensive memory; suits high-batch serving (14.g).
Depth vs width deeper = more sequential layers, more launches, more KV;
wider = bigger GEMMs that use the GPU better.
Vocabulary size bigger = fewer tokens per text but a larger LM head.
head_dim decides which attention kernels exist; 64/128 are safe (13.l).
MTP layers built-in speculative decoding (13.o).
Tied embeddings saves V × d parameters.Deeper versus wider. Two models with the same parameter count, one with 80 layers of width 8,192 and one with 48 layers of width ~10,600:
80 × 8192: more sequential steps per token, more launches, more KV (∝ layers),
smaller GEMMs
48 × ~10.6k: fewer, larger GEMMs; less KV; fewer launches
→ usually faster to serve, especially at small batchTraining dynamics tend to favour depth; inference favours width. This is a real tension, and inference engineers should be in the room when it is decided.
7. Performance implications#
Technique Speedup Quality cost Effort Generality lost
Distillation (task) 5–20× small, on task weeks most other tasks
Prune + distill 1.5–2.5× small–moderate weeks some
Layer pruning + FT 1.2–1.5× 1–3% (task-dep.) days some
2:4 sparsity + FT 1.1–1.5× 1–3% days little
Architecture choice 1.2–8× 0 (a different — depends
(at design time) model)Ranges are typical of published results, not guarantees. Distillation dominates when you have a narrow task and real volume. Everything else is incremental.
8. Production implications#
- Do the serving optimizations first. They are cheaper and reversible; model surgery is neither.
- No evaluation harness, no distillation. Without a task eval you cannot know what you lost.
- Model variants have ownership costs: retraining when the base model updates, provenance and licence tracking (the teacher’s licence may restrict distillation), separate evaluation and rollout (23.g).
- A cascade may beat a single distilled model: route easy queries to a small model and hard ones to a large one (21.k). It often captures most of the saving with less risk on hard queries.
- When choosing a model, weigh the architecture factors. Two models with equal benchmark scores can differ several-fold in serving cost.
- Prefer vendor-pruned siblings (Minitron-style releases) before pruning yourself — someone else already paid for the distillation.
9. Common mistakes#
- Doing model surgery before serving optimization. Wrong order; far more effort.
- Unstructured pruning expecting a speedup. Dense GPU kernels do not benefit from scattered zeros.
- Distilling without a task evaluation. You cannot tell what broke.
- Evaluating a distilled model only on public benchmarks. It was distilled for your task; measure that.
- Ignoring architecture when selecting a model. KV bytes per token is a direct cost multiplier.
- Assuming quality loss is uniform. Reasoning and long-chain tasks degrade faster than knowledge recall.
- Ignoring the teacher’s licence. Some model and API terms forbid using outputs to train competing models.
10. Hands-on exercise#
A. Layer pruning. Take a small model. Remove layers one at a time (try deep layers first, then middle ones) and measure perplexity and one reasoning benchmark after each. Plot quality against layers removed. Where is the cliff, and does it differ between the two metrics?
B. Distillation. Distill a 7–8B model into a 1B one for a narrow task (classification or field extraction). Measure quality on the task and on a general benchmark. Quantify the generality lost.
C. Architecture cost comparison. For five open models of similar benchmark quality, compute serving cost per million tokens with your 12.q calculator. Rank them. Does the ranking match the benchmark ranking?
D. Depth vs width. Find two models with similar parameter counts but different depth/width ratios. Measure decode throughput at batch 1 and 64. Does the wider one win, and by how much?
E. Cascade. Build a two-model cascade with a confidence signal that routes uncertain queries to the large model. Measure cost and quality against always using the large model.
11. Interview questions#
- When would you distill a model rather than optimize serving?
- Why does unstructured pruning not speed up GPU inference?
- What is 2:4 sparsity, and why has it seen limited adoption for LLMs?
- Describe the prune-then-distill recipe. Why distill from the original model?
- Given equal parameters, would you prefer a deeper or wider model for inference? Why?
- Name five architecture decisions that set a model’s serving cost.
- What does a model cascade buy you compared with a distilled model?
12. Further reading#
Checked on 12 November 2026.
- [ESTABLISHED] Hinton et al., “Distilling the Knowledge in a Neural Network” (2015)
- [ESTABLISHED] Muralidharan et al., “Compact Language Models via Pruning and Knowledge Distillation” (Minitron, 2024); Sreenivas et al., “LLM Pruning and Distillation in Practice: The Minitron Approach” (2024)
- [ESTABLISHED] NVIDIA, “Nemotron Nano 2” (2025) — Minitron compression of a hybrid model
- [EMERGING] Bercovich et al., “Puzzle: Distillation-Based NAS for Inference-Optimized LLMs” (2024); “FFN Fusion” (2025); “Llama-Nemotron: Efficient Reasoning Models” (2025)
- [EMERGING] Gromov et al., “The Unreasonable Ineffectiveness of the Deeper Layers” (2024)
- [ESTABLISHED] Frantar & Alistarh, “SparseGPT” (2023)
- [REFERENCE] NVIDIA — Accelerating inference with sparsity on Ampere and TensorRT