Architecting Large Language Models from Scratch: From Perceptrons to Post-Training
Master the inner workings of LLMs by building a GPT-2-style transformer from scratch. Learn neural network fundamentals, GPU optimization, attention mechanisms, pre-training pipelines, instruction tuning, and policy optimization using PyTorch.

Course Overview
Demystify Large Language Models (LLMs) by building, training, and optimizing a GPT-2-style transformer from first principles. This course bridges the gap between high-level API usage and low-level implementation, taking you on a journey from a single perceptron to advanced reinforcement learning techniques.
What You'll Learn
- Fundamentals of Neural Networks: Build perceptrons, implement activation functions (ReLU, GELU, ReLU²), and construct Multi-Layer Perceptrons (MLPs) using PyTorch.
- Training Mechanics & Optimization: Understand cross-entropy loss, backpropagation, and state-of-the-art optimizers like AdamW.
- Deep Network Stability: Prevent training collapse using He/Xavier initialization, additive residual streams, and pre-norm RMSNorm/LayerNorm.
- The Transformer Architecture: Implement causal self-attention, Multi-Query Attention (MQA), Grouped-Query Attention (GQA), and assemble a complete generative transformer.
- Data & Pre-Training: Clean raw web crawls, implement Byte Pair Encoding (BPE), build high-throughput sharded dataloaders, and run pre-training.
- Post-Training & Alignment: Fine-tune models using LoRA/QLoRA, and align them with human preferences using direct policy optimization (SimPO).
Prerequisites
- Strong proficiency in Python programming.
- Comfort with basic programming concepts (no prior advanced math or machine learning experience required, as fundamentals are built from the ground up).
- Access to Google Colab or a local GPU environment for training exercises.
Tools & Technologies
- Frameworks: PyTorch, Hugging Face Transformers, Tiktoken
- Hardware Acceleration: CUDA, Triton, GPU-performant coding
- Analysis & Visualization: Microsoft Excel / Google Sheets (for visual math demos), Bertviz, Neuronpedia
Course Content
Introduction to LLMs, Text Generation, and Architecture Exploration
Autoregressive Text Generation and Sampling Heuristics
Reverse-Engineering GPT-2 and Mapping the Architecture
Neural Network Foundations: Perceptrons, Activations, and GPU Optimization
Perceptrons: The Mathematical Engine of Deep Learning
Activation Functions: Injecting Non-Linearity
GPU Coding: Optimizing PyTorch Execution with Fused Kernels
Multi-Layer Perceptrons (MLPs) and Feed-Forward Networks
Training Mechanics: MLPs, Loss Functions, Backpropagation, and Model Persistence
Building Multi-Layer Perceptrons and Feed-Forward Networks
Loss Functions: From Residuals to Cross-Entropy
Backpropagation and Optimization Loops
Saving and Loading Models: Serialization Formats
Stabilizing Deep Networks: Initialization, Residuals, Normalization, and Regularization
Random Initialization & Preventing Training Collapse
Residual Connections & Signal Preservation
Normalization: LayerNorm, RMSNorm, and Pre-Norm Architectures
Regularization: Weight Decay, Gradient Clipping, and Dropout
SoftMax: Mapping Logits to Probabilities
Representing Text: Tokenization, Embeddings, and Positional Encodings
Subword Tokenization and Byte Pair Encoding (BPE)
Token Embeddings and Positional Encodings
The Core Transformer: Causal Attention, Multi-Head Architectures, and Full Model Assembly
Implementing Causal Self-Attention and Multi-Head Attention
Assembling the Full GPT-2 Transformer Block
Pre-Training Pipelines and LLM Evaluation Strategies
Building High-Quality Pre-Training Pipelines with FineWeb-Edu
Scientific Evaluation of LLMs: Benchmarks, Lambada, and Perplexity
Post-Training Adaptation: Instruction Tuning, Reinforcement Learning, and Scaling
Instruction Tuning, Alpaca Formats, and LoRA Fine-Tuning
Alignment and Direct Preference Optimization with SimPO
Scaling Up: Parallelism, FlashAttention, and KV Caching
This course includes
- 14h 23m on-demand video
- 24 lessons across 8 chapters
- 8 interactive quizzes
- Access on mobile and desktop
- Source playlist on YouTube
Topics Covered
About the Channel
AI, ML, LLMs.
Share
Related Courses

Mastering AI-Driven Development with OpenAI Codex: From Setup to Autonomous Agents
Master OpenAI Codex to build, manage, and deploy applications using autonomous AI agents. Learn to set up workspaces, leverage git worktrees, configure Agents.md, and build three complete applications step-by-step from scratch.

Data Analysis and Visualization Fundamentals with Python, Pandas, and Matplotlib
Master the basics of data science by learning how to analyze and visualize real-world datasets. Using Python, Pandas, and Matplotlib within Jupyter Notebooks, you will plot population growth trends and compare relative data.

LLM App Development: Building Powered Applications with LangChain
Master the fundamentals of LangChain to build LLM-powered applications. This beginner-friendly course guides you through prompt templates, chains, agents, conversational memory, and document loaders using Python and OpenAI.