Fitting a Model onto a Rack
Part 2 of 4
How mixture-of-experts models are spread across GPUs, why one rack is the natural unit, and what pipelining across racks does and does not buy you.
From Part 1
A decode step takes at least \(\max(t_{\text{compute}}, t_{\text{memory}})\). Every step reads all the weights, which the whole batch shares, and every sequence's KV cache, which nobody shares. Weight reads stop dominating at a batch of about \(B^{*} \approx 300 \times N_{\text{total}}/N_{\text{active}}\) sequences. When HBM is full of KV cache, a step takes roughly 25 ms.
Part 1 treated the hardware as one big GPU with a total FLOPS and a total memory bandwidth. Real models are spread across many GPUs, and the way you cut a model up decides how much data has to move between them every step. This part looks at how mixture-of-experts (MoE) models are laid out, why one rack is the natural unit, and what you get when you spread a model across more than one rack.
- The experts in an MoE layer are spread across GPUs, a few whole experts per GPU. Each token travels to whichever GPUs hold its experts and back. Any GPU may need to talk to any other, and a rack's NVLink switches provide exactly that. The network between racks is roughly ten times slower.
- Layers can be split across racks, which is called pipeline parallelism. Each rack boundary carries one vector per token, against many vectors per token inside the rack, so the slow network keeps up easily.
- In inference, pipelining doesn't change speed or cost. It only lowers the memory each rack needs for weights. The KV cache per GPU doesn't shrink at all.
- So in practice you spread experts across a whole scale-up domain and pipeline as little as possible. The size of the scale-up domain sets the latency floor, because it decides how many GPUs read the weights in parallel.
What a mixture-of-experts layer does
In a dense transformer, every token goes through the same feed-forward block in every layer. In an MoE model, that block is replaced by many smaller blocks, the experts, and a small router that picks a few of them for each token.
Each expert is an ordinary MLP: an up projection, a nonlinearity, and a down projection. The router scores the experts for each token and keeps the top few. The chosen experts' outputs are added up, weighted by the router's scores, and the result is added back to the token through the residual connection. DeepSeek-V3 has 256 routed experts per layer and sends each token to 8 of them, plus one shared expert that every token goes through. The experts are also small. Each one has a hidden width of 2,048, against a model width of 7,168.
Spreading the experts across GPUs
The standard layout is expert parallelism: each GPU holds a few whole experts. Take DeepSeek-V3's 256 experts and a 72-GPU rack. 256 doesn't divide evenly by 72, so we use 64 GPUs and leave the other 8 idle or give them other work. That's 4 experts per GPU.
Every GPU also holds a slice of the batch and its own copy of the router, which is tiny. After routing, each token is sent to the GPUs that hold its experts, and the expert outputs are sent back. Which GPU sends to which depends on the router's decisions, so the traffic pattern is all-to-all. It's still much less traffic than sending every token everywhere. A DeepSeek-V3 token goes to 8 of 256 experts, so it visits at most 8 of the 64 GPUs.
What a rack is
All-to-all traffic wants every GPU connected directly to every other GPU, and that's what a rack-scale system like NVIDIA's GB200 NVL72 is built for. Physically it's a cabinet a couple of meters tall that draws around 120 kW and weighs well over a tonne. It holds 18 compute trays with 4 GPUs each, and in the middle, 9 trays of NVLink switches. A spine of thousands of copper cables at the back connects every GPU to every switch, so any GPU can reach any other in two hops: up to a switch and back down. Each GPU gets 1.8 TB/s of NVLink bandwidth, 900 GB/s in each direction.
Leaving the rack is a different path. Each GPU also has a network card, at 400 or 800 Gb/s (50 to 100 GB/s), which goes up to switches shared with the rest of the data center. That's 9 to 18 times less bandwidth than NVLink. I'll call it 10 times. The fast in-rack network is called the scale-up network, and the slower one between racks is the scale-out network.
Why not wire thousands of GPUs to one giant switch? Mostly because of cables. Double the GPUs in a rack and you double the cables that have to run through the same backplane. Connector density, cable bend radius, weight, power delivery, and cooling are all pushed close to their limits in current racks. NVIDIA went from 8 GPUs per NVLink domain in Hopper servers to 72 in Blackwell largely by moving from a single server board to a whole-rack design, and its roadmap reaches larger domains with new, denser racks. Google's TPU pods connect thousands of chips with their fast interconnect, but as a 3D torus in which each chip links directly only to its neighbors, which suits all-to-all traffic less well than a switch.
Splitting an expert layer across two racks
Now suppose one expert layer is spread across two racks. On average, half of each token's expert visits land in the other rack, and with 8 experts per token almost every token needs at least one of them. That traffic has to cross the scale-out network at a tenth of the bandwidth, and the whole layer waits for it. So the scale-up domain is effectively the limit on how big an expert layer you can run comfortably. It's possible to go beyond it with enough engineering. DeepSeek, working with 8-GPU H800 servers, spread its decode experts across many servers over InfiniBand and wrote custom communication kernels to make that work. But you pay for it, and it's a big part of why larger scale-up domains have been worth so much.
Pipelining layers across racks
Experts are one way to cut a model. Layers are another. A model has dozens of layers, and nothing stops us from putting the first group on one rack, the next group on the next rack, and so on. That's pipeline parallelism. Does the slow network between racks become the bottleneck?
Count the vectors. Inside a rack, every MoE layer sends each token to its \(k\) experts and brings the results back, so that's \(2k\) vectors per token per layer over NVLink. With \(L\) layers per stage, it's \(2kL\) vectors per token per stage. At the rack boundary, each token crosses the network once, as a single vector. The network is about 10 times slower, so the time spent on the boundary is smaller than the time spent inside the rack when
\[ \frac{t_{\text{scale-up}}}{t_{\text{scale-out}}} \approx \frac{2kL}{\text{BW}_{\text{up}}/\text{BW}_{\text{out}}} \approx \frac{2kL}{10} \ \geq\ 1 \]For DeepSeek-V3, \(k = 8\), so even one layer per stage gives \(16/10\). Any realistic number of layers per stage makes the rack boundary cheap. The layout that falls out mirrors the model itself: experts go on different GPUs, and layers go on different racks.
You could cut along other dimensions too. Tensor parallelism splits individual weight matrices across GPUs, along the model width or the expert's hidden width. That used to be common for dense models. With experts this small (a hidden width of 2,048), splitting them further costs more in communication than it saves.
What pipelining buys in inference
To keep all the racks busy, we split the batch into micro-batches and keep one micro-batch in each stage at a time. Decoding is a loop: when a micro-batch leaves the last stage with its new token, it goes straight back to the first stage to produce the next one.
As the figure shows, the number of micro-batches has to equal the number of stages. With fewer, a rack sits idle while it waits for the next micro-batch to come around.
What does this do to latency? A micro-batch passes through four racks, and each one runs a quarter of the layers, so the total time per token is the same as one rack running all the layers, plus a few network hops. Throughput is four times higher, but we're also using four times the hardware. In inference, pipelining neither speeds a token up nor makes it cheaper. What it saves is memory: each rack only holds a quarter of the weights.
What pipelining costs in training
Training is where pipelining gets painful. A training step runs the forward pass for the whole batch, then the backward pass, then updates the weights. The backward pass for a micro-batch can't start on a rack until the forward pass for it has finished on every later rack, and the weight update has to wait for every micro-batch's gradients.
The hatched region is the pipeline bubble. With \(P\) stages and \(M\) micro-batches in this simple schedule, the idle fraction is \((P-1)/(M+P-1)\), which is 3/7 in the figure. More micro-batches shrink the bubble, but you either grow the global batch or make each micro-batch smaller and less efficient. Smaller global batches are better for learning, since each update uses fresher gradients. The best choice balances these.
There are cleverer schedules, such as interleaved one-forward-one-backward, zero-bubble pipelines, and DeepSeek's DualPipe, which split the work more finely and overlap forward and backward passes to fill the gaps. They work, but they add a lot of complexity. They also constrain the architecture. A model with connections that skip across many layers is awkward to cut into stages. Pipelining is worth that trouble only when the model doesn't fit any other way.
Why pipelining doesn't shrink the KV cache
Back to inference. Pipelining saves memory on weights, so you might expect it to help with memory in general. Let's check. Spread the model over \(E\) GPUs per rack (the expert-parallel width) and \(P\) racks. The memory needed per GPU is the total divided by \(EP\):
\[ \text{memory per GPU} = \frac{\beta N_{\text{total}} + B\,n_{\text{ctx}}\,s_{\text{kv}}}{E\,P} \]The problem is \(B\). We just saw that a pipeline needs one micro-batch per stage, and each micro-batch needs its own \(b \approx B^{*}\) sequences to amortize the weights in each stage. So the global batch is \(B = P\,b\). Substituting,
\[ \text{memory per GPU} = \frac{\beta N_{\text{total}}}{E\,P} + \frac{b\,n_{\text{ctx}}\,s_{\text{kv}}}{E} \]The \(P\) cancels in the KV term.
The weight term keeps falling as you add stages. The KV term doesn't move. A natural objection: each stage only stores the KV cache for its own layers, so shouldn't the KV per rack shrink? It does, per sequence. But you now need \(P\) times as many sequences in flight to keep every stage busy, and the two effects cancel exactly. Just as no amount of batching shares a sequence's KV cache across the batch, no amount of pipelining spreads it more thinly per GPU.
For DeepSeek-V3 on 64 GPUs, the weights take about 10.5 GB per GPU out of 186 GB, so there's nothing to gain from pipelining at all. A model five times larger in total parameters would put about 52 GB of weights on each GPU, and splitting it over two racks would halve that. Pipelining is a fix for models whose weights don't fit comfortably. It does nothing for long contexts.
What gets used in practice
Put together, the layout for serving a large MoE model is simple. Use expert parallelism across the whole scale-up domain. Add pipeline stages only if the weights won't fit otherwise, and then only a couple. DeepSeek's published inference setup for V3, for example, uses wide expert parallelism for the MoE layers and no pipelining. Splitting individual experts with tensor parallelism has mostly faded, because the experts are already small.
Why bigger scale-up domains mattered
If pipelining solves capacity for weights, why was the jump from 8-GPU servers to 72-GPU racks such a big deal? Because of the latency floor from Part 1. The time to read all the weights once is
\[ t_{\text{floor}} = \frac{\beta N_{\text{total}}}{E \times \text{BW}_{\text{per GPU}}} \]Only the GPUs in one stage read weights at the same time, because the stages run one after another. So the floor depends on the scale-up width \(E\), not on the total number of GPUs.
A trillion-parameter model in 8 bits on one 8-GPU H200 server fills almost all of its 1.1 TB of memory, leaving no room for KV cache, and it can't produce tokens for any one sequence faster than about 38 per second. On 64 GPUs of an NVL72, the same model's floor is about 2 ms, or 500 tokens per second. Pipelining across several H200 servers would fix the memory problem but not the speed problem.
This may be part of why frontier model sizes grew slowly for a while after GPT-4, which was widely reported to have well over a trillion parameters. A much larger sparse model would have been slow to serve on 8-GPU NVIDIA servers, and rack-scale NVLink only became mainstream with Blackwell. Google's TPU pods had large fast domains much earlier. Total parameter count is limited by what one scale-up domain can serve quickly. Active parameter count is limited by compute cost.
Next, in Part 3, we'll use this model to read API price sheets and work out what they reveal about KV cache sizes, prefill and decode, and where cached prompts are stored.
Diagrams are drawn in TikZ.