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
12 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 Sampling: temperature, top-k, top-p How the model actually picks the next token from its probability distribution, and when to use which sampling strategy in production.
- 04 Reasoning models & test-time compute o-series and R1-style models trade inference compute for accuracy by thinking longer before they answer. How test-time scaling works, when it's wor…
- 05 Structured outputs How to make an LLM emit valid JSON every time using Pydantic, JSON Schema, and constrained generation.
- 06 Constrained decoding How structured generation actually guarantees valid JSON — by masking illegal tokens at each decode step. The FSM/grammar trick behind XGrammar and…
- 07 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…
- 08 Multimodal (vision & audio) LLMs How a model 'sees': a vision encoder turns an image into patch tokens that flow into the LLM alongside text. Why images cost so many tokens, and th…
- 09 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…
- 10 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…
- 11 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…
- 12 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…
- Chapter 02
Prompting & Tools
3 lessons - 13 Prompt patterns that work Anthropic's priority-ordered prompt techniques — clarity, multishot, chain of thought, XML tags, document ordering, prefill, and prompt caching. Pl…
- 14 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.
- 15 Function/tool calling How LLMs invoke functions — the schema contract, the request/response loop, and the production patterns for tool use.
- Chapter 03
RAG & Adaptation
10 lessons - 16 Embeddings What an embedding actually IS — a point in semantic space. Distance metrics, dimensionality, and clustering short texts by meaning.
- 17 Sentence embeddings: SBERT Embeddings as vectors showed what a sentence vector is; this is how you get a good one. BERT's cross-encoder is accurate for pairs but too slow to…
- 18 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.
- 19 RAG basics Retrieval-augmented generation: chunk, embed, store, retrieve, generate. The single most important pattern for any LLM app that touches private data.
- 20 Chunking for RAG RAG retrieves chunks — but where do chunks come from? You have to split documents first, and how you split is one of the highest-leverage decisions…
- 21 Advanced RAG Contextual retrieval (Anthropic's 49% recall win) plus the supporting techniques — hybrid retrieval with RRF, query rewriting (HyDE, multi-query),…
- 22 Vectorless retrieval (PageIndex) Retrieval without embeddings — PageIndex turns a document into a tree the LLM reasons down. When it beats a vector database, and when it doesn't.
- 23 RAG evaluations How to actually measure RAG quality. Retrieval metrics (recall@k, MRR, hit rate) vs generation metrics (faithfulness, answer relevance, context pre…
- 24 Fine-tune vs RAG: the decision RAG adds knowledge; fine-tuning changes behavior. The decision framework every team gets wrong, what LoRA/QLoRA actually change, and why 'we need t…
- 25 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
Evaluation & Safety
11 lessons - 26 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…
- 27 Hallucination & grounding Why models hallucinate, and how to measure faithfulness for real — decompose an answer into atomic claims and check each against the source. The me…
- 28 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…
- 29 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…
- 30 Llama Guard: safety classification The guardrails lesson named an 'ML-classifier tier' for safety. Llama Guard is that tier, concretely — a dedicated LLM fine-tuned to classify conte…
- 31 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…
- 32 Red-teaming LLMs Safety training and guardrails are defenses — red-teaming is how you find out whether they hold, by attacking your own system before anyone else do…
- 33 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…
- 34 Watermarking AI content As machine-generated text and images flood the web, 'did an AI make this?' becomes a real question — for misinformation, academic integrity, and ke…
- 35 Differential privacy for LLMs LLMs memorize their training data — and can be coaxed into regurgitating verbatim secrets, PII, and copyrighted text. Differential privacy is the m…
- 36 Bias & fairness in LLMs Classical fairness is about a classifier's decisions — who gets the loan. LLMs add a second, language-shaped problem: they generate text, so they c…
- Chapter 05
Frontier safety
7 lessons - 37 Mesa-optimization & inner alignment Reward hacking is when your training objective is wrong. Mesa-optimization is subtler and scarier: even with a perfect objective, the trained model…
- 38 Evidence for deceptive alignment Mesa-optimization predicted deceptive alignment — a model that fakes alignment during training. Is it real? Recent empirical work says the failure…
- 39 AI control If a model might be deceptively misaligned and you can't be sure, alignment isn't the only lever. AI control takes a different tack: assume the mod…
- 40 Scalable oversight RLHF works because humans can judge model outputs. But how do you supervise a model smarter than the humans supervising it? You can't reliably eval…
- 41 Frontier safety frameworks How do labs decide a model is too dangerous to deploy — or even to keep training? Frontier safety frameworks turn that judgment into an if-then com…
- 42 Recursive self-improvement Self-improving agents get better at a task. Recursive self-improvement is the scarier idea: a system that improves its own ability to improve, so g…
- 43 Model welfare Every other safety topic asks whether AI is safe for us. Model welfare asks the inverted question: could an AI system itself be a moral patient — c…
- Chapter 06
Operations
11 lessons - 44 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…
- 45 KV cache offloading & memory tiers When the KV cache outgrows GPU VRAM, tier it across VRAM, CPU RAM, and SSD. Why the cache is working memory, and which tier to never use for live d…
- 46 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…
- 47 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…
- 48 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…
- 49 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…
- 50 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…
- 51 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…
- 52 GGUF & running LLMs locally Run LLMs on your own machine — the GGUF format, llama.cpp, and quantization tiers like Q4_K_M — with a tool that tells you which tier fits your RAM.
- 53 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…
- 54 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 —…
- Chapter 07
Systems Design at Scale
9 lessons - 55 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.
- 56 System design boundaries Choose correctly between stateless and stateful services, Lambda and ECS, databases and caches, queues and streams, retrieval and reranking, and mo…
- 57 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.
- 58 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.
- 59 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…
- 60 AI gateways The moment you call more than one model or provider, you have N SDKs, N auth schemes, N failure modes — and nowhere central for retries, rate limit…
- 61 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.
- 62 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…
- 63 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 / 63 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.