## Introduction to Mechanical Dreams and the AdamW Scaling Problem
Norris: Welcome back to Mechanical Dreams, the podcast where we parse the tensors, tune the hyperparameters, and try to make sense of the ever-expanding universe of machine learning and natural language processing. I am Professor Norris, and across the desk from me is my brilliant graduate student, Linda. How are the GPUs treating you this week, Linda? Linda: They are running very hot, Professor! But I am doing great. I am incredibly excited about the paper I brought for us today. It tackles a problem that literally costs the industry millions of dollars in compute every single week. Norris: Ah, you have my attention. And my grant funding's attention. Let me guess: hyperparameter tuning at scale? It is the bane of my existence. We cannot just run a grid search on a 100-billion parameter model. We have to tune on toy models and cross our fingers that the math holds when we scale up the run. Linda: Exactly. The paper is called 'How to set AdamW's weight decay as you scale model and dataset size' by Xi Wang and Laurence Aitchison. It is from a very recent batch of research, and it answers a massive open question for anyone training large language models. Norris: I have been burned by scaling papers before, Linda. Usually, someone finds a neat little rule of thumb that works flawlessly on CIFAR-10 or ImageNet, and then the moment you try to pre-train a real transformer on a terabyte of text, the loss diverges into the stratosphere. Linda: I know you are naturally skeptical of these heuristics, but this one is different! It provides a rigorous mathematical framework that works all the way from small vision models right up to LLM pre-training on OpenWebText. It specifically solves the transfer of optimal weight decay from small prototyping runs to the massive, expensive final runs. Norris: Well, the field desperately needs that. We have had the muP framework, Maximal Update Parametrization, for a few years now. That gave us a beautiful theoretical basis for scaling the learning rate as model width increases. But weight decay in AdamW has always been the awkward variable that everyone just leaves fixed and hopes for the best. Linda: Right! And the authors show that leaving weight decay fixed while scaling the learning rate actually breaks the predictions of the muP framework if you train for a sufficient number of steps. This paper fixes that gap by completely reframing how we look at AdamW. Norris: Reframing AdamW? That is a bold claim. It is arguably the most widely used optimizer in the world right now for large models. You are telling me there is a fundamental mechanic in there that we have all just been missing? Linda: I am! They discovered that to understand weight decay properly, you have to stop looking at it just as a standard regularization penalty, and start looking at the optimizer's trajectory mathematically as an Exponential Moving Average. Norris: An Exponential Moving Average? Interesting. I think we need to open up the hood and see exactly how they proved that.
## Reframing AdamW as an Exponential Moving Average
Norris: Let us pick up right where we left off. You said the weights in AdamW are an Exponential Moving Average. But Adam already uses EMAs. It keeps an exponential moving average of the gradient, and an EMA of the squared gradient. That is literally how it computes its adaptive steps. Linda: Exactly, and the authors point that out immediately to avoid confusion. Both Adam and AdamW estimate the first and second moments of the gradients using EMAs. That is not what this paper is about. The core insight here is that in algorithms with decoupled weight decay, the actual model weights themselves form an EMA of the past updates. Norris: The weights themselves? Walk me through the math there. How do we get an EMA out of the weight update rule? Linda: It comes down to how AdamW decoupled weight decay from the gradient calculation. If you look at the update equation for a single parameter, the new weight equals the old weight multiplied by a decay factor. That decay factor is one minus the learning rate times lambda, which is the weight decay parameter. Norris: Right, so the weight at time t equals the weight at time t-minus-one times the quantity one minus eta lambda. And then you subtract the learning rate times the adaptive gradient step. Linda: Precisely! Now, compare that to a generic exponential moving average formula. An EMA at time t equals the EMA at time t-minus-one times the quantity one minus alpha, plus alpha times the new observation. Norris: I see it. The decay factor, the alpha, is exactly eta times lambda. The learning rate multiplied by the weight decay. Linda: Yes! And because of that mathematical equivalence, we can define the timescale of this EMA. For any exponential moving average, the timescale is roughly one over the decay factor. So the timescale of AdamW, measured in iterations, is one divided by eta times lambda. Norris: So the weight decay parameter is not just pushing the weights towards zero like a rubber band, which is the classical L2 regularization view. It is actually defining a window of memory. Linda: That is a great way to put it. The timescale describes the number of previous iterations that the EMA averages over. If you have a high weight decay, the timescale is short. The optimizer has amnesia, heavily favoring only the most recent batches. If you have a very small weight decay, the timescale is long, and the optimizer averages its updates over a massive history of past batches. Norris: That is genuinely profound. Does this only work for AdamW, or can we look at standard Adam this way too? Linda: It only works for AdamW. In standard Adam, the L2 penalty is added to the gradient before the gradient is normalized by the moving averages. Because of that coupling, the weights do not form a clean EMA. This actually provides a theoretical explanation for why AdamW generalizes better and behaves so differently from standard Adam in practice. Norris: Ilya Loshchilov and Frank Hutter gave us AdamW back in 2017, and it took a while for the community to realize how important it was. Now it is the default for training transformers. But knowing it behaves as an EMA over the updates... what does this let us do practically? Linda: It lets us perfectly determine the optimization trajectory! The authors formulated Theorem 1. It states that if you have a scale-invariant network, and you initialize it correctly, the entire optimization trajectory is controlled solely by this iteration timescale. Norris: Wait, completely controlled? You are saying if I change the learning rate, I can still get the exact same model out at the end? Linda: As long as you keep the product of the learning rate and weight decay constant! If you halve your learning rate, but double your weight decay, your timescale remains the same. The authors proved mathematically, and verified empirically, that the network will output the exact same values at every single point along the trajectory. Norris: Okay, hold on. A scale-invariant network? Most networks are not perfectly scale-invariant out of the box. You have the final linear layer, you have batch norm or layer norm parameters. Linda: You are absolutely right, and the authors are very thorough about that in the appendix. To make the network fully scale-invariant, they had to add a normalization layer before the final output logits, and they had to decouple the learning rates for the scale and bias parameters in the norm layers. But once they made those structural tweaks, the learning trajectory became completely independent of the learning rate, as long as the timescale was fixed. Norris: That is staggering. So instead of tuning learning rate and weight decay as two separate, highly sensitive knobs, they are really just two levers that control a single fundamental property: how far back in time the optimizer remembers. Linda: Exactly. And once you understand that the EMA timescale is the true fundamental hyperparameter, it tells you exactly how to adjust things when your training environment changes. Norris: I am starting to see where the dataset scaling comes in. If the timescale is the number of batches the model averages over, then changing the size of the dataset changes what that timescale actually represents in terms of the whole data distribution. Linda: Spot on, Professor. And that sets us up perfectly to talk about what happens when we move from our small prototyping datasets to our massive pre-training datasets.
## Scaling Weight Decay with Dataset Size
Norris: So, Linda, at the end of the last chapter you teased that understanding AdamW as an Exponential Moving Average tells us exactly how to handle scaling up our datasets. If the timescale is just the number of iterations the optimizer remembers, what happens when our dataset gets massively larger? Linda: That is exactly the question the authors asked. As we established, the weight decay and learning rate together define an iteration timescale, which we call tau-iter. But iterations are a relative measure. If you double your dataset size, but keep your batch size the same, a single epoch now requires twice as many iterations. Norris: Right. So if my iteration timescale stays fixed, I am now averaging over a much smaller fraction of my total data. My optimizer is getting short-sighted. It is forgetting updates from the beginning of the epoch before it even reaches the end. Linda: Exactly! And that is why the authors introduce a new metric: tau-epoch. It is simply the iteration timescale divided by the number of iterations in a single epoch. Intuitively, it tells us how many epochs of past updates the EMA is averaging over, rather than just raw batches. Norris: Let me do the math in my head. The number of iterations per epoch, let us call it M, is the total dataset size N, divided by the batch size B. So the epoch timescale is the iteration timescale divided by M. Linda: Perfect. And since the iteration timescale is one over the learning rate times lambda, the epoch timescale becomes one over the product of the learning rate, lambda, and M. Now, here is the million-dollar empirical finding from the paper: as you change the dataset size, the optimal epoch timescale remains incredibly stable. Norris: Wait. If the optimal epoch timescale is a constant... and I increase my dataset size N... then M goes up. To keep the equation balanced, assuming a fixed learning rate and a fixed batch size, the weight decay lambda has to go down. Linda: Yes! It scales inversely with the dataset size. If you multiply your dataset size by ten, your optimal weight decay should be divided by ten. If you do not decrease it, your model forgets its past updates too quickly relative to the scale of your data. Norris: That is a beautifully simple rule. But let us pause and think about standard machine learning intuition for a second. Classically, we think of weight decay as L2 regularization to prevent overfitting. If you have a massive dataset, you are less prone to overfitting anyway, so reducing regularization makes qualitative sense. But having an exact, quantitative one-over-N scaling law? That is rare and incredibly powerful. Linda: It is so much more precise than just guessing or relying on rough intuition. And they proved this empirically across multiple domains. They trained ResNet-18s and Vision Transformers on progressively larger subsets of ImageNet. They also trained a 124-million parameter NanoGPT on subsets of OpenWebText. Norris: Let me guess the results. As the dataset grew, the optimal lambda plummeted, but if they plotted performance against the epoch timescale, the curves perfectly aligned? Linda: You nailed it. When they plotted validation loss against weight decay on the x-axis, the optimal points drifted wildly to the left as dataset size changed. But when they swapped the x-axis to be the epoch timescale, the optimal point was rock solid across all dataset sizes. For instance, on the NanoGPT pre-training, the optimal epoch timescale stayed completely stable even as they scaled the data from a quarter of the dataset up to the full dataset. Norris: This is fantastic for real-world workflows. It means a grad student can take a small, manageable subset of their training data, run a hyperparameter sweep to find the optimal epoch timescale, and then mathematically project the exact weight decay they need for the full, multi-terabyte run. Linda: Yes, exactly! It removes the guesswork. And it also highlights a massive flaw in how we usually run these experiments. If you naively keep your weight decay fixed while throwing more data at the model, you are accidentally forcing your optimizer to behave differently. Norris: It makes you wonder how many failed scaling experiments out there were just victims of an improperly scaled EMA timescale. The architecture was fine, the data quality was fine, but AdamW was just effectively averaging over too little information because the weight decay was left at the default zero-point-zero-one. Linda: Probably more than we would like to admit! And looking at the formula, it also ties beautifully into batch size. Because batch size is in the denominator of M, if you increase your batch size to utilize more GPUs, you can maintain the same epoch timescale by scaling your weight decay up linearly. Though the authors note that for really large batch sizes, the dynamics of learning rate scaling can make it a bit more complex. Norris: The implications just keep rolling out. Okay, so dataset scaling is solved by keeping the epoch timescale constant. But what about the other side of the coin? What happens when we want to make the model itself bigger? We briefly touched on the Maximal Update Parametrization, or muP, in our introduction. How does this EMA perspective interact with scaling model width? Linda: That is exactly where the paper goes next. And honestly, it is arguably their most impactful contribution for the large language model space. They actually show how standard muP is broken for AdamW, and how their timescale framework completely fixes it.
## Fixing muP for AdamW Across Model Sizes
Norris: Alright Linda, you ended the last chapter on quite a cliffhanger. You claimed that the Maximal Update Parametrization, or muP, which is basically gospel for scaling large language models, is actually broken for AdamW. That is a massive claim. Greg Yang's tensor programs framework is the bedrock of how we transfer learning rates today. Linda: It is a huge claim, but the authors bring the receipts! To understand why it breaks, we have to look at what muP actually recommends. Standard muP tells us that to keep activation variances stable as we scale up a model's width, we need to scale the learning rate proportionally to one over the fan-in. Norris: Right. If you double the width of your hidden layers, your fan-in doubles, so you cut your base learning rate in half. That ensures the initial updates do not cause the network outputs to blow up. It is mathematically beautiful. Linda: It is beautiful for the initial updates. But remember, muP theory largely considered the behavior of the first few optimization steps relative to the random initialization. It didn't account for how weight decay affects the learned weights late in the optimization phase. And crucially, standard muP implementations leave the weight decay fixed as you scale the model up. Norris: Oh, I see it. I see exactly where this is going based on our timescale equation. If the iteration timescale is one over the product of the learning rate and weight decay, and muP tells us to decrease the learning rate as the model gets wider... Linda: ...And if you leave weight decay fixed, then the product of eta and lambda shrinks! Which means the timescale, which is the inverse of that product, grows larger. Norris: The optimizer's memory stretches out. A wider model ends up averaging its updates over a much longer history of batches than the smaller prototype model did. You are fundamentally changing the optimization dynamics just by making the matrix bigger. Linda: Exactly! And because the timescale changes, the optimal base learning rate stops transferring. The authors show this clearly. When they ran ResNet-18s and Vision Transformers of varying widths using the standard muP approach with AdamW, the optimal base learning rate varied wildly across model sizes. It broke the zero-shot transfer promise completely. Norris: I have actually seen this in practice. You tune on a small transformer, apply the muP scaling rules, spin up a massive cluster for the large model, and the loss curve just looks sub-optimal. We always assumed it was just bad luck or system noise. So, the fix is to keep the EMA timescale constant? Linda: Yes, it is that simple. We have two competing goals: we must scale the learning rate with one over fan-in to satisfy muP, but we must also keep the timescale constant to satisfy the AdamW EMA dynamics. The only way to reconcile those is to allow the weight decay to strengthen for larger models. Norris: So if the width scaling factor is 's', and we divide our base learning rate by 's', we have to multiply our base weight decay by 's'. The learning rate goes down, the weight decay goes up by the exact same factor, and the timescale stays perfectly constant. Linda: Exactly! Weight decay must scale linearly with model width. When the authors applied this fix, it was like magic. They tested this on 8-layer GPT models trained on OpenWebText, varying the number of attention heads to change the width. By scaling weight decay up as the models got wider, the optimal hyperparameters transferred perfectly across all model sizes. Norris: That is brilliant, but let me stress-test the intuition here. If we are scaling weight decay up linearly with model width, we are applying massive weight decay to these large LLMs. Doesn't that squash the learned weights down too much? Linda: That is actually the most elegant part of the whole paper, Professor! Think about what muP fundamentally requires. To keep the network outputs stable, muP demands that the learned weights scale as one over fan-in. Norris: Right, because the output of a linear layer is the sum of inputs multiplied by weights. If you have ten times as many inputs coming in from a wider layer, the individual weights need to be ten times smaller so the sum doesn't explode. Linda: Precisely. Now, based on the EMA framework, the magnitude of the learned weights in AdamW naturally scales with one over lambda. So, if we scale lambda to be proportional to fan-in, then the learned weights will naturally scale as one over fan-in! Norris: Oh, wow. It perfectly satisfies the core desideratum of muP, not just at initialization, but throughout the entire training run. By scaling the weight decay, you don't just fix the optimizer's memory timescale; you organically force the weights to obey the exact magnitude scaling required for stable wide networks. Linda: It is a stunning unification of two completely different theoretical frameworks. And it is highly practical. Other researchers, like those working on large-scale transformers in follow-up papers, have already started citing this and observing that increasing weight decay with width is the key to fixing learning rate transfer. Norris: I am honestly blown away. It takes something we treat as a dark art and turns it into clean, predictable math. We scale weight decay down as dataset size increases, and we scale weight decay up as model width increases. It is a complete recipe for large-scale training.
## Conclusion and Practical Takeaways
Norris: So, Linda, to bring this all together for our listeners who are about to kick off a massive, multi-million dollar training run. This paper essentially gives us a foolproof mathematical recipe for AdamW. Linda: Exactly! The practical takeaway is that you don't need to rely on guesswork or expensive grid searches at scale anymore. You find your optimal hyperparameters on a small prototype model and a small subset of your data. That gives you your optimal epoch timescale. Norris: And then we apply our two golden rules. Rule number one: as your dataset size goes up, your weight decay goes down proportionally to maintain that timescale. Rule number two: as your model width goes up, your weight decay goes up proportionally to satisfy the Maximal Update Parametrization. Linda: You summarized it perfectly, Professor! Data goes up, weight decay goes down. Width goes up, weight decay goes up. It completely demystifies AdamW by revealing that the epoch timescale is the true fundamental hyperparameter you should care about. Norris: It really is elegant. Though I should remind our listeners, as you pointed out earlier, the devil is always in the details. To get this perfect theoretical transfer, you do need to ensure your network is fully scale-invariant. You cannot forget to decouple the learning rates for your layer norm parameters and add that normalization layer before your logits. Linda: That is a great point. It requires a few minor architectural tweaks in your PyTorch code. But honestly, modifying a few lines of code is a tiny price to pay compared to saving thousands of GPU hours and dodging failed scaling runs. Norris: I completely agree. This is exactly the kind of rigorous, mathematically grounded research that the field of deep learning desperately needs right now as models grow to astronomical sizes. You really delivered on your promise today, Linda. This paper should be required reading for any ML engineer. Linda: Thank you, Professor! It was an absolute blast to break this one down with you. Norris: That brings us to the end of this episode of Mechanical Dreams. To our audience of graduate students and industry professionals, thank you for tuning in. Until next time, keep your timescales constant, and keep dreaming in gradients.