The Memory Wall, How a Giant Model Is Trained Across Thousands of GPUs
From the publisher’s feed, collected in the ZeroLabs newsroom.
A large language model reaches you only after four stages, pre-training, fine-tuning, inference optimisation, and production serving. This series walks all four, from random weights to a service answering real users, using Meta’s Llama family as the worked example throughout. Part one is where it all begins, and where the enemy is not intelligence. It is memory.The End-to-End LLM Lifecycle, Part 1 of 4. Pre-training.Here is the problem that quietly shapes everything about how a large language model is built. Meta’s Llama 3 405B has roughly 405 billion parameters. To train it, a machine does not simply store those parameters. It also keeps a working copy, a set of gradients, and two extra numbers per parameter for the optimiser, which works out to about sixteen bytes for every single parameter before any real computation begins. Multiply that out and the training state alone is around six and a half terabytes. The best training GPU you can rent, an NVIDIA H100, holds eighty gigabytes. So before the model learns a single word, you already need more than eighty of those GPUs just to hold it still, and that is before the memory the actual maths demands.Pre-training, it turns out, is a memory problem long before it is an intelligence problem. The clever architecture and the trillions of tokens matter enormously, but none of it happens until you have solved the plainer, more brutal question of how to fit a model that does not fit. That is what this whole first stage is about, and once you see it that way, every technique below stops looking like a bag of tricks and starts looking like a series of answers to one question. How do you split one model across thousands of chips without drowning in the cost of making them talk to each other.One idea runs underneath all of it, and it is worth holding from the start. Almost every technique here is really about moving fewer bytes. Not doing less maths, moving fewer bytes, because on modern hardware the arithmetic is fast and the waiting for data is slow. Keep that in mind and the stage tells one story rather than ten.Why one GPU cannot hold the modelThe sixteen bytes are worth pulling apart, because they explain the entire memory crisis. Modern training runs in mixed precision, which keeps most numbers in a compact sixteen-bit format for speed while holding a few in higher precision for stability. For each parameter, the machine stores the weight itself and its gradient, two bytes each. It also keeps a full-precision master copy of the weight at four bytes, so tiny updates are not lost to rounding. And the AdamW optimiser, the standard choice, remembers two running statistics per parameter, a momentum and a variance, at four bytes each. Add those up and it is sixteen bytes per parameter, every step, before you count anything else.That anything else is activations, the intermediate results each layer keeps so it can compute its gradients on the way back. Activations grow with how many examples you process at once and how long each sequence is, so training on long documents makes an already tight situation worse.Every parameter costs about 16 bytes to train. For Llama 3 405B that is roughly 6.5 TB of state, against 80 GB on a single H100, so about 81 GPUs are needed just to hold it before any activations.The takeaway is stark. A one-billion-parameter model needs about sixteen gigabytes of training state, which fits comfortably on one GPU. Llama 3 405B needs about six and a half terabytes, which fits on none. Everything that follows exists to close that gap, and each technique closes it from a different direction.Splitting the work, the parallelism familyThe first direction is to cut the model into pieces and put each piece on a different GPU. There is more than one way to cut, and each way splits something different, pays a different communication cost, and belongs on a different kind of network link. The skill is matching the most talkative split to the fastest wire.Start with the simplest cut. Data parallelism gives each GPU a full copy of the model and a different slice of the training batch, then averages everyone’s gradients at the end of each step so the copies stay identical. It is easy and it scales well, right up until the model plus its training state no longer fits on one GPU, at which point a full copy per GPU is exactly the thing you cannot afford. Its modern successor, fully sharded data parallelism, fixes this by refusing to keep full copies. It splits the parameters, gradients, and optimiser state across the data-parallel GPUs, gathers each layer’s weights only for the moment they are needed, and throws them away again straight after. Each GPU stores only its shard between uses, which is how a model far too large for one card still trains across many.The next cut goes inside the model. Tensor parallelism splits the individual weight matrices of a single layer across several GPUs, so they cooperate on one matrix multiplication and then combine their partial results. Because the GPUs have to talk inside every layer, tensor parallelism is enormously chatty, and it is kept strictly within one server node where the GPUs are joined by the fastest links available, NVLink, rather than crossing the slower network between machines. A third cut, pipeline parallelism, splits the stack of layers into stages and puts each stage on a different node, so a batch flows through them like items along an assembly line. Its danger is idle time, since a naive pipeline leaves most stages waiting, so the work is chopped into small micro-batches that keep every stage busy at once.Two more cuts handle very long inputs, where the memory of the attention step itself becomes the wall. Sequence parallelism spreads the activations along the length of the text so they are not duplicated, and context parallelism goes further and splits the whole input sequence, attention included, across GPUs. And a final cut, expert parallelism, belongs to a specific kind of model we will meet shortly, placing different expert subnetworks on different GPUs.Tensor parallelism shares each layer inside a node, pipeline parallelism splits the layers across nodes, and data parallelism runs a second full copy on a different batch.Real training runs combine several of these at once. To train Llama 3 405B on up to sixteen thousand H100 GPUs, Meta used four cuts together, tensor, pipeline, context, and fully sharded data parallelism, chosen so that each GPU’s share of parameters, gradients, optimiser state, and activations fit inside its eighty gigabytes. The art was not any single technique. It was the blend, and getting the most talkative cut onto the fastest wire.Removing the duplication, ZeROData parallelism has a hidden waste. When every GPU keeps a full copy of the training state, most of that memory is identical copies of the same numbers. ZeRO, which stands for Zero Redundancy Optimizer, removes that duplication in stages, and each stage shards one more kind of state across the GPUs. The first stage shards only the optimiser statistics, which alone gives a fourfold memory saving for AdamW, since those statistics are the bulkiest part. The second stage shards the gradients too. The third stage shards the parameters as well, which is the same idea as fully sharded data parallelism from the previous section, and it leaves each GPU holding only its own small slice of everything.The effect is dramatic. Training Llama 3.1 8B across sixty-four GPUs without ZeRO would need about a hundred and twenty-eight gigabytes of state on each one, which simply does not fit. The first stage of ZeRO brings that down to about thirty-three gigabytes, the second to about eighteen, and the third to about two, leaving almost the whole GPU free for the activations that do the learning. The price is communication, because sharing the parameters means gathering them back before each layer runs, which is exactly the moving-bytes cost the whole stage is trying to minimise. When even that is not enough, a further trick called offloading pushes the optimiser state off the GPU entirely and into the far larger, far cheaper, far slower memory of the host machine, trading speed for the ability to fit at all.Making attention cheap, FlashAttentionEven with the model split and the duplication removed, one operation stays stubbornly expensive. Attention is the step where every token looks at every other token, and its cost grows with the square of the sequence length. The surprising part is where that cost actually lives. It is not mainly in the arithmetic. It is in shuffling a huge intermediate table between two kinds of GPU memory, a large but slowish pool called HBM and a tiny but blazing-fast scratchpad called SRAM. Standard attention builds the full table in the slow pool, writes it out, and reads it back, and all that traffic is the real bottleneck.FlashAttention rewrites the operation so that table never has to travel. It cuts the inputs into tiles small enough to fit in the fast scratchpad, computes attention tile by tile, and keeps a running tally so it never needs the whole table at once. The answer is exact, not an approximation, and the memory it uses grows only linearly with sequence length instead of quadratically, which is what makes long-context training possible at all.Standard attention writes and re-reads a full N by N table through slow memory, which is the real bottleneck. FlashAttention keeps only small tiles in the fast scratchpad and sends back just the result.The idea keeps being re-tuned for each new generation of hardware. The latest, FlashAttention-4, was published on 5 March 2026 as a redesign for NVIDIA’s newest Blackwell chips, and it reaches about 1,605 trillion operations per second on a B200, roughly seventy-one per cent of what the hardware can theoretically do, and about 1.3 times faster than NVIDIA’s own tuned library. To feel the scale of what it saves, consider Llama 3 8B, which has thirty-two attention heads. At an eight-thousand-token sequence, the table for one head holds about sixty-seven million numbers, and across all thirty-two heads standard attention would push roughly four gigabytes to slow memory for a single layer of a single sequence. FlashAttention avoids that entirely.There is a second, cheaper way to shrink attention’s appetite, this time by changing the architecture rather than the kernel. In ordinary attention, every query head carries its own set of keys and values, and during generation the model must cache and re-read all of them for every new token. Grouped-query attention lets several query heads share one set of keys and values, which shrinks that cache without noticeably hurting quality. Llama 3 8B uses it with thirty-two query heads sharing just eight key-value sets, which cuts the memory each token must read to a quarter of what full attention would cost. This is a decision made once, at design time, that pays back at every later stage.Growing parameters without growing compute, Mixture of ExpertsThere is one more architectural idea that changes the memory story, and it is the one behind the very largest models. Ordinarily, making a model smarter means making every part of it bigger, which means every token pays for every parameter. Mixture of Experts breaks that link. It replaces the dense feed-forward part of a layer with many smaller subnetworks called experts, and a tiny router that, for each token, picks only the best few to run. The token is processed by those chosen experts alone, so the model can store an enormous number of parameters while any single token uses only a small fraction of them.The router sends each token to just two of the eight experts. The other six are never computed for that token, so the model stores a great many parameters while using only a few.The catch, and it is the reason expert parallelism exists, is that the saving is in compute, not memory. Every expert still has to sit in GPU memory in case the router picks it, so a Mixture of Experts model is generous with parameters and stingy with the maths per token, which is a very different trade from a dense model. Llama 4 Maverick is the clearest example. It holds about four hundred billion parameters in total, spread across a hundred and twenty-eight routed experts per layer plus one shared expert, yet each token activates only about seventeen billion of them. It carries the knowledge of a four-hundred-billion-parameter model while paying roughly the compute of a seventeen-billion one. The router’s other job is balance, spreading tokens evenly so a few popular experts do not become the bottleneck while the rest sit idle.One big model, a whole family, distillationThe last idea in this stage is how one expensive model gives rise to several cheap ones. Training every model size from scratch would be wasteful, so instead a large model is trained once and then teaches smaller ones. Distillation trains a small student model to copy not just the right answers of a large teacher, but the teacher’s full sense of how likely every possible answer was. After the phrase the capital of Australia is, a teacher does not only say Canberra. It quietly signals that Sydney and Melbourne were plausible too, and that richer signal teaches the student far more than a single correct token ever could.In practice this is often paired with pruning, which bluntly removes whole layers, attention heads, or neurons from a trained model. Pruning makes the model small fast but damages it, and distillation then repairs the damage by having the shrunken student learn from the untouched teacher. This is exactly how Meta built the smallest Llama 3.2 models. The one-billion and three-billion versions were pruned down from Llama 3.1 8B, then taught using the outputs of Llama 3.1 8B and 70B to recover what pruning had cost. The same pattern built the Llama 4 family from the larger Behemoth teacher. One large model, trained once at great expense, becomes the parent of a whole range of smaller, cheaper, faster ones.What this stage was really aboutStep back and every technique here was an answer to the same pressure. The model does not fit, and the data does not want to move. Parallelism cut the model into pieces small enough to hold. ZeRO deleted the duplicated copies of those pieces. FlashAttention stopped the most expensive operation from shuffling a giant table through slow memory. Grouped-query attention and Mixture of Experts changed the architecture itself so it demanded fewer bytes and less compute per token. And distillation turned one enormous model into a family. Underneath all of it ran the single idea, move fewer bytes, because a modern GPU spends most of its life waiting for data rather than short of arithmetic.That is pre-training. At the end of it you have a raw, capable model that has read a very large slice of human text and can predict what comes next, but it does not yet reliably follow instructions or behave the way you would want an assistant to. Teaching it that, cheaply and without retraining the whole thing, is the job of the next stage. Part two is fine-tuning.SourcesThe Llama 3 Herd of Models, Meta, for the 405B training setup and 4D parallelism. https://arxiv.org/pdf/2407.21783Scaling Llama 3 Training with Efficient Parallelism Strategies, ISCA 2025. https://dl.acm.org/doi/10.1145/3695053.3731410FlashAttention-4, Algorithm and Kernel Co-Design for Blackwell GPUs, 5 March 2026, for the B200 performance figures. https://arxiv.org/abs/2603.05451 and https://tridao.me/blog/2026/flash4/The Llama 4 herd, Meta, for the Maverick expert counts and distillation from Behemoth. https://ai.meta.com/blog/llama-4-multimodal-intelligence/LLM Pruning and Distillation in Practice, the Minitron approach, for pruning plus distillation. https://arxiv.org/pdf/2408.11796v3Distilling Llama 3.1 8B into 1B with torchtune, PyTorch, for the Llama 3.2 small-model recipe. https://pytorch.org/?p=2785The Memory Wall, How a Giant Model Is Trained Across Thousands of GPUs was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.