Neural Mastery

LLMs & GenAI Overview

This is where the Transformer architecture from Deep Learning turns into systems like GPT, Claude, and LLaMA: how they're built internally, how they're trained to be helpful and aligned, how to prompt and ground them effectively, and how to serve them efficiently in production.

The Pipeline, End to End

A frontier LLM isn't the output of one training run — it's the end of a pipeline where each stage does a distinct job, and each stage is its own page in this section:

ArchitectureFoundation Model InternalsPretrainTraining PipelinePost-trainTraining PipelineExtendPrompt Eng. / RAGServeEvaluation & Serving
Click a stage. Everything from "extend" onward runs with weights already frozen.
Architecture (Foundation Model Internals): tokenization, attention, MoE, sampling -- the machinery that makes the model run at all

Foundation Model Internals covers the architecture that makes the model run at all (tokenization, attention variants, MoE, sampling). Training Pipeline covers turning that architecture into weights, in two very different phases: pretraining (learn language and world knowledge from raw text, self-supervised) and post-training (SFT, RLHF, DPO, GRPO — turn a raw next-token predictor into something that follows instructions and reflects human preferences). Everything after that — Prompt Engineering, RAG — happens with the weights already frozen.

Capability, Cost, and Latency Are Always in Tension

Before any of the pipeline stages, one axis shapes almost every downstream decision: bigger models are more capable, and also slower and more expensive to serve, with no free point in that space:

cost / request →capability →Small (7-8B)Mid (30-70B)Frontier (400B+)
Dot size = latency. Click a model — there's no free point in this space, only which axis you're willing to trade.
Mid (30-70B): capability 78%, cost 45% of frontier, latency 45% of frontier (dot size).

This is the same tension ML System Design covers in general terms, specialized to LLMs specifically — and it's why model-size selection is one of the highest-leverage decisions in Evaluation & Serving.

Two Ways to Change What a Model Does

A recurring decision in this whole section: does changing the model's behavior require touching its weights, or not?

Weights stay frozen
Weights get updated
Zero/few-shot prompting
Chain-of-thought
RAG (retrieval)
Tool use / agents
Click a lane to compare its techniques.
Zero training cost, instantly reversible, limited by what fits in a context window -- the default first move.

Prompting, RAG, and tool use all operate entirely at inference time — zero training cost, instantly reversible, limited by what fits in a context window. Fine-tuning (full or PEFT — LoRA, QLoRA, DoRA) actually updates weights — more durable behavior change, but real training cost, and a new artifact to version and serve. In practice, most production systems reach for the frozen-weights options first (they're cheaper to iterate on and to roll back) and only fine-tune once prompting/RAG have demonstrably hit a ceiling.

Why Post-Training Exists at All

Pretraining alone produces a model that continues text plausibly, not one that's reliably helpful — post-training is specifically the fix for that gap:

Pretrained+ SFT+ RLHF/DPO/GRPO
Click a stage — each fixes what the one before it left unsolved.
Gives: Learns from comparisons, not just examples. Still missing before this stage: Reward hacking risk -- must be actively guarded against

Each stage narrows a specific failure of the one before it: SFT teaches the format of being a helpful assistant (answer directly, follow instructions) from curated examples; RLHF/DPO/GRPO then teach preference — which of several acceptable responses is actually better — from comparison data, since "better" is much harder to specify with direct examples than "correct." Training Pipeline covers every stage's mechanics in full, including the newer, cheaper alternatives to full RLHF.

Why Scale Works (And Why It's Not Free)

Pretraining loss falls predictably as model size and data scale up together — a real, measured empirical relationship, not a hand-wave:

pretraining losslog10(compute) →
loss ≈ 2.48 · compute-optimal split ≈ 2.9e+0 params × 5.8e+1 tokens
Loss falls as a smooth power law in compute -- precise enough to extrapolate a training run's expected final loss before running it at full scale. Chinchilla's finding: at any point on this curve, compute-optimal training keeps tokens-per-parameter fixed (~20:1), so a bigger compute budget means a bigger model AND proportionally more data, not one or the other.

The Chinchilla result (covered in depth in Training Pipeline) showed that for a fixed compute budget, model size and training data need to scale together — a smaller model trained compute-optimally on more data beats a larger, undertrained one at the same cost. But scale isn't free at the other end either:

one-time training costdays since launch →
cumulative inference cost overtakes training cost after ~10000 days
At high enough request volume, cumulative inference cost overtakes the one-time training cost within weeks, not years -- which is exactly why Evaluation & Serving invests so heavily in batching, speculative decoding, and Paged Attention: shaving a few percent off per-request cost compounds across every request, forever.

Training is a large one-time cost; inference is a recurring cost paid on every single request, forever — which is exactly why Evaluation & Serving devotes so much attention to batching, speculative decoding, and Paged Attention. At scale, the aggregate cost of serving a model typically dwarfs the one-time cost of training it.

Evaluation Runs Through Every Stage, Not Just the End

"Does this model work" isn't one question asked once at the end — it's asked differently at every stage:

Pretraining
Loss curve, perplexity
Post-training
Reward-model score, preference accuracy
Serving (live)
Benchmarks, LLM-as-judge, online metrics
Click a stage. Same underlying question ("is this good?") answered with a different tool each time.
Serving (live) asks: "Does it actually satisfy real users, in production?" — measured via: Benchmarks, LLM-as-judge, online metrics.

Perplexity and loss curves during pretraining, preference-model accuracy during RLHF, benchmark suites and LLM-as-judge once serving — see Evaluation & Serving for the serving-time methods, and treat any of them the way ML System Design treats an offline metric: a proxy to validate, not a guarantee.

One Architecture, Many Modalities

Attention doesn't care whether a token represents a word or an image patch — the same mechanism generalizes with only the input embedding changed:

Text input
Image input
BPE tokensembedding lookupTransformerblocks(identicaleither way)
Toggle modality — only the box before the Transformer changes.
Text: a BPE tokenizer splits text into subword tokens, each looked up in an embedding table.

Multimodal & Generative Models covers what changes when the modality isn't text: vision-language models, VLAs for robotics, and diffusion models as the dominant non-autoregressive alternative for images.

From Answering to Acting

RAG is the natural end of "extend the model without retraining it" — but it's still one retrieval-then-generate pass. The next step past that is deciding, autonomously, whether and how to act:

Base promptingRAGTool useAgents
Click a level — each adds autonomy the one before it didn't have.
Multi-step: reason, act, observe, repeat autonomously -- decides *whether* and *how many times* to act.

That's where this section hands off to Agents — tool use, multi-step planning, and multi-agent coordination, all still built on the same frozen-or-fine-tuned model this section covers.

How This Section Fits Together

Foundation Model Internals
Training Pipeline
Prompt Engineering
RAG
Evaluation & Serving
Multimodal & Generative
Click a page for what it actually covers.
Training Pipeline: How weights are produced: pretraining, then SFT/RLHF/DPO/GRPO, PEFT.

Follow the roadmap for the full ordered path, or jump straight to a topic:

Last updated Sep 5, 2026Edit this pageReport an issue
← Previous
Speech & Audio Tasks
Next →
LLMs & GenAI — Roadmap