Transformer Math & CPU SLM

Transformer Math & CPU SLM

Linear algebra, attention math, training, CPU inference, weight storage — depth-first.

383Articles
383Topics covered
Articles in this category

All 383 articles, sorted alphabetically

Advertisement
ARTICLE · 001

The Autoregressive Generation Loop

How a language model actually produces text: the autoregressive factorization p(sequence) = prod p(x_t | x_<t), the two phases of infer…

Read article →
ARTICLE · 002

Backpropagation Through Transformers

How backpropagation and the chain rule train transformers: forward vs backward pass, the chain rule for composed functions, the vector-Jacobian-produc…

Read article →
ARTICLE · 003

Beam Search

The mathematics of beam search decoding: approximate search for the highest-probability sequence, accumulating log-probabilities along beams, beam wid…

Read article →
ARTICLE · 004

The Complete Transformer Block

How a complete pre-norm transformer block composes attention, a feed-forward network, two residual connections, and two normalizations end to end: the…

Read article →
ARTICLE · 005

CPU Cache Hierarchy and Transformer Inference

How the CPU memory hierarchy -- registers, L1, L2, L3, and DRAM -- decides small-language-model inference speed on a CPU. Latency and bandwidth for ea…

Read article →
ARTICLE · 006

CPU Inference Pipelines

The end-to-end CPU serving path for LLMs and small language models: tokenize, prefill, the autoregressive decode loop, and detokenize. Why prefill is …

Read article →
ARTICLE · 007

CPU Matmul Kernels and BLAS

How a fast CPU matmul (GEMM) is really built: why GEMM is the transformer workhorse, the naive triple loop and its cache-miss problem, loop reordering…

Read article →
ARTICLE · 008

CPU Memory Budget for SLM Training

