{mvGPT}

Episodes

  1. Our GPT's own GPU kernels in Mojo on a Mac

    We write our GPT's writing path as GPU kernels in Mojo, call them from Python, check them against PyTorch, and make them faster in three versions, racing PyTorch and MLX on this Mac.

    37 min

  2. Measuring and fixing our C++ BPE tokenizer

    We measure episode eleven's C++ tokenizer on web pages, its memory, its time, its threads and its long chunks, and fix what we find with an LRU cache, a GIL-free encoder, a cache per call and a heap.

    50 min

  3. Sparse autoencoder features inside our GPT

    We train a sparse autoencoder on the residual stream of our web model, read what its features fire on, measure what it costs the model, and steer the model's writing with a feature.

    26 min

  4. Our GPT in Apple's MLX vs PyTorch on a Mac

    We port our GPT from PyTorch to MLX, Apple's array library for its own chips, check that it gives the same numbers, and race the two on this Mac at writing and at training.

    24 min

  5. Mixture of experts from scratch in PyTorch

    We replace each block's MLP in our GPT with a mixture of eight experts and a router, write it as a loop and then as one batched multiply, balance it three ways, and train it next to the dense model at the same compute per token.

    37 min

  6. GRPO in Hugging Face TRL on our own small GPT

    We train our own GPT with GRPO in Hugging Face's TRL, set up like the GRPO we wrote by hand and then with TRL's defaults, and measure both against our own.

    28 min

  7. Hyena, a GPT without attention, measured

    We replace attention in our GPT with Hyena's long convolutions and gates, computed with the FFT, and measure it against our own attention models on speed, loss, long context and recall.

    61 min

  8. Attention heads in our GPT, seen and tested

    We look inside our agent while it copies a name into a query, with each head's attention written out, the logit lens, and a page of our own, then turn the heads that look at the name off to see what they do.

    23 min

  9. Speculative decoding from scratch

    A draft guesses the next few tokens, and our agent checks them in the pass that writes its own, so it writes what greedy decoding writes in fewer passes. Two drafts, prompt lookup and a small model trained for thirty minutes, measured on the agent's tasks.

    26 min

  10. Structured LLM output with constrained decoding

    Nothing is trained. Before each token inside a query's name, our agent's graph role masks the tokens that would take the name off a list, and we measure two lists, the graph's names and the task's words.

    25 min

  11. AI agent with a graph database and a calculator

    Our agent gets a fourth role, which queries smollerGraph in Cypher, so it can take two facts from a graph database and combine them with the calculator, and we measure what it kept of its old tasks.

    27 min

  12. Our GPT writes Cypher to ask a graph database

    We fine-tune our agent to write Cypher queries for smollerGraph, the graph database built in our sibling series, and to answer from what comes back, then measure it with the graph and without.

    27 min

  13. Muon vs AdamW, Lion and Sophia in a fair race

    We write AdamW from scratch, then race it against Lion, Sophia and Muon on our stories model, each with its own sweep of the learning rate, and measure the steps, the time and the memory each needs.

    46 min

  14. Long context LLM by stretching RoPE with YaRN

    We stretch the rotary embeddings of our web model to read four times its window, four ways and then with fifteen minutes of fine-tuning, and measure the loss by position and a pass key hidden in filler.

    39 min

  15. AI agent from scratch, with subagents

    We fine-tune our web model into an agent that writes files and hands work to subagents, each a fresh context of the same model, and measure what the subagents buy.

    23 min

  16. LLM tool calling from scratch with a calculator

    We fine-tune the model we pretrained on the web to call a calculator, in plain text, and measure how often it calls it right, on questions asked the way training asks and in new ways, with the calculator and without it.

    21 min

  17. Pretraining a GPT on the web overnight

    We pretrain a model in GPT-2 small's shape on educational web pages for a whole night, on one RTX 4090 rented for under four dollars, and measure it against GPT-2 small on HellaSwag.

    27 min

  18. Grouped-query attention for a smaller KV cache

    We give our model grouped-query attention, where the query heads share their keys and values in groups, so the KV cache keeps fewer heads, and we check it against the attention we had and work out what it saves.

    22 min

  19. A modern GPT block with RMSNorm, SwiGLU and QK-norm

    We bring our GPT's transformer block up to date with RMSNorm, SwiGLU, QK-norm and no biases, the changes recent open models made to it, each behind a config flag, with tests, and work out what they do to the parameter count.

    36 min

  20. Reinforcement learning without a critic using GRPO

    Our model writes eight stories per instruction, and each is scored against the others, in place of PPO's critic, with group relative policy optimisation, the reinforcement learning behind DeepSeek-R1.

    22 min

  21. A text diffusion GPT that writes all at once

    We turn our GPT into a masked diffusion model, which writes a story by unhiding it, train it on the laptop and on four rented GPUs, start one from our next-token models' weights, and measure it against next-token prediction, comparing our code with LLaDA's, which trains this recipe at 8 billion parameters.

    34 min

  22. Batching to serve a GPT to many users at once

    We serve the model as an API in the shape of OpenAI's completions, measure it against a crowd of players from a game, write the stories for the requests that arrive together as a batch, and run it in Docker, with vLLM as the alternative.

    25 min

  23. Flash attention from scratch in PyTorch and Triton

    We write attention without its table of scores, first in PyTorch on the Mac, then as a Triton kernel on a rented NVIDIA GPU, forwards and backwards, and measure it against the FlashAttention-2 inside PyTorch.

    39 min

  24. Distributed training in PyTorch on 4 GPUs with DDP

    We pretrain a model about six times bigger, in GPT-2 small's shape, on four RTX 4090s rented by the hour, with PyTorch's DistributedDataParallel, and measure how the speed scales from one GPU to four, and how much better the model gets in thirty minutes.

    29 min

  25. A byte-level BPE tokenizer for a GPT in C++

    We write a byte-level BPE tokenizer in C++, test it against a Python reference, pretrain our model on the stories in BPE, and compare the two tokenizers' models in bits per character.

    32 min

  26. Rotary position embeddings (RoPE) from scratch

    We replace our model's table of positions with rotary position embeddings, which turn each query and key by its position, so attention scores depend on how far apart two tokens are, and the KV cache can slide past the context window.

    17 min

  27. LoRA fine-tuning a GPT with 2% of its weights

    We fine-tune our model on instructions again with LoRA, which freezes its weights and trains a small low-rank update beside them, and measure what it saves and what it learns against full fine-tuning.

    15 min

  28. Reinforcement learning for a GPT with PPO

    Our model learns from its own stories, scored as it writes them, with proximal policy optimisation, a critic and a penalty for drifting, and we measure it next to DPO.

    22 min

  29. Teaching a GPT from preferences with DPO

    With direct preference optimisation, our fine-tuned model learns from pairs of its own stories, where the one that uses more of the words asked for is preferred, and we measure what it gains and what it costs.

    17 min

  30. Profiling a GPT with PyTorch's profiler

    We look at our model as a graph of operations in Model Explorer, profile it with PyTorch's profiler, and measure how decisions in its code change its speed on a CPU and a GPU.

    18 min

  31. Deploy a GPT with Hugging Face, Gradio and a browser

    We save our model as a GPT-2 and push it to the Hugging Face Hub, with a tag per episode, serve it from a Gradio app on a VPS, and run it in the browser with Transformers.js.

    28 min

  32. KV cache from scratch in PyTorch

    We add a KV cache to our model, so it runs each new token on its own and not the whole story again, and we check and time it on the CPU and the GPU.

    20 min

  33. Fine-tuning a GPT to follow instructions with SFT

    Our pretrained model learns to write the story an instruction asks for, with a loss on the story alone, and we measure how much better it follows instructions.

    27 min

  34. Pretraining a GPT from scratch in PyTorch

    From random tokens to short stories in a first training run on a laptop, with a tokenizer, the next-token objective, a training loop and evaluation written from scratch.

    27 min

  35. Build a GPT from scratch in PyTorch

    A small GPT written from scratch in PyTorch, from its parameters to how a prompt flows through it to the next token.

    32 min