ML SYSTEM DESIGN & MLOPS · INTERVIEW QUESTION
What are the key techniques for making Transformers efficient in production? Explain KD, quantization, pruning, and graph optimization.
🔴 advanced · Model Serving
Hint: Think about the full optimization stack from model compression to runtime optimization.
Answer
Production transformer optimization stack:
-
Knowledge Distillation: train a smaller student to mimic a larger teacher. Student achieves near-teacher accuracy with far fewer parameters. DistilBERT reduces BERT by ~40% retaining ~97% performance. Match soft logits (dark knowledge) and optionally intermediate features.
-
Quantization: represent weights/activations with fewer bits (FP16→INT8→INT4). Post-training quantization (simple, some accuracy drop) vs QAT (simulates low-precision during training). 4-bit (QLoRA, GPTQ) allows billion-param models on single GPU. 2-8× memory reduction.
-
Pruning: remove redundant weights. Unstructured (zero out small weights, harder for hardware) vs Structured (remove entire attention heads/neurons/layers, hardware-friendly). Often combined with retraining.
-
Graph Optimization: operator fusion (MatMul+BiasAdd+LayerNorm into one kernel), kernel specialization (TensorRT, ONNX Runtime), static graph optimization. Lowers latency 20-40%.
Combined: this stack yields 3-10× faster inference, 2-5× lower memory, often <1% accuracy drop.
Related questions
- What is model distillation? How is it used in production?
- How do you deploy a fine-tuned LLM in production on cloud infrastructure?
- What is continuous batching for LLM inference? How does it improve throughput?
- Design a real-time ML serving system for a recommendation engine handling 10k QPS.
- What is LLMOps and how does it differ from traditional MLOps?