Let’s Build a Transformer!
The series
From our first GPU kernel to a transformer that generates text. Each lesson extends the same C# program.
The series
0 of 18 lessons published
Start here · Prologue
Prologue: Getting the cradle ready
Set up the tools, build the starting program, and check the dependencies we’ll use in the first lesson.
Published ·
Latest: Prologue: Getting the cradle ready
- The cradle Planned
Run our first kernel on the GPU.
- Buffers and shapes Planned
Give the data a shape we can work with.
- Matrix multiplication Planned
Build the operation at the heart of the model.
- Softmax Planned
Turn scores into a stable distribution.
- Tokens in Planned
Convert text to token IDs and back with byte-level BPE.
- Embeddings Planned
Look up a vector for each token on the GPU.
- One attention head Planned
Combine projections, a causal mask, and a weighted sum.
- Many heads Planned
Extend attention to multiple heads and grouped queries.
- Position Planned
Give queries and keys a sense of position with RoPE.
- Normalization and residuals Planned
Add RMSNorm and the connections around attention.
- The gated MLP Planned
Complete our first transformer block.
- GGUF Planned
Read model weights and load them into GPU buffers.
- A real block Planned
Check the loaded block against an independent reference.
- The whole model Planned
Run every block and generate text with greedy decoding.
- The KV cache Planned
Reuse previous keys and values during generation.
- Sampling Planned
Add temperature, top-k, and top-p to the generation loop.
- Quantized weights Planned
Run four-bit weights and examine the tradeoffs.
- Performance Planned
Measure the engine and improve the kernels we already have.