Skip to main content

LLM Mental Model

Most discussions about LLMs focus on prompts, tools, and frameworks. However, few explain how the model actually works under the hood and why that matters when building real systems.

This is a 20,000-ft view of the LLM lifecycle in four stages.

The big picture: one model, four stages.

A model's whole life is just four stages. The shape and vocabulary are fixed first; training only fills in the values, and inference is read-only and never learns.


StageWhat happensKey ideas
BeforeDecide the blueprintArchitecture dials set the shape, tokenizer builds the vocabulary, and parameter count is fixed.
DuringFill in the valuesRandom weights become meaningful through training: a four-step loop run millions or trillions of times.
AlignmentMake it helpfulShow good examples (SFT) and teach which answers are better (RLHF/DPO).
AfterRun it, read-onlyWeights are frozen (no learning); inference traverses the model geometry one token at a time.
TAKEAWAY

Shape + vocabulary are fixed first. Training only fills the values. Inference never learns.

Stage 1 - Before training

Two human decisions are baked in before any gradient is computed.

  • Architecture dials - hidden size, layers, heads, FFN width, vocab size.
  • Tokenizer vocabulary - the integer alphabet the model reads and writes.

A "7B" model is 7B because of these dials — training never grows it, and most parameters live in the FFN, not attention.

The Architecture dials

HyperparameterExampleDescription
hidden_size(D)4096How much "thinking space" the model has for each word or idea at a given moment.
num_layers(L)32How many rounds of refinement - 32 editors in a row.
num_heads(H)32A panel of specialists, each spotting a different pattern.
head_dim(D_h)128The size of each specialist's notebook.
ffn_hidden(D_ff)16,384The knowledge bank — where most facts are stored (~4*D).
vocab_size(V)32000The size of the model's dictionary—the building blocks it uses to read and write language.
TAKEAWAY

The model is fully sized and described before it sees a single token.

Stage 2 - During training

Learning is one four-step loop, repeated hundreds of thousands to millions of times.

  1. Forward Pass - Predicts what comes next in a sequence, based on previous tokens.
  2. Loss - How wrong was our prediction?
  3. Backpropagation - Calculate how much, and how each weight contributed to the error.
  4. Optimizer step - Update every weight, slightly adjusting each weigh.
note

The only thing learned here is the next-token prediction — the statistical relationship between tokens given their surrounding context. Pre-training delivers languages and knowledge; it does not shape behavior (following instructions, being helpful, staying safe). No behavior is learned at this stage — that comes later, in alignment.

From random numbers to learned meaning

Before training (random)After training (meaning)
Every weight is a random numberEvery weight holds a learned value
Output is gibberishOutput is fluent, coherent text
No grammar, facts, or reasoningGrammar, facts, and reasoning emerge
Structure exists, meaning doesn'tSame structure — now full of meaning
TAKEAWAY

Learning is the same four-step loop, running hundreds of thousands to millions of times, turning random numbers into meaning.

The roles that emerge after training

Components start as random numbers with no predefined purpose. After millions or billions of training steps, gradient descent gradually shapes them into specialized roles—learned through experience, not explicitly designed.

ComponentRole it settles into
EmbeddingsWhat tokens mean (lexical meaning)
AttentionHow tokens relate — routes relevant context
FFNsTransformation / "thinking" — most parameters and reasoning
LayerNormKeep signals stable and usable
Depth (layers)Progressive refinement of understanding
TAKEAWAY

No one designs these roles; training gradually turns them into specialist roles through learning rather than design.

Stage 3 - Alignment

A raw pre-trained model is a brilliant autocomplete, not yet a helpful assistant. Alignment is a thin, cheap layer on top of pre-training that shapes behavior.

Main trainingPolish (alignment)
DataTrillions of wordsThousands to millions of examples
Length (cost)Weeks/months, huge costShort, cheap
What it doesTeaches knowledgeShapes behavior
  • SFT - show it good (prompt, response) examples.
  • RLHF/DPO - teach it which answer is better.
TAKEAWAY

Alignment turns a raw model into a helpful assistant — it shapes behavior; it doesn't add new knowledge.

Stage 4 - After training

Once training stops, weights are frozen — no learning, no gradients. The model is a fixed function f(tokens) -> next token probabilities.

During inference, the model has no memory of what was asked or answered before — each request starts fresh.

TAKEAWAY

Training builds the geometry. Inference just navigates it one token at a time. Treat the LLM as frozen dependency; engineer everything else around it.