FeaturedCertificateAdvanced

Deep Dive into LLMs: Building and Training GPT Models from Scratch

Master the inner workings of Large Language Models by coding a complete GPT-style architecture from scratch. Learn tokenization, multi-head attention, pretraining, and supervised fine-tuning using PyTorch and Python. Build, train, and align your own deep learning models.

Sebastian Raschka
Sebastian Raschka@sebastianraschka
Published Jul 2, 2026
Updated Jul 2, 2026
Deep Dive into LLMs: Building and Training GPT Models from Scratch
12h 28m
1Enrolled0Bookmarked
/ 5.0

Course Overview

This comprehensive course takes you on an educational journey to build, pretrain, and fine-tune a Large Language Model (LLM) completely from scratch. By writing code from the ground up, you will gain a deep, intuitive understanding of how modern generative AI models like GPT and LLaMA operate.

What You'll Learn

  • Data Preparation: Tokenize raw text, implement Byte Pair Encoding (BPE), and construct high-performance PyTorch DataLoaders with sliding windows.
  • Architecture Implementation: Code self-attention, causal attention, and multi-head attention mechanisms from scratch.
  • GPT Model Construction: Assemble transformer blocks with layer normalization, GELU activation functions, shortcut connections, and feed-forward networks.
  • Pretraining & Generation: Pretrain your model on unlabeled text, implement decoding strategies (temperature scaling and top-k sampling), and load pretrained weights.
  • Fine-Tuning & Alignment: Adapt your model for classification tasks and perform supervised instruction fine-tuning to build custom conversational agents.

Target Audience

  • Python Developers & AI Engineers who want to move beyond using APIs and understand the mechanics of LLMs.
  • Data Scientists & Machine Learning Engineers looking to master PyTorch for deep learning architectures.
  • Researchers seeking a clear, code-first walkthrough of transformer components.

Prerequisites

  • Proficient Python Programming: Familiarity with object-oriented programming in Python.
  • PyTorch Basics: Understanding of tensors and basic neural network concepts.
  • Machine Learning Fundamentals: Conceptual knowledge of training loops, loss functions, and optimization.

Tools & Technologies Used

  • Python (managed via the modern uv environment tool)
  • PyTorch (for neural network construction and training)
  • tiktoken (for Byte Pair Encoding tokenization)
  • Jupyter Notebooks (for interactive experimentation)

Course Content

5Chapters15Lessons5Quizzes
1

Environment Setup and Data Preparation

2 lessons · 1h 49mQuiz
1

Setting up a Reproducible PyTorch Environment with uv

21:02
2

Preprocessing Text Data and Building a Data Loader

88:01
2

Coding Attention Mechanisms from Scratch

4 lessons · 2h 15mQuiz
1

Simplified Self-Attention without Trainable Weights

41:01
2

Implementing Self-Attention with Trainable Weights

39:59
3

Causal Attention Masking and Dropout

25:55
4

Implementing Multi-Head Attention

28:46
3

Implementing the GPT Architecture

4 lessons · 1h 45mQuiz
1

Understanding GPT Architecture and Implementing Layer Normalization

36:02
2

Implementing Feed-Forward Networks with GELU Activations

16:14
3

Adding Shortcut Connections and Assembling the Transformer Block

22:57
4

Coding the Complete GPT Model Architecture

30:24
4

Pretraining and Decoding Strategies

3 lessons · 2h 36mQuiz
1

GPT Text Generation and Loss Computation

70:27
2

Pretraining the GPT Model from Scratch

26:09
3

Advanced Decoding Strategies: Temperature and Top-K

60:08
5

Fine-Tuning and Model Alignment

2 lessons · 4h 1mQuiz
1

Fine-Tuning GPT for Classification Tasks

135:29
2

Supervised Instruction Fine-Tuning

106:04
PriceFree
LanguageEnglish
XP7490
This course includes
About the Channel
Sebastian Raschka
Sebastian Raschka
@sebastianraschka89.5K
1 Course1 Learner

ML/AI researcher & former stats professor turned LLM research engineer. Author of "Build a Large Language Model From Scratch" (amzn.to/4fqvn0D) & reasoning (mng.bz/Nwr7).

Share

Related Courses