Machine learning

Reference implementations of the algorithms behind modern machine learning, written from scratch and explained. Each page derives the math, implements the algorithm twice, in PyTorch and in JAX behind a language switcher so the two idioms can be read against each other, then covers where the algorithm earns its keep in practice and how the from-scratch version compares with the production libraries (scikit-learn, FAISS, XGBoost, torchvision, diffusers, and friends). GPU-bound submodules additionally carry Triton and CUDA kernels beside the reference, as the softmax page shows.

Featured page

Attention, from soft lookup to transformer block

Scaled dot-product attention derived as a differentiable dictionary lookup, multi-head attention, causal masking, and a complete transformer block, verified against the fused kernels, with the variants that power modern LLMs covered in their own section below.

Read the page →

Classical machine learning

The pre-deep-learning toolkit, still the right answer surprisingly often. Each implemented in PyTorch and JAX and measured against scikit-learn and its cousins.

Neural networks and building blocks

From backpropagation written by hand up through the submodules transformers are assembled from. The GPU-bound pages add Triton and CUDA kernels beside the reference.

Attention

The mechanism at the center of modern ML, from the core derivation through the variants every production model ships, with what each one is actually useful for.

Architectures and generative models

The model shapes that keep reappearing, each implemented completely and tied to the production codebases that ship them.

Optimization and training

What happens between the forward pass and the updated weights, from-scratch optimizers verified step-for-step against torch.optim and optax.