Backpropagation and LLM Training
Transcript
Backpropagation. From first principles, to large language model training. Let's start with something you have probably noticed. You keep hearing words like neural networks, gradients, model weights, training, fine tuning, Adam, and learning rate. And lately, LLM parameters. Behind almost all of these ideas sits one single mechanism. Backpropagation. Now, one important clarification. Backpropagation matters enormously for understanding how modern neural networks are trained.
But AI as a whole is much broader than backpropagation. So before we go further, let's ask a few honest questions. How does an AI actually learn? What exactly changes inside a model when it learns? Who tells billions of parameters what to change? Why is training so much more expensive than simply using a model? What is the difference between training and inference? Why does fine tuning modify weights? Where does gradient descent fit in? And does ChatGPT perform backpropagation while it is answering you? Those are exactly the questions this video will answer. But to understand backpropagation, we first need to understand what a neural network is actually learning. Let's make this concrete. Imagine we want to predict the price of a house. We give the model a few inputs. The size of the house. The number of bedrooms. A location score. And the age of the building. The model combines these into one output: a predicted price.
In the simplest possible form, the price equals size times W one, plus bedrooms times W two, plus location times W three, plus age times W four. Don't worry about the notation. The important part is that W one, W two, W three, and W four are adjustable numbers called weights. Here is the analogy I want you to keep. Think of each weight as a physical knob. One knob controls how important the size is. Another controls location. Another controls the number of rooms. And another controls age.
Turn a knob, and the model's behaviour changes. And real neural networks can contain millions, or even billions, of these adjustable parameters. Which creates the central problem of this entire video. If the model makes a mistake, which knobs should we turn, in which direction, and by how much? Let's leave computers for a moment, and make some tea. You are in control of four things. How much tea you use. How much sugar. How much milk. And how long you brew it. These are your weights.
Suppose you choose two spoons of tea, three spoons of sugar, one hundred millilitres of milk, and five minutes of brewing. You make the tea, and someone tastes it. They give it a four out of ten. And the feedback is simple: too sweet, slightly too much milk, and slightly too strong. Here is the key idea. Telling you only that the tea is bad is not enough. You need to know which decision caused the problem. How strongly each decision contributed. And which direction each one should move.
So you trace the rating backward toward the recipe. In this analogy, the recipe choices are the weights. Making the tea is the forward propagation. The taste, and the rating, are the loss. Tracing the error back to the recipe is backpropagation. Changing the recipe is optimization. And repeating the whole process is training. Attempt one: four out of ten. Attempt two: six out of ten. Attempt three: eight out of ten. Attempt four: nine point five out of ten.
And that is the entire loop, and it never really changes. Now we can give the technical name to the first half of that loop. Look at a neural network. Information enters at the input. It passes through a series of layers. And it exits as an output. This is forward propagation. Forward propagation simply means sending the input through the network to produce a prediction. So remember the short version: forward means, make a prediction. For example, show the network a picture of a cat.
It produces cat thirty percent, dog seventy percent. That is a forward pass. And the same idea applies to a language model. Give it the phrase, Paris is the capital of. It produces France seventy two percent, London eight percent, and Rome four percent. That is also a forward pass. No learning has happened yet. The model has simply made a guess. But in that cat example, the model was wrong. The correct answer was cat. The model said dog. So the model now needs a way to measure how wrong it was.
That measurement is called the loss. A perfect prediction produces a very low loss. A bad prediction produces a high loss. Loss converts the question, how wrong was the model, into a single number that training can work with. And now look at the real difficulty. Zoom out, and the model is not four knobs. It can be more than a billion parameters. The answer was wrong. But which of those billion weights actually caused the error? And by how much? This is the problem backpropagation solves.
Here is the intuitive definition. Backpropagation starts from the final error, and works backward through the network, to determine how changing each parameter would affect that error. Watch the direction change. Forward, information flows from the input, through the layers, to a prediction. Backward, we start from the loss, and move back through the same layers. It is important to be precise here. This is not a literal error object being copied backward. Backpropagation calculates gradient information, backward, through the computational graph. So hold on to this contrast. Forward asks: what did I predict? Backward asks: what needs to change to make the prediction better? Let's try a second analogy, because this one maps naturally onto layered systems. Imagine a company that ships a product. Market research feeds product design. Product design feeds engineering. Engineering feeds marketing. And marketing feeds the customer experience.
Now suppose the product receives a score of three out of ten. Management asks a simple question: what caused this result? One option is to blame every department equally. But that makes no sense. Marketing did not choose the architecture. Engineering did not decide what customers wanted. So instead, the investigation moves backward through the pipeline. From the customer experience, back to marketing. Back to engineering. Back to product design. And back to market research.
Each department gets an influence, not a verdict. Research had a small influence. Design had a strong influence. Engineering had a medium influence. And marketing had a small influence. But be careful with this analogy. It is conceptual. Backpropagation is not literally assigning human blame. It calculates mathematical sensitivity. If this value changed slightly, how much would the final loss change? That sensitivity is what we call a gradient.
Now we can answer the question the last scene raised. What exactly is a gradient? Forget calculus for a moment. Go back to a single knob. Its weight is five point zero. Suppose we nudge it up, to five point one. And the error gets worse. Then increasing this weight is the wrong direction. So training should push it the other way. Down to four point nine nine. A gradient tells us two things. The direction the loss moves when the parameter moves. And how strongly the loss reacts to that movement.
In plain language, the gradient is which way the knob should move, and how strongly the loss responds. One important precision. The gradient does not update the parameter by itself. It is information. An optimizer reads that information, and decides the update. This is where two terms often get confused, so let's separate them. Imagine you are standing on a hill, in fog. Your height on the hill is the loss. Your goal is to reach a low point. You ask a simple question: which way is downhill?
Backpropagation computes the slope, that is, the gradient. It tells you the direction of steepest descent. But knowing the slope does not move you. An optimizer is what actually takes the step. So remember the split. Backpropagation calculates the gradient. The optimizer uses that gradient to update the weights. There are many optimizers. Stochastic gradient descent, usually shortened to SGD, takes a simple step in the downhill direction. Adam keeps a running estimate of the slope, and adapts the step over time. AdamW is a refinement of Adam, with a different way of handling weight decay. You do not need their formulas. You only need the division of labour. Backpropagation gives us the direction. But one question remains. How big should the step be? That is the learning rate. If the learning rate is too small, you take tiny steps. Progress is painfully slow. If it is too large, you keep overshooting the valley.
The loss jumps around, and may never settle. With an appropriate learning rate, you move smoothly toward lower loss. So the learning rate controls the scale of each update. It is a hyperparameter. We choose it, rather than learn it from data. And it is one of the first things an engineer tunes. Let's put all of it together now. Training data goes in. Forward propagation produces a prediction. The loss measures how wrong that prediction was. Backpropagation calculates the gradients.
The optimizer uses those gradients to update the weights. And then the loop repeats. Over and over, on example after example. Now let's make it even simpler, using the words from our tea analogy. Guess. Score. Trace the blame. Adjust. Repeat. One clarification: blame is only a memory aid. Mathematically, backpropagation calculates gradients. Let's watch learning happen with the smallest possible model. The output equals the input, multiplied by a single weight. One training example.
The input is five. The expected output is ten. The weight starts at one. Run the forward pass: five times one equals five. But we expected ten. So the model is too low. Intuitively, if we increase the weight, the output increases. So that is the direction to move. Weight one point zero, gives output five. Weight one point two, gives output six. Weight one point five, gives output seven point five. And by weight two point zero, the output is ten.
Of course, real training does not guess increments like this. It uses gradient based updates to choose each step. The point here is simpler than the formula. This is what learning a weight physically means. Here is why the backward direction is not just convenient. It follows directly from how the calculations depend on each other. Start with a simple chain. A tap position controls the water flow. The water flow controls the tank level. So the tap indirectly affects the tank level.
If you want the tank level to change, you can think backward. How does the tank level depend on the flow? And how does the flow depend on the tap? Multiply those two effects together, and you get the effect of the tap. That is the chain rule. It connects dependent effects, one link at a time. A neural network is exactly this kind of chain, but much longer. The loss depends on the output. The output depends on the last layer. That layer depends on the one before it.
And so on, back to the very first weight. Backpropagation is an efficient application of the chain rule, across the whole computational graph. It reuses shared intermediate results, instead of recomputing them. So when you see this notation... Loss, with respect to a weight... Read it as a question. If this weight changes slightly, how does the loss change? That is all the symbol means. Where did backpropagation actually come from? The mathematics underneath it is older than neural networks.
It comes from calculus, and specifically from the chain rule. The idea of accumulating derivatives in reverse, through a chain of computations, developed over many years. In the nineteen sixties and seventies, researchers in control theory and optimization were already using these ideas. In nineteen seventy four, Paul Werbos described using backpropagation style ideas for neural networks in his doctoral thesis. For about a decade, that work did not receive much attention.
Then, in nineteen eighty six, David Rumelhart, Geoffrey Hinton, and Ronald Williams published a landmark paper. That paper showed how to train multi layer neural networks using backpropagation. It made the method practical, and popular. So this was not a single sudden invention. It was a long line of mathematical and computational work. Backpropagation is a rediscovery and popularization of an idea whose time had come. Why was backpropagation such a big deal?
Imagine a model with one billion weights. That is a wall of a billion knobs. The naive way to train it would be brutal. Change weight one, run the model, and measure the effect. Change weight two, run the model, and measure the effect. Change weight three, and so on. That is a billion full evaluations, just to make one update. It does not scale. Backpropagation replaces that with something far better. Build one computational graph. Do a forward calculation. Compute the loss.
Then compute all of the gradients in a single backward pass. It reuses shared intermediate results across the whole network. So the cost stays close to the cost of the forward pass, instead of a billion times more. That is why deep networks became practical. This is the connection at the centre of everything. Weights are what the neural network learns. Backpropagation helps determine how those weights should change. Watch the path. An input enters a neuron through a weight.
The network produces a prediction. If the prediction is wrong, the loss is high. Backpropagation computes a gradient for that weight. The optimizer then updates the weight, based on that gradient. Repeat this across the whole network, and the weights improve. So remember this sentence. Weights are what the model learns. Backpropagation is how it learns them. Now, a question people often ask. Can AI exist without backpropagation? The answer is yes. AI is a much broader field than neural networks.
Rule based systems do not use it. Search algorithms do not use it. Expert systems do not use it. Decision trees and random forests do not use it. Evolutionary algorithms do not use it. Many reinforcement learning approaches do not require it. So AI does not depend on backpropagation. But modern deep learning leans heavily on gradient based training. And backpropagation is the standard, efficient way to compute those gradients. Can a neural network itself exist without backpropagation? Yes.
A neural network is a computational structure. Forward calculations work regardless of how the weights were found. You could set the weights by hand. You could search them randomly. You could evolve them. The structure still computes. The hard question is different. How do we efficiently find useful values for millions, or billions, of weights? Backpropagation became the dominant practical answer for differentiable networks. But it is an answer to training, not a requirement for the structure itself. So what are the alternatives? One family is evolutionary strategies and genetic algorithms. Imagine several networks, each with random weights. Network A scores forty two. Network B scores seventy three. Network C scores ninety one. Network D scores thirty. Keep the better performers. Mutate their weights, and create the next generation. Repeat for many generations, and the population improves.
This can optimize systems without traditional backpropagation. Other approaches include zeroth order optimization, which estimates gradients by probing. Numerical gradient estimation, which perturbs parameters directly. Local learning rules, and Hebbian style methods. Feedback alignment, which uses fixed random feedback connections. Target propagation, which sends target activations instead of gradients. And forward mode differentiation, useful when outputs are many and inputs are few.
None of this means backpropagation is the only way. It means that for huge differentiable networks, backpropagation is extremely computationally useful. It exploits known mathematical relationships, instead of blindly testing changes. Can a large language model exist without backpropagation? Conceptually yes. You can imagine language models built with other optimization approaches. Practically, modern large transformers are overwhelmingly trained with gradient based optimization.
And those gradients are computed through automatic differentiation, which is backpropagation. Let's watch one training step. The model sees: the sky is. It predicts blue at twenty percent, green at thirty five percent, and cloud at ten percent. The correct next token is blue. So we compute the loss. Then gradient information flows backward through the transformer. The optimizer updates the parameters. And the loop repeats, over billions of tokens. Eventually, the model becomes much more confident. Blue at eighty two percent, green at three percent. The exact numbers and objective vary in practice. But next token prediction is an excellent conceptual model for pretraining. Let's look inside a transformer, at the level we actually need. Tokens go in. They become embeddings. Then self attention mixes information between positions. A feed forward network transforms each position. Those two pieces form a transformer block.
Stack many blocks, and you get depth. Finally, an output projection produces logits. The logits become token probabilities. Compare them to the correct token, and you get the loss. Now reverse the direction. From the loss, gradient information flows back through the output projection. Back through every transformer block. Back through attention, and the feed forward layers. Back through earlier blocks. And finally, back into the embeddings. Backpropagation works through the operations that created the prediction. We do not need every equation to see the pattern. This distinction matters more than almost any other. Training and inference are not the same thing. On the left, training. A forward pass produces a prediction. The loss measures the mistake. Backpropagation computes the gradients. The optimizer updates the weights. So the weights change. On the right, inference. A prompt goes in. The model performs a forward computation.
It produces the next token. Then the next, then the next. No loss, no backward pass, and no weight updates. So talking to an LLM is not the same as training the LLM. That is a major distinction, and it explains a lot. Why is training so much more expensive than inference? Because training has to remember more. Inference mainly needs the forward computation, and the weights. Training needs all of that, plus much more. It needs the loss. It needs the intermediate activations, because the gradients will need them. It needs the backward computation. It needs to store the gradients. And it needs optimizer state, which can be large. Adam, for example, keeps additional values for every parameter. So both memory and compute per token are much higher during training. Inference is not free, of course. Serving a model has real costs, including the key value cache. But per token processed, training is generally substantially heavier.
This is why GPUs matter so much. Neural networks are built from enormous amounts of matrix multiplication. Forward propagation needs it. Backpropagation needs it too. And training adds all of the extra work on top. A GPU is designed for exactly this kind of parallel numerical workload. Thousands of small operations run at the same time. Put it together. More parameters. Plus more training tokens. Plus forward compute. Plus backward compute. Plus optimizer state.
That is a very large compute requirement. And that explains the connection between GPUs and modern AI. Now let's look at two things that can go wrong. Imagine fifty people passing a message backward. The first person shouts: change this a lot. As the message travels, it gets quieter and quieter. By the time it reaches the start, it may be barely audible. Gradients can behave the same way. In a very deep computation graph, gradient signals can become extremely small.
That is called the vanishing gradient problem. When it happens, the earliest parts of the network learn very slowly. Their weights barely move, even though they matter. This is one reason deep networks were historically hard to train. The opposite problem also exists. This time, the message gets louder as it travels. Change, becomes change, becomes change with three exclamation marks. Eventually, it is enormous. Gradients can also explode. When gradient values grow excessively, updates become unstable. The loss can jump wildly, or even turn into not a number. That is the exploding gradient problem. There are practical remedies. Careful initialization. Normalization layers. Architectural choices, like residual connections. And gradient clipping, which caps the size of the update. These are not exotic tricks. They are standard tools in modern training. Why do activation functions matter so much? Here is the key reason.
If every layer were purely linear, stacking them would collapse. A linear function of a linear function is still linear. No matter how many layers you add. So the network could never learn genuinely complex shapes. Nonlinear activation functions break that collapse. They let the network represent curved, complicated relationships. Historically, sigmoid and tanh were common. Then ReLU made deep networks much easier to train. Modern transformers commonly use smoother variants, such as GELU.
And SwiGLU style feed forward blocks. The details matter, but the principle is simple. Neural networks need useful, nonlinear, differentiable structure, so that gradients can guide learning. Now let's connect all of this to practical AI engineering. Suppose you have a pretrained model with seven billion parameters. It already knows a lot about language. But it does not know your domain. Your telecom incident data. Your network documentation. Your operational terminology.
So you give it examples from your domain. The fine tuning loop looks familiar. Examples go in. Forward pass. Compute the loss. Backpropagation. The optimizer updates selected parameters. And the model adapts to your domain. Fine tuning is additional training. So backpropagation returns. But there is a smarter way to fine tune. Meet LoRA, low rank adaptation. Picture the enormous pretrained model. Most of its parameters are frozen. We do not touch them.
Attached to it are much smaller trainable adapters. Only those small adapter parameters are optimized. So the amount of trainable state drops dramatically. But the training still works the same way. Forward pass. Loss. Backpropagation. Optimizer. So even if you never train a model from scratch, understanding weights and gradients still matters. Now, the practical question for people building with AI. Do I need to know backpropagation? The honest answer depends on what you build.
If you mainly build prompt workflows, tool calling agents, retrieval augmented generation, MCP integrations, or orchestration pipelines, then you do not need to derive the mathematics to be productive. But conceptual knowledge is still valuable. Think in three levels. Level one: the AI application developer. Know the concepts: forward pass, weights, loss, backpropagation, gradient, optimizer, and the difference between training and inference. No heavy calculus required.
Level two: the AI or ML engineer. Understand gradient computation, optimizer behaviour, learning rates, and training stability. Also fine tuning, memory implications, batch size, gradient accumulation, and gradient clipping. Level three: the model or research engineer. This is where the deeper mathematics lives. Derivatives, the chain rule, Jacobians, automatic differentiation, optimization theory, numerical stability, and distributed training. The key point is not that everyone must go deep.
It is that the depth should match your responsibilities. This is the section that pays for itself. What decisions can you actually make if you understand backpropagation? First: training versus inference. You can reason about why training infrastructure differs from inference infrastructure. Second: full fine tuning, versus parameter efficient fine tuning. You understand why updating billions of parameters is expensive. Third: fine tuning versus retrieval. Backpropagation changes model parameters. Retrieval changes the context you supply, without retraining base weights. Fourth: frozen versus trainable models. Should the weights change at all? Fifth: GPU memory. You can predict why training needs substantially more memory than serving. Sixth: learning rate. You can reason about why optimization diverges, or learns slowly. Seventh: gradient accumulation and gradient clipping.
Why training may accumulate gradients across micro batches, and why large gradients need stabilising. And finally, architecture. When do you need a hosted API, retrieval, prompt engineering, fine tuning, or training? That is exactly the kind of decision an AI solution architect makes. What happens if you do not know any of this? Honestly, you can still build many AI applications. You can call APIs, write prompts, and ship useful products.
But without the conceptual model, the vocabulary stays disconnected. Parameters, gradients, frozen layers, fine tuning, learning rate, optimizer, training loss, gradient accumulation, LoRA. They feel like unrelated jargon. With the model, they snap into place. Prediction, loss, backpropagation, gradient, optimizer, weight update. Every term has a home. That is the real difference. Not gatekeeping. Just clarity. Let's clear up one big misconception.
Backpropagation does not mean that the AI is thinking backward. When you ask a model a question... it performs a forward computation and produces an answer. That is inference. There is no backward pass through the weights. Backpropagation is fundamentally a training mechanism for computing gradients. It is not the same as reasoning, reflection, chain of thought, self correction, or an agent retrying a task. An AI agent can go back and retry something without performing backpropagation.
This matters a lot for people learning about agents. Let's finish with one complete example. It is a cat classifier. The training image is a cat. The model initially says dog at seventy percent, cat at thirty percent. Forward pass. Loss. Backpropagation. Gradients. Optimizer. Weight update. After many examples, the model says cat at ninety seven percent, dog at two percent. Now watch something important. Replace the cat with the phrase: once upon a. The transformer predicts the next token. Loss.
Backpropagation. Gradients. Optimizer. Weight update. It is structurally the same process. A cat classifier and a large language model are the same loop, at different scale. Let's end with the simplest possible version. Guess. Score. Trace. Adjust. Repeat. And what each one actually means. Guess is forward propagation. Score is the loss. Trace is backpropagation. Adjust is the optimizer updating the weights. Repeat is training. Weights are what the model learns. Forward makes the prediction.
Loss measures the mistake. Backpropagation calculates how parameter changes affect that mistake. The optimizer updates the parameters. Repetition creates learning. If that loop makes sense, backpropagation makes sense.

Ask anything
We've read this whole study set, so questions about it get the best answers.