A ten-part series, written from first principles

Deep Learning
from the Inside Out

I take modern language models apart — the transformer, BERT, GPT-2, T5, and LLaMA — down to their weight matrices, tensor shapes, and FLOP counts. Every claim here is one you can check with arithmetic.

Written from the presentations and the CS199 independent study I did at UC Berkeley EECS in 2023, surveying eleven papers from Attention Is All You Need through GPT-4.

Hiva Mohammadzadeh  ·  Stanford MSCS, UC Berkeley EECS

one transformer block self-attention feed-forward add & norm add & norm tokens richer ×N
stack N of these — that’s the whole model

Contents

Foundations

four
00
The Transformer: where attention replaced recurrence

Self-attention and multi-head attention from first principles, and the three model families every LLM descends from. Attention Is All You Need.

01
A survey of activation functions

The nonlinearities that let a network learn curves, from sigmoid and tanh to ReLU, GeLU, and Swish. Derivatives and smoothness.

02
Normalization, from BatchNorm to RMSNorm

Why activations drift during training, and how each normalizer fixes it. Batch, Layer, Group, RMS.

07
GLUE and SuperGLUE: measuring understanding

The benchmarks that defined the field, task by task, with real examples and metrics. 17 tasks.

Model architectures

four
03
BERT: an encoder that reads both directions

The full data path with exact tensor shapes and a FLOP count per block. 12 blocks, 768-dim, 1.86B FLOPs.

04
GPT-2: a decoder that writes one token at a time

The causal mask, the computation diagram, and how its FLOPs compare to BERT. Autoregressive.

05
T5: encoder and decoder, joined by cross-attention

Encoder self-attention, decoder masked attention, and the cross-attention bridge. Text-to-text.

06
LLaMA: smaller models, more data, three sharp ideas

RMSNorm, SwiGLU, and rotary embeddings, traced through the forward pass. 7B to 65B.

Techniques

two
08
Prompt tuning: from fine-tuning to chain-of-thought

Soft prompts, prefix tuning, and CoT, ending with MedPrompt at 90.2% on medical QA. Parameter-efficient.

09
Scaling: from GPT-3 to GPT-4

What changes from millions to hundreds of billions of parameters: few-shot, multimodality, risk. GPT-3, PaLM, GPT-4.