AI Engineering on fine-tuning and inference
Prompt first, then RAG, then fine-tune
- A better prompt is the fastest and cheapest fix. Try it first.
- If the model lacks knowledge, add RAG. Fine-tuning is a poor way to add facts.
- If it needs a new style, format or narrow skill, consider fine-tuning.
- A big model's answers can also train a small one to do the same job cheaper.
- 1. Promptingfastest, cheapest, try first
- 2. RAGadds knowledge
- 3. Fine-tuningchanges behavior
How chat models are made
- Pretraining: predict the next token across a huge amount of text.
- Instruction tuning: learn to follow requests from example conversations.
- Preference tuning, like RLHF or DPO: learn which answers people prefer.
- Each stage uses far less data than the one before it.
LoRA makes fine-tuning cheap
- Full fine-tuning updates all of a model's weights: billions of numbers.
- LoRA freezes them and trains small add-on matrices instead.
- It needs far less memory, and one base model can serve many adapters.
Inference is where the money goes
- Quantization stores weights in fewer bits, like 8 or 4: less memory, faster.
- Batching runs many requests together to keep the GPU busy.
- Two speeds matter: time to the first token, and tokens per second after it.
- More throughput usually means more latency per request. Choose per use case.
Cut cost before quality
- Prompt caching reuses a long, fixed start of a prompt: cheaper and faster.
- Send easy requests to small models and hard ones to big models.
- Shorter prompts and answers cut cost directly, since you pay per token.
- Stream answers, so people see words right away.