Everything from the ten parts on one page. Each heading links to the part’s first deck.
- Dot product: a⋅b=∑iaibi=∥a∥∥b∥cosθ
- Norm: ∥a∥=a⋅a; cosine: cosθ=∥a∥∥b∥a⋅b
- Random directions in d dimensions: cosθ≈0±1/d
- Unit-variance entries: q⋅k has standard deviation dk
- Shapes: (m×k)(k×n)=m×n; inner sizes must match
- (AB)ij=Ai,:⋅B:,j; AB = sum of k outer products A:,kBk,:
- (AB)⊤=B⊤A⊤; AB=BA in general
- Cost: 2mkn FLOPs; group products so the vectors stay vectors
* is elementwise (⊙), @ is the matrix product
- Column j of M is where ej lands
- Rotation: [cosθsinθ−sinθcosθ], R⊤R=I
- det = area scale; det=0 ⇔ not invertible ⇔ a non-zero null space
- rank(uv⊤)=1; rank(AB)≤min(rankA,rankB)
- Projection onto unit u: (x⋅u)u, matrix uu⊤
- Broadcasting: align from the right; each axis equal or 1
view keeps memory order; split heads with view(B, T, h, d_h).transpose(1, 2)
- Reductions remove the axis;
keepdim=True keeps it as size 1
einsum('bhqd,bhkd->bhqk', q, k) = QK⊤ per batch and head
-
softmax(z)i=ezi−maxz/∑jezj−maxz
- Attn=softmax(dkQK⊤+mask)V; mask −∞ above the diagonal; softmax along rows
- Heads: h⋅dh=d; GQA shares each K/V head across h/hkv query heads
- KV cache: 2⋅L⋅hkv⋅dh⋅bytes per token
nn.Linear(i, o): weight (o,i), y=xW⊤+b
- Block: x+=Attn(norm(x)), then x+=MLP(norm(x))
- RMSNorm: x/rms(x)⊙g, no mean-centering, no bias
- SwiGLU: (SiLU(xWg)⊙xWu)Wd, 3ddff parameters
- RoPE: rotate pair i by pθi, θi=b−2i/dh; scores depend on p−q
- Classic block: 12d2 parameters; forward ≈ 2N FLOPs per token
- Av=λv; symmetric ⇒ real λ, orthogonal eigenvectors
- SVD: A=UΣV⊤=∑iσiuivi⊤; σi2 = eigenvalues of A⊤A
- Best rank-r: keep the top r terms; error σr+12+… (Frobenius)
- LoRA: W0+rαBA, r(din+dout) parameters, B=0 at init
- Spectral norm ∥A∥2=σ1; condition number σ1/σn
- A gradient has its parameter’s shape; descent: w←w−η∂L/∂w
- Y=XW: ∂L/∂W=X⊤G, ∂L/∂X=GW⊤; bias: sum G’s rows
- Softmax + cross-entropy: ∂L/∂z=p−onehot(y)
- Training ≈ 6ND FLOPs; Adam in mixed precision ≈ 16 bytes per parameter
- Bytes: FP32 4, BF16 2, FP8 and INT8 1, INT4 ½; BF16 has FP32’s range
- Intensity I = FLOPs / bytes; matrix × vector I≈1, batch B gives I≈B
- Decode ≤ bandwidth / bytes per token; prefill ≈ 2NT+4LT2d
- INT8: s=max∣x∣/127, q=round(x/s), error ≤s/2
- Online softmax: ℓ′=ℓem−m′+∑ezj−m′