Equation sheet¶
Every equation is a shape contract. Symbols: batch \(B\), sequence \(T\), residual width \(C\), heads \(H\), head width \(D=C/H\), vocabulary \(V\), experts \(E\), selected experts \(K\).
Embedding¶
Layer normalization and RMS normalization¶
Scaled dot-product attention¶
Per head: [B,T,D] @ [B,D,T] -> [B,T,T]; then [B,T,T] @ [B,T,D] -> [B,T,D]. Causal mask \(M_{ij}=-\infty\) when key position \(j\) is in the future of query \(i\).
SwiGLU feed-forward¶
The transformation expands from \(C\) to hidden width \(F\), gates elementwise, then projects back to \(C\).
Pre-normalized residual block¶
Next-token cross-entropy¶
Perplexity under the same tokenization and loss convention:
Do not compare perplexity directly across different tokenizers without careful normalization.
MoE routing¶
Router logits and probabilities for token vector \(x\):
Let \(S=\operatorname{TopK}(p,K)\). Renormalized combine weight for selected expert \(e\):
Sparse FFN output:
A simple expected capacity per expert for \(N\) token vectors is:
Actual implementations differ in grouping, capacity, padding, token dropping, and routing objective.
AdamW sketch¶
With bias-corrected moments \(\hat m_t,\hat v_t\), a simplified decoupled weight-decay update is:
Sampling temperature¶
As \(\tau\) decreases above zero, the distribution sharpens. \(\tau=0\) is implemented as a special greedy case, not literal division.
KV-cache size approximation¶
For \(L\) layers, batch \(B\), cached length \(T\), key/value heads \(H_{kv}\), head width \(D\), and \(s\) bytes per element:
Allocator metadata, block rounding, prefixes, and parallel placement add implementation-specific overhead.