A full accounting of the CPU RAM budget for running a small language model: model weights (params x bytes by precision), the KV cache (2 x L x n_kv x …

Read article →
ARTICLE · 009

Cross-Entropy Loss for Next-Token Prediction

Cross-entropy loss for language modeling from first principles: maximum likelihood and negative log-likelihood, the one-hot target and -log p(correct …

Read article →
ARTICLE · 010

Dataloader and Tokenization Pipeline

How the data loading and tokenization pipeline feeds a language model: raw text to tokens, document packing with separators into fixed-length sequence…

Read article →
ARTICLE · 011

The Geometry of Dot Products

The geometry of the dot product and why attention is built on it: the dot product as projection and as similarity, the a·b = |a||b|…

Read article →
ARTICLE · 012

End-to-End CPU SLM Recipe

A single worked recipe that ties the whole series together: build and run a ~100M-parameter small language model destined for CPU inference. Pick an a…

Read article →
ARTICLE · 013

Feed-Forward Network

A first-principles deep-dive on the position-wise feed-forward network (FFN/MLP) in a transformer block: the two linear layers with a 4x expansion fac…

Read article →
ARTICLE · 014

Fine-Tuning Math

The math of fine-tuning: the memory ledger of full fine-tuning (weights + gradients + optimizer states = ~16 bytes/param for Adam in fp32), why that c…

Read article →
ARTICLE · 015

FlashAttention

A first-principles walk through FlashAttention: the IO-aware, tiled attention algorithm, online (streaming) softmax with a running max and running nor…

Read article →
ARTICLE · 016

Gradient Accumulation and Microbatches

How gradient accumulation simulates a large effective batch on limited memory by summing gradients over K microbatches before an optimizer step: the e…

Read article →
ARTICLE · 017

Gradient Clipping and Training Stability

Gradient clipping and training stability from first principles: why gradients explode and loss spikes appear, global-norm clipping (scale g by min(1, …

Read article →
ARTICLE · 018

KV Cache

The exact math of the transformer KV cache: why autoregressive decode would recompute every past key and value without it, what the cache stores, the …

Read article →
ARTICLE · 019

KV Cache Quantization

A deep dive on KV cache quantization: why the stored keys and values dominate long-context decode memory, the bytes-per-token math and how it scales w…

Read article →
ARTICLE · 020

LayerNorm

The math of layer normalization: normalizing across the feature dimension per token, the mean and variance, (x - mu)/sqrt(sigma^2 + epsilon), the lear…

Read article →
ARTICLE · 021

Learning Rate Schedules

A first-principles deep dive on learning-rate schedules for training transformers: why a constant learning rate fails, linear warmup and why it stabil…

Read article →
ARTICLE · 022

Linear Algebra for Transformers

The linear algebra that underlies transformers, from first principles: vectors and matrices, matrix multiplication as the workhorse operation, dot pro…

Read article →
ARTICLE · 023

Long Context Strategies

A taxonomy of long-context strategies with the complexity math for each: the two costs that explode with sequence length -- O(N^2) attention compute a…

Read article →
ARTICLE · 024

Diagnosing Loss Curves

A practical guide to reading training and validation loss curves: the healthy power-law decay shape, learning-rate-too-high divergence and NaN spikes,…

Read article →
ARTICLE · 025

Mixed Precision Training

A first-principles deep dive on mixed-precision training: the FP32, FP16, and BF16 bit layouts, the exponent-vs-mantissa (range-vs-precision) trade, w…

Read article →
ARTICLE · 026

Mixture of Experts

The math of Mixture-of-Experts: replacing a dense FFN with N experts and a softmax router, top-k sparse activation, the decoupling of total parameters…

Read article →
ARTICLE · 027

Multi-Head Attention

The math of multi-head attention: why multiple heads give the model different representation subspaces, splitting d_model into h heads of size d_k = d…

Read article →
ARTICLE · 028

Multi-Token Prediction (MTP)

A deep dive on multi-token prediction (MTP): predicting several future tokens per position instead of one, multiple prediction heads sharing a trunk, …

Read article →
ARTICLE · 029

Output Projection and Logits

How a transformer turns its final hidden state into next-token probabilities: the output projection (unembedding / LM head) mapping d_model to vocab, …

Read article →
ARTICLE · 030

Perplexity and Evaluation Metrics

A first-principles deep dive on perplexity and language-model evaluation: perplexity as exp(cross-entropy), the branching-factor intuition, a fully wo…

Read article →
ARTICLE · 031

Positional Encoding

The math of positional encoding: why self-attention is permutation-equivariant and order-blind, the original sinusoidal encoding and its 10000^(2i/d) …

Read article →
ARTICLE · 032

Quantization Layouts in Memory

How quantized transformer weights are actually laid out in memory: the affine quantization map q = round(x/scale) + zero_point, symmetric vs asymmetri…

Read article →
ARTICLE · 033

Residual Connections and Gradient Flow

The math of residual connections in transformers: the y = x + F(x) skip, why it creates a gradient highway (dL/dx = dL/dy (1 + F')), …

Read article →
ARTICLE · 034

RLHF and DPO

The math of RLHF and DPO: preference data and the Bradley-Terry model, learning a reward model, the KL-constrained reward-maximization objective and i…

Read article →
ARTICLE · 035

RMSNorm

The math of RMSNorm: normalizing a vector by its root-mean-square only, with no mean subtraction and no bias — y_i = x_i / sqrt(mean…

Read article →
ARTICLE · 036

Extending RoPE to Longer Contexts

How to extend a RoPE model's context window: a brief recap of rotary position embedding (rotating Q/K by position-dependent angles), …

Read article →
ARTICLE · 037

Sampling Strategies

The math of sampling from a language model: how logits become a probability distribution via softmax, greedy/argmax decoding, temperature scaling and …

Read article →
ARTICLE · 038

Scaled Dot-Product Attention

Scaled dot-product attention from first principles: how Q, K, and V are projected from the input, the QK^T score matrix, why we divide by sqrt(d_k) (t…

Read article →
ARTICLE · 039

SGD vs Adam vs AdamW Optimizer Math

A first-principles walk through optimizer math: plain SGD, momentum as an exponential moving average of gradients, RMSProp as an EMA of squared gradie…

Read article →
ARTICLE · 040

SIMD Instructions for Transformer Math

How SIMD vectorization speeds up transformer kernels on the CPU: one instruction over many lanes, AVX2/AVX-512 (8/16 fp32 lanes) and ARM NEON, how the…

Read article →
ARTICLE · 041

SLM Architectures

A deep dive comparing modern small language model architectures across the design axes that actually differentiate them: depth vs width, attention var…

Read article →
ARTICLE · 042

Softmax Derivation

Deriving softmax from first principles: turning a vector of logits into a positive normalized probability distribution, why the exponential is the rig…

Read article →
ARTICLE · 043

Speculative Decoding

The math of speculative decoding: a small draft model proposes k tokens, the large target verifies them in one parallel forward pass, and modified rej…

Read article →
ARTICLE · 044

The Future of CPU SLM in 2026 and Beyond

Why CPU-based small language models are becoming genuinely viable: sub-4-bit and QAT quantization, stronger small models from over-training and distil…

Read article →
ARTICLE · 045

Tied Embeddings and Parameter Sharing

How weight tying shares the input embedding matrix with the output projection: the parameter savings (one vocab x d_model matrix instead of two), the …

Read article →
ARTICLE · 046

3D Parallelism

How data, tensor, and pipeline parallelism combine to train giant models: the N = DP x TP x PP factorization of the GPU count, the standard placement …

Read article →
ARTICLE · 047

Ablation Study Math

The math behind ablation studies in LLM research: treatment effects, compute- and parameter-matched controls, seed variance and standard error, confid…

Read article →
ARTICLE · 048

Beyond ReLU

GeLU, SiLU, and SwiGLU compared from first principles: exact formulas and derivatives, why smooth and gated activations beat ReLU in transformers, the…

Read article →
ARTICLE · 049

Activation checkpointing architecture

Deep-dive on activation (gradient) checkpointing: why activations dominate training memory, how the forward pass saves only segment boundaries and dro…

Read article →
ARTICLE · 050

Activation Memory Math

How to count activation memory in a transformer from first principles: which tensors autograd must save and why, the per-layer 34sbh + 5as^2b accounti…

Read article →
ARTICLE · 051

Activation Patching

Activation patching from first principles: the clean/corrupted two-prompt setup, the intervention written as math, logit-difference and normalized-rec…

Read article →
ARTICLE · 052

Activation Quantization

Why activations are harder to quantize than weights: per-input dynamic range, outlier channels and tokens, static vs dynamic quantization, per-tensor …

Read article →
ARTICLE · 053

Activation Recomputation Math

The math of activation recomputation in transformer training: the 34sbh + 5as^2b activation-memory formula, the one-third FLOPs overhead of full recom…

Read article →
ARTICLE · 054

Activation Scaling

How activation variance propagates through a transformer: the fan-in variance identity, Xavier and He init, why the residual stream accumulates varian…

Read article →
ARTICLE · 055

Adafactor

Adafactor from first principles: why Adam's second moment costs a full extra copy of the model, how a rank-1 factorization under the …

Read article →
ARTICLE · 056

Adam and AdamW -- the optimizer that trains transformers

Deep-dive on Adam and AdamW: the single-learning-rate limitation, momentum (first moment, smoothed gradient), adaptive per-parameter scaling (second m…

Read article →
ARTICLE · 057

AdamW Math Deep Dive

The math of AdamW: why L2 regularization in the gradient and weight decay on the weights are the same thing under SGD but provably different under Ada…

Read article →
ARTICLE · 058

Adapter Theory

The math of bottleneck adapters for parameter-efficient fine-tuning: the down-project / nonlinearity / up-project structure, near-identity initializat…

Read article →
ARTICLE · 059

Adaptive RAG

Adaptive RAG explained from first principles: deciding whether to retrieve at all, routing queries by predicted complexity into no-retrieval, single-s…

Read article →
ARTICLE · 060

Admission Control Math

The math of admission control for LLM serving: Little's law, M/M/1 latency blowup near saturation, why token-length variance makes LL…

Read article →
ARTICLE · 061

Agent Scaling Laws

How LLM agent capability scales: the geometric horizon model S(H) = p^H, why per-step error compounds, the H_50 task-horizon metric and its doubling t…

Read article →
ARTICLE · 062

ALiBi

How ALiBi (Attention with Linear Biases) encodes position by adding a linear, head-specific distance penalty to the raw attention scores instead of us…

Read article →
ARTICLE · 063

Alignment Tax Math

The alignment tax: the capability-benchmark regression that can accompany RLHF, why it happens (KL drift from the pretrained distribution, reward-mode…

Read article →
ARTICLE · 064

Annoy

How Annoy (Approximate Nearest Neighbors Oh Yeah) works: random-projection binary trees that split space by the perpendicular bisector of two sampled …

Read article →
ARTICLE · 065

MongoDB Atlas Vector Search

The math behind MongoDB Atlas Vector Search: why exact kNN is O(N*d), how the HNSW graph reaches sublinear search, what M, efConstruction and numCandi…

Read article →
ARTICLE · 066

Attention compute and memory -- the quadratic cost of context

Deep-dive on attention compute and memory: the O(N^2) QK^T attention matrix, quadratic compute and memory, the attention-vs-FFN FLOPs breakdown, compu…

Read article →
ARTICLE · 067

Attention Math

Attention derived from first principles: start with a hard dictionary lookup, relax it into a differentiable soft lookup, and the query-key-value form…

Read article →
ARTICLE · 068

Attention variants architecture

A comparative map of attention variants: multi-head, multi-query, grouped-query, multi-head latent, sliding-window, sparse and linear attention, score…

Read article →
ARTICLE · 069

AWQ Math

The math of AWQ (Activation-aware Weight Quantization): why a small set of salient weight channels identified by activation magnitude dominate quality…

Read article →
ARTICLE · 070

Backpressure Math

The math of backpressure in an LLM serving pipeline: queue depth as the integral of arrival-minus-service rate, Little's law applied …

Read article →
ARTICLE · 071

Backprop architecture

The systems architecture of the transformer backward pass: what the chain rule actually costs in memory and bandwidth, gradient accumulation as a batc…

Read article →
ARTICLE · 072

Bandwidth-Bound Operations

Why autoregressive decoding is memory-bandwidth-bound, not compute-bound: the arithmetic intensity of GEMV, bytes-per-token accounting for weights and…

Read article →
ARTICLE · 073

Batched GEMM Math

Batched GEMM in transformer workloads: the shape algebra of per-head attention matmuls, strided-batched stride arithmetic, grouped GEMM for MoE and ra…

Read article →
ARTICLE · 074

Batch Size Math for LLM Training

The math of batch size in LLM training: the gradient as a noisy estimator and its 1/B variance, the gradient noise scale and critical batch size, the …

Read article →
ARTICLE · 075

Beam Search Math

The math of beam search decoding: MAP inference over sequences, the log-prob scoring recurrence, length normalization derived, the beam-search curse, …

Read article →
ARTICLE · 076

BF16 Training

BF16 training in depth: the bfloat16 bit layout (1 sign, 8 exponent, 7 mantissa), why matching FP32's exponent range makes it a drop-…

Read article →
ARTICLE · 077

BGE Embeddings Math

The math behind BGE and BGE-M3 text embeddings: the bi-encoder architecture, CLS versus mean pooling, L2 normalization and cosine similarity, contrast…

Read article →
ARTICLE · 078

Bio Capability Evals

How to measure the biology and bio-risk capabilities of large language models: the difference between knowledge probes and task-based evals, the uplif…

Read article →
ARTICLE · 079

BitFit Theory

BitFit explained from first principles: freeze every weight matrix and train only the bias vectors. Which biases are updated, the exact parameter coun…

Read article →
ARTICLE · 080

bitsandbytes int8 Quantization

How bitsandbytes does 8-bit: block-wise absmax quantization and why blocks bound outlier damage, the linear vs dynamic (dynamic-exponent) 8-bit format…

Read article →
ARTICLE · 081

Bottleneck Theory of Deep Learning

The information bottleneck theory of deep learning: layers as a Markov chain, the two mutual informations I(X;T) and I(T;Y), the information plane, th…

Read article →
ARTICLE · 082

Byte-Pair Encoding Deep Dive

A math-first deep dive on the Byte-Pair Encoding merge algorithm: the base vocabulary, frequency counting over adjacent symbol pairs, the greedy argma…

Read article →
ARTICLE · 083

Blockwise Parallel Transformer

Blockwise Parallel Transformer (BPT) from first principles: why the feedforward network becomes the memory bottleneck once FlashAttention removes the …

Read article →
ARTICLE · 084

Capability Evaluation Overview

The math of LLM capability evaluations: accuracy as a Bernoulli estimate, standard error, Wald vs Wilson vs Clopper-Pearson confidence intervals, samp…

Read article →
ARTICLE · 085

Capability Transitions in Training

The math of capability phase transitions: why some skills appear to switch on sharply with scale while the loss falls smoothly. Sigmoid vs step curves…

Read article →
ARTICLE · 086

Causal Tracing

Causal tracing from first principles: the three-run recipe of clean, corrupted, and corrupted-with-restoration passes that Meng et al. used in ROME to…

Read article →
ARTICLE · 087

Classifier-Free Guidance (CFG)

The math of classifier-free guidance: the score-function view of diffusion, how Bayes' rule turns a conditional and unconditional mod…

Read article →
ARTICLE · 088

Chinchilla Scaling Law

The Chinchilla scaling law as a strategic turning point: how Kaplan-era advice built a generation of giant under-trained models, how Hoffmann et al. (…

Read article →
ARTICLE · 089

Chinchilla Scaling

The Chinchilla compute-optimal scaling result (Hoffmann et al. 2022): the parametric loss law L(N,D) = E + A/N^α + B/D^&…

Read article →
ARTICLE · 090

Chroma Math + Architecture

The math and architecture behind Chroma: the embedded, in-process design that makes it the SQLite of vector stores, how it delegates search to hnswlib…

Read article →
ARTICLE · 091

Chunked Prefill

Chunked prefill in LLM serving: why one long prompt stalls every decode in the batch, how splitting the prompt into fixed-size chunks and piggybacking…

Read article →
ARTICLE · 092

Circuit Analysis

The math of transformer circuits: the residual stream as a shared communication channel, attention heads as low-rank read/write maps, the factoring of…

Read article →
ARTICLE · 093

Classifier Guidance Math

Classifier guidance for diffusion models, derived from first principles: the score-function view, Bayes' rule splitting the condition…

Read article →
ARTICLE · 094

Coding Capability Evals

How code-generation ability is actually measured: HumanEval and MBPP, the pass@k metric and its unbiased estimator, unit-test execution and functional…

Read article →
ARTICLE · 095

ColBERT Math

The math of ColBERT and late interaction: per-token embeddings for query and document instead of one pooled vector, the MaxSim scoring formula (max co…

Read article →
ARTICLE · 096

Communication Math for Distributed Training

The collective communication primitives behind distributed training: all-reduce, all-gather, reduce-scatter, broadcast, and all-to-all; the ring all-r…

Read article →
ARTICLE · 097

Compute-Bound Operations

The compute-bound regime in transformer inference and training: the FLOP ceiling, arithmetic intensity and the roofline ridge point, why prefill and l…

Read article →
ARTICLE · 098

Compute-Optimal Training in Practice

A practitioner's recipe for compute-optimal training: how to read an isoFLOP frontier, allocate a fixed FLOP budget across model size…

Read article →
ARTICLE · 099

Compute-Optimal Training

The compute-optimal frontier from first principles: the C = 6ND compute identity (2 forward + 4 backward FLOPs per parameter per token), the Lagrangia…

Read article →
ARTICLE · 100

Constitutional AI Math

How Constitutional AI (CAI) and RLAIF replace human harmlessness labels with AI feedback steered by a written constitution: the two phases (supervised…

Read article →
ARTICLE · 101

Context Length Extension Math

The math behind extending a pretrained transformer's context window: why RoPE breaks out of distribution past its training length, Po…

Read article →
ARTICLE · 102

Contextual RAG Math

The math of contextual retrieval: why chunks lose their meaning, how an LLM prepends document-level context, contextual embeddings and contextual BM25…

Read article →
ARTICLE · 103

Continuous Batching Math

The math of continuous (iteration-level) batching for LLM serving: why static batching wastes GPU, how Orca-style per-iteration admit/evict keeps the …

Read article →
ARTICLE · 104

Contrastive Search

Contrastive search decoding from first principles: the model-confidence minus degeneration-penalty objective, the alpha tradeoff, the max cosine simil…

Read article →
ARTICLE · 105

Corrective RAG (CRAG)

Corrective RAG (CRAG): a lightweight retrieval evaluator scores the relevance of retrieved documents, two thresholds sort them into correct, ambiguous…

Read article →
ARTICLE · 106

CPU Offload Math

The arithmetic of CPU offload for training and running transformers on one GPU: what lives in GPU memory (parameters, gradients, Adam optimizer state)…

Read article →
ARTICLE · 107

Cross-entropy loss architecture

Cross-entropy for language models as an engineering system, not a formula: the fused softmax-CE kernel and the p - y gradient, why the logits tensor d…

Read article →
ARTICLE · 108

Cyber Capability Evals

How to measure the cyber-offense capability of a language model: CTF and vulnerability-discovery benchmarks, decomposing an attack into scorable sub-t…

Read article →
ARTICLE · 109

Dangerous Capability Evaluations

The general framework for dangerous-capability evaluations and responsible scaling: threat modeling from harm scenario to measurable proxy, capability…

Read article →
ARTICLE · 110

Training Data Filtering

A focused walk through pretraining data filtering: heuristic rules, classifier-based quality filters, perplexity filtering with an n-gram language mod…

Read article →
ARTICLE · 111

Training Data Mixing

The math of pretraining data-mixture optimization: the mixture as a distribution over domains, token-proportional baselines, upsampling and downsampli…

Read article →
ARTICLE · 112

Data Quality Math

How to put numbers on training-data quality: reference-model perplexity and classifier scores as quality metrics, the deduplication math behind effect…

Read article →
ARTICLE · 113

Data Quality Scaling

How data quality changes scaling: curation and filtering shift the loss-vs-compute curve leftward and downward, so the same loss is reached with fewer…

Read article →
ARTICLE · 114

Data Scaling for LLMs

Data-constrained scaling: what happens when you run out of unique tokens. The Muennighoff et al. result that repeating data for up to ~4 epochs is nea…

Read article →
ARTICLE · 115

DDIM

The math behind DDIM: a non-Markovian forward process that shares DDPM's marginals, deterministic sampling, the probability-flow ODE …

Read article →
ARTICLE · 116

DDP Math

The math of Distributed Data Parallel training: why averaging gradients across N replicas is exactly the gradient of the loss on the union batch, grad…

Read article →
ARTICLE · 117

DDPM

The math of DDPMs from first principles: the forward noising process q, the closed-form marginal, the tractable posterior, the reverse process p, the …

Read article →
ARTICLE · 118

Deception Capability Evals

How to actually measure deception in language models: the metrics behind sandbagging tests, sycophancy flip rates, strategic-deception scenarios, cons…

Read article →
ARTICLE · 119

DeepMind Scaling Law Series

How DeepMind reshaped LLM scaling: the Gopher 280B baseline, the isoFLOP experimental method, and the three independent estimation approaches in Hoffm…

Read article →
ARTICLE · 120

Dense Retrieval Math

The math of dense retrieval: the dual-encoder (bi-encoder) architecture mapping queries and documents into a shared embedding space, similarity as dot…

Read article →
ARTICLE · 121

Depth Scaling

Depth scaling in transformers: how adding layers (holding width fixed) changes capability and trainability, why parameter count is linear in depth, th…

Read article →
ARTICLE · 122

Dictionary Learning for NN

Dictionary learning for neural-network interpretability: the overcomplete generative model, the sparse-coding objective, the two-phase alternating opt…

Read article →
ARTICLE · 123

DoRA

DoRA (Weight-Decomposed Low-Rank Adaptation), from the mechanics up: how it splits every weight matrix into a magnitude vector and a direction matrix,…

Read article →
ARTICLE · 124

DoRA Theory

The theory behind DoRA (Weight-Decomposed Low-Rank Adaptation): why decoupling a weight's magnitude from its direction matters, the l…

Read article →
ARTICLE · 125

Double Descent

Double descent explained from first principles: the classic bias-variance U-curve, the interpolation threshold where test error peaks, and the second …

Read article →
ARTICLE · 126

Double Descent Deep Dive

A mathematical deep dive on double descent: the bias-variance decomposition in the overparameterized regime, a solvable random-features linear-regress…

Read article →
ARTICLE · 127

DPM-Solver Sampling

DPM-Solver explained from first principles: the semi-linear structure of the diffusion probability-flow ODE, the change of variables to log-SNR, the e…

Read article →
ARTICLE · 128

DPO Math

A deep dive on the Direct Preference Optimization loss mechanics: the log-sigmoid of the implicit-reward margin, the gradient and its self-modulating …

Read article →
ARTICLE · 129

DyT

The math of Dynamic Tanh (DyT): the normalization-free transformer layer DyT(x) = gamma * tanh(alpha * x) + beta that replaces LayerNorm and RMSNorm. …

Read article →
ARTICLE · 130

E5 Embeddings Math

The math behind E5 text embeddings: weakly-supervised contrastive pre-training on the CCPairs corpus, consistency-based filtering, mean pooling, the q…

Read article →
ARTICLE · 131

EAGLE

A deep dive into EAGLE speculative decoding beyond the base idea: the exact feature-autoregression recurrence, the one-layer draft head, EAGLE-2&a…

Read article →
ARTICLE · 132

EAGLE in Context

The math of EAGLE speculative decoding: drafting at the feature level (second-to-top hidden states) with a small autoregressive head that conditions o…

Read article →
ARTICLE · 133

EDM

EDM (Karras et al.) recast diffusion models around a single continuous noise level sigma: a unified sigma-parameterization, the c_skip / c_out / c_in …

Read article →
ARTICLE · 134

Effective Batch Size

Effective (global) batch size = micro-batch x gradient-accumulation x data-parallel world. How the identity decouples the batch your optimizer sees fr…

Read article →
ARTICLE · 135

Elasticsearch Vector Search

The math behind Elasticsearch vector search as Lucene implements it: the dense_vector field, per-segment HNSW graphs and why segment merging rebuilds …

Read article →
ARTICLE · 136

Embeddings -- turning tokens into vectors

Deep-dive on transformer embeddings: token embeddings as a lookup into the embedding matrix (vocab x d_model), learned representations and embedding-s…

Read article →
ARTICLE · 137

Emergent Capabilities Deep Dive

A critical, quantitative look at emergent abilities in large language models: the claim that capabilities appear abruptly at scale, the mirage argumen…

Read article →
ARTICLE · 138

Emergent Abilities in LLMs

A foundational overview of emergent abilities in large language models: the Wei et al. definition, the canonical examples (multi-digit arithmetic, wor…

Read article →
ARTICLE · 139

Emergent Abilities Math

The mathematics of emergent abilities: how a smoothly improving per-token accuracy p turns into a sharp jump once you measure exact-match success as p…

Read article →
ARTICLE · 140

EP Math

The systems math of expert parallelism for Mixture-of-Experts: the all-to-all dispatch and combine communication volume, how experts are placed across…

Read article →
ARTICLE · 141

Expert Choice Routing

Expert-choice routing for Mixture-of-Experts: the transposed selection where experts pick their top-k tokens instead of tokens picking experts, the ga…

Read article →
ARTICLE · 142

Expert Parallel Math Deep

A math deep dive on expert parallelism for Mixture-of-Experts models: routing as an expectation over a batch, why imbalance is a parallelism problem r…

Read article →
ARTICLE · 143

Faiss Math

A practical guide to FAISS as an approximate-nearest-neighbor toolkit: the index zoo and how to choose. IndexFlat exact search, IVF inverted-file coar…

Read article →
ARTICLE · 144

Feature Disentanglement

The math of feature disentanglement in interpretability: the linear representation hypothesis and features-as-directions, the interference term, super…

Read article →
ARTICLE · 145

Transformer Math: Big Picture

A capstone map of the whole Transformer Math series: the residual stream and embeddings, attention and the transformer block, training math, scaling l…

Read article →
ARTICLE · 146

Fine-Tuning Scaling

How fine-tuning scales: the effective-data-transfer law from Hernandez et al., how downstream performance depends on pretraining compute and fine-tune…

Read article →
ARTICLE · 147

Flash Attention Architecture

A first-principles overview of FlashAttention (FA-1): why standard attention is memory-bound, the HBM-vs-SRAM memory hierarchy, IO-aware tiling, the o…

Read article →
ARTICLE · 148

FlashAttention-2

FlashAttention-2 in depth: why FlashAttention-1 only reached a fraction of peak FLOPs, the 16x cost gap between matmul and non-matmul work, deferring …

Read article →
ARTICLE · 149

Flash Attention Math

A from-first-principles derivation of the FlashAttention online-softmax recurrence: the running max m_i, the running denominator l_i, the rescaling id…

Read article →
ARTICLE · 150

Flow Matching

Flow matching for generative models: the probability path and velocity-field ODE, the continuity equation, the conditional flow matching objective, st…

Read article →
ARTICLE · 151

FP4 Quantization

Post-training 4-bit weight quantization for inference: NF4 (4-bit NormalFloat, quantile-optimal for Gaussian weights, from QLoRA) and FP4 (E2M1), why …

Read article →
ARTICLE · 152

FP4 Training on Blackwell

FP4 training explained: the 4-bit E2M1 float and its sixteen representable values, the extreme range and precision limits of four bits, fine-grained m…

Read article →
ARTICLE · 153

FP8 Training on H100+ Hardware

How FP8 training works: the E4M3 and E5M2 formats, their bit layouts and representable ranges, per-tensor and delayed (amax-history) scaling with a wo…

Read article →
ARTICLE · 154

FSDP Math

How PyTorch FSDP implements ZeRO-3-style full sharding: the FlatParameter sharding unit and wrapping policy, the forward all-gather/compute/reshard an…

Read article →
ARTICLE · 155

Full FT vs PEFT Trade-offs

Full fine-tuning versus parameter-efficient fine-tuning as a decision, worked in numbers: the 16-bytes-per-parameter memory bill of full FT, why freez…

Read article →
ARTICLE · 156

Fusion RAG

RAG-Fusion explained from first principles: generating multiple sub-queries from one question, retrieving a ranked list for each, and merging those li…

Read article →
ARTICLE · 157

Game Theory for LLM Agents

A focused, game-theoretic reading of LLM interactions: framing agents as players, Nash equilibrium and best response, negotiation and debate as games,…

Read article →
ARTICLE · 158

Activation function architecture

A focused deep-dive on the GELU activation: GELU(x) = x*Phi(x), the probabilistic stochastic-regularizer interpretation, the exact erf form and the ta…

Read article →
ARTICLE · 159

GGUF Format Deep Dive

How the GGUF container and llama.cpp k-quants actually work: the single-file metadata-plus-tensors layout that makes GGUF mmap-friendly, block quantiz…

Read article →
ARTICLE · 160

Distillation Math

The mathematics of knowledge distillation: temperature-softened softmax, the KL-divergence objective, the combined soft/hard loss, the T-squared gradi…

Read article →
ARTICLE · 161

GLU FFN

The GLU FFN family: the gating template FFN(x) = (activation(xW) ⊙ xV)W2 and its members -- GLU (sigmoid), ReGLU (ReLU), GEGLU (G…

Read article →
ARTICLE · 162

GPTQ Math

The math of GPTQ post-training quantization: the layer-wise output-error objective, the second-order Hessian (OBQ lineage) formulation, greedy per-col…

Read article →
ARTICLE · 163

GQA Math

The math of grouped-query attention: sharing K/V projections across groups of query heads, the g-groups design that interpolates between multi-head (g…

Read article →
ARTICLE · 164

Gradient Accumulation Math

The math of gradient accumulation: the accumulate-then-step loop, why you divide the loss by K, how gradient linearity makes K micro-batches equal one…

Read article →
ARTICLE · 165

Gradient Checkpointing Math

The math of gradient checkpointing: why activation memory grows linearly with depth, how recomputation trades FLOPs for memory, the sqrt(L) optimal ch…

Read article →
ARTICLE · 166

Gradient clipping architecture

Deep-dive on gradient clipping: why deep and recurrent networks explode gradients and NaN out runs, the clip-by-global-norm algorithm and how it prese…

Read article →
ARTICLE · 167

Gradient Memory Math

The gradient as a concrete mathematical object: its shape and norm, the gradient as a vector field over parameter space, how per-layer gradient scale …

Read article →
ARTICLE · 168

Graph RAG Math

The math of GraphRAG: extracting entities and relations into a knowledge graph, community detection with the Leiden algorithm and modularity, hierarch…

Read article →
ARTICLE · 169

Grokking

A foundational overview of grokking: the delayed-generalization phenomenon Power et al. found on modular-arithmetic tasks, the long train/validation g…

Read article →
ARTICLE · 170

Grokking Deep Dive

A mechanistic deep dive into grokking: how a one-layer transformer trained on modular addition reverse-engineers into a Fourier-multiplication circuit…

Read article →
ARTICLE · 171

Grokking Math

A theoretical account of grokking: why weight decay drives delayed generalization, the norm-growth-versus-generalization tradeoff, the two competing s…

Read article →
ARTICLE · 172

Grouped Query Attention (GQA)

A practitioner's guide to grouped-query attention: why cutting the number of K/V heads is the right efficiency lever, the arithmetic-…

Read article →
ARTICLE · 173

GTE Embeddings Math

The math behind GTE (General Text Embeddings) from Alibaba: the bi-encoder with mean pooling, L2 normalization and cosine similarity, the improved con…

Read article →
ARTICLE · 174

Guided Generation Math

The math of constrained / guided LLM decoding: turning a regex or JSON schema into a finite-state machine over the vocabulary, logit masking, grammar-…

Read article →
ARTICLE · 175

HNSW Math

The math of HNSW (Hierarchical Navigable Small World) graphs: the multi-layer navigable-small-world structure, greedy search descending the layers, pr…

Read article →
ARTICLE · 176

Hoffmann Chinchilla Paper

The 2024 Epoch AI replication of Hoffmann et al. (2022): reconstructing the parametric loss-fit data from Figure 4, why the published Approach 3 estim…

Read article →
ARTICLE · 177

Hybrid Architectures

Hybrid attention + SSM architectures: why a handful of attention layers rescues a recurrent stack, the interleaving ratio, the FLOP and KV-cache arith…

Read article →
ARTICLE · 178

Hybrid Parallelism Math

How to compose data, tensor, pipeline, and expert parallelism into one training run: the device mesh, factoring N = DP x TP x PP, the communication-vo…

Read article →
ARTICLE · 179

Hybrid Retrieval Math

The math of hybrid retrieval: why dense (semantic) and sparse (lexical) retrieval are complementary, and how to fuse their ranked lists. Reciprocal Ra…

Read article →
ARTICLE · 180

HyDE Math

The math of HyDE (Hypothetical Document Embeddings): why dense retrieval suffers a query-document embedding gap, how generating a hypothetical answer …

Read article →
ARTICLE · 181

Hyena

The math of the long convolution, the primitive Hyena uses in place of attention. Causal convolution as a lower-triangular Toeplitz operator, why filt…

Read article →
ARTICLE · 182

Hyena Hierarchy Math

The math of Hyena: replacing attention with a recurrence of long implicit convolutions and data-controlled gating. How the long filter is parameterize…

Read article →
ARTICLE · 183

IA3 Theory

IA3 (Infused Adapter by Inhibiting and Amplifying Inner Activations): the three learned scaling vectors on keys, values, and the FFN intermediate, the…

Read article →
ARTICLE · 184

Inference-Optimal Training

Why the Chinchilla compute-optimal point ignores inference cost, and how minimizing total lifetime cost -- training FLOPs (6ND) plus expected inferenc…

Read article →
ARTICLE · 185

Inference-Time Scaling Laws

Inference-time scaling laws: how accuracy grows with test-time compute, the log-linear best-of-N curve, the geometric coverage of pass@N, compute-opti…

Read article →
ARTICLE · 186

In-Flight Batching

In-flight batching in TensorRT-LLM: the runtime's iteration-level scheduler, mixing prefill and decode requests in one batch via the …

Read article →
ARTICLE · 187

Information Bottleneck Method

The foundational information bottleneck method of Tishby, Pereira and Bialek: the IB Lagrangian min I(X;T) - beta I(T;Y), the Markov constraint, the t…

Read article →
ARTICLE · 188

Initialization Scaling

How weight-initialization variance is scaled in transformers: the variance-preservation principle, the fan-in rule, Xavier/Glorot and Kaiming/He init,…

Read article →
ARTICLE · 189

Mechanistic Interpretability Overview

A map of mechanistic interpretability: the ladder of methods from attribution and probing up through activation patching, circuit analysis, and sparse…

Read article →
ARTICLE · 190

Iteration-Level Scheduling

Iteration-level scheduling in LLM serving: why the scheduling quantum is a single forward pass, the per-iteration admit/run/evict loop, FCFS versus pr…

Read article →
ARTICLE · 191

Kaplan Scaling Laws (2020)

The original Kaplan et al. (2020) neural scaling laws: the power-law relations of test loss to model size N, dataset size D, and compute C, the L = (N…

Read article →
ARTICLE · 192

Kaplan Scaling Laws Deep Dive

A deep dive on Kaplan et al. 2020: the power-law fits for loss versus parameters, data, and compute; the N^0.73 compute-optimal allocation; the critic…

Read article →
ARTICLE · 193

KTO Math

A math-first deep dive on KTO (Kahneman-Tversky Optimization): aligning a language model with a prospect-theory value function using binary desirable …

Read article →
ARTICLE · 194

KV cache math architecture

A first-principles overview of the KV cache: why autoregressive decoding recomputes without it, the O(N^2) to O(N) saving, the bytes-per-token sizing …

Read article →
ARTICLE · 195

KV Cache Deep Dive

KV cache internals in depth: the per-layer tensor shapes [batch, heads, seq, head_dim], memory-layout choices and strides, how the cache is indexed an…

Read article →
ARTICLE · 196

KV Cache Compression

KV-cache compression beyond quantization: token eviction (H2O, Scissorhands), attention sinks and sliding windows (StreamingLLM), low-rank projection,…

Read article →
ARTICLE · 197

KV Cache Quantization

A foundational overview of KV cache quantization: why the cache dominates long-context memory, the bytes-per-token math, int8 and int4 quantization of…

Read article →
ARTICLE · 198

KV Cache Quantization at Low Bits

A deep dive on aggressive KV-cache quantization: why keys and values need asymmetric treatment, per-channel key vs per-token value quantization, the o…

Read article →
ARTICLE · 199

Label smoothing architecture

Deep-dive on label smoothing: why one-hot cross-entropy causes runaway logits and overconfidence, the 1-ε soft target and its gradient, the calibratio…

Read article →
ARTICLE · 200

Layer-wise LR Decay

Layer-wise learning-rate decay (LLRD) for fine-tuning transformers: the per-layer rule lr_l = base * ξ^(L-l), why lower layers dese…

Read article →
ARTICLE · 201

Layer Normalization

Layer normalization from first principles: the per-token mean/variance formula, the learnable scale and shift, a worked numeric example, the backward-…

Read article →
ARTICLE · 202

LayerNorm vs RMSNorm architecture

An implementation-focused look at LayerNorm and RMSNorm: epsilon placement, fp16/bf16 mixed precision, one-pass and Welford variance, catastrophic can…

Read article →
ARTICLE · 203

Learning Rate Math for LLM

The math of the learning rate itself: its role as the step size in gradient descent, the loss-landscape and curvature view, the maximum stable step si…

Read article →
ARTICLE · 204

Learning-rate schedules

Deep-dive on learning-rate schedules for transformer training: why warmup stabilizes adaptive optimizers, cosine vs inverse-sqrt vs linear decay, how …

Read article →
ARTICLE · 205

Linear Attention

A guided tour of linear attention and its variants: the kernel feature-map factorization that turns O(N^2) into O(N), and how Linear Transformer, Perf…

Read article →
ARTICLE · 206

Linear Attention Math

The math of linear attention: replacing softmax(QK^T)V with a kernel feature map phi so attention factorizes as phi(Q)(phi(K)^T V), the associativity …

Read article →
ARTICLE · 207

Lion Optimizer Math

The math of Lion (EvoLved Sign Momentum): the sign-of-interpolated-momentum update rule, the two EMA coefficients, why it stores only one optimizer st…

Read article →
ARTICLE · 208

LLM Inference Architecture: The Full Pipeline in Depth

An end-to-end map of the LLM serving stack: the request lifecycle from tokenize to prefill to the decode loop to detokenize, the engine components (sc…

Read article →
ARTICLE · 209

LLM.int8() Paper Math

How LLM.int8() runs transformer matmuls in 8-bit at inference time: vector-wise (row/column) absmax INT8 quantization, the emergent-outlier-features p…

Read article →
ARTICLE · 210

Lookahead Decoding

Lookahead decoding as transformer math: the Jacobi-iteration view of autoregressive decoding, the evolving n-gram pool, a lookahead branch that refine…

Read article →
ARTICLE · 211

LoRA

The mathematics of Low-Rank Adaptation: the update W' = W + (alpha/r)BA, the low-rank factorization, rank r and scaling alpha, the tr…

Read article →
ARTICLE · 212

LoRA Theory

The theory behind Low-Rank Adaptation: the intrinsic-dimensionality hypothesis (Aghajanyan et al.), why fine-tuning weight updates live in a low-rank …

Read article →
ARTICLE · 213

Loss Curves

How to read and interpret an LLM training loss curve: the power-law descent in log-log axes, the warmup bump, the noise floor, spikes and divergence, …

Read article →
ARTICLE · 214

Loss Scaling for fp16 Training

Loss scaling for FP16 training: why FP16 gradients underflow to zero in the subnormal range, the FP16 range math, and the scale-then-unscale algorithm…

Read article →
ARTICLE · 215

Lottery Ticket Hypothesis

A foundational overview of the Lottery Ticket Hypothesis: Frankle and Carbin's claim that a dense network contains a sparse subnetwor…

Read article →
ARTICLE · 216

Lottery Ticket Hypothesis

A deep dive into the modern Lottery Ticket Hypothesis: iterative magnitude pruning with rewinding to iteration k, linear mode connectivity and the ins…

Read article →
ARTICLE · 217

Lottery Ticket Hypothesis

The formal side of the lottery ticket hypothesis: the strong LTH, the Malach et al. proof that a randomly initialized network already contains an appr…

Read article →
ARTICLE · 218

Learning Rate Schedules for LLM

A focused guide to learning-rate schedule shapes for training transformers: why warmup exists, linear vs cosine decay, why cosine must be matched to t…

Read article →
ARTICLE · 219

Learning Rate Transfer

How to tune the learning rate on a small proxy model and transfer it to a large one: standard parametrization drifts the optimal LR with width, the ma…

Read article →
ARTICLE · 220

Mamba SSM Math

The math of Mamba's selective state-space model: the SSM recurrence h_t = A h_(t-1) + B x_t and y_t = C h_t, the selectivity innovati…

Read article →
ARTICLE · 221

Math Capability Evals

How mathematical reasoning is measured in language models: the benchmark ladder from GSM8K to MATH to AIME and olympiad problems, answer-matching vers…

Read article →
ARTICLE · 222

Matmul Arithmetic Intensity

The arithmetic intensity of matrix multiply from first principles: FLOPs/byte = 2MNK / bytes moved, how M, N, and K set data reuse, the roofline ridge…

Read article →
ARTICLE · 223

Matryoshka Embeddings

How Matryoshka Representation Learning (MRL) trains embeddings so nested prefixes — the first 64, 128, 256, ... dimensions &…

Read article →
ARTICLE · 224

Medusa Speculative Heads

A deep dive on Medusa speculative decoding: the extra heads as residual blocks, the conditional-independence gap that makes them decay with distance, …

Read article →
ARTICLE · 225

Medusa

The math of Medusa decoding: bolting multiple lightweight residual heads onto a frozen model so each predicts a future token, expanding their top-k ou…

Read article →
ARTICLE · 226

LLM Memory Math

How to compute the memory a language model needs to train: the four buckets (parameters, gradients, optimizer state, activations), why mixed-precision…

Read article →
ARTICLE · 227

Mesa-Optimization

Mesa-optimization explained: the distinction between the base optimizer that trains a model and a learned optimizer that can emerge inside it, mesa-ob…

Read article →
ARTICLE · 228

Micro-Batch Size Selection

Micro-batch size as the unit of work that must fit in memory: how it drives peak activation memory, how it trades against GEMM/kernel efficiency, and …

Read article →
ARTICLE · 229

Milvus Math + Architecture

The math and architecture behind Milvus: the disaggregated, log-first design that separates compute from storage, collections and partitions and segme…

Read article →
ARTICLE · 230

Min-P Sampling

Min-p sampling explained from first principles: the relative threshold p_base * max_prob, why scaling the cutoff with the model's con…

Read article →
ARTICLE · 231

Mirostat Sampling

Mirostat as a feedback controller for text generation: how it targets a fixed surprise value tau, models the token distribution as Zipfian, estimates …

Read article →
ARTICLE · 232

Mixed-precision training math

An overview of mixed-precision transformer training: fp16/bf16 compute copies over an fp32 master-weight spine, why gradient updates round to zero in …

Read article →
ARTICLE · 233

MoE math architecture

The core math of Mixture-of-Experts layers: the router softmax, top-K selection, the sparse FFN forward pass, active vs total parameters, sparse-vs-de…

Read article →
ARTICLE · 234

MQA Math

Multi-Query Attention (MQA): all query heads share one key/value head, cutting the KV cache by a factor of h. The shapes and math, the KV-cache reduct…

Read article →
ARTICLE · 235

Multi-Agent Communication

The token-cost math of communication between LLM agents: message passing, the context-budget tradeoff of shared versus private state, star / chain / f…

Read article →
ARTICLE · 236

Multi-Agent Coordination

How multiple LLM agents coordinate: decomposing a goal into a task graph, allocating tasks to agents, orchestrator/worker versus decentralized pattern…

Read article →
ARTICLE · 237

Multi-Agent Debate

Multi-agent debate as a truthfulness and accuracy mechanism: several model instances argue, then a judge or a vote decides. Why debate can amplify cor…

Read article →
ARTICLE · 238

Multi-Agent Emergence

Emergent collective behavior in multi-agent LLM systems: the analogy to swarms and complex adaptive systems, how division of labor and roles arise wit…

Read article →
ARTICLE · 239

Multi-Agent Negotiation

Negotiation mechanics for LLM agents: utility functions and reservation values, the bargaining zone (ZOPA), offer and counter-offer protocols, Pareto-…

Read article →
ARTICLE · 240

Multi-Agent Planning

How a team of LLM agents plans together: joint versus individual plans, the hierarchical planner-executor split, decomposing a goal into subgoals, a s…

Read article →
ARTICLE · 241

Multi-Agent Reflection

Reflection in multi-agent systems: self-critique and cross-agent critique loops, the Reflexion pattern of verbal reinforcement, actor-evaluator-self-r…

Read article →
ARTICLE · 242

Multi-Agent Shared Memory

Shared memory in multi-agent LLM systems: the blackboard / shared-state architecture versus message passing, consistency and staleness, memory as shar…

Read article →
ARTICLE · 243

Multi-Agent System Theory

A unifying theory of multi-agent LLM systems: when several agents beat one, the decomposition-versus-overhead tradeoff, a taxonomy tying communication…

Read article →
ARTICLE · 244

Multi-Hop RAG

Multi-hop retrieval-augmented generation: why one retrieval fails on compositional questions, query decomposition into sub-questions, the iterative re…

Read article →
ARTICLE · 245

Multi-Head Attention

Multi-head attention as a structural choice: split d_model into h heads of d_model/h dimensions, run scaled dot-product attention in each independentl…

Read article →
ARTICLE · 246

Multilingual Scaling

How languages scale together inside one model: the curse of multilinguality and capacity dilution, positive cross-lingual transfer versus interference…

Read article →
ARTICLE · 247

Multilingual Tokenization

Why the same sentence costs 2-4x more tokens in some languages than in English: tokenizer fertility and tokens-per-word disparity across scripts, the …

Read article →
ARTICLE · 248

Multimodal Scaling

Multimodal scaling laws: per-modality power laws, competition and synergy between modalities under a shared parameter and compute budget, the data-mix…

Read article →
ARTICLE · 249

Muon optimizer architecture

Deep-dive on the Muon optimizer: momentum, orthogonalizing 2D weight updates toward U V^T, the quintic Newton-Schulz iteration, RMS-to-RMS shape scali…

Read article →
ARTICLE · 250

muP

muP as a parametrization: the per-layer initialization-variance and learning-rate scaling rules that keep every activation, logit, and gradient update…

Read article →
ARTICLE · 251

Neural Scaling Law Theory

Why neural scaling laws are power laws, not just that they are: the data-manifold-dimension theory (Sharma & Kaplan, alpha = 4/d where…

Read article →
ARTICLE · 252

Neural Tangent Kernel

An intuitive overview of the Neural Tangent Kernel: why very wide neural networks behave almost linearly in their parameters, how training turns into …

Read article →
ARTICLE · 253

Neural Tangent Kernel

A formal treatment of the neural tangent kernel: the definition Theta(x,x') = <grad_theta f(x), grad_theta f(x&amp…

Read article →
ARTICLE · 254

NTK-Aware Interpolation

NTK-aware RoPE scaling explained from first principles: why rotary frequencies break outside the training window, the spectral-bias argument for leavi…

Read article →
ARTICLE · 255

NVMe Offload Math

The arithmetic of NVMe/SSD offload for training giant transformers: how ZeRO-Infinity spills parameters and optimizer state to solid-state disk, the c…

Read article →
ARTICLE · 256

Offload Math

The general framework for offloading model state off the GPU: the GPU-HBM to CPU-DRAM to NVMe memory-tier hierarchy, the overlap-vs-stall condition t_…

Read article →
ARTICLE · 257

OpenAI Scaling Law Contributions

OpenAI's broader scaling program beyond the Kaplan power laws: GPT-2 zero-shot task transfer, the compute-efficient frontier, why lar…

Read article →
ARTICLE · 258

OpenSearch Vector Search

The math behind OpenSearch vector search and the k-NN plugin: the knn_vector field, the three engines (Lucene, nmslib, Faiss) and when each wins, spac…

Read article →
ARTICLE · 259

Optimized Product Quantization

Optimized Product Quantization (OPQ): why PQ's fixed subspace split is suboptimal when variance is unevenly spread across dimensions,…

Read article →
ARTICLE · 260

Optimizer State Offload Math

The math of optimizer-state offload: why Adam's momentum and variance are the biggest, coldest bucket of training memory, how ZeRO-Of…

Read article →
ARTICLE · 261

Optimizer State Memory Math

Optimizer-state memory in transformer training: the bytes-per-parameter for SGD, momentum, and Adam, why the fp32 master copy plus m and v add up to 1…

Read article →
ARTICLE · 262

Optimizer Math for LLM Training

A unifying overview of the optimizers used to train transformers: the general update template, the SGD to momentum to RMSProp to Adam progression, ada…

Read article →
ARTICLE · 263

PagedAttention architecture

Deep-dive on PagedAttention, the KV-cache management scheme behind vLLM that treats the cache like OS virtual memory. Covers why KV-cache fragmentatio…

Read article →
ARTICLE · 264

Paged Attention Deep Dive

A deep dive on PagedAttention: how vLLM stores the KV cache in fixed-size blocks with a per-sequence block table, eliminates internal and external fra…

Read article →
ARTICLE · 265

PagedAttention

Why naive contiguous KV-cache allocation wastes 60-80% of GPU memory to internal and external fragmentation and max-length over-reservation, and how P…

Read article →
ARTICLE · 266

Paged KV Cache Deep Dive

A deep dive on the paged KV-cache block manager: choosing block size (tokens per block) and its fragmentation-vs-overhead trade-off, the block table a…

Read article →
ARTICLE · 267

PEFT Theory Overview

The unifying theory behind parameter-efficient fine-tuning: why full fine-tuning is over-parameterized, the intrinsic-dimension hypothesis, the additi…

Read article →
ARTICLE · 268

Persuasion Capability Evals

How to measure a language model's persuasion capability: the estimand of attitude and belief shift, randomized human-subject designs,…

Read article →
ARTICLE · 269

pgvector Math + Architecture

The math and architecture of pgvector, the Postgres vector extension: the vector type, the L2 / cosine / inner-product operator classes, exact versus …

Read article →
ARTICLE · 270

Pinecone Math + Architecture

A focused look at Pinecone, the managed vector database: serverless vs pod-based architecture, namespaces, the black-box managed ANN index, metadata f…

Read article →
ARTICLE · 271

Pipeline Parallel Math Deep

Pipeline parallelism for transformers: splitting layers into stages across GPUs, the pipeline bubble of idle time under naive execution, microbatching…

Read article →
ARTICLE · 272

Polysemanticity

Polysemanticity: why a single neuron in a transformer responds to many unrelated features, how it differs from its cause (superposition), how to measu…

Read article →
ARTICLE · 273

Position Interpolation Math

Linear Position Interpolation (PI) for RoPE, derived from first principles: why direct extrapolation puts rotation angles out of distribution, the m -…

Read article →
ARTICLE · 274

Positional Encoding

Why self-attention is blind to word order, and how positional encoding fixes it: permutation invariance, the absolute sinusoidal construction and its …

Read article →
ARTICLE · 275

PP Math

The math of pipeline parallelism: splitting transformer layers into stages, the pipeline bubble fraction (p-1)/(m+p-1), GPipe versus 1F1B scheduling, …

Read article →
ARTICLE · 276

PPO for LLMs Math

How PPO drives RLHF for LLMs: framing generation as a token-level RL problem, the reward-model-minus-KL-penalty reward, GAE advantage estimation, the …

Read article →
ARTICLE · 277

PQ Math

The math of Product Quantization (PQ): splitting a vector into m sub-vectors, learning a k-means codebook per subspace, encoding a vector as m codewor…

Read article →
ARTICLE · 278

Prefill Math

The math of the prefill phase: processing the whole prompt in one parallel forward pass to populate the KV cache and emit the first token, why prefill…

Read article →
ARTICLE · 279

Prefix Tuning Theory

Prefix tuning explained from first principles: trainable prefix key and value vectors prepended to attention at every transformer layer, the reparamet…

Read article →
ARTICLE · 280

Pre-norm vs post-norm transformers

Deep-dive on transformer normalization placement: post-norm on the residual path versus pre-norm inside the branch, gradient flow and attenuation, war…

Read article →
ARTICLE · 281

Pretraining Scaling

How pretraining loss falls with compute, the C = 6ND accounting identity, planning a pretraining run from a fixed FLOP budget, token budgets and data …

Read article →
ARTICLE · 282

Priority Scheduling

Priority scheduling for LLM serving: priority classes and strict priority queues, weighted fair queuing, preemption of low-priority requests and KV-ca…

Read article →
ARTICLE · 283

Linear Probes

Probing classifiers for interpretability: linear and MLP probes trained on frozen activations to test what information is linearly decodable, why prob…

Read article →
ARTICLE · 284

Prompt Prefill vs Decode

The decode phase in depth: why generating one token at a time is memory-bandwidth-bound with arithmetic intensity near 1, the per-token latency formul…

Read article →
ARTICLE · 285

Prompt Lookup Decoding Math

The math of prompt lookup decoding (PLD): a zero-model speculative method that drafts from the prompt itself. How n-gram matching against the context …

Read article →
ARTICLE · 286

Prompt Tuning Theory

Prompt tuning from first principles: relaxing discrete prompt search into a continuous soft-prompt matrix P: [p, d], where the gradient actually flows…

Read article →
ARTICLE · 287

Qdrant Math + Architecture

The math behind Qdrant: collections, shards and segments; cosine as normalize-then-dot; the HNSW m / ef_construct / hnsw_ef budget and its memory bill…

Read article →
ARTICLE · 288

QLoRA Theory

The theory behind QLoRA: why NF4 is a quantile grid rather than a uniform one, how double quantization recovers ~0.37 bits per parameter, the differen…

Read article →
ARTICLE · 289

Quantization Quality Evaluation

How to evaluate a quantized LLM: perplexity delta and why it hides behavior changes, downstream task accuracy, per-layer error norms (MSE), signal-to-…

Read article →
ARTICLE · 290

Advanced RAG Techniques Overview

The math of advanced RAG: query rewriting and multi-query expansion, why sparse and dense scores cannot be added directly, reciprocal rank fusion work…

Read article →
ARTICLE · 291

Reasoning Capability Evals

The statistics of reasoning benchmarks: why GPQA Diamond, MMLU-Pro, ARC-AGI and BBH are structurally small, chance-corrected accuracy and the guessing…

Read article →
ARTICLE · 292

Reasoning Model Scaling

How reasoning accuracy scales with chain-of-thought length and sampling: self-consistency (majority vote over K sampled chains) and its accuracy-vs-K …

Read article →
ARTICLE · 293

Rectified Flow Math

Rectified flow from first principles: the linear interpolation between noise and data, the conditional-expectation velocity field and its L2 regressio…

Read article →
ARTICLE · 294

Redis Vector Search Math

The math behind Redis vector search and RediSearch: inverted-index posting-list memory, TF-IDF and BM25 scoring with a worked example, why cosine, inn…

Read article →
ARTICLE · 295

Representation Learning Theory

The math of learned representations: the InfoNCE objective and its log N mutual-information bound, temperature, the alignment-uniformity decomposition…

Read article →
ARTICLE · 296

Reranking Math

The retrieve-then-rerank pipeline explained from the math up: dense bi-encoder first-stage retrieval, the cross-encoder that jointly encodes query and…

Read article →
ARTICLE · 297

RetNet

Retentive Networks (RetNet) explained from first principles: retention as a fading-memory replacement for softmax attention, the recurrent form with a…

Read article →
ARTICLE · 298

RetNet Math

The math of RetNet (Retentive Network): retention as a decay-weighted alternative to softmax attention, its three equivalent forms (parallel for train…

Read article →
ARTICLE · 299

Retrieval Architectures Overview

Retrieval fundamentals from first principles: the bi-encoder factorization that turns ranking into vector search, embedding geometry, why dot product,…

Read article →
ARTICLE · 300

Reward Hacking Math

The math of reward over-optimization in RLHF: Goodhart's law, the KL-regularized objective and its Gibbs-tilted optimum, the empirica…

Read article →
ARTICLE · 301

Reward Model Math

How a reward model is trained for RLHF: bolting a scalar value head onto a pretrained language model, the Bradley-Terry preference model, the pairwise…

Read article →
ARTICLE · 302

Reward Model Scaling

Reward normalization and scaling in RLHF: why raw reward-model scores need whitening before the PPO update, running mean/std normalization, per-batch …

Read article →
ARTICLE · 303

Ring Attention

Ring Attention as a distributed systems problem: the activation and KV-cache memory bill at million-token context, where context parallelism sits amon…

Read article →
ARTICLE · 304

Ring Attention Math Deep

Ring Attention explained from the math up: sharding a long sequence across P devices, keeping each query block fixed while K/V blocks rotate around a …

Read article →
ARTICLE · 305

RLHF Math Deep Dive

A deep look at the RLHF objective itself: the KL-regularized reward-maximization objective max E[r(x,y)] - beta*KL(pi || pi_ref), why the KL leash is …

Read article →
ARTICLE · 306

RLHF Scaling Laws

How RLHF results scale with policy-model size, reward-model size, and preference-data volume; the reward-model overoptimization scaling law from Gao, …

Read article →
ARTICLE · 307

RLHF Scaling Math

The quantitative side of scaling RLHF: why sqrt(KL) is the natural coordinate for the reward-vs-drift frontier (a second-order Fisher argument), the b…

Read article →
ARTICLE · 308

RMSNorm architecture - root-mean-square normalization in modern transformers

Deep-dive on RMSNorm: the root-mean-square formula, contrast with LayerNorm's mean-centering and bias, forward and backward passes, pre-norm resi…

Read article →
ARTICLE · 309

RMSNorm Deep Dive

A deep dive on RMSNorm below the formula: the Jacobian as a rank d-1 projector, why the input gradient is exactly orthogonal to the input, a worked ba…

Read article →
ARTICLE · 310

Roofline Model for LLM Ops

The roofline model applied to LLM inference: building the compute and bandwidth ceilings for a real machine, computing the ridge point, plotting a pre…

Read article →
ARTICLE · 311

Rotary Position Embedding (RoPE)

The mechanism of Rotary Position Embedding, derived from scratch: the 2-D rotation-matrix and complex-exponential formulations, a proof that the inner…

Read article →
ARTICLE · 312

Rotary Position Embedding Architecture in Depth

Positional encoding as a design problem: what a scheme must provide, how learned absolute, sinusoidal, T5 relative bias, ALiBi and rotary compare, whe…

Read article →
ARTICLE · 313

RWKV Math

The math of RWKV: token shift as a two-tap causal convolution, the WKV operator as decay-weighted attention without QK^T, why it factorizes into a con…

Read article →
ARTICLE · 314

Sparse Autoencoders (SAE)

Sparse autoencoders for transformer interpretability: the superposition hypothesis and why features outnumber dimensions, the encoder/decoder architec…

Read article →
ARTICLE · 315

Sampling mathematics

The unified math of LLM decoding: softmax shift invariance, temperature as a rescaling of log-odds, the proof that entropy rises monotonically with te…

Read article →
ARTICLE · 316

Scaled Dot Product Attention

Scaled dot-product attention worked out quantitatively: the variance derivation behind the 1/sqrt(d_k) factor, what softmax saturation does to gradien…

Read article →
ARTICLE · 317

Scaling law architecture

How to use scaling laws as a design tool: the compute-optimal rule of thumb (C = 6ND, ~20 tokens per parameter), why compute-optimal is the wrong targ…

Read article →
ARTICLE · 318

Scaling Laws

The mathematics of neural scaling laws: why loss follows a power law rather than an exponential, the joint form L(N, D) = E + A/N^alpha + B/D^beta and…

Read article →
ARTICLE · 319

Scaling Laws

Where neural scaling laws break down: data-constrained scaling and the decaying value of repeated tokens, the effective-data model, mixture-of-experts…

Read article →
ARTICLE · 320

Hyperparameter Scaling Transfer

Hyperparameter transfer across model scale from first principles: why the optimal learning rate drifts with width under standard parametrization, the …

Read article →
ARTICLE · 321

ScaNN

How ScaNN accelerates maximum inner-product search with anisotropic, score-aware vector quantization: why the residual component parallel to a datapoi…

Read article →
ARTICLE · 322

Score Matching

Score matching from first principles: why the normalizing constant makes maximum likelihood intractable, what the score function &nabl…

Read article →
ARTICLE · 323

Search Scaling in Reasoning

Verifier-guided search as a test-time scaling axis: Best-of-N with a reward model and the coverage ceiling 1-(1-p)^N, why flat sampling wastes compute…

Read article →
ARTICLE · 324

Selective Activation Recomputation

Selective activation recomputation from first principles: the ratio of FLOPs to rebuild a tensor over bytes freed by dropping it, why that ratio equal…

Read article →
ARTICLE · 325

Self-Consistency Scaling

The math of self-consistency: majority voting over k independently sampled chains of thought. Derives the vote-accuracy curve, shows why the real bar …

Read article →
ARTICLE · 326

Self-RAG

Self-RAG from first principles: reflection tokens as a learned vocabulary, the retrieve-or-not decision and when retrieval actively hurts, per-passage…

Read article →
ARTICLE · 327

SentencePiece Deep Dive

SentencePiece as a complete tokenization system: raw text in and integer ids out with no pre-tokenization, the whitespace meta-symbol and the lossless…

Read article →
ARTICLE · 328

Sequence Length Math

The cost math of sequence length in a transformer: the quadratic attention term versus the linear projection and FFN term, the crossover at s = 6d, th…

Read article →
ARTICLE · 329

Sequence Parallel Math

Sequence parallelism explained with the math: partitioning activations along the sequence dimension to cut activation memory, the Megatron-style SP th…

Read article →
ARTICLE · 330

Shampoo

How Shampoo works: the full-matrix AdaGrad ideal and why it is intractable, Kronecker factorization of the preconditioner into left and right factors,…

Read article →
ARTICLE · 331

Shared KV Cache

Cross-layer KV sharing: cutting the KV cache by reusing keys and values across transformer LAYERS, not just across heads. How Cross-Layer Attention (C…

Read article →
ARTICLE · 332

Signal Propagation in Deep Networks

Signal propagation theory for deep networks: the variance recursion through a layer and its fixed point, the mean-field order-chaos phase transition a…

Read article →
ARTICLE · 333

Sliding Window Attention

The math of sliding-window attention (Mistral-style): each token attends only to the previous w tokens, cutting attention from O(N^2) to O(N*w) and ca…

Read article →
ARTICLE · 334

SLO-Aware Scheduling Math

The queueing and scheduling math behind LLM latency SLOs: TTFT versus TPOT, prefill/decode interference, sizing a chunked prefill, utilization versus …

Read article →
ARTICLE · 335

SmoothQuant Math

The math of SmoothQuant: enabling INT8 weight-and-activation (W8A8) quantization by migrating quantization difficulty from activations to weights with…

Read article →
ARTICLE · 336

Softmax numerics architecture

How softmax is actually computed: the overflow range of fp16 and bf16, the max-subtraction identity and its proof, why the sum is accumulated in fp32,…

Read article →
ARTICLE · 337

Sophia Optimizer

How Sophia builds a cheap diagonal curvature preconditioner for language-model pre-training: the clipped second-order update rule, the Hutchinson and …

Read article →
ARTICLE · 338

SP Math

Sequence parallelism as a configuration decision: what the SP knob actually buys, why its degree is welded to the tensor-parallel degree, how it compa…

Read article →
ARTICLE · 339

Sparse Retrieval Math

Sparse retrieval from first principles: the bag-of-words vector and the inverted index, TF-IDF and the full BM25 formula with term-frequency saturatio…

Read article →
ARTICLE · 340

Speculative decoding architecture

Deep-dive on speculative decoding: exploiting memory-bound decode with a cheap draft model whose K proposals the target verifies in one parallel pass,…

Read article →
ARTICLE · 341

Speculative Decoding in Practice

A systems deep dive on speculative decoding: choosing a draft model and the tokenizer-mismatch trap, self-speculation with Medusa heads and EAGLE feat…

Read article →
ARTICLE · 342

Speculative Decoding

The probability theory of speculative decoding: the modified rejection sampling rule, a proof that the output distribution is exactly the target distr…

Read article →
ARTICLE · 343

SPLADE Math

The math of SPLADE learned sparse retrieval: projecting hidden states through the masked-language-model head into vocabulary space, the log(1 + ReLU(w…

Read article →
ARTICLE · 344

State Space Models Math

The math of linear time-invariant state space models (SSMs): the continuous system x' = Ax + Bu, y = Cx + Du, zero-order-hold and bil…

Read article →
ARTICLE · 345

Selective SSM

How selective state space models work: making Delta, B and C functions of the input so the recurrence becomes time-varying, per-token ZOH discretizati…

Read article →
ARTICLE · 346

Stable Diffusion Math

How Stable Diffusion works as a system: latent diffusion and the compute arithmetic that justifies it, the VAE encoder/decoder and the 0.18215 scale f…

Read article →
ARTICLE · 347

State Space Models

The state space model (SSM) foundation behind S4, S4D and Mamba: the continuous linear system x'(t) = Ax(t) + Bu(t), ZOH and bilinear…

Read article →
ARTICLE · 348

Stochastic Rounding

Stochastic rounding explained for low-precision training: round up with probability equal to frac(x/ulp) so the rounded value is unbiased, E[round(x)]…

Read article →
ARTICLE · 349

Superposition Hypothesis

The superposition hypothesis from first principles: features as directions, the toy model of sparse features through a bottleneck, the Johnson-Lindens…

Read article →
ARTICLE · 350

SwiGLU

How SwiGLU works: the gated feed-forward variant used in Llama and PaLM, FFN(x) = (Swish(xW) ⊙ xV)W2, why the gate needs three w…

Read article →
ARTICLE · 351

Switch Transformer Math

Switch Transformer math: top-1 routing and why k=1 still gives the router a gradient, the expert capacity formula and token dropping, the product-of-f…

Read article →
ARTICLE · 352

Synthetic Training Data

The mathematics of training on model-generated data: the recursive model-collapse recursion and a worked variance-shrinkage example, tail loss from fi…

Read article →
ARTICLE · 353

Temperature Sampling Math

How sampling temperature acts on generation quality, measured rather than asserted: the asymmetric convergence rates at the cold and hot limits, the e…

Read article →
ARTICLE · 354

Temperature scaling in LLM sampling

Deep-dive on temperature scaling: dividing logits by a scalar T before softmax to rescale logit differences, the cold/neutral/hot regimes and their ef…

Read article →
ARTICLE · 355

Tensor Parallel Math Deep

A first-principles derivation of Megatron-style tensor parallelism: splitting a single matmul across GPUs with column-parallel then row-parallel linea…

Read article →
ARTICLE · 356

Tensor Programs (Yang’s Framework)

Tensor Programs explained: what a tensor program is, what the master theorem says about infinite-width limits, the abc-parametrization of init scale, …

Read article →
ARTICLE · 357

Test-Time Compute Math

Test-time (inference-time) compute scaling: spending more compute at inference to get better answers. The four ways to spend it -- longer chains of th…

Read article →
ARTICLE · 358

tiktoken Deep Dive

How tiktoken actually works: byte-level BPE with 256 atoms and no unknown token, the pre-tokenization split regex used by the GPT-2, cl100k and o200k …

Read article →
ARTICLE · 359

Top-K Sampling Math

The math of top-k sampling: the fixed-cardinality truncation rule and its renormalization, the k-th logit as an order statistic, why a fixed k imposes…

Read article →
ARTICLE · 360

Top-P (Nucleus) Sampling Math

Nucleus sampling from first principles: the smallest-prefix cumulative-mass rule and its boundary token, why retained mass overshoots p and by how muc…

Read article →
ARTICLE · 361

Transfer Learning Scaling

Transfer and downstream scaling laws: how pretraining scale turns into fine-tuning and downstream performance, the effective-data-transferred power la…

Read article →
ARTICLE · 362

Typical Sampling

Locally typical sampling derived from first principles: the typical set and the asymptotic equipartition property, the uniform-information-density arg…

Read article →
ARTICLE · 363

Unigram LM Tokenizer

The unigram language model tokenizer as a probabilistic model: the generative story of a sentence as independently drawn subword pieces, marginalizing…

Read article →
ARTICLE · 364

Variance Maintenance in Deep Nets

The practical engineering of variance maintenance in deep transformers: what to instrument (per-layer activation RMS, the residual-stream growth curve…

Read article →
ARTICLE · 365

Vector DB Math

How a vector database actually works: embedding storage and its memory cost, the ANN index (HNSW / IVF / PQ as pointers), distance metrics (cosine, do…

Read article →
ARTICLE · 366

Verifier Scaling

Verifier-guided and best-of-N scaling: the accuracy-vs-N curve, why a good verifier beats majority vote, outcome vs process reward models, verifier-gu…

Read article →
ARTICLE · 367

Vespa Math

The math that makes Vespa different from a vector store: first-class tensor fields and tensor ranking expressions, the multi-phase ranking cost equati…

Read article →
ARTICLE · 368

LR Warmup Deep Dive

Why the first few hundred steps of transformer training need a smaller step size: Adam's thin second-moment estimate and what bias co…

Read article →
ARTICLE · 369

Weaviate Math + Architecture

The arithmetic behind Weaviate: what a collection stores per object, named vectors, the dynamic-ef formula, thresholds measured in objects rather than…

Read article →
ARTICLE · 370

Width Scaling

How transformer quality and training dynamics change as you widen d_model at fixed depth: the quadratic parameter law (about 12 * L * d^2 non-embeddin…

Read article →
ARTICLE · 371

YaRN + NTK Scaling

YaRN explained from first principles: RoPE frequencies and wavelengths, why linear position interpolation crushes the high-frequency dimensions, the N…

Read article →
ARTICLE · 372

ZeRO Stage 1 Math

How ZeRO Stage 1 partitions Adam optimizer states across data-parallel ranks: the 16-bytes-per-parameter memory model, why the fp32 master weights, mo…

Read article →
ARTICLE · 373

ZeRO Stage 2 Math

ZeRO Stage 2 explained with the memory math: partition gradients as well as optimizer states so each rank keeps only its gradient shard, cutting gradi…

Read article →
ARTICLE · 374

ZeRO Stage 3 Math

The memory and communication math of ZeRO Stage 3: full parameter partitioning that puts 1/N of every parameter, gradient, and optimizer state on each…

Read article →
ARTICLE · 375

Zero-bubble pipeline parallelism

Deep-dive on zero-bubble pipeline scheduling: the (p-1)/m bubble, GPipe vs 1F1B vs interleaved 1F1B, splitting backward into input-gradient B and weig…

Read article →
ARTICLE · 376

ZeRO-Infinity

ZeRO-Infinity as a synthesis: the arithmetic-intensity threshold that decides which memory tier can hold which state, bandwidth-centric partitioning a…

Read article →
ARTICLE · 377

ZeRO Math

ZeRO (Zero Redundancy Optimizer) explained from the memory model up: the redundancy in vanilla data parallelism where every GPU holds full parameters,…

Read article →
ARTICLE · 378

ZeRO-Offload

ZeRO-Offload explained with the math: why optimizer states dominate the 16-bytes-per-parameter Adam memory budget, how moving the fp32 states, the fp3…

Read article →
ARTICLE · 379

Token Embedding Lookup

How the token embedding matrix works: the vocab x d_model lookup table, why a row lookup equals one-hot times E, the shapes from token ids to [N, d_mo…

Read article →
ARTICLE · 380

Tokenizer Math

A first-principles deep-dive on tokenizer math: why subword tokenization sits between characters and words, the frequency-based BPE merge algorithm wi…

Read article →
ARTICLE · 381

Training Data for SLMs

How to choose training data for a small language model: the quality-over-quantity thesis behind Phi's 'textbooks&amp…

Read article →
ARTICLE · 382

Weight Initialization

Why weight initialization matters: variance preservation through layers to avoid vanishing and exploding activations and gradients, the forward and ba…

Read article →
ARTICLE · 383

How Weights Are Stored on Disk

How model weights are stored and laid out in memory: row-major vs column-major order, strides and address arithmetic, why layout decides cache localit…

Read article →