Skip to content

September 2026

Building an LLM from Scratch in PyTorch: The Full Lifecycle Cheatsheet

Most LLM tutorials give you one of two things: a high-level diagram with boxes and arrows, or a 10,000-line codebase with no explanation of why each piece exists.

This post is neither. It's a step-by-step lifecycle — 8 phases, each with working PyTorch code, the reasoning behind every decision, and an explicit Do / Don't list that captures the mistakes that cost most beginners weeks of wasted compute.

By the end you'll have built, trained, modernised, scaled, and aligned a language model — the exact same lifecycle that produced every major LLM you've used.

Phase 1: Core Transformer    → the engine
Phase 2: Train a Tiny LLM    → prove the pipeline works
Phase 3: Modernise           → match 2026 architecture
Phase 4: Scale Efficiently   → push past toy datasets
Phase 5: Mixture of Experts  → conditional computation
Phase 6: SFT                 → turn autocomplete into an assistant
Phase 7: Reward Modelling    → teach the model what "good" looks like
Phase 8: RLHF                → optimise for human preference

Every snippet in this post has been executed end-to-end on Python 3.13 + PyTorch 2.12, CPU only — including the full 5,000-step Phase 2 training run. Where a verification test caught a bug in an earlier draft (the KV cache, the reward model head, the PPO log-prob gather), the fix is in the code below and the test that caught it is shown so you can run it on your own implementation.

Prerequisites: comfortable Python, basic tensor operations (view, transpose, broadcasting), and the chain rule. No prior transformer experience — that's what Phase 1 is for.

LLMs and the Transformer Architecture: A Beginner's Complete Guide

You've chatted with ChatGPT. You've asked Claude for help. You've seen GitHub Copilot finish your sentences. But have you ever wondered what is actually happening inside these systems? How does a computer — a machine that ultimately only understands 0s and 1s — produce text that reads like it was written by a thoughtful human?

This guide answers that question from the ground up. No PhD required. We'll start with an analogy a child could follow, then gradually build up to a precise technical understanding of the Transformer architecture that powers every major LLM today.

Master Generative AI — Part 1: Foundation of AI & Machine Learning

This is Part 1 of the Master Generative AI: A Step-by-Step Challenge series — a practical, no-fluff guide to going from complete beginner to confident AI practitioner in 2026.

Series Map:


The AI revolution isn't just for researchers anymore. In 2026, the tools, libraries, and models that used to require a PhD and a supercomputer are now accessible to any developer willing to invest a few weeks of focused learning. This series is your step-by-step map.

We start at the very beginning — not because you're not smart, but because the best practitioners always have the strongest foundations.

Master Generative AI — Part 3: Advanced Generative AI

Part 3 of the Master Generative AI: A Step-by-Step Challenge series.

Series Map:


You've mastered text generation. Now we go wider — into images, audio, video, and multimodal systems. We also confront the hardest question in the field: how do we make these powerful systems safe, fair, and trustworthy?

Master Generative AI — Part 4: Practical Applications

Part 4 of the Master Generative AI: A Step-by-Step Challenge series.

Series Map:


Theory meets reality in this part. We take the tools from Parts 1–3 and apply them to the domains where generative AI is already creating measurable business value — and where practitioners are most in demand in 2026.

Master Generative AI — Part 5: Career & Capstone Projects

Part 5 (Final) of the Master Generative AI: A Step-by-Step Challenge series.

Series Map:


You've covered the full landscape of generative AI — from backpropagation to AI agents, from GANs to responsible AI. This final part is about turning that knowledge into a career. We'll build three production-grade capstone projects, prepare you for interviews, and map the real career paths available to you in 2026.

RAG and LLMOps: How to Build a Production-Grade AI Second Brain

You've built a RAG chatbot that works great on your laptop. It answers questions from a handful of PDFs, the responses feel smart, and you're excited. Then you try to make it production-ready — and everything gets complicated.

How do you keep the knowledge base fresh? How do you know when the LLM starts giving bad answers? How do you fine-tune the model on your own data without breaking what already works? How do you monitor 10,000 daily queries for quality degradation?

This is where LLMOps enters the picture.

This post walks through a complete, real-world architecture: a Second Brain AI assistant that combines RAG, fine-tuned LLMs, agentic inference, and a full observability layer — using the same patterns the best ML teams run in production in 2026. We'll trace every numbered step in the system, explain the why behind each component, and show you what the code looks like.

You ask an AI assistant a question. It confidently gives you an answer — but the answer is wrong, outdated, or completely made up. This is called a hallucination, and it's one of the most frustrating problems with large language models (LLMs) out of the box.

RAG (Retrieval-Augmented Generation) was invented to fix exactly this. And Agentic RAG takes that fix to a whole new level. In this guide, we'll break down both architectures from scratch — what they are, how they work step by step, and when to use which.

vLLM: Production LLM Serving from Zero to Scale

You've downloaded a large language model. You've got it running. But you notice something uncomfortable: it's slow, it can only handle one request at a time, and your GPU is mysteriously underutilized. The moment two people try to use your model at the same time, one of them waits — and waits.

This is the LLM serving problem, and vLLM is the most widely adopted open-source solution to it.

DDD in Action: From Sticky Notes to Production Code

Theory is easy. Practice is where DDD gets real — and where most teams get stuck.

You've read about Bounded Contexts and Aggregates. You understand Ubiquitous Language. But when you sit down with your team in front of a real codebase and real business requirements, a critical question remains: how do you actually do this?

This guide takes you through the complete DDD journey on a concrete real-world system — an online bookstore — from the first collaborative workshop all the way to working production code. Every design decision is explained. Every mistake is shown before the fix. By the end, you'll have a repeatable playbook you can apply to your own system.