Course · 8 chapters · 73 lessons
Generative AI
What an LLM is and isn't, the autoregressive loop, structured outputs, RAG that doesn't break, evals that mean something, and self-hosting at the edge of the GPU.
- Chapter 01
Foundations
6 lessons - 01 What an LLM is A demystified, no-magic explanation of large language models — what they actually do, and what that implies for how you build with them.
- 02 The autoregressive loop How an LLM actually generates text, one token at a time — and what that means for streaming, latency, and your UX.
- 03 Tokens, chat templates and budgets Understand the units that determine an LLM request's cost, latency, context fit, and truncation behaviour.
- 04 Sampling: temperature, top-k, top-p How an LLM turns next-token probabilities into an answer, what temperature, top-k, and top-p actually change, and how to choose settings without fo…
- 05 Long context: windows, costs and failure modes A practical guide to what an LLM context window contains, what long prompts cost, and why more tokens can still produce worse answers.
- 06 Structured outputs How to make an LLM emit valid JSON every time using Pydantic, JSON Schema, and constrained generation.
- Chapter 02
Prompting & Tools
5 lessons - 07 Prompt patterns that work Anthropic's priority-ordered prompt techniques — clarity, multishot, chain of thought, XML tags, document ordering, prefill, and prompt caching. Pl…
- 08 Few-shot & chain-of-thought The two prompting techniques that still earn their keep — when to use few-shot examples, when to ask for reasoning, and when neither helps.
- 09 Reasoning models & test-time compute Reasoning models spend extra inference compute on hard problems before answering. Learn how test-time scaling works, how to tune thinking budgets,…
- 10 Function/tool calling How LLMs invoke functions — the schema contract, the request/response loop, and the production patterns for tool use.
- 11 Constrained decoding How structured generation guarantees grammar-valid output by masking illegal tokens at each decode step, and what that guarantee does not cover.
- Chapter 03
RAG & Adaptation
12 lessons - 12 Embeddings What an embedding actually IS — a point in semantic space. Distance metrics, dimensionality, and clustering short texts by meaning.
- 13 Sentence embeddings: SBERT A cross-encoder can judge two sentences accurately, but it must do so again for every candidate. SBERT turns each sentence into a reusable vector w…
- 14 Multimodal (vision & audio) LLMs How multimodal models turn images, audio, and video into representations an LLM can reason over, why resolution drives token cost, and the producti…
- 15 Vector databases Why a vector DB beats a numpy array at scale. HNSW, metadata filters, and the honest answer: most teams should start with pgvector.
- 16 RAG basics Retrieval-augmented generation: chunk, embed, store, retrieve, generate. The single most important pattern for any LLM app that touches private data.
- 17 OCR & document AI for RAG Turn scanned and digital documents into text a RAG system can trust: when to skip OCR entirely, classic engines vs layout pipelines vs vision-langu…
- 18 Chunking for RAG A retriever cannot find context that your chunks destroyed. Learn how chunk size, overlap, document structure, semantic boundaries, and parent-docu…
- 19 Advanced RAG Contextual retrieval (Anthropic's 49% recall win) plus the supporting techniques — hybrid retrieval with RRF, query rewriting (HyDE, multi-query),…
- 20 Vectorless retrieval (PageIndex) Retrieval without embeddings: PageIndex turns a document into a tree the LLM reasons down. Learn when it beats a vector database, where it fails, a…
- 21 RAG evaluations How to actually measure RAG quality. Retrieval metrics (recall@k, MRR, hit rate) vs generation metrics (faithfulness, answer relevance, context pre…
- 22 Fine-tune vs RAG: the decision RAG supplies changing facts at query time; fine-tuning changes a model's behavior. A practical framework for choosing between prompts, retrieval, a…
- 23 Fine-tuning: LoRA & QLoRA Full fine-tuning rewrites billions of weights you can't afford to store. LoRA freezes the model and trains a tiny low-rank 'diff' instead — here's…
- Chapter 04
How LLMs are built & trained
7 lessons - 24 Pretraining data: curation & dedup A model is what it eats. The internet is mostly junk, so the gap between a mediocre LLM and a frontier one is as much about the data pipeline — ext…
- 25 Synthetic data and model collapse How generated examples become useful training material, and how recursive reuse can erase the rare cases your model needs.
- 26 Mixture of Experts How do you get a trillion-parameter model that costs like a 13B one to run? Don't use all the parameters for every token. That's the MoE trick behi…
- 27 Alignment: SFT, RLHF & DPO A freshly pretrained model completes text — it doesn't answer you. Three post-training stages turn that document-predictor into a helpful assistant…
- 28 Direct Preference Optimization (DPO) RLHF aligns models with a reward model and a finicky RL loop. DPO throws both away — deriving, from the same preference data, a single classificati…
- 29 Constitutional AI & RLAIF Training a model to be harmless usually means humans reading piles of toxic text to label it. Constitutional AI replaces that human feedback with t…
- 30 RLVR — reinforcement learning from verifiable rewards Replace the learned reward model with a program that can actually check the answer. It removes the hackable middleman, and it is why reasoning mode…
- Chapter 05
Evaluation & Safety
11 lessons - 31 LLM evals & LLM-as-judge Vibes don't ship. How to build eval suites that catch regressions, when to use an LLM as a grader, and how to stop position, verbosity, and self-pr…
- 32 Hallucination & grounding Understand why LLMs produce confident errors, how grounding differs from truth, and how to measure support claim by claim instead of trusting a ple…
- 33 Prompt injection & guardrails Why LLMs can't tell instructions from data, the OWASP #1 risk, and the types of guardrails — input, output, instruction-hierarchy, and least-privil…
- 34 Guardrails & output validation An LLM is a probabilistic text generator wired into deterministic systems that expect valid JSON, no leaked PII, and on-policy answers. A guardrail…
- 35 Llama Guard: safety classification Llama Guard is a dedicated safety model that classifies prompts, responses, and multimodal content against a hazard taxonomy. Learn its output form…
- 36 Reward hacking & Goodhart's law Alignment introduced reward hacking as the 'proxy risk' of preference training. This is the full picture: optimize any measurable proxy hard enough…
- 37 Red-teaming LLMs Red-teaming is adversarial testing for an LLM system: attack the model, prompts, retrieval, and tools before real users do, then turn every breakth…
- 38 A taxonomy of jailbreaks A jailbreak makes an aligned model do what its safety training forbids — and unlike prompt injection, the adversary is the user, attacking the mode…
- 39 Watermarking AI content A practical guide to AI watermarking: how statistical text watermarks bias token sampling, how detectors use green-token counts and z-scores, how i…
- 40 Differential privacy for LLMs A model can memorize rare training examples and leak names, medical details, or private text. Differential privacy limits how much any one protecte…
- 41 Bias & fairness in LLMs Classical fairness asks whether a model's decisions treat groups fairly. LLMs add a language-shaped problem: their outputs can stereotype, demean,…
- Chapter 06
Frontier safety
7 lessons - 42 Mesa-optimization & inner alignment Underdetermination can produce a proxy or shortcut. Mesa-optimization is the narrower case in which a learned system contains an internal optimizat…
- 43 Evidence for deceptive alignment Deceptive alignment is the possibility that a model behaves well during training and evaluation while preserving a different objective for deployme…
- 44 AI control When a capable model may be scheming and behavioral tests cannot prove otherwise, AI control designs a protocol that limits harm anyway. Learn how…
- 45 Scalable oversight A model can become better at solving a task than the humans judging it. Scalable oversight uses debate, decomposition, weak-to-strong training, and…
- 46 Frontier safety frameworks How do labs decide what safeguards a dangerous model needs? Frontier safety frameworks turn that judgment into a precommitted process: define dange…
- 47 Recursive self-improvement Recursive self-improvement is a system improving its own ability to improve. See why that can compound into an intelligence explosion, how takeoff…
- 48 Model welfare Could an AI system itself have experiences that matter morally? Model welfare is the careful study of that possibility: what evidence could bear on…
- Chapter 07
Operations
16 lessons - 49 KV cache & continuous batching The KV cache is why LLM serving is memory-bound, not compute-bound. How caching keys and values makes generation fast, and how PagedAttention plus…
- 50 KV cache offloading & memory tiers When the KV cache outgrows GPU VRAM, move idle cache blocks through CPU RAM and storage without confusing extra capacity for free speed.
- 51 Cost & latency engineering Input vs output token economics, time-to-first-token, prompt caching, the router pattern, and semantic caching — the levers that move your bill by…
- 52 Inference metrics: TTFT, ITL & goodput 'Fast' and 'high throughput' are different, often opposing numbers. To run an LLM service you need the operator's metrics — time-to-first-token, in…
- 53 Model routing & cascades Most queries are easy. Routing only the hard ones to an expensive model — and cascading cheap-first — cuts LLM cost 45–85% at near-equal quality. T…
- 54 Self-hosting with vLLM When to run your own model and when to stay on an API. vLLM, quantization (GPTQ, AWQ, GGUF, bitsandbytes), VRAM math, and the honest break-even wit…
- 55 Disaggregated serving (prefill/decode) Prefill is compute-bound, decode is memory-bound — yet a normal server runs both on the same GPU, where they fight. Disaggregated serving splits th…
- 56 Quantization A 70B model needs 140 GB in full precision and zero consumer GPUs can hold it. Quantize it to 4-bit and it fits in 40 GB — for a few points of accu…
- 57 GGUF & running LLMs locally Run LLMs on your own machine: understand GGUF, llama.cpp, quantization tiers, memory budgets, chat templates, and the failure modes that make local…
- 58 Choosing open-weight models: licences, lineage & residency How to pick an open-weight model for a company: what 'open weights' does and does not mean, how licences differ, why a model's base-model lineage m…
- 59 Distillation Quantization shrinks a model's weights. Distillation trains a brand-new, smaller model to copy a big one's behaviour — fewer layers, genuinely fast…
- 60 On-policy distillation Classic distillation trains the student on text the teacher wrote. On-policy distillation trains it on text the student wrote, graded by the teache…
- 61 Speculative Decoding LLMs generate one token at a time, which is slow. Speculative decoding lets a small model sprint ahead and a big model check its work in one shot —…
- 62 Test-time compute — buying accuracy at inference You can spend more compute at inference instead of more parameters at training. Sampling many answers, revising one answer, and searching with a ve…
- 63 Small language models and on-device inference How to choose, quantize, distil, evaluate, and run a small language model where a large one is wasteful.
- 64 Continuous batching and the inference scheduler How an in-flight scheduler keeps variable-length generations moving without turning KV memory and tail latency into surprises.
- Chapter 08
Systems Design at Scale
9 lessons - 65 Async vs sync — handling concurrency Why an LLM API serves 10,000 waiting requests on one thread — and when async helps, when it doesn't.
- 66 System design boundaries Choose correctly between stateless and stateful services, Lambda and ECS, databases and caches, queues and streams, retrieval and reranking, and mo…
- 67 Load balancing LLM inference One GPU replica can't serve 10,000 users. How to spread LLM traffic across replicas — and why round-robin is the wrong default.
- 68 Rate limiting & denial-of-wallet How to stop one client from running up a five-figure token bill on your inference API — the attack that targets your wallet, not your uptime.
- 69 Caching: exact, semantic & prompt Your embedding API keeps answering the same question. Three kinds of cache that cut LLM cost and latency — and the one that can silently return wro…
- 70 AI gateways When several applications call several model providers, an AI gateway gives them one controlled front door for routing, fallback, retries, budgets,…
- 71 Queues & batch pipelines 50,000 documents won't go through your summarization pipeline in one request. How queues, workers, retries, and backpressure get the job done.
- 72 Circuit breakers & resilience Your database (or model provider) goes down mid-query. How timeouts, retries, circuit breakers, and fallbacks stop one failure from taking down eve…
- 73 LLM serving ops An LLM endpoint is still a production service — but GB-sized weights, minutes-long cold starts, GPU scarcity, and token-based capacity break the us…
- End of section 0 / 73 complete
Make it stick — pass every quiz.
Each lesson has a short quiz at the bottom. Passing the quiz is what marks the lesson complete and counts toward your certificate.
Generative AI — frequently asked questions
Straight answers to the questions people ask most about generative ai.
What actually is a large language model?
An LLM is a neural network (a transformer) trained to predict the next token in text. From that single objective, at scale, it learns grammar, facts, reasoning patterns, and style, then generates by predicting one token at a time. It doesn't look things up — it produces statistically likely continuations.
What is RAG and why use it?
RAG (Retrieval-Augmented Generation) retrieves relevant documents and feeds them into the model's context so it answers from your data instead of only its training. It reduces hallucination, lets you use private or up-to-date information, and avoids the cost of retraining the model.
Read the lessonWhat do temperature, top-k, and top-p control?
They control randomness in generation. Temperature scales how sharply the model favors high-probability tokens — low is focused and near-deterministic, high is creative and riskier. Top-k and top-p (nucleus) limit sampling to the most likely tokens. Use low temperature for factual tasks, higher for brainstorming.
Read the lessonWhy does an LLM hallucinate, and how do I reduce it?
Because it generates plausible continuations rather than retrieving facts, it can state confident falsehoods, especially outside its training data. Reduce it by grounding answers with RAG, asking for citations, lowering temperature, and constraining the task — but you can't eliminate it, so verify critical outputs.
What's the difference between fine-tuning and RAG?
Fine-tuning adjusts the model's weights to change its style or specialise its behavior; RAG leaves the model unchanged and supplies knowledge at query time. Use RAG for facts that change or are private, and fine-tuning for consistent format, tone, or task behavior — they're often combined.