Note
This is not a complete notes for chapters, but mostly prompted by working on things inside the chapter
History
Google birthed transformers in 2017
- Its application on BERT led to unprecendented natural language generation results
New backbone of deep learning
LLM vs Multimodel models
Autoregression already existed (i.e. LSTM, etc)
GPT 1
- Decoder only transformers on wikipedia text
GPT 2
- If you train on the right data, you get implicit multitask learning - i.e. the model understands multiple types of tasks, you just need the right adapters for them
GPT 3
- The task can just be provided or described in the same token stream and the model will handle the rest
Terminology

Context (for chatgbots, etc)
- Typically composed of system prompt, user input, toens already generated by the model
Feed forward network
Architecture
- Typically when ML practitioners refer to architecture, they mean coarsely to i.e.
- decoder only transformer
- 32 layers
- residual with 4096
- etc
- Typically when ML practitioners refer to architecture, they mean coarsely to i.e.
Parameterization
- i.e. is weight stored directly as W or UV?
- is positive scalr stored directly or as
- is weight vector stored directly or as magnitude times normalized direction?
- Are input/output embeddings separate or tied?
- is a residual branch represented as F(x) or alpha F(x) with learned alpha?
- Are attention projections independent, shared, or low rank?
Encoding
- extremely overloaded term
- Meaning 1:
- Encoding text
- string -> token IDs
- Meaning 2:
- Transformer encoder
- refers to the "neural net encoder" part of the original transformer paper
- Mapped ENTIRE SEQUENCE to contextual representations Z
- Decoder then generated target sequence one symbol at a time using both
- target tokens generated so far and
- encoder's output Z
- Decoder then generated target sequence one symbol at a time using both
Embedding
- token IDs -> embedding vectors
Positional encoding
- position -> numerical positional information
Contextual encoding
- hiddent vectors come to represent the surrounding prefix
Transformer encoder
- a particular noncausal source proceeing architecture
Decoding
- unfortunately, also overloaded term. Can mean
- choosing tokens from model probabilities
- converting token ids back to text
- or operating target side network of an encoder decoder architecture
Numbers
- LLM
- Billions to trillions of parameters
Example
- Why just K and V? why not Q?
- Let's walk through what happens when

Architecture
Attention
- To some extent resembles a classificaiton process within a neurla net
- Generate probabilities with softmax
- Indication of relative importance
- To some extent resembles a classificaiton process within a neurla net
Types of tasks
- Transformers that perform discriminative rather than generative tasks do not need a decoder
- They do not need to generate anything and auto regress on itself
- Decod
- Transformers that perform discriminative rather than generative tasks do not need a decoder
Things that affect model architecture
- Hard information constraints
- i.e. causal mask
- h_t can only depend on 1,...,t
- i.e. causal mask
- How much memory/compute is needed to learn something
- Worth noting that two parameterizations with exact same represented function class can train differently:
i.e.
But consider what happens to in the factorized case
- and
- This means in the factorized case,
- Note the above does NOT equal
- Also the initial distributions, optimizers, normalization, regularization, parameterization can all affect resultant fits
- On a first order, useful architectures make the desired regularities relatively cheap and undesirable memorization or patterns expensive
- Hard information constraints
for
- Note Input and Output of each block has the same shape, but within each block
- There is cross-N contamination (causal) in N
- MLP mixes across D
- Residual stream carries exact same info across
Note that have the same shape. The difference in their function is only determined by the differences in weight
Unembedding
- Turning embedding back into text
Rough architecture of a GPU
HBM stacks
│
HBM PHYs/controllers
│
physically sliced L2
│
on-chip fabric / crossbar
│
GPU Processing Clusters
│
┌─────────────┴─────────────┐
│ │
SM SM
┌────────────────┐ ┌────────────────┐
│ warp schedulers│ │ warp schedulers│
│ register files │ │ register files │
│ Tensor Cores │ │ Tensor Cores │
│ FP/INT ALUs │ │ FP/INT ALUs │
│ LSU / SFU │ │ LSU / SFU │
│ L1/shared SRAM │ │ L1/shared SRAM │
│ barriers/TMA │ │ barriers/TMA │
└────────────────┘ └────────────────┘Rough architecture of a TPU
HBM
│
asynchronous DMA
│
┌───────────┴───────────┐
│ │
VMEM SMEM
vector SRAM scalar SRAM
│ │
VREG SREG
│ │
┌──────┼──────────┐ │
│ │ │ │
MXU VPU XLU scalar unit
matmul vector transpose/ control,
permutation addressesSemantic interpretation
- For head
h, how important is token at source position when updating ?
- For head
Softmax
Each 's row is a token position.
Each 's column is a token position
Dotting 's 'th row with 's 'th column gives
- Can see it's i for j because in the mask

- Softwax over each row -> (semantically probability) coefficients for position for
- The element at in is semantically seen as the logit
- is subtracted from to prevent overflow. Both numerator and denominator so it cancels out
- i.e.
- Multiply by
- Interpreted as each row in :
- for row ,
- for column
- Add times 's 'th row to
- for column
- for row ,
- Interpreted as each row in :
is the output
Note in reality there is a sacling factor of
Numbers
Indices
- (TOKEN POSITION)
- (HIDDEN DIMENSION POSITION)
- (HEAD, AXIS)
- Attention matrix - one for each head
Dimensions
Note, if batches exist, typically do
- l - depth l circuit
- B - independent sequences in the batch
- N - token positions in each sequence
- D - - feature channels carried by each token
- Block interfaces keep the same shape