1 · Pretraining
Learn broad language patterns from next-token prediction over large text corpora.
Objective: predict the continuation.
Lesson 14 of 23 · LLM preliminaries capstone
Your win: follow token IDs to logits, separate architecture from training stages, and explain how pretraining, supervised fine-tuning, and generation use the same decoder.
| Stage | Shape | What changes |
|---|---|---|
| Token IDs | \([B,T]\) | Discrete vocabulary indices |
| Token embeddings | \([B,T,D]\) | Add one learned feature vector per token |
| \(N\) decoder blocks | \([B,T,D]\) | Build contextual representations while preserving the residual shape |
| Final normalization | \([B,T,D]\) | Rescale each token's features |
| LM head logits | \([B,T,V]\) | Score every vocabulary token at every position |
Learn broad language patterns from next-token prediction over large text corpora.
Objective: predict the continuation.
Continue next-token training on structured prompt-response demonstrations.
Objective: imitate useful responses.
Use preference data or rewards to favor responses judged more helpful and safe.
Objective: improve behavioral choices.
The model still produces next-token logits in every stage. What changes is the data, loss construction, or optimization procedure.
Forward all positions, compare \([B,T,V]\) logits with shifted targets, backpropagate the loss, update weights.
Forward the visible context, read final-position logits, sample one ID, append it, repeat without updating weights.
This is the outer structure completed by the code checkpoints in Module 3. Lesson 23 assembles the pieces and then maps the readable block toward MiniMind's production contract.
def forward(self, token_ids):
x = self.token_embedding(token_ids) # [B, T] -> [B, T, D]
for block in self.layers:
x = block(x) # [B, T, D] -> [B, T, D]
x = self.final_norm(x) # [B, T, D]
logits = self.lm_head(x) # [B, T, D] -> [B, T, V]
return logitsTrace it: Which operation changes the final axis from \(D\) to \(V\)?
Where do next-token vocabulary logits first appear?