Home › Courses › Transformers & LLMs from Scratch

Transformers & LLMs from Scratch

Pre-train a real 124M parameter GPT: tokenizer, data pipeline, training and evaluation

5 phases. 40 lessons. 40 labs. 1 capstone. The transformer from the ground up: self-attention from scratch, multi-head attention, positional encoding, the full encoder-decoder, the BERT and GPT families, and then a real LLM: a tokenizer from scratch, a data pipeline, pre-training a 124M-parameter GPT, instruction tuning, RLHF, DPO, and current architecture changes (MoE, KV cache, flash attention, speculative decoding, quantization). You pre-train a model, not only fine-tune one.

5 phases · 40 lessons · 40 labs · 1 capstone

Take Deep Learning from Scratch first — this course builds on it.

What you finish with

Curriculum

Tools

PyTorch · Hugging Face Transformers · NumPy · tiktoken · Weights & Biases

What transformers & LLMs from scratch actually is

It's building the transformer architecture from the ground up — self-attention, multi-head attention, positional encoding, encoder-decoder — and then using that understanding to pre-train a real 124M parameter GPT model. You build the tokenizer, the data pipeline, the training loop, the instruction tuning, and the alignment. By the end, you've built a complete LLM, not just used one.

What you do every day

You build LLM systems — fine-tuning, inference, evaluation. But you understand every component at the implementation level. When generation quality drops, you know whether it's the tokenizer, the model architecture, the training data, or the inference setup. When a new architecture is released, you can read the paper and understand what changed.

Why companies hire for this

Every company wants to use LLMs, but most engineers treat them as APIs. The engineer who pre-trained a GPT from scratch is the one who can build custom fine-tuning pipelines, optimize inference, and implement novel architectures from papers. That's the engineer companies pay top dollar for.

What this course is not

It is not a prompt engineering course. It is not a LangChain tutorial. It is not about using the OpenAI API. This course is about building the model itself — the architecture, the training, the alignment — from scratch. If you want to use LLMs as a black box, take ML & AI Engineering instead.

Common questions

Do I need Deep Learning from Scratch first?

Yes. This course uses PyTorch, autograd, backpropagation and training loops throughout. Deep Learning from Scratch builds those foundations; this course applies them to the transformer and LLM pre-training.

Can I really pre-train a 124M-parameter model?

Yes. A 124M-parameter model is small enough to train on one GPU, or a good CPU with patience. The capstone is designed to run on consumer hardware, using the same pipeline as billion-parameter models.

How is this different from the Transformers phase in ML & AI Engineering?

ML & AI Engineering covers transformers in 6 lessons, enough to fine-tune a pre-trained model. This course spends 20 lessons building attention from scratch, implementing BPE tokenization, pre-training a GPT model, implementing RLHF and DPO, and covering current architecture changes. Using an LLM versus building one.

What do I end up with?

A pre-trained 124M-parameter GPT with your own tokenizer, data pipeline, training loop, instruction tuning and evaluation, as a pipeline you can extend for later LLM projects.

Key terms in this course

Mixture of Experts (MoE) · Speculative Decoding · KV Cache · RLHF · Transformer · DPO (Direct Preference Optimization) · Inference · Quantization

Continue your learning path

Deep Learning from Scratch · Multimodal AI Systems · NLP & Speech Processing · ML & AI Engineering

Start the Transformers & LLMs from Scratch course

Create a free account — the opening phases of 29 of 35 courses, and the first lesson of every phase, are free, no credit card. Or see Pro pricing.

All courses · Pricing · About · FAQ · Glossary · Projects by topic