
This course contains the use of artificial intelligence
Everyone uses large language models. Very few people know what happens inside one, and even fewer have trained and
fine-tuned one themselves. Companies now fine-tune their own models on their own data, and they need engineers who
understand every step, not only how to call an API.
In this course you build a complete small language model from random numbers, in pure PyTorch, and then turn it into
a chat assistant. It is a real, modern design: a 10-block, Llama-style transformer with 53,507,200 parameters, trained
on about one billion tokens on a single 8 GB laptop GPU.
First you build the model. You start with the basics: tensors, loss, gradients and next-token prediction. Then you
build a byte-level BPE tokenizer with 16,384 tokens, a data pipeline that filters, mixes and packs text into binary
shards, and the transformer itself: token embeddings, RoPE, causal attention with grouped-query attention, RMSNorm and
SwiGLU. You train it with a real engine: gradient accumulation, bf16, AdamW, a learning-rate schedule, resumable
checkpoints and a GPU heat guard. You watch the loss fall from 9.82 to 2.93, and you make it write text with
temperature, top-k, top-p and a KV-cache.
Then the heart of the course: fine-tuning. A base model only continues text. You turn it into an assistant with
supervised fine-tuning on 20,000 real chat conversations, with a loss mask so the model learns only from the
assistant's words. Then you align it with Direct Preference Optimization on 5,000 pairs of good and bad answers: the
DPO loss in code, the reference model, beta, reward accuracy and margin. And when alignment goes wrong (it does: the
model starts repeating itself), you diagnose it honestly instead of hiding it.
Then you test, shrink and serve it. You measure the model with perplexity, a sliding window and bits per byte, you
compare base, SFT and DPO answers side by side, and you learn the honest limits of a small model. You repeat the whole
fine-tuning process on your own data. Finally you shrink the model to INT8 (204.6 MB down to 81.8 MB, with perplexity
27.73 to 27.81) and 4-bit, and serve it with a streaming FastAPI chat server at about 108 tokens per second.
Everything is real. Every number, loss value, answer and timing on screen comes from a real run of the real code.
The full project is on GitHub, so you can rebuild and retrain every part yourself. Every package we use is open
source, and every training dataset is openly licensed and credited.
How it is taught. Face to face and step by step: every new word is explained with an everyday picture first, every
idea is shown as a moving animation, and every code file is opened and explained block by block.
What you need. Basic Python. An Nvidia GPU with 8 GB helps to train the model yourself, but it is not required to
follow the course: the lectures show every real run, and the smaller setting runs on a normal computer.
By the end, you will be able to build, pre-train, fine-tune, align, test, shrink and serve a language model of your
own, and you will understand every line that does it.