Part 5: Large language models
How large language models work, how to design one, how to train a small one on your laptop and scale it to big hardware, how to fine-tune and run models locally, and how to evaluate them.
Key terms in this part (20)
- QLoRA
- BPE (byte-pair encoding)
- Context window
- DPO (direct preference optimisation)
- Fine-tuning
- Fine-tuning vs prompting
- GGUF
- GPU
- Hallucination
- KV cache
- Large language model (LLM)
- LoRA (low-rank adaptation)
- Mixture of experts (MoE)
- Perplexity
- Pretraining
- Quantisation
- RLHF (reinforcement learning from human feedback)
- Sampling temperature
- Speculative decoding
- Token
- UnderstandHow LLMs work, tokens, sampling
- DesignSize, context and vocabulary
- TrainA small model on your laptop
- ScaleThe same code on GPUs and many machines
- Adapt and runFine-tune, run locally, evaluate
Realistic scope. You will train small models that show every mechanism. Training a modern large model from scratch needs very large datasets, many GPUs and a specialised team; this part teaches the principles so you understand, adapt and run such models.
How LLMs work
- How large language models work
Explain pretraining, next-token prediction, context windows, instruction tuning, open-weight versus hosted models, and why LLMs sometimes make things up.
- Tokens and sampling settings
Explain how tokenisers split text, why tokens drive cost and limits, and how temperature and top-p change generated text.
Design and train
- Designing a language model
Choose tokeniser, vocabulary, width, depth, heads and context length for a model, estimate its size and memory, and plan experiments.
- Train a small language model on your laptop
Train a character-level language model end to end on a laptop, read training and validation loss, save and reload checkpoints, and run the same loop as a tiny transformer.
- From laptop to big hardware: scaling training
Estimate memory for training and inference, and choose the right scaling tools (GPUs, mixed precision, gradient accumulation and checkpointing, data and model parallelism, FSDP) as models grow.
Adapt, run and evaluate
- Fine-tuning: SFT, LoRA, QLoRA and preference tuning
Decide between prompting, RAG and fine-tuning, prepare instruction data, and fine-tune an open model with LoRA or QLoRA, then compare it fairly with the base model.
- Running language models on your own machine
Run an open-weight model locally, understand quantization and memory needs, and call the local model from Python and .NET through the same interfaces used for hosted models.
- Evaluating language models
Evaluate language models with perplexity, benchmarks and your own task tests, and avoid contamination and misleading comparisons.