LLMs from Scratch – Practical Engineering from Base Model to PPO RLHF

LLMs from Scratch – Practical Engineering from Base Model to PPO RLHF

🎙 Vivek Kalyanarangan 👥 11.8M 📅 September 23, 2025 ⏱ 366 min 👁 189K 📄 tutorial 🧭 2026-08-06
Available in: English (current) Français

Keywords

transformerattentionPPORLHFfine-tuning

Summary

This comprehensive 6-hour course by Vivek Kalyanarangan, published on freeCodeCamp, provides a hands-on, from-scratch implementation of large language models (LLMs) using PyTorch. It covers the entire lifecycle, starting with the core transformer architecture, including multi-head attention, feed-forward layers, and positional encoding. The course then progresses to training a tiny LLM on a small text corpus, covering tokenization, batching, loss functions, and sampling. It modernizes the architecture with techniques like RMSNorm, rotary embeddings, SwiGLU, KV cache, and sliding window attention. Scaling up is addressed through byte-pair encoding, gradient accumulation, mixed precision training, and checkpointing. The course also covers Mixture-of-Experts (MoE) layers, supervised fine-tuning (SFT), reward modeling with pairwise preference data, and finally reinforcement learning from human feedback (RLHF) using proximal policy optimization (PPO). Each part includes modular, well-commented code available on GitHub, with an orchestrator.py as the entry point. The course is designed to be practical and accessible, with minimal theory and a focus on implementation. It is suitable for learners with basic Python and PyTorch knowledge, and a GPU is optional. The instructor emphasizes understanding the building blocks of models like GPT, enabling learners to build and customize their own LLMs.

191 words

Critical Evaluation

The course is an exceptional resource for anyone seeking a deep, practical understanding of LLMs. Its primary strength lies in its comprehensive, end-to-end approach, covering everything from the fundamental transformer architecture to advanced alignment techniques like RLHF with PPO. The instructor, Vivek Kalyanarangan, demonstrates a clear and methodical teaching style, breaking down complex concepts into manageable, code-driven segments. The use of pure PyTorch ensures that learners gain a genuine understanding of the underlying mechanics, rather than relying on high-level abstractions. The course is well-structured, with each part building logically on the previous, and the provided GitHub repository contains modular, well-commented code that facilitates hands-on learning. The theoretical explanations are concise but sufficient, providing the necessary context without overwhelming the learner. The course also incorporates modern techniques such as rotary embeddings, RMSNorm, SwiGLU, and mixture-of-experts, ensuring that learners are exposed to current best practices. The alignment phase, including reward modeling and PPO, is particularly valuable, as it addresses the critical aspect of making LLMs helpful and safe. The main limitation is the lack of formal citations to academic papers or external sources, which could enhance the credibility and allow learners to explore the underlying research. However, the content is accurate and aligns with established knowledge in the field. The title accurately reflects the content, and the course delivers on its promise of building an LLM from scratch. The public comments are overwhelmingly positive, with viewers expressing gratitude and enthusiasm, and many indicating they plan to follow along and build their own models. The course’s practical, hands-on nature is highly praised, and it is considered a valuable contribution to the learning community. Overall, this is an excellent, high-quality resource that deserves a top rating.

282 words

Title / Content Match

The title accurately reflects the content: a comprehensive, from-scratch implementation of LLMs, covering base model training to PPO-based RLHF.

Quality & Reliability

9/10

The course is a hands-on tutorial with code available on GitHub, covering the full LLM pipeline from transformer architecture to RLHF. The content is technically accurate, well-structured, and based on established research (e.g., Attention Is All You Need, PPO). The instructor demonstrates deep expertise and provides practical implementation details. The main limitation is the lack of formal citations to sources, but the code and explanations are reproducible.

Chapters

Cited Sources

Concurring Sources

External References

Contribution & Novelties

The course provides a unique, single-place, end-to-end implementation of modern LLMs, from base transformer to RLHF, using pure PyTorch. It bridges the gap between theory and practice, offering a comprehensive hands-on experience that is rare in existing tutorials. The inclusion of advanced techniques like MoE and PPO in a from-scratch context is particularly valuable.

Pour aller plus loin :

135 words

Radar Profile

The radar profile shows very high scores across all dimensions, indicating a comprehensive, technically rigorous, and highly reliable tutorial. The course excels in quantity and quality of information, with a strong technical depth and high reliability, making it an excellent resource for learners.

Reliability 9/10

💬 Très positif. Sur les 30 commentaires analysés, l'accueil est extrêmement enthousiaste, avec des remerciements et des éloges pour la clarté et la profondeur du cours, et plusieurs demandes de contenus similaires.