Skip to content
ML to LLMs
Learning path

Module 15

Large language models

Tokens, pretraining, decoding, adaptation, and the limits of models that predict probable text.

  1. 1. Tokenization and pretrainingTurn text into tokens with byte-pair encoding, understand context windows, and train a language model on next-token prediction measured by cross-entropy and perplexity.40 min
  2. 2. DecodingTurn next-token distributions into text with greedy decoding, temperature, top-k, top-p, and beam search; compute their effects by hand; and choose settings for a task.30 min
  3. 3. Adapting LLMsChoose between prompting, RAG, fine-tuning, LoRA, and preference optimization; compute LoRA's parameter savings; and explain hallucinations and how to reduce them.40 min
  4. 4. Fine-tuning in practiceRun the post-training pipeline end to end (SFT data, loss masking, LoRA and QLoRA, DPO, GRPO-style RL) and size the GPU memory a fine-tuning job needs before you launch it.45 min
  5. 5. Mixture of expertsRoute each token to a few of many feed-forward experts, compute gates, capacity, and dropped tokens, balance expert load, and separate total parameters (memory) from active parameters (compute).40 min
  6. 6. Scaling lawsPredict pretraining loss from parameters and tokens, find the compute-optimal model size for a FLOP budget, and explain why production models are deliberately over-trained.35 min
  7. 7. Open models: architecture walkthroughsRead the config.json of Llama 3, Mistral, Mixtral, Gemma 2, Qwen2.5, and DeepSeek-V3, name each design choice, and compute parameter counts and KV-cache memory from the config alone.45 min

An LLM is a decoder-only transformer trained to predict the next token. Everything else, from chat to code generation, is built on top of that objective. This module covers what goes in (tokens), how it is trained (next-token cross-entropy), how text comes out (decoding), and how to adapt it (prompting, fine-tuning, LoRA, preference optimization).

Key distinction

An LLM produces probability distributions over tokens. It is not a factual database, and confident wording is not calibrated certainty.

#LessonYou will be able to
1Tokenization and pretrainingexplain subword tokenization, the next-token objective, cross-entropy, and perplexity
2Decodingturn logits into text with greedy, temperature, top-k, top-p, and beam search
3Adapting LLMschoose between prompting, RAG, fine-tuning, LoRA, and preference optimization, and explain hallucinations
4Fine-tuning in practicebuild SFT data with loss masking, size GPU memory for full fine-tuning, LoRA, and QLoRA, and explain DPO and GRPO
5Mixture of expertsroute tokens with top-k gates, compute expert capacity and dropped tokens, balance load, and separate total from active parameters
6Scaling lawsestimate training FLOPs with 6ND, find the compute-optimal model size and token count for a budget, and explain why served models are over-trained
7Open models: architecture walkthroughsread a config.json, compute total and active parameters and KV-cache memory, and name the design choices behind Llama, Mixtral, Gemma, Qwen and DeepSeek

Interactive labs: Temperature, top-k, top-p · LoRA fine-tuning memory · Mixture-of-experts routing

Next moduleModule 16: Retrieval-augmented generation