Learn LLM internals step by step - from tokenization to attention to inference optimization.
See the code
Learn LLM internals step by step - from tokenization to attention to inference optimization.
Prepared and maintained by the Founder of Outcome School: Amit Shekhar
Note: This series will continue to grow as I write more blogs and create more videos on new topics. Keep learning.
Before diving into the internals of an LLM, it’s a good idea to first understand what an LLM actually is.
In this video, we will cover the following:
Let's get started: AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, Quantization
In this video, we will learn about Tokenization and why they are essential for Large Language Models.
Let's get started: Tokenization in Large Language Models (LLMs)
In this blog, we will learn about Tokenization in LLMs, the very first step that turns our text into numbers before a Large Language Model can process it. We will also see what a token is, the three approaches to break text into tokens, how BPE works, how tokens are decoded back to text, and how tokenization affects LLMs in practice.
We will cover the following:
Let's get started: Tokenization in LLMs
In this blog, we will learn about BPE (Byte Pair Encoding) - the tokenization algorithm used by most modern Large Language Models (LLMs) to break text into smaller pieces before processing it.
We will understand what BPE is, why it is needed, and how it works step by step with a simple example.
We will cover the following:
Let's get started: Byte Pair Encoding in LLMs
In this blog, we will learn about Stop Tokens in LLMs, the special tokens that tell a Large Language Model when to stop generating text. We will also see how an LLM generates text one token at a time, why it needs to stop, how the model learns to produce a Stop Token, how a Stop Token differs from a Stop Sequence, and how chat models use Stop Tokens to end their turn.
We will cover the following:
Let's get started: Stop Tokens in LLMs
In this blog, we will learn about the math behind Attention: Query(Q), Key(K), and Value(V) with a step-by-step numeric example.
We will cover the following:
Let's get started: Math behind Attention - Q, K, and V
In this blog, we will learn about why we scale the dot product attention by √dₖ in the Transformer architecture with a step-by-step numeric example.
We will cover the following:
Let's get started: Math behind √dₖ Scaling Factor in Attention
In this blog, we will learn about causal masking in attention.
We will start with the introduction of causal masking, understand the problem of seeing future tokens through an example, and then walk through its implementation to see how masked attention prevents the model from accessing future tokens.
We will cover the following:
Let's get started: Causal Masking in Attention
In this blog, we will learn about the math behind backpropagation in neural networks.
Backpropagation is the core algorithm that allows neural networks to learn from their mistakes. Without it, training neural networks efficiently would not be possible. Understanding the math behind it gives us a deeper understanding of how neural networks actually learn. Do not worry, we will learn about each concept step by step so that everything is clear.
We will cover the following:
Let's get started: Math Behind Backpropagation
In this blog, we will learn about the math behind Cross-Entropy Loss with a step-by-step numeric example.
When we train a classification model in machine learning, the model predicts probabilities for each class. For example, given an image, the model outputs something like: "I am 70% sure this is a cat, 20% sure it is a dog, and 10% sure it is a rabbit." To train the model, we need a way to measure how wrong these predictions are compared to the true answer. This is exactly what Cross-Entropy Loss does. It is the most widely used loss function in classification tasks, and it powers the training of almost every modern AI model, including GPT, BERT, and image classifiers.
We will cover the following:
Let's get started: Math Behind Cross-Entropy Loss
In this blog, we will learn about the Transformer architecture by decoding it piece by piece - understanding what each component does, how they work together, and why this architecture powers every modern Large Language Model (LLM).
We will cover the following:
Let's get started: Decoding Transformer Architecture
In this blog, we will learn about Feed-Forward Networks in LLMs - understanding what they are, how they work inside the Transformer architecture, why every Transformer layer needs one, and what role they play in making Large Language Models so powerful.
We will cover the following:
Let's get started: Feed-Forward Networks in LLMs
In this blog, we are going to learn about Batch Normalization vs Layer Normalization. We will also see how Batch Normalization and Layer Normalization differ from each other and when to use which one.
We will cover the following:
Let's get started: Batch Normalization vs Layer Normalization
In this blog, we will learn about KV Cache - where K stands for Key and V stands for Value - and why it is used in Large Language Models (LLMs) to speed up text generation.
We will start with how LLMs generate text one token at a time, understand the role of Key, Value, and Query inside the model, see the problem of repeated computation through an example, and then walk through how KV Cache solves this problem by storing and reusing past results.
We will cover the following:
Let's get started: KV Cache in LLMs
In this blog, we will learn about Paged Attention, a technique that solves the memory waste problem of KV Cache, allowing LLMs to serve many more users at the same time.
We will start with a quick recap of KV Cache, understand the memory problem it creates, see how traditional memory allocation wastes space through an example, and then walk through how Paged Attention solves this problem by borrowing an idea from how computers manage memory.
We will cover the following:
Let's get started: Paged Attention in LLMs
In this blog, we will learn about Flash Attention by decoding it piece by piece - understanding why standard attention is slow, what makes Flash Attention fast, how it uses GPU memory cleverly, and why it is used in almost every modern Large Language Model (LLM).
We will cover the following:
Let's get started: Decoding Flash Attention in LLMs
In this blog, we will learn about Speculative Decoding - what it is, why LLM generation is slow without it, how a small draft model and a big target model work together to produce tokens faster, the rejection sampling math that guarantees no quality loss, real numbers showing the 2x to 3x speedup, where it is used in production, and the trade-offs to watch out for.
We will cover the following:
Let's get started: Speculative Decoding
In this blog, we will learn about Medusa, a simple way to make a language model generate text 2 to 3 times faster by giving it several extra heads that guess multiple future tokens at once.
We will cover the following:
Let's get started: Decoding Medusa
In this blog, we will learn about EAGLE, a state-of-the-art way to speed up language model generation by drafting tokens at the feature level instead of the token level.
We will cover the following:
Let's get started: Decoding EAGLE
In this blog, we will learn about Continuous Batching, a technique that lets LLM servers handle many more users at the same time by keeping the GPU busy at every single step of generation.
We will cover the following:
Let's get started: Continuous Batching in LLMs
In this blog, we will learn about how Prompt Caching works. We will also see why we need it, how it actually works inside a large language model, and where it is used in real systems like AI assistants and agents.
We will cover the following:
Let's get started: How does Prompt Caching work?
In this blog, we will learn about Prefill vs Decode, the two phases of LLM inference, and how understanding them helps us optimize the speed of an LLM. We will also see how the prefill and decode phases work, how the KV cache connects them, how they differ and when to use which one based on our use case, and how we optimize each phase to make an LLM faster.
We will cover the following:
Let's get started: Prefill vs Decode: LLM Inference Optimization
In this blog, we will learn about the Mixture of Experts (MoE) architecture - understanding what experts are, how the router picks them, why MoE makes large models faster and cheaper, and why it powers many of today's most powerful Large Language Models (LLMs).
We will cover the following:
Let's get started: Mixture of Experts Explained
In this blog, we will learn about Grouped-Query Attention (GQA) and how it differs from Multi-Head Attention (MHA). We will also learn about Multi-Query Attention (MQA) along the way and see when to use which one.
We will cover the following:
Let's get started: Grouped Query Attention
In this blog, we will learn about the math behind Rotary Position Embedding (RoPE) and why it is used in modern Large Language Models.
We will cover the following:
Let's get started: Math Behind RoPE (Rotary Position Embedding)
In this blog, we will learn about RMSNorm, a faster and simpler alternative to Layer Normalization that powers most modern Large Language Models like Llama, Mistral, Gemma, Qwen, PaLM, and DeepSeek.
We will cover the following:
Let's get started: RMSNorm (Root Mean Square Layer Normalization)
In this blog, we will learn about LoRA - Low-Rank Adaptation of Large Language Models.
We will cover the following:
Let's get started: LoRA: Low-Rank Adaptation of LLMs
In this blog, we will learn about Large Reasoning Models (LRMs), how they are different from standard Large Language Models, how they think before they answer, how they are trained, and when we must use them.
We will cover the following:
Let's get started: Large Reasoning Models (LRMs)
In this blog, we will learn about Reinforcement Learning from Human Feedback (RLHF), the training technique that turns a raw pre-trained LLM into a helpful, honest, and safe assistant by teaching it from human preferences.
We will cover the following:
Let's get started: Reinforcement Learning from Human Feedback (RLHF)
In this blog, we will learn about DeepSeek-V4, the new family of open Mixture-of-Experts language models that natively supports a one-million-token context with dramatically lower inference cost.
DeepSeek-V4 makes one-million-token context roughly a tenth as expensive as it was in DeepSeek-V3.2. It introduces a new attention design, a new way of doing residual connections, a new optimizer, and a new post-training pipeline. We will decode each of these one by one.
We will cover the following:
Let's get started: Decoding DeepSeek-V4
In this blog, we will learn about Prompt Injection in Large Language Models. We will also see why it happens, how an attacker uses it, why the obvious fixes fail, and how we can defend our AI applications against it in the real world.
We will cover the following:
Let's get started: Prompt Injection in LLMs
In this blog, we will learn about the Lost in the Middle problem in LLMs, the strange behaviour where a model reads a very long text, uses the beginning and the end very well, and quietly ignores whatever is sitting in the middle. We will also see what a context window really means, how the accuracy forms a U-shaped curve, why the middle gets forgotten, how this silently breaks RAG systems and long conversations, how we can test our own model for it, and what we can do to fix it.
We will cover the following:
Let's get started: The Lost in the Middle Problem in LLMs
In this blog, we will learn about how LLM watermarking works, the hidden signal that a model quietly leaves inside the text it writes. We will also see why we need it, how an LLM picks one token at a time, how a secret key silently changes those choices without touching the meaning, how a detector finds that hidden pattern later, why the quality of the text does not break, how it is different from an AI text detector, and where it works well and where it fails.
We will cover the following:
Let's get started: How Does LLM Watermarking Work?
In this blog, we will learn about Harness Engineering in AI. We will understand what a harness is, why we need it, and how it is used in AI Agents and evaluation systems.
We will cover the following:
Let's get started: Harness Engineering in AI
Copyright (C) 2026 Outcome School
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
6,597 followers · starred Apr 2026
1,129 followers · starred Jun 2026
143 followers · starred Jun 2026
114 followers · starred Apr 2026
Learn LLM internals step by step - from tokenization to attention to inference optimization.
See the code
Learn LLM internals step by step - from tokenization to attention to inference optimization.
Prepared and maintained by the Founder of Outcome School: Amit Shekhar
Note: This series will continue to grow as I write more blogs and create more videos on new topics. Keep learning.
Before diving into the internals of an LLM, it’s a good idea to first understand what an LLM actually is.
In this video, we will cover the following:
Let's get started: AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, Quantization
In this video, we will learn about Tokenization and why they are essential for Large Language Models.
Let's get started: Tokenization in Large Language Models (LLMs)
In this blog, we will learn about Tokenization in LLMs, the very first step that turns our text into numbers before a Large Language Model can process it. We will also see what a token is, the three approaches to break text into tokens, how BPE works, how tokens are decoded back to text, and how tokenization affects LLMs in practice.
We will cover the following:
Let's get started: Tokenization in LLMs
In this blog, we will learn about BPE (Byte Pair Encoding) - the tokenization algorithm used by most modern Large Language Models (LLMs) to break text into smaller pieces before processing it.
We will understand what BPE is, why it is needed, and how it works step by step with a simple example.
We will cover the following:
Let's get started: Byte Pair Encoding in LLMs
In this blog, we will learn about Stop Tokens in LLMs, the special tokens that tell a Large Language Model when to stop generating text. We will also see how an LLM generates text one token at a time, why it needs to stop, how the model learns to produce a Stop Token, how a Stop Token differs from a Stop Sequence, and how chat models use Stop Tokens to end their turn.
We will cover the following:
Let's get started: Stop Tokens in LLMs
In this blog, we will learn about the math behind Attention: Query(Q), Key(K), and Value(V) with a step-by-step numeric example.
We will cover the following:
Let's get started: Math behind Attention - Q, K, and V
In this blog, we will learn about why we scale the dot product attention by √dₖ in the Transformer architecture with a step-by-step numeric example.
We will cover the following:
Let's get started: Math behind √dₖ Scaling Factor in Attention
In this blog, we will learn about causal masking in attention.
We will start with the introduction of causal masking, understand the problem of seeing future tokens through an example, and then walk through its implementation to see how masked attention prevents the model from accessing future tokens.
We will cover the following:
Let's get started: Causal Masking in Attention
In this blog, we will learn about the math behind backpropagation in neural networks.
Backpropagation is the core algorithm that allows neural networks to learn from their mistakes. Without it, training neural networks efficiently would not be possible. Understanding the math behind it gives us a deeper understanding of how neural networks actually learn. Do not worry, we will learn about each concept step by step so that everything is clear.
We will cover the following:
Let's get started: Math Behind Backpropagation
In this blog, we will learn about the math behind Cross-Entropy Loss with a step-by-step numeric example.
When we train a classification model in machine learning, the model predicts probabilities for each class. For example, given an image, the model outputs something like: "I am 70% sure this is a cat, 20% sure it is a dog, and 10% sure it is a rabbit." To train the model, we need a way to measure how wrong these predictions are compared to the true answer. This is exactly what Cross-Entropy Loss does. It is the most widely used loss function in classification tasks, and it powers the training of almost every modern AI model, including GPT, BERT, and image classifiers.
We will cover the following:
Let's get started: Math Behind Cross-Entropy Loss
In this blog, we will learn about the Transformer architecture by decoding it piece by piece - understanding what each component does, how they work together, and why this architecture powers every modern Large Language Model (LLM).
We will cover the following:
Let's get started: Decoding Transformer Architecture
In this blog, we will learn about Feed-Forward Networks in LLMs - understanding what they are, how they work inside the Transformer architecture, why every Transformer layer needs one, and what role they play in making Large Language Models so powerful.
We will cover the following:
Let's get started: Feed-Forward Networks in LLMs
In this blog, we are going to learn about Batch Normalization vs Layer Normalization. We will also see how Batch Normalization and Layer Normalization differ from each other and when to use which one.
We will cover the following:
Let's get started: Batch Normalization vs Layer Normalization
In this blog, we will learn about KV Cache - where K stands for Key and V stands for Value - and why it is used in Large Language Models (LLMs) to speed up text generation.
We will start with how LLMs generate text one token at a time, understand the role of Key, Value, and Query inside the model, see the problem of repeated computation through an example, and then walk through how KV Cache solves this problem by storing and reusing past results.
We will cover the following:
Let's get started: KV Cache in LLMs
In this blog, we will learn about Paged Attention, a technique that solves the memory waste problem of KV Cache, allowing LLMs to serve many more users at the same time.
We will start with a quick recap of KV Cache, understand the memory problem it creates, see how traditional memory allocation wastes space through an example, and then walk through how Paged Attention solves this problem by borrowing an idea from how computers manage memory.
We will cover the following:
Let's get started: Paged Attention in LLMs
In this blog, we will learn about Flash Attention by decoding it piece by piece - understanding why standard attention is slow, what makes Flash Attention fast, how it uses GPU memory cleverly, and why it is used in almost every modern Large Language Model (LLM).
We will cover the following:
Let's get started: Decoding Flash Attention in LLMs
In this blog, we will learn about Speculative Decoding - what it is, why LLM generation is slow without it, how a small draft model and a big target model work together to produce tokens faster, the rejection sampling math that guarantees no quality loss, real numbers showing the 2x to 3x speedup, where it is used in production, and the trade-offs to watch out for.
We will cover the following:
Let's get started: Speculative Decoding
In this blog, we will learn about Medusa, a simple way to make a language model generate text 2 to 3 times faster by giving it several extra heads that guess multiple future tokens at once.
We will cover the following:
Let's get started: Decoding Medusa
In this blog, we will learn about EAGLE, a state-of-the-art way to speed up language model generation by drafting tokens at the feature level instead of the token level.
We will cover the following:
Let's get started: Decoding EAGLE
In this blog, we will learn about Continuous Batching, a technique that lets LLM servers handle many more users at the same time by keeping the GPU busy at every single step of generation.
We will cover the following:
Let's get started: Continuous Batching in LLMs
In this blog, we will learn about how Prompt Caching works. We will also see why we need it, how it actually works inside a large language model, and where it is used in real systems like AI assistants and agents.
We will cover the following:
Let's get started: How does Prompt Caching work?
In this blog, we will learn about Prefill vs Decode, the two phases of LLM inference, and how understanding them helps us optimize the speed of an LLM. We will also see how the prefill and decode phases work, how the KV cache connects them, how they differ and when to use which one based on our use case, and how we optimize each phase to make an LLM faster.
We will cover the following:
Let's get started: Prefill vs Decode: LLM Inference Optimization
In this blog, we will learn about the Mixture of Experts (MoE) architecture - understanding what experts are, how the router picks them, why MoE makes large models faster and cheaper, and why it powers many of today's most powerful Large Language Models (LLMs).
We will cover the following:
Let's get started: Mixture of Experts Explained
In this blog, we will learn about Grouped-Query Attention (GQA) and how it differs from Multi-Head Attention (MHA). We will also learn about Multi-Query Attention (MQA) along the way and see when to use which one.
We will cover the following:
Let's get started: Grouped Query Attention
In this blog, we will learn about the math behind Rotary Position Embedding (RoPE) and why it is used in modern Large Language Models.
We will cover the following:
Let's get started: Math Behind RoPE (Rotary Position Embedding)
In this blog, we will learn about RMSNorm, a faster and simpler alternative to Layer Normalization that powers most modern Large Language Models like Llama, Mistral, Gemma, Qwen, PaLM, and DeepSeek.
We will cover the following:
Let's get started: RMSNorm (Root Mean Square Layer Normalization)
In this blog, we will learn about LoRA - Low-Rank Adaptation of Large Language Models.
We will cover the following:
Let's get started: LoRA: Low-Rank Adaptation of LLMs
In this blog, we will learn about Large Reasoning Models (LRMs), how they are different from standard Large Language Models, how they think before they answer, how they are trained, and when we must use them.
We will cover the following:
Let's get started: Large Reasoning Models (LRMs)
In this blog, we will learn about Reinforcement Learning from Human Feedback (RLHF), the training technique that turns a raw pre-trained LLM into a helpful, honest, and safe assistant by teaching it from human preferences.
We will cover the following:
Let's get started: Reinforcement Learning from Human Feedback (RLHF)
In this blog, we will learn about DeepSeek-V4, the new family of open Mixture-of-Experts language models that natively supports a one-million-token context with dramatically lower inference cost.
DeepSeek-V4 makes one-million-token context roughly a tenth as expensive as it was in DeepSeek-V3.2. It introduces a new attention design, a new way of doing residual connections, a new optimizer, and a new post-training pipeline. We will decode each of these one by one.
We will cover the following:
Let's get started: Decoding DeepSeek-V4
In this blog, we will learn about Prompt Injection in Large Language Models. We will also see why it happens, how an attacker uses it, why the obvious fixes fail, and how we can defend our AI applications against it in the real world.
We will cover the following:
Let's get started: Prompt Injection in LLMs
In this blog, we will learn about the Lost in the Middle problem in LLMs, the strange behaviour where a model reads a very long text, uses the beginning and the end very well, and quietly ignores whatever is sitting in the middle. We will also see what a context window really means, how the accuracy forms a U-shaped curve, why the middle gets forgotten, how this silently breaks RAG systems and long conversations, how we can test our own model for it, and what we can do to fix it.
We will cover the following:
Let's get started: The Lost in the Middle Problem in LLMs
In this blog, we will learn about how LLM watermarking works, the hidden signal that a model quietly leaves inside the text it writes. We will also see why we need it, how an LLM picks one token at a time, how a secret key silently changes those choices without touching the meaning, how a detector finds that hidden pattern later, why the quality of the text does not break, how it is different from an AI text detector, and where it works well and where it fails.
We will cover the following:
Let's get started: How Does LLM Watermarking Work?
In this blog, we will learn about Harness Engineering in AI. We will understand what a harness is, why we need it, and how it is used in AI Agents and evaluation systems.
We will cover the following:
Let's get started: Harness Engineering in AI
Copyright (C) 2026 Outcome School
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
6,597 followers · starred Apr 2026
1,129 followers · starred Jun 2026
143 followers · starred Jun 2026
114 followers · starred Apr 2026