## The Multi-Million Dollar NaN
Linda: Welcome back to another episode of Mechanical Dreams! I’m Linda. Norris: And I’m Professor Norris. And Linda, you look like you’ve just seen a ghost. Or worse, a segfault. Linda: Worse, Professor. I’ve been reading about the multi-million dollar NaN. Imagine this: You’re training Llama 4. You’ve got thousands of H100 GPUs humming away, consuming the power output of a small city. You’re weeks into the run. The bill is already in the seven figures. Norris: I can feel my grant money evaporating just hearing this. Linda: And then, suddenly... the loss spikes. It doesn't recover. It diverges. The model parameters hit infinity or NaN—Not a Number. The run is dead. The money is gone. Norris: The absolute worst-case scenario. We’ve seen this since the early days of RNNs, though usually, we blame the graduate student who set the learning rate too high. It’s an optimization failure, right? You push the gradients too hard, they explode. Linda: That is the conventional wisdom. But today’s paper asks a different question: What if it wasn't the learning rate? What if the data itself murdered the model? Norris: Data? Come on. I know the saying is 'Garbage In, Garbage Out,' but usually that means you get a model that speaks nonsense, not a model that mathematically implodes. The web is full of noise—unregulated HTML, random binary strings, cat memes. If noise killed models, ChatGPT wouldn't exist. Linda: That’s exactly the skepticism this paper addresses! It’s titled 'An Empirical Study on Noisy Data and LLM Pretraining Loss Divergence,' coming out of Oxford and Meta FAIR. The authors, Zhang et al., wanted to move beyond speculation. Everyone *guesses* that bad data causes instability, but nobody had really proven it in a controlled way. Norris: Controlled? How do you control the chaos of the internet? Linda: You simulate it. They took clean data—a subset of the Llama 4 pretraining mix—and they deliberately injected synthetic noise. They tried to induce that catastrophic divergence on purpose. Norris: So they built a torture chamber for Transformers. I appreciate the scientific rigor, even if it sounds cruel. But did they succeed? Can a few typos really crash a billion-parameter model? Linda: They absolutely did. They found that noise doesn't just make learning slow; it can cause full-blown divergence. And the scary part, Professor? It wasn't just about how much noise there was. It was about *what kind* of noise it was. Norris: Now you have my attention. I assumed random noise is random noise. You're telling me there are specific flavors of garbage that are more toxic than others? Linda: Oh, absolutely. And one specific flavor is incredibly dangerous. It turns out, if your noise looks like a repeating hash code... you’re in trouble.
## The Toxic Five Tokens
Norris: Okay, Linda, you left us on a cliffhanger. You mentioned repeating hash codes. I'm picturing a computer having a seizure, just spitting out hexadecimal strings. But why is that worse than any other kind of garbage? Linda: That’s the million-dollar—or rather, the multi-million dollar—question. So, Zhang and the team set up this really elegant experiment. They defined a 'noise vocabulary.' Let's call it V-n. Norris: V-n. Alright. I assume this is the subset of tokens they use to generate the noise. Linda: Exactly. They compared two scenarios. In scenario one, V-n is huge. They pull noise tokens from the entire tokenizer vocabulary—all 200,000 possible tokens. Total chaos. Maximum entropy. Norris: Right. That sounds like the worst case. You’re feeding the model pure white noise. It’s statistically impossible to predict. The loss should go through the roof. Linda: That’s what I thought too! But then they tried scenario two. They restricted V-n to just... five tokens. Norris: Five? Just five specific words repeating over and over? Linda: Yes. Imagine inserting just five random tokens, like 'apple', 'blue', 'hash', 'seven', 'void', randomly scattered into the text. And here is the shocker: The model trained on the full vocabulary noise? It survived. It was stable. But the model trained on the five-token noise? It crashed and burned. Norris: Wait. That is completely counter-intuitive. The five-token noise is low entropy. It’s predictable! The model should just learn to ignore those five specific tokens and move on. Why does the simpler noise break the machine? Linda: The paper suggests it’s about distribution shifts. When you have a massive noise vocabulary, the noise looks somewhat 'uniform' to the model. But when you hammer it with a specific, tiny subset of tokens appearing way more often than they should, it creates these massive activation spikes. It distorts the feature space. Norris: I see. It’s like... if I'm listening to static on the radio, I can tune it out. But if someone screams the word 'BANANA' every three seconds at random intervals, I’m going to lose my mind. Linda: That is... actually a perfect analogy, Professor. And they proved it wasn't about the specific words either. They tested with five ultra-common words, and then five words that never appear in the training data. The result was the same. The content of the noise didn't matter—only the fact that the vocabulary was restricted. Norris: So, the 'Toxic Five' aren't specific cursed words. Any five words become toxic if you force-feed them to the model randomly. Linda: Precisely. And there’s one more layer to this toxicity. They tested *how* the noise enters the data. You can either 'overwrite' existing tokens—like replacing a valid word with a noise token—or you can 'insert' new tokens in between valid words. Norris: I’d wager insertion is worse. Overwriting destroys information, sure, but inserting breaks the positional structure. It shifts everything to the right. Linda: Spot on. Insertion was significantly more destabilizing. So, the deadliest cocktail for an LLM isn't just random garbage. It’s a small, repetitive set of tokens, inserted randomly into the stream, breaking the grammatical flow. That is what causes the divergence. Norris: Which sounds suspiciously like a lot of bad web scraping. Broken HTML tags, repeating error logs, '404 Not Found' over and over again... Linda: Exactly! Unregulated web content is full of these low-vocabulary, repetitive patterns. It’s not the randomness of the web that kills Llama 4; it’s the structured, repetitive junk.
## Bigger, Deeper, More Fragile
Norris: So, we have established that specific, repetitive noise—the 'Toxic Five'—is the kryptonite for these models. But Linda, surely this is a problem for the little guys? If I’m training a massive, state-of-the-art model with billions of parameters, it has the capacity to route around that damage, right? 'Scale is all you need,' as they say. Linda: You would hope so, Professor. That is the dream—that a bigger brain is a more resilient brain. But Zhang et al. found exactly the opposite. They scaled their experiments from 480 million parameters up to 5.2 billion, and the trend was brutal. Norris: Brutal how? It didn't get better? Linda: It got significantly worse. As the model size increased, the probability of divergence skyrocketed. The larger models were effectively *more* sensitive to the noise, not less. Norris: That is disturbing. It suggests that as we race toward trillion-parameter models, we are actually building glass cannons. Powerful, but one tap in the wrong spot and they shatter. Linda: Exactly. And they dug deeper into the architecture to find the weak point. They decoupled width—the dimension of the model—from depth—the number of layers. They wanted to know: is it the fat models or the tall models that break? Norris: My intuition says depth. Backpropagation through time, vanishing gradients... deeper networks have always been the troublemakers in optimization history. Linda: Your intuition wins this round. They kept the width constant and scaled the layers from 5 up to 35. The 5-layer models? Rock solid. But the 35-layer models? They were falling apart. In the most extreme case, a 35-layer model diverged 15% of the time even with a tiny noise ratio of just 5%. Norris: Five percent noise? That’s barely anything! You could get five percent noise just by accidentally including a subreddit in your training data. Linda: And meanwhile, when they scaled the width—making the model wider but keeping it shallow—the stability hardly changed. You could make it as fat as you want, and it would handle the noise. But stack those layers too high, and that 'Toxic Five' noise propagates errors that compound until—pop—you hit NaN. Norris: So the skyscraper is swaying in the wind. This really puts a damper on the 'deeper is better' philosophy, at least until we figure out how to stabilize the signal.
## CSI: Gradient Descent
Norris: So, we are at the crime scene. We have a multi-billion parameter corpse lying on the server rack. The loss curve has flatlined into NaNs. The graduate students are weeping in the hallway. The question is: who killed the model? Linda: Welcome to CSI: Gradient Descent. Usually, when a run dies, everyone just assumes it was the learning rate. You know, the 'sugar rush' hypothesis—we fed it too many gradients too fast, it got hyperactive, and crashed. Norris: Right. The classic response is to restart the run, lower the learning rate, and pray. But if the killer was actually the 'Toxic Five' noisy data we discussed, lowering the learning rate might not help at all. You’re just feeding it the poison more slowly. Linda: Exactly! And this paper provides the forensic tools to tell the difference. They found a 'smoking gun' in the model’s internal organs—specifically, the maximum attention logits. Norris: Ah, the attention logits. That’s the dot product of the Query and Key vectors before we smash them through the Softmax function. If those numbers get too big, the Softmax saturates. It turns into a one-hot vector, paying 100% attention to one token and ignoring everything else. Linda: Precisely. Previous research—specifically Wortsman et al.—established that when a learning rate is too high, these logits explode. They grow uncontrollably until they hit a specific threshold. For these models, that number is around 4000. Norris: 4000. Okay. So if I check my logs and see the attention logits hit 4500 before the crash, I know I was driving too fast. Guilty as charged. Linda: But here is the twist: when the killer is *noisy data*, the model dies much, much sooner. The authors found that noise-induced divergences consistently happen when the attention logits hit around 1800. Norris: Wait, 1800? That is less than half the 'speed limit' for the learning rate failure. It’s dying of something else entirely. Linda: It is. It’s a distinct failure mode. The model isn't just overheating; it’s getting confused. The noise causes these sharp, sudden spikes in activation that break the training dynamics before the weights even have time to blow up. Norris: So that’s our diagnostic test. If your run crashes and your logits are at 5000, fire the person who set the learning rate. If it crashes and your logits are at 1800, fire the person who cleaned the data. Linda: Harsh, Professor! But accurate. And there is a second clue: the parameter norms. In a high-learning-rate death, the model weights themselves grow massive. It’s like an explosion. But with noisy data? The weights look normal. They stay small. Norris: That is fascinating. The model looks healthy on the outside—normal weights, reasonable gradients—but internally, in the attention mechanism, it’s screaming at a volume of 1800 and then suddenly drops dead. Linda: It really changes how we debug these massive runs. Instead of blindly tuning hyperparameters, you can look at these two numbers—logits and norms—and know exactly where to look. It turns a guessing game into a science. Norris: I like it. Less prayer, more plotting. Though I suppose the real solution is to stop feeding the model repeating hash codes in the first place.
## MoE Stability and The QK-Fix
Norris: All right, Linda, we’ve diagnosed the murder weapon—the 'Toxic Five' tokens—and we have our forensic tools. But I have to ask about the elephant in the room. Or rather, the 'Mixture of Experts' in the room. Linda: Ah, MoEs. The architecture of choice for the modern giant. Norris: Exactly. But they are notoriously finicky. You have these router networks sending tokens to different expert layers... surely, if you inject this structured noise, the router is going to get confused? Or worse, one specific expert gets fed all the 'poison' tokens and implodes, taking the whole model down with it. Linda: That is a very reasonable fear. Everyone assumes MoEs are more fragile than dense models because of that routing complexity. But Zhang and the team tested this head-to-head. They compared dense models against MoEs with the same number of active parameters. Norris: And? Did the MoE crumble? Linda: It didn't! The divergence rates were almost identical. The MoE was no more sensitive to the noise than the standard dense model. They even looked at the routing patterns to see if the experts were 'specializing' in garbage. Norris: I can imagine an 'Expert #4' that just processes hash codes all day. Linda: You’d think so, but the correlation between noisy tokens and expert activation was near zero. The noise gets spread out. So, the architecture itself isn't the problem. Norris: That is a relief, I suppose. But we still have the problem that the model *does* diverge if the noise is bad enough, regardless of whether it's dense or MoE. So what is the solution? Better regex? Linda: Data cleaning is obviously the gold standard. If you can filter out those toxic repetitive tokens, do it. But at web scale, you can't catch everything. So the paper proposes a 'safety belt': QK-LayerNorm. Norris: Query-Key Layer Normalization. I’ve seen this popping up in recent vision transformers. It normalizes the vectors before you compute the attention scores. Linda: Exactly. Remember those exploding attention logits we talked about? The ones hitting 1800 and killing the run? QK-LayerNorm physically prevents them from growing that large. It clamps the magnitude. Norris: So it’s a surge protector. You can feed it dirty power, and it won't blow the fuse. Linda: Precisely. They showed that with QK-LayerNorm, you could ramp the noise up to 70%—levels that guaranteed a crash before—and the model stayed stable. It didn't diverge. Norris: Now, to be clear, a model trained on 70% garbage is probably a terrible model. Linda: Oh, the performance was awful, sure. But the training run finished. And that means in a real-world scenario with just a *little* bit of slipped-through noise, QK-LayerNorm is the difference between a wasted month of compute and a successful model.
## Closing Thoughts
Linda: So, the takeaway is crystal clear. Scale doesn't save you from bad data. In fact, as we saw with the depth scaling experiments, it actually makes you *more* vulnerable. Norris: Indeed. The bigger they are, the harder they crash. It’s a humbling reminder that we can't just compute our way out of messy reality. Linda: But at least now we have the tools to fight back. Monitor those attention logits—if they hit 1800, check your data pipeline immediately. And honestly? Just use QK-LayerNorm by default. Norris: Think of it as a helmet for your model. You hope you don't need it, but when you inevitably hit a patch of 'Toxic Five' gravel on the information superhighway, you'll be very glad it's there. Linda: That’s it for this week! Thanks for listening to Mechanical Dreams. Norris: And I’m off to clean my reading glasses. I wouldn't want a smudge to cause a divergence in my grading. See you next time.