Free with a sign-in.
The best 17 min of 134
How GPT, Claude, and Gemini are actually trained and served – Reiner Pope
Reiner Pope argues that batch size, KV-cache traffic and rack bandwidth—not just model FLOPs—set the cost and latency of frontier AI.
Dwarkesh Podcast · Dwarkesh Patel
- Reiner Pope is CEO of MatX.
The best minutes
- 1:23:56Serving demand may push models far past Chinchilla optimal8 min
- 1:33:10API price tiers can reveal a model's context-memory costs8 min
Also worth watching
- 1:52:10Memory bandwidth, not compute, limits very long contexts3 min
- 33:29One rack bounds the size of an MoE expert layer8 min
- 2:08:08Reversible networks trade compute for lower training memory5 min
Skip the MoE quality survey, the extended pipeline-parallelism derivation, and the cache-tier storage calculations.
Full analysis · 6 min read
Real Alpha · Nov 10
Reiner Pope says serving could imply about 100x overtraining
- Pope’s rough model suggests serving could support training about 100 times past Chinchilla.
- The estimate relies on guessed traffic, model lifetime and a heuristic cost balance.
- Builders should budget KV-cache traffic separately from weights and batching.
Free with an account
Read the rest of the analysis
6 sections, the 4 other voices it tests Pope against, and what it means for you. Every episode we cut gets one.
Check your inbox
We sent a link to your address. Click it to finish signing up. Not there in a minute? Look in spam.
or
Signed up before? The same buttons sign you in. The episode, its moments and the transcript stay free.
Serving use could imply about 100x overtraining
About 100 times past Chinchilla is Pope’s rough estimate for frontier-model training, inferred from serving demand. That is the figure a founder might repeat, but it is a scenario, not a disclosed training run.
Pope starts from a guess of 500 million tokens per second globally, then divides by five or ten for one model. He estimates maybe 50 million inference tokens per second for that model, live for about two months.
He estimates roughly 200 trillion inference tokens over that lifetime. For a model with about 100 billion active parameters, his comparison uses 20 tokens per parameter, yielding about two trillion.
He then compares about 200 trillion with about two trillion. The ratio is roughly 100 to one. These are broad estimates, not audited totals.
The host also mentions an unverified report of 150 trillion training tokens, close to Pope’s rough inference estimate. That is an interesting cross-check, but neither number is confirmed in the conversation.
Pope assumes pretraining, RL and inference costs should roughly balance. He calls this heuristic and acknowledges another split, half on training and half on inference, could also fit. MatX is a chip startup, so Pope has a commercial interest in hardware economics.
Our read
The calculation makes post-training use part of the training-economics question. But its result depends on assumptions the episode cannot verify, so treat 100x as a scenario, not a reported lab fact.
Batching spreads weight reads, not cache costs
Batching spreads a model’s fixed weight read across more sequences, lowering weight cost per generated token. At batch size one, the same weights are read for a single sequence. But each sequence carries its own KV-cache history.
For example, Pope’s simplified balance point is a batch of about 300 times the model’s sparsity ratio. The host restates a DeepSeek-related example as 2,000 to 3,000 tokens per batch. Pope clarifies that batch here means unique sequences, each producing one next token.
His rough model first ignores KV fetches. Adding them raises the batch needed to balance compute and memory. Real systems miss roofline efficiency, so he says practitioners often go two or three times above that clean balance.
At his 20 millisecond train schedule, a request might wait up to 20 milliseconds for the next batch. Pope says execution adds another 20 milliseconds in the worst case. For a founder, slower batching is not a generic discount. It depends on arriving traffic and tolerated wait.
“the cost initially starts very high at batch size of one.”
Our read
Batching can reduce the weight-read cost, but it cannot pool away each request’s context. A lower serving price has to be weighed against queue time and cache traffic.
Long context turns KV traffic into a budget limit
Each decode step reads past-token KV state, so longer histories add memory traffic and occupy capacity. Pope says attention arithmetic grows more slowly than the memory burden in ordinary dense-attention setups. His simplified model treats compute as nearly flat at long context, so it is not a full latency forecast.
Context windows jumped from about 8K to 100K or 200K, Pope says, then hovered there for a year or two. He did not recall exactly when that transition happened. Sparse attention can reduce the memory burden, but Pope says quality loss limits how far sparsity can go.
Aravind Srinivas on Sourcery in October 2026 says expanding personal context can dominate batch size. He says the cloud advantage can shrink to roughly three times or parity with local hardware.
Diogo Almeida on The TWIML AI Podcast in October 2026 suggests curating agent context instead of appending every prior step. Diogo Almeida on Unsupervised Learning in November 2026 says append-only KV state constrains coding-agent routing and sub-agent design. These are product-design responses, not independent measurements of Pope’s hardware estimates.
Aravind Srinivas · Sourcery · Oct 12Long-context agents make local hardware cost-competitive with data centers
Diogo Almeida · The TWIML AI Podcast · Oct 6Agent designs can curate context instead of appending every step
Diogo Almeida · Unsupervised Learning · Nov 5The KV cache constrains how coding agents are designed
Our read
Pope’s explanation makes long context a memory-throughput and capacity problem, not merely a model feature. But context management can reduce what a system needs to carry forward.
MoE routing makes rack topology part of capacity
MoE saves compute by activating only a subset of experts per token, but routing still moves activations among GPUs. Pope simplifies a 72-GPU rack to 64 usable GPUs for his example. With 256 experts, that gives four experts per GPU.
The router can send tokens from any GPU to any other, creating all-to-all traffic. Within the rack, Pope says scale-up networking is about eight times faster than scale-out links. On average, he says half of tokens may need to leave the rack in a two-rack split. That makes slower scale-out links a likely bottleneck.
Pierre Stock on The MAD Podcast in October 2026 explains MoE’s reduced active-parameter load. That compute saving leaves the routing traffic intact. Amin Vahdat on Training Data in October 2026 says agents raise CPU, network and storage demand too. His point widens the infrastructure budget, but does not validate Pope’s eight-times comparison.
Pope previously worked at Google on software efficiency, compilers and TPU architecture. MatX is now his chip startup, giving him relevant experience and a commercial interest in hardware design. Builders should measure cross-rack traffic, not infer capacity from GPU count alone.
Pierre Stock · The MAD Podcast · Oct 22Mixture-of-experts models trade training complexity for inference capacity- AVAmin Vahdat · Training Data · Oct 6Long-horizon agents push CPU, storage and network demand up
Our read
For MoE serving, chip count alone cannot predict throughput. The location of expert traffic and the cost of crossing rack boundaries matter too.
Pipeline parallelism divides weights, not cache demand
Pipeline parallelism divides model weights across racks, so each rack need not hold the full model. It helps fit model size, but Pope says it does not reduce KV-cache demand per GPU.
His calculation starts with a global batch split into micro-batches, one per pipeline stage. More stages lower each stage’s share of weights, while added sequences in flight cancel the expected per-GPU KV reduction.
This distinction matters for system design. Pipeline can solve a weight-capacity problem without solving context capacity. In his idealized inference diagram, pipeline leaves latency unchanged. Real inter-rack hops may still add milliseconds.
Pope says inference uses little pipeline when weights already fit within a rack. That makes the choice workload-specific rather than automatically beneficial. Operators planning context-heavy agents should separate pipeline scaling from context and cache strategy.
Our read
Pipeline parallelism addresses where weights reside, not the total state active sequences require. So it is not a shortcut to cheaper long-context serving.
API price tiers offer clues, not a model blueprint
The host cites a 50 percent price increase for Gemini API requests beyond 200K tokens. Pope suggests the tier may sit near the crossover where KV-memory costs overtake compute, though not necessarily exactly there.
He assumes roughly 100 billion active parameters and a context around 200K tokens. He also assumes enough batching makes weight reads negligible. He concludes about two kilobytes per token, which he says is plausible.
He says eight KV heads with a head dimension of 128 could fit the estimate. Fewer KV heads with more layers could also reach it. Sparse attention offers another route to a similar byte count.
Those alternatives make public pricing a clue, not a unique architecture fingerprint. The exercise treats the tier as a rough signal of marginal cost. The episode does not establish how closely price tracks that cost.
For builders, the useful move is to test cost by context band, not reverse-engineer a vendor from one public tier.
Our read
Public prices can help frame the cost curve, but they do not disclose a provider’s system design. Use the tier to form a hypothesis, then test it against measured workload costs.
What it means for you
- Model traffic ranges. Estimate low, base and high tokens per second and model lifetime. Compare implied inference tokens with training tokens, and label the result as a scenario.
- Measure cache by context. Record KV bytes, throughput and latency at representative context lengths. Include all three in a serving estimate.
- Track batch delays. Measure batch fill, queue wait and tokens per second. Compare any cost savings with the workflow’s latency tolerance.
- Trace expert traffic. For MoE services, measure the share of token traffic crossing racks and its delay. Do not infer capacity from GPU count alone.
What to watch
- Whether published traffic and model-lifetime figures become precise enough to test Pope’s roughly 100x scenario.
- Whether context windows move materially beyond the plateau Pope describes, and what memory tradeoffs make that feasible.
- Whether MoE systems keep expert layers inside racks or improve cross-rack all-to-all bandwidth.
Send this to the infrastructure lead planning inference capacity.
Watch the estimate that turns rough use assumptions into about 100x overtraining
Written by Real Alpha from the episode's transcript and the other moments it links, then checked against the transcript. Quotes are the speaker's exact words.
Minute by minute
- 37:52Rack networks constrain expert parallelism
Pope says a rack typically holds about 64 GPUs, with a fast scale-up network connecting GPUs within it; scale-out connections between racks are about eight times slower. Because MoE routing creates all-to-all traffic, tokens sent across rack boundaries can become a bottleneck. He says rack size also faces physical limits from cabling, power, weight and cooling.
- 46:50Pipeline parallelism can span racks
Pope says MoE’s all-to-all traffic favors a single rack, while pipeline parallelism can distribute model layers across racks because it sends less data across rack boundaries. In his analysis, the eightfold scale-up-to-scale-out bandwidth difference can be offset by the number of activated experts and layers per pipeline stage, making a multi-rack pipeline viable.
- 55:00Pipeline bubbles complicate training
Pope says pipeline parallelism does not reduce inference compute or latency; its main benefit is reducing the model weights stored per rack. Pipelines create idle bubbles, and training must coordinate forward and backward passes across batches. Microbatching and other schedules can reduce the bubbles, but add complexity.
- 1:03:20KV caches limit pipeline gains
Pope separates memory capacity from bandwidth: per GPU, weights and KV cache share memory, with KV demand scaling with batch size, context length and bytes per token. Pipeline stages reduce the weight footprint, but the larger number of sequences in flight offsets the KV-cache savings per GPU. He says the KV cache can become the dominant memory requirement.
- 1:14:00Scale-up bandwidth reduces latency
Pope says pipelining can solve model-weight capacity limits, but not KV-cache capacity limits. He estimates that rack-to-rack hops may add a few milliseconds per stage, though he says he cannot give a firm figure; sequential decode stacks those hops. He argues that larger scale-up domains matter because they increase aggregate memory bandwidth and let GPUs load weights in parallel.
- 1:18:51Pope estimates roughly 100x overtraining
Pope models pretraining, RL and inference as compute costs to be balanced, noting that RL is less efficient in part because it includes decoding. Using rough assumptions of 50 million inference tokens per second per model for two months, about 100 billion active parameters and around 2 trillion Chinchilla-optimal tokens, he estimates that roughly 200 trillion inference tokens could imply about 100 times overtraining. He stresses that the inputs are guesses.
- 1:32:31API prices hint at KV costs
Pope treats Gemini 3.1’s 50% surcharge above 200K context tokens as a clue that KV-cache reads approach the compute-memory crossover around that length. Under his assumptions, he estimates about 1,667 bytes per token. He says output has been priced about five times higher than input, and argues that prefill can be cheaper because it processes many tokens while amortizing weight reads, whereas decode is memory-bandwidth-bound.
- 1:48:47Cache tiers trade storage for recomputation
Pope distinguishes a cache hit, which retrieves stored KV state, from a miss, which requires recomputing it from token IDs. He compares holding KV in HBM, DDR or flash with the costs of retrieval and rematerialization, and says API retention durations may indicate which storage tiers are used. He argues that memory bandwidth and capacity, more than compute, have kept context lengths near 100K–200K; sparse attention helps, but quality limits how far it can go.
- 2:03:39Neural nets and ciphers share mixing
Pope compares ciphers’ scrambling of inputs with neural networks’ effort to extract structure, noting that gradient descent and design choices such as residual connections help make neural nets trainable. He describes reversible networks based on a Feistel-cipher construction: invertible layers can reconstruct activations during backpropagation, trading extra compute for lower activation memory.
Published Apr 29, 2026.
Transcript · 1 h 33 m read
Dwarkesh Podcast, hosted by Dwarkesh Patel, with Reiner Pope.
Transcribed by machine (Whisper) from the episode’s audio, so a word may be off here and there. Where the podcast’s audio and the video part ways, some times are a minute or so off.
in Maddox, but that's unrelated to this podcast. Reiner, maybe to kick us off, I'll ask this question. So we have a couple of companies like Claude and Codex and Cursor are offering something like FastMode, where for 6x the price, they'll give StreamY tokens at 2.5x to speed. Mechanically, I'm curious what's going on here. Why is it the case if you can pay more to get faster latency? And two, could you keep going? Could you pay 100x more and somehow get even faster speeds or much, much faster speeds? And three, could you go the other way? Could you have something like quad code slow mode where if you are willing to wait for minutes on end, you could get even cheaper prices?
So maybe this will help motivate the kind of analysis that you'll be doing through the lecture. Great. I mean, a little bit to jump to the conclusion, the big effect is batch size. but what we're going to do now is quantify exactly what that looks like and what its implications are on latency and cost. There's going to be another effect, which is, you can call it speculative decoding or multi-token prediction. We can maybe come back to that later, but I think the first thing that we'll talk through is batch size. So what I'd like to introduce is sort of the two principles of analysis. Firstly, we're going to look at a roofline analysis of how we run a transformer model on a cluster of chips.
we'll take a sort of, let's say, a Blackwell NVL72 cluster, so a rack of 72 GPUs. And so the roofline analysis means we look at memory bandwidth and compute performance. And then the other side of that is that we're going to look at just two simple factors of the model, which are the time to operate on the weights and then the time to operate on the context, the KB cache. So let's jump in. What we're going to try and do is we're going to try estimate the time that it takes to run an inference of a certain shape. Now, we're not perfect here, we can't exactly predict the time, and so instead we're going to approximate, and so we're going to say that the time must be greater than or equal to a certain quantity. And so we're going to consider two different aspects. We're going to look at the time for it takes to do the memory fetchers, and then the time it takes to do the compute.
Read the whole transcript
And it'll turn out that this actually gives us a very strong predictive power, even with a simple one. So one by one, what is the time that it takes to do the compute? So there are really two things I need to do in the compute. I need to multiply by all of the active parameters, and then I need to do some work on the attention. So multiplying by all the active parameters, I have a certain batch size that I'm running, And then I've got a number of active parameters in my model. And then I'm just going to divide this by the compute throughput, which is the flops of the chip. So this is a hardware constant.
So this actually accounts for all of the compute. time for all of the weight matrix multiplies. There's a little caveat here. We've sort of ignored the time to do any of the attention computation, but that in general will be quite small in comparison to this, so we'll ignore this. Maybe I'll just interrupt from time to time to ask some very naive questions or to clarify some basic points, but just for the audience, you're not serving one user at a time. The batch refers to the fact that you're serving many different users at the same time, and that's a whole batch. Yeah, so I can motivate the batch at least a little bit.
So, I mean, we will see exactly why batch is such a favorable optimization. But what will turn out to be the case is that if you do not batch together many users, the cost and the economics you get can be like a thousand times worse than if you do batch many two users together. And we'll be able to see that quite explicitly. And then a number of active parameters. This is saying, like, if I look at, for example, a DeepSeq model, the DeepSeq v3 model has about 30, 37 billion active parameters. and then 700 billion total parameters. So we're focusing on just the ones that are active for a single token.
Okay, so we're modeled compute performance. I'm going to keep writing equals, but in all of these cases, you can think of this time as being at least this much, and maybe there'll be some terms we ignored. On the memory side, what do we need to do with memory? We need to fetch all of the weights, and so there is some time to fetch all of the total number of parameters, not just the active parameters. So there's wait fetch time. And then in addition, there's a kvcache fetch time. So there is, this actually depends on batch size. So for every element in the batch, we have to fetch an entire context length worth of tokens. And then there's a size per token. So like bytes bytes for one token.
And so this is a model parameter. And maybe just back in, let's just explain what the KV cache is real quick. Yeah. So when I do a forward pass, let me draw actually how the autoregressive inference works. So this is during decode. So if I think I have a bunch of tokens of text, I'm drawing a tensor because ultimately the tokens are represented as some tensor of in some embedding dimension and then in this direction I have the sequence length. The work of running a decode is I have to run each token through a whole bunch of matrix multipliers over a bunch of different layers and I have in general I'm going to have to do that work over all of these tokens but then one step of decode is actually to produce just this one additional token out here yep and so what i'm going to do there is i'm going to run a full forwards pass of uh multiplying by all of the weight matrices in the entire model um but then i've got this attention mechanism where this token sort of it's it's like looking at all of the past tokens um in this way and what is it looking at specifically it is looking at some internal representation that the model has produced of the tokens and we call that the kb cache so So this process of attending, this single token attending to all of the history of tokens, that's attention.
It is mostly dominated by memory fetches rather than matrix multiplies. So we've got the amount of memory that we're fetching shown over here. And then there's, of course, just then divided by the memory bandwidth. So the memory writes per second. So, in fact, these equations here are actually enough for us to now draw some fit lines. And so the things that we'd like to look at are sensitivity to batch, and then also, which we'll draw separately to context links. So we said that the big effects you can get is like some trade-off in latency versus cost in batch size. So let's draw them out. I think there's just really two graphs we want to draw.
We'll first just draw batch size versus time here. So when we look at the shape of this, we've got a maximum of the sum and then another term. And so let's look at these terms one by one and how they scale the time for compute and memory and how they show up. So let's first look at this compute time. This is just purely linear in batch size with no offset. So it is some curve like this, this is t compute. and then on the memory side we've got some portion here that that is just this constant that that is you know constant in some base offset here which is the weight fetch weight fetch and then finally we have this term here which is the kb fetch and which we're going I'm going to draw as the KBFH, which is linear in batch size, and so it looks like that.
So the sum of this plus this maxed with this, so let's at least first draw the sum. So the two memory times in conjunction end up looking on this curve slope like this, and then we get a the overall maximum is I'll draw a little thicker here is the maximum of these two curves makes sense okay so what does this mean actually so this is a latency plot so if I grow my batch size I get initially some not very strong dependence on batch size and so there's some lower bound on latency here latency lower bound lower bound so this already partially answers the question for a given hardware configuration and we can talk about varying hardware configuration but for a given hardware configuration there is a lower bound on latency which is simply the I need to read all of my total parameters from memory into the chips and that takes a certain amount of time If I use all of my memory bandwidth, I can't do any better than that.
It seems like the way you've drawn the slopes for compute time and how the KV grows and what implication the KV has on memory time, that as a batch size... Yeah, what if this were above or below? Yeah, or is that necessarily the case? Because if this is always true, then as batch size grows, compute always dominates KV, and which suggests that if you have big enough batch size, maybe memory is never an issue. Yeah, this is really sensitive to the context length. So I think we should come back and explore this. There will be, as you vary the context length, the KB fetch time will go up and up. And so that'll cause a transition from compute limited to memory limited.
And is there something especially significant about the slope being exactly the slope of the compute time? Yeah, whenever we have balance points, it kind of says that you're getting it exactly right and so for the particular context length where the slopes match that says i am equally memory bound and compute bound right which is a really desirable place yeah but suppose it's like this is a very simple algebra algebra problem but suppose it's you know the the optimal is 100k context length and you go to 200K context length, does your MFU go down to like 50%? Like, does it have a humongous impact on MFU?
Yeah, it does. To be like slightly outside of context length, optimal range, Goldilocks zone? That's right. So that is true as modeled here. There's a key point here that I'm modeling this context length as, or I'm modeling the memory fetch as linear in context length. That actually depends on model architecture. It is true for many of the, all of the model architectures with dense attention. Yeah. There's a, sparse attention actually scales much better than that. Got it. And is sparse attention that everybody uses in practice? I'm pretty excited about sparse attention. It's hard to know what the labs are using.
DeepSeq has published a sparse attention mechanism. I'll just like put a plug in that sparse attention, some of the DeepSeq papers that have published sparse attention end up putting a square root to this term. Okay. So, so far we've done, we've looked at the latency. It's kind of hard to read off cost from this. So if I think, what does cost mean? I'm going to, like, to run this inference, I'm going to use the GPU for a certain number of seconds, like one millisecond or 20 milliseconds or something like that. And I have to pay the rental time for that time. So, like, it's $2 an hour per GPU or something like that.
So that's the cost of this inference. But how much value have, how many tokens have I processed during that inference? That is the batch size. And so what we actually want to plot is going to be the cost versus batch size, which is like T over B versus batch size. This is the cost per token. So we have to imagine dividing each of these three curves by B, so multiplying by this reciprocal. And so what we end up with there is the compute curve is going to, it was linear, we divide by B, that makes it a constant here. And this is T compute. The KV fetch was linear, now it becomes a constant as well.
KV fetch. and then the wait fetch was constant and now we're divided by b and so it becomes this hyperbole. And so again, we're going to compute the max of the sum. So the sum of these two terms shifts the parabola up. Some of the kbfetch and the waitfetch gives us a sort of a higher parabola that's like this. And then we're going to take the max with the compute here. So we end up with this being the overall shape that we care about. So again, so like we see some limiting behavior. The cost initially starts very high at batch size of one. Actually, like, it almost goes to infinity. Like, it's because we've got so many waitfetchers which are not amortized over a large batch size.
But then as we increase the batch size, the waitfetchers become amortized over so many different batch elements that their cost grows very small. And eventually the compute time ends up driving the cost. So there is a limiting, like, lower bound on cost which is this one here yeah um so claude code slow or codex slow or whatever would just live on this line and it wouldn't help much because you're you're not able to amortize the kv values over a much bigger batch yeah yeah they're unique per batch the compute is also unique per batch and so what is the minimum work you can do per batch after amortizing everything else away So this point where you are no longer memory bandwidth bound, what practically, how big a batch do you need to, like, how big are the batches practically for frontier models?
You can just solve for that, actually. And it's not even particularly sensitive to model architecture. So let's go ahead and do that. So what we're talking about is we're going to say when the memory time is equal to the compute time. That's what that question is. For now, I'm going to discard the, because we're focused on what the batch size is, and really there's a question of when the weights are amortized over the multiplies, I'm going to focus on comparing the weight fetch time to the weight multiply time. I'm going to disregard the kbfetch term just to simplify the analysis so we can get a kind of a clean answer out.
So we're going to equate... this portion with this, with these two times. Yep. So, writing that out, we get n number of total parameters over memory bandwidth is equal to batch size times number of active parameters divided by the compute performance. So looking over here, everything on the top, these are model parameters. Everything on the bottom, these are hardware parameters. It turns out to be nice to rearrange them such that we have the hardware parameters on one side. So this is equivalent to flops over memory bandwidth being equal to batch size times number of active parameters divided by the number of total parameters.
So this is a hardware parameter. Actually, this actually ends up being a dimensionless constant. If you look in terms of flops, what are the dimensions of this? This is multiplies per second, this is bytes per second, so that's not quite dimensionless. But what you do is you say, like, multiplies per second times, let's say I'm doing fp4. So I do, like, how many fp4 multiplies per second times the fact that each fp4 is half a byte. And so I can actually make this ending up being dimensionless. and this ends up being on most GPUs around 300, somewhere around 300. I'm sorry, has that ratio changed over time as we've gone from model generation to model generation where the flops keeps increasing?
So there's a hardware parameter. To what extent has the hardware changed? So from like A100 to H100 to B100, the flops has increased substantially, the memory battery has also increased substantially and it has remained reasonably stable. Well, and we can express this one as well. This is a sparsity parameter. And I might even phrase it slightly different. Let's solve for batch size in total. We end up with, I'm sorry, just moving this back over to the other side. We end up with batch size needs to be bigger than approximately 300 times sparsity. So for example, if I have 100, like I activate in DeepSync, I activate 32 out of 256 experts.
So this would be like eight for the Tiki. Got it, okay. So this actually gives you a ballpark, which is remarkably accurate to practice. Generally, people will go a little bit larger than this. They don't really want to be exactly at the balance point because real-world efficiencies aren't as good as a roofline analysis would say. But take this and maybe double it or triple it. Okay, so basically it's like 2,000 to 3,000 tokens per batch. But then if you included... the KB cache, the implication would be that the optimal batch size should grow larger. So this is like, we solve for the equivalence between when compute time is equal to memory time.
If I add in more memory bandwidth, like something that consumes more memory bandwidth, then I have less available for the white loads. And so I need to grow the memory bandwidth more and therefore the batch size more. This seems incredibly small. Like a batch, this would be like less than one sequence, right? Yeah, okay. So I guess this is, keep in mind that I'm talking about the number of tokens that I'm generating one more token for. So it's like, it's actually 2,000 unique sequences. Okay, we're just talking about a single forward pass on these sequences. This is like, do you think of it like the batch as the number of sequences rather than like...
That's right. Okay, cool. When I'm prepping for interviews, I often talk to experts in the field. So for Reiner, I chatted with two of Jane Street's engineers, Clark and Axel. Clark, who works on low latency trading systems, walked me through why Jane Street uses FPGAs to make sure that they have predictable nanosecond latencies. You can just build these like giant grids of compute very easily that do exactly what you need to touch 100 megabytes of SRAM and then get your response back in tens of nanoseconds very easily. And that's basically impossible on CPU. He then went on to explain why CPUs just wouldn't work for this kind of thing.
And so if you have a clock that's going every three nanoseconds, you actually have several bytes of information at a time to make your decision. That's as opposed to a CPU where you'll just collect up a whole packet, you know, let's say a 1500-byte packet, and then you say, okay, this packet's ready, here you go, CPU, you can start thinking about it now. FPGAs allow you to react to the earliest part of the packet as it arrives, rather than having to wait for the full thing. We also talked about liquid cooling, network design, and many other things. If you're interested in this stuff, JaneStreet is hiring.
You can check out their open roles at jainestreet.com slash dworkhash. And if you want to watch the full prep conversation, we posted it there too. If you've got a frontier model and you are actually doing inference, surely they must have more than 2,000 concurrent users. Yeah. Is there any added latency from the fact that you need to have the whole bash fill up? Or is it if you have a reasonable amount of users, it's so unlikely that you wouldn't, it would not take you 100 milliseconds to fill up the next 2,000 slots. Yeah. The way to think about this, I guess we think of it as, like, when does the train depart as a model?
So let's say I've picked a batch size that I'm going to run at. Maybe I pick, you know, this batch size. And so, like, well, and by the way, this intersection point is the same intersection point here. So I pick this batch size. I know that it's going to take, for example, maybe it's something like 20 milliseconds is a common place to sense up landing. What I'm going to produce is like, so this is a timeline of what is running on the GPU. It's going to start a new batch every 20 milliseconds regardless. And so, sorry, this is 20, this is 40. Thanks. You can think of this as a schedule for the train.
A new train departs every 20 milliseconds. Any passengers who are ready, board the train. If the train is full, then they wait to the next train. If the train is not full, the train's going to go anyway. And so in terms of what that means for queuing latency, it means that the worst case is that a request arrives just after the train departed. It has to wait for the next train, so that's up to 20 milliseconds, and then it has to wait for that train to complete. And so the worst case latency is 40 milliseconds. Sure. How is a train in milliseconds derived? I mean, rule of thumb, but where it comes from is not fully explained yet, but so far we've focused on memory bandwidth and compute time when we look at memory the other consideration is that we want to use all of the memory capacity we have and so generally we're going to use all of that memory capacity to or the weights, or the KVs, and so we just want to read, like in the time of doing a forward pass, maybe we want to read all of the memory capacity into the chip, and so that is capacity divided by bandwidth. That tends to be 20 milliseconds on many different generations of HPM.
The units make sense. You would have a byte divided by bytes per second. Yeah, so for example, I mean, on I think the Rubin generation, it is something like 288 gigabytes divided by 20 terabytes per second. And this looks like it comes out to about 15 milliseconds. Let me just make sure I understand what it's saying. I mean, I understand why the units can't do the sort of unit analysis. But what it's saying is we can evacuate and replace the HBM in this amount of time and so we don't want to meet a situation where the HBM is not big enough that we're not actually able to write everything we want to it or take everything out of it or we don't want to meet a situation where our ability to write back and forth is so big or so small compared Yeah, there's sort of two scenarios. Why don't we pick a latency that is bigger than 15 milliseconds and if I think what that means, it means I actually have time to read the HBM like twice.
By the way, most of HBM access is reads, not writes. It's like almost all reads because the weight matrices are read only and then almost all of the KV cache accesses are reads. So in like, let's say around 30 milliseconds, I can read all of HBM twice, but what's the point of that? Like, I don't want to read the weight matrices twice. I don't want to read the KVs twice. Yeah, makes sense. Makes a ton of sense. Okay. So a couple of actually quick questions. One, if it is the case that the optimal batch size is something like 2,000, and that actually true, it's totally dependent on the sparsity.
It's not dependent on the model size or anything. I mean, sparsity shows up in model size. But beyond that, it only depends on sparsity, not on scale. But that's a very interesting result. And that seems to imply that you can... One question is, how much of a push towards centralization is it that you would have these economies of scale from inference, from batching? Yeah. But it seems like it's not that big a deal. Like, I don't know, is 2,000 users at the same time a lot? It doesn't seem like a lot? We can do a bit of analysis on this, which would be actually, it's like, you can think of it in terms of number of users, but maybe a more productive way to think of it is in terms of number of tokens per second.
So what does this batch size mean in terms of tokens per second of the system? So tokens per second, tokens per second is going to be equal to the batch size. We run a batch, many tokens, and then we do that every T. ever. So every time in tools, which is, let's say, which is, which is, this thing is equal to the 15 milliseconds, 20 milliseconds number. So this ends up being batch size itself times about 60. So like 64 times B. And so this ends up being around around 2,000 times 64, so like 128k token-specific. So this is sort of in more digestible units, like it's hard to reason about concurrent users, but what is the global traffic for a system?
When you look at some of the announcements, sometimes the API providers will brag about how much traffic they have. the numbers that I've remembered from some announcements of Gemini last year were in the hundreds of millions of tokens per second worldwide. So about a thousandth of that range. But I mean, Gemini is big. So that's actually one thousandth of Gemini is a lot. To actually be competitive at scale, you need to be able to serve at least one thousandth of Gemini. That's interesting. Cool. Okay, so the more sparsity you have, the less compute you need. And it does seem that as batch sizes get bigger, compute ends up being the bottleneck, according to this analysis.
So then the question is, how far can you take sparsity? That is to say, as the sparsity ratio increases, as you have fewer and fewer active parameters relative to total parameters, how much is performance of the model degrading? And is it degrading faster than you're saving compute by increasing the sparsity factor? Yeah, so quality of the model, rather than speed of the model. Yeah. So unfortunately, we're not able to answer that analytically. That is an empirical question of model quality. Best I can do is pull up a paper and answer that empirically. Okay. Should we pull up the paper now? Yeah.
Yeah. So this paper, this is Unified Laws for Routed Language Models. It's a somewhat old paper by this stage, but one of the things that they did is looked at, if I keep increasing sparsity, what is the model quality impact? This answer is very sensitive to the actual choice of mixture of experts. Mixture of experts has been around for a really long time. I think it was even back in 2017. But the techniques have changed a lot. DeepSeq mixture of experts was a big change in how it worked. There have been older papers which are G-shared switch transformer. So the actual empirical results are going to depend on all of that.
But on one of the older techniques that is shown here, you can see if I hold constant the number of active parameters at a certain size and then I increase the sparsity, which they call expert count here, the quality keeps increasing. And then if you imagine like drawing a horizontal line from 1.3b dense across, you end up seeing that, for example, in this case, the 64 expert 370 million activated parameters model is as good as a dense 1.3 billion model. So in some sense, it's actually not amazing returns where you need to increase total parameters 100-fold to get the equivalent of 10x as many active parameters.
Yeah, I mean, actually, even more so. Yeah, it's a huge increase in parameter count for a modest increase in... Yeah, so in this case, actually, it's, what is it, 4x? 64x for 4x. Yeah, so while it is true, I guess, that you get this benefit of being able to economize on your compute time if you increase sparsity, naively it would seem like, oh, that's a trade-off worth making. But if you're decreasing this by 2x and then having this go up by 8x, every time you double... sparsity. So is that good or bad, actually? Even from a memory point of view, keep in mind, you are doubling this portion of the memory fetches, which is amortized by batch. And so just keep running a larger batch size. From the point of view of the analysis we've done here, this is pure win. Keep doing it. Keep doing it until you run out of available users, basically.
So there's actually this equivalence between if I want to go sparse or if I have a lot of users, I can go to a much sparser model. So from that point of view, it's a reasonable tradeoff. The other tradeoff that shows up here is that it also consumes memory capacity, which we've only reasoned about memory bound with it, but it also consumes memory capacity. So let me just make you understood. You're saying we want to spend less time computing. Therefore, we do more sparsity. To make that work, we need bigger batch sizes, which means we need more memory capacity to have more sparsity. Yeah, so maybe this would be a good point.
to actually talk about how a mixture of experts layer is typically laid out on a rack of GPUs or something. Yeah, yeah, makes sense. Yeah, where were we? Sparse mixture of experts. Yes. Maybe how we lay that out on a GPU. Yep. So let's zoom in on the mixture of experts layer first and sort of draw what that looks like. So we typically will have some kind of a router layer, which is making the decision of where we route the experts, the tokens to. So we have tokens coming in here. They go through a router layer, and then we have a bunch of different experts. I'll draw a few more to line some up.
And then the router will make a decision, which experts am I going to route to? And it'll be a small fraction of them, maybe one in 32. So maybe it'll make a decision to route to this one. maybe this one, and maybe this one. These experts, so each expert itself is a normal MLP. It has an up projection and then a down projection and a non-linearity in between. And then finally, we sort of do the inverse operation. So where we were broadcasting things out here, we're going to bring them back in and sum them up. So bringing them in like this. And then finally, we have our residual connections that the token is also passed through here and it gets added to the result of the MOE layer.
So this is a normal MOE layer.
“one rack actually bounds the size of an expert layer you can do.”
Sorry, is this, is that question you just asked basically, why isn't it a bigger scalar? Yeah, exactly. Why not just have a million chips and scale up? What has changed that has allowed NVIDIA to go from Hopper was 8, then Blackwell is 72, and now Rubin will be, is it 500 or something? Yeah, 500 or something, yeah. What has allowed that to happen? From Hopper to Blackwell is mostly just the decision to switch from trays as the form factor, one of these as a trait, just switching to racks as the form factor. That's a product decision.
There wasn't a substantial technical barrier there. Switching from the 64 to 500 or so, there's a bit of jense and math there, but there is at least a genuine 4x increase, which is coming from a much more complicated and difficult rack design. So that is actually like new physical design to run more cables. And the cable complication is just the cost of figuring out which cable hops to which, or like which signal from what to what. Let's sort of zoom in on this and look at the wire density. I'll draw this diagram just once more so we have a bit of a cleaner version to work with. I'm in a larger version.
Let's say I have some switches in the middle. Yep. And let's say I'm going to have, initially I'm going to start with just two GPUs on each side or two trays of GPUs on each side. And let's say maybe each tray wants to have two cables coming out of it. So I get some kind of, I physically run vertical cables that look like this running to the switches. Now, if I want to double the number of GPUs in a rack, I need to run like literally twice the density of cables. So, I need to run these as well. It's really not a question, but if you look at a physical data center, it seems like there's a lot of space within a rack.
I don't know, just like the cables are really big. Yeah, so there is space outside the rack. Inside the rack, these racks are, I mean, as they become more optimized, these racks are very tight. So there's connector density going from the tray into the rack and the rack's backplane. And then the backplane itself has a really high density. There are other physical constraints, including like bend radius of cables. You don't want to snap them and so on. It's literally the physical space to put a cable that's constraining it. I had no idea. Interesting. That seems surprising. that like the rack is so big and they're just like we can't just stuff more cables in there yeah so i mean rack design is not my expertise but like when i talk to folks and what are the constraints they're up against it's it's a combination of um uh so what are the big physical things you're optimizing for um space uh weight of the rack like it's actually really heavy and so like you need enough metal to not sag and fall but then Add more metal and it's heavier, and then power and cooling.
And so all of those are competing for, like, modern racks are pushing all of those to very extreme physical limits. Deep work is by its nature quite aversive, so even things which seem like work, like Slack and email, can be easy ways to distract yourself. So I often wish that I could just turn the internet off. But if I'm prepping for an interview, even if I have the papers and books on hand, it's still super useful to be able to do a back and forth in the LLM so I can break down concepts and research follow-ups. Google's new Gemma 4 is the first open model that allows me to have this kind of fully disconnected focus machine.
It's small enough to run on my laptop, but good enough to actually be useful. So to prep for this episode, I downloaded Reiner's scaling book and shut off the internet. I was able to have Gemma help me understand the material and answer my questions. If you want an LLM that you can run locally on your laptop or even your phone, you should check out Gemma 4. When was GPT-4 released again? It was 2022 or 2023? Three, three, yeah. and it was rumored to be over one trillion parameters and it seems like only now and within the last six months have models been getting released that are significantly more parameters than a model released three years ago yeah when supposedly there should have been this um uh scaling in the meantime is the reason that we were just waiting for racks with enough memory to hold a five trillion parameter model along with its kv cash for enough you know users for powerful for a lot of sequences, or if you're doing RL, kind of a similar consideration of actually holding the KVCache for all the batch of problems you're trying to solve.
So if you look at like Hopper, you had eight Hoppers, and I think that's 640 gigabytes as of 2022. With Blackwell finally, which was deployed, what, 2020? Very recently. Maybe last year. Last year? Yeah. You finally have a scale-up with on the order of like 10, 20 terabytes, which is enough for like a 5T model plus KB cache. Yeah. Deploying in larger scale-up domains is a huge unlock. Yeah. I mean, I've drawn here the sort of NVIDIA Blackwell deployment. The Google deployment has actually had very large scale-up domains for a long time. And that also explains why Gemini seemed to be ahead. Like was Gemini 2.5 was a successful, or it just seems like Gemini has that successful pre-train.
longer than some of the other labs not having been there at the time i'm not sure how much is coming from like successfully deploying higher sparsity ratios which which could be um it could also be i mean there's a whole bunch of actual modeling things of like uh specifically how do you do the mixture of experts uh i've seen the um deep seek uh like the deep seek mixture of expert has said actually activate more experts but fine-grained experts was a big innovation I'm sure that there are many other innovations on the model architecture as well as on the training data. It's kind of hard to disentangle all of them.
But what shows up in terms of the limits of what you can do, the active parameters, as we saw, is limited by the compute cost, and then the total parameters are limited by the scale-up size. Yep. When you're operating within a single scale-up domain, is that a consideration specifically for either forward or backward or specifically for pre-fill versus decode or is it is it preferred to always be within a scale up whatever kind of workload you have whether you're doing a pre-training run or whether you're doing rl generation or whether you're doing inference for users yeah really interesting um so So, okay, so to answer that question, we're going to need to talk about the communication patterns that, so we've talked about the mixture of expert communication pattern, that is this all-to-all, this all-to-all.
All-to-all. All-to-all very strongly favors full connectivity, which is what we've kind of just shown here, and favors being within one rack. There are other kinds of parallelism besides expert parallelism, which we just showed here. In the literature is tensor parallelism. This is, with the trend towards smaller experts, this has become much less relevant, so we can ignore that. But the other two things that we have available are data parallelism and pipeline parallelism. And they are actually much, they can be a much better fit for using multiple racks. So let's focus on pipeline parallelism specifically.
This is one layer of MOE. I'm going to have like 100 more layers above. I could decide at this point, for example, to move to a different rack, change rack. now is that going to become a communication bottleneck so we can actually just solve for when this becomes a communication bottleneck but before we do that algebraically like let's just sort of visualize it out and sketch the path so we're going to have a bunch this is another moe layer and we're going to have another moe layer here and so on um uh so let's say i change right here and then some number of layers later i change right here as well um so our our our methodology that we're going to use to determine whether we have a communication bottleneck in this like in this point where we change rack um is we're going to compare the this this is the scale out um scale out um bandwidth requirements to the scale up bandwidth requirements so let's try this and I mean the hint is going to be that there's a lot more transcends here like we're sending many things here whereas we're only sending one thing here and then we're also maybe doing it many times so that's going to be what makes the difference can I try to guess just out of curiosity
to see if I'm actually understanding it seems like you're sending like batch size into the rack in here yes but the communication within a rack is sort of batch size times number of gpus yeah so number of activated gpus right so like i i don't send to this gpu at all right so there's an explosion from one to like it's three times larger here in this diagram yeah um the key thing is that i didn't even need to send to this gpu at all and so that's a big saving i see yeah okay so we're going to talk through sort of how much more, what is the slowdown of, to what extent is scale-up a bottleneck over scale-out? So we will directly jump to the ratio of the time spent on scale-up, time on scale-up over the time spent on scale-out. This is the quantity we're talking about.
And the first consideration is that the scale up is eight times faster than scale out generally. And so, at a baseline, if the bandwidths were the same, we would have this one over eight, which is coming from bandwidths, but then we have some amount of expansion in how much data we're sending. so if one token comes in here then this one token gets routed to in the deep sea case it'll get routed to maybe 32 experts or 16 experts gets routed to some number of experts so this is the number of activated experts Number of activated experts. Um, and then it also, this, the same thing applies on multiple different layers.
So maybe I'm going to run two layers. So, um, there's also multiple times, um, number of layers, uh, per stage. And there's just need to multiply the whole thing by 2 for the for the up and down. Yes, yes. And there's a factor of 2. Thank you. So what we would like is the for the scale up time to be greater than the scale out time because like the scale up time is the more important and precious resource. And so we just we want this one. We would like this number to be greater than or equal to 1. And this really doesn't seem hard. Like there's just a factor of 8 that we need to overcome. So we need the product of these three things to be bigger than eight.
Typically, we have a fairly large number of activated experts. It could be eight by itself. And then we can increase the number of layers per stage a lot until we satisfy this. So what this ends up looking like is that I can, in fact, have an entire pipeline of racks where one rack does one layer, and then I move on to the next rack, and I do another layer, and then I move on to the next rack, I can do another layer. It's interesting to me that the best parallelism strategy in practice ends up being one which physically resembles the actual architecture. It's not some galaxy brain thing. It's like, oh, we have experts, we're going to put them on different GPUs.
Oh, we have different layers, we're going to put them on different racks. I feel that's interesting that the physical and... The model architecture matches, the cutting matches the model architecture. Yeah, exactly. I mean, it could have been something wackier with tensor parallelism and whatever. Yeah. So, I mean, I think a way to think of it is, I mean, okay, the galaxy brain way to think of it is, like, what are all the different dimensions in which a model is scaled up? And so there is, it is scaled up by layers, it is scaled up by the, like, demodeled dimension, it is scaled up by the DFF dimension, it is scaled up by the number of experts. Every single one of those numbers you can choose to cut along. And if those numbers are big enough, it eventually becomes profitable to cut along there. And we have selected two of them. The other two, in the way models are typically sized, are not profitable. So there's a talk by Ilya where he says, today we know not to do pipeline parallelism. And Horace gave my friends and me, I hate that it sounds like a Dr. Seuss quote, but he gave us a lecture on these different kinds of parallelisms and you said the problem pipeline parallelism is that it other than the bubbles
it constrains it creates these architectural constraints yes on um like kimmy for example has these uh residuals where attention attends to the a fewer back or something yeah layers a few back and so that it becomes hard to implement in this way yeah um so and i guess we didn't really fully articulate even what is the benefit that we're getting from pipelining yeah um uh And so, these complexities are real. Pipelining is a massive hassle, but it does give you some benefits. And then you can then decide whether those benefits are worth the costs. The biggest benefit that shows up, so it has some benefits in inference, maybe bigger benefits in training.
In inference, what are we saving on? Are we saving on memory time or compute time? Not really. we're just moving the memory time from one chip to another chip, or one rack to a different rack. There's no actual benefit in runtime. However, what we are saving on is that the memory capacity is the amount of memory used per rack. If we think that the memory in a rack as a bottleneck. then there's a constraint on how sparse we can go. Pipelining allows us to massively reduce that bottleneck. I guess the opposite connotation to this, which actually, before this interview I was chatting with Axel, who's a GPU performance engineer at Jane Street, he was explaining, well, to do pipelining, you have to do micro-batches rather than full-batches.
And if you do micro-batches, then you're by definition not able to amortize the weight loading the weights that's right across all the users or all the sequences and so the positive connotation of that is you don't have to use this memory the negative connotation is that of that is that we can't amortize loading the weights across all those users maybe it's worth explaining why you had to do micro batches because you can't so we draw the pipeline bubble um yeah okay so so why do we do um uh what what What is this micro-batching that shows up in pipeline parallelism? So I'll focus on inference first, it's a slightly simpler problem.
And I'm going to draw, so this is time, and then this is which rack we're on. And so the idea is that maybe I'll have like four racks, so I've got an inference that going to step through these four racks in some time like this. So this is inference number zero. It runs at a certain batch size and it steps through all the pipeline stages like this. Now, if we were to say, well, we're going to run inference number one here, like this is clearly like a massive waste, right? Like three quarters of the time, each of the racks is doing nothing. So we don't actually run inference one here. we run it as soon as we can, which is immediately after inference zero finishes like this.
And then we keep going. So if we hadn't filled this in, we would call this the pipeline bubble. When I've drawn it in this inference context, where we're only going in a forwards pass, it's like obvious, like, why would you do this stupid thing? But in a training context, it's maybe less obvious. But in the inference context, it's sort of really natural to make this change oh interesting so this sort of obvious but um the difference between micro batch and batch doesn't matter at all in inference because you can just call whatever you want whatever yeah it only matters in training because there is an optimal batch size yes and before you do the backward step you want to have accumulated before you do a full backward step you want to accumulated all the sequences in that batch and if you want to do pipeline and training in order to avoid that bubble you need to should we draw the the training diagram yeah let's do that um so so this is the inference diagram and i'll call this four or so we don't have the wrong thing showing up there um so let's do the same thing for training now we've got a forwards pass but at some stage we're going to have to transition to a backwards pass so we'll we'll do some number
of batches in the forwards pass, and then we're going to transition to the backwards pass for everyone all in one go. So the inference part is the same here, but then we do a hard stop at this point and then transition everyone to backwards pass similar numbering like this it may be worth clarifying the reason there is that hard stop is because you want to do a whole batch at once for the backwards step and then there is an optimal size for how big that batch should be yeah i mean smaller is always better actually is is a way to put it but uh it's like from a ml convergence rate perspective, smaller is always better because basically you're getting the freshest information from the gradient descent. But total trading time perspective.
Total trading time perspective, it's like smaller is worse from a systems perspective. And so the optimum is the trade-off between these two. So you pick a batch size and then for that batch size, you do some amount forwards and then some amount backwards. You asked why is there even a hard stop there pipeline parallelism because of this the like the fact that you've got this idle time here which is the the bubble um there are so many techniques in the literature for how to um lay this out differently and and avoid that there are more complicated schemes called like zero bubble or one forward one backward which sort of interleave the forwards and the backwards in complicated ways but you can mine bitcoin yeah right right more usefully you can do the It's a weight gradient step, but you can also weight it.
Yeah. So in inference, actually, the effect of pipelining on anything you care about, like batch size or latency, actually is neutral. It doesn't improve it. It doesn't make it worse. So if you look at the latency of this inference running it if it were pipelined versus if it were all on one rack, if it were all on one rack, we would just slide all of the boxes down and still put them in a row, and the latency would be the same. So pipelining is neither better nor worse for latency, but it does mean that you just use less memory per rack, like memory capacity, because now instead of needing the whole model, you only need a quarter of the model.
It makes a ton of sense. So basically, no brainer to use pipelining during inference, but there's this harder trade-off during training. So even in inference, in fact, it is not used a ton. It reduces your memory capacity requirements, There's actually a huge surplus. Like, I think you're saying that a rack of Blackwell has many, many terabytes, maybe tens of terabytes. That's much bigger than, like, a trillion parameter model. A trillion parameter model only needs one terabyte. And so it already fits, in fact. And so there's not a huge benefit from pipelining because you're reducing a number that's already pretty small.
But it does say that theoretically maybe you had too much memory and maybe you could have done a different, like built a different hardware that has less memory, in fact. If you were designing your hardware and you said, I actually didn't need that much memory because I don't need the weights to fit in one rack. I can fit the weights in eight racks. Then I could have maybe built a hardware that didn't have so much HPM per GPU. Last week, Horace was kind enough to give me and my friends a great lecture on large-scale pre-training systems. And there were some concepts that I wanted to animate for a write-up on my blog, like how weight shard and gradients flow depending on the parallelism that you're using. So I gave Cursor my lecture notes and a sketch that I made during the lecture, and I asked it to visualize a specific hierarchical collective that Horace had explained.
The first version was already pretty good, and then I was able to use design mode to select and tweak any specific components from there. I was able to do all of this without a clear end state in mind. Cursor's Composer2Fast model was quick enough that I was able to iterate almost instantaneously. I could try an idea, test the results in the built-in browser, and immediately make any changes. I went through 10 different versions in under 20 minutes. If you want to check out this animation, I published it along with the lecture notes in a blog post. The link is in the description. And if you want to try out this kind of iterative design flow for yourself, go to cursor.com slash lower cash to get started. So macro question, everybody's talking about the memory wall right now. Memory's getting super expensive. There's not enough memory. Smartphone volume will go down 30 because there's not enough memory hyperscalers are spending this is shocking if i'm dylan said they're spending 50 of their capex this year on memory on memory that's believable yeah so but it's so like What is hyperscaler capex?
It's like high hundreds of billions, maybe a trillion. And they're spending half of that on memory. Okay, so that is this huge constraint. That's why we're not going to get new laptops and phones this year. But at the same time, we have too much memory. Like people are willing to put too much memory into these systems. Right. So this is... Like why is JetSense shoving all this memory into these racks if you don't need it? Yeah, so in the equations we had here before we raised them, we were doing memory time, so memory bandwidth and compute bandwidth. but let's now start looking at memory capacity.
Yeah. So we'll start off with just like memory capacity without even thinking about parallelism scheme. And so the capacity of memory or the demand on memory is the number of total parameters plus, so this is what we need to fit the weights in some system that we are using. and then we need to fit the kVs as well. So kVs go as batch size times the length of the context times the bytes per check. Okay, so what I was arguing about in this context and the case I was making for pipelining is that we will actually, there are some techniques that allow us to solve this. are there techniques that allow us to solve this?
So let's consider, so we're going to run this on some number of GPUs, and we're going to say we're going to have one extent, which is E is going to be the expert parallelism. So how many, when we had this charting of expert layer across many GPUs, how much of that, to what extent do we do that? How many GPUs? So we're going to say that this is fact, for example, 64. And then P is going to be the extent of pipeline, pipelining. And so this is the number of racks, which who knows, maybe we'll pick four or something like that. What we want to calculate, so this is like the total memory requirement across the system.
But now I'm going to calculate a memory requirement per GPU. So per GPU memory requirement, we're going to have, I guess I'll use a lower case C mem. And well, obviously we just take all of these numbers and divide it by ENP, really easy. So it's this n total plus the batch times length of context times bytes per toque. All of this is divided by E and speed. Okay, so this is like, why is this correct divided this way? Well, we're saying, we knew that the parameters were perfectly divided amongst all the GPUs in a rack. The layers are perfectly divided amongst the different racks. So that works here.
And somehow we're going to arrange, I'll hand wave exactly how, Somehow we can arrange the same perfect sharding of the contexts across GPUs and a rack and then based on layer across racks. And sorry, four is the number of racks. Yeah, for example. So this is the place where we actually need to go back and analyze this batch size B. And you were making this comment that there's micro-batching versus global batching. So let's come back to this pipelining diagram here. We've got one batch going forward here. And then as I drew it, it kind of just like disappeared. That's not really correct. If you think about how decode is working, I have a bunch of tokens that I have.
generated already i do one forwards pass where i generate a new token and then and then i push like then i write that to my kb cache and then i do another forwards pass that generates the next token so i'm actually going to be running this batch zero in a loop so in fact i go forwards once i finish i can start the next iteration of the loop up here yeah so we'll just fill this in we'll have the Oh, uh, yeah, so we've got the two or three, uh, two or three, uh, so let's split this batch. This batch will be the global batch size, so B is going to be the, um, number of, number of micro-batches times the batch of, like, the batch size per micro-batch.
So how many micro-batches do we need? So the number of micro-batches in this diagram is 4, 0, 1, 2, 3. And then the batch size per, like, the micro-batch size, this is still this, like, 2,000-ish number. This is the one that is like, this is the like 2000 times sparsity. Sorry, no, this is the 300 times sparsity. 300 times sparsity. This is how big the train that takes up every 20 milliseconds is. Right, yes. This is going to be the 20 milliseconds train. So the global batch size is the number of micro-batches times the local batch size. Local batch size is set by this hardware parameter. The number of micro-batches Well, the number of microbrashes is as small as possible such that we can wrap around and not leave any idle time when we wrap around.
So if we had fewer, we would have this idle time when we wrap around. And so you can sort of just visually see that it is equal to the number of pipeline stages. I mean, proof by visual here, it is four and it's four this way as well. But you can sort of look and see that it goes along here and then it wraps around number of pipeline stages. yeah and sorry a very basic question this is what is actually done okay like as in a frontier model today we'll actually have during inference have pipeline uh for sure during massive scale training this is done um it can be done for inference i'm actually going to make the case for why it is less attractive it is useful for weights but not so useful for kb's yeah yeah um the big challenge is so let's let's fill this in the micro batch size here ends up being equal to the number of pipeline stages yep when we go back and substitute that's that's all of that into here we get a um number of pipeline stages times um this little b showing up in here.
And then when we factor this out, I'm going to split this plus into two terms. We get the full division by E times P over here. We still have division by E times P over here, but the P's cancel, this P and this P. They cancel. And so what we find, if you increase the number of pipeline stages, the memory footprint for the number of weights keeps going down and down and down, but the memory footprint for the number of activations stays constant. So it doesn't actually work. Like, most of your memory ends up, like, once you do enough pipelining, and it's really not much, like, even two is often enough, this term becomes very small.
This becomes the dominant term. The KB cache becomes the dominant term. Yeah. I know this is wrong. I'm just trying to think out why my train of logic here is wrong. If you have many different, you're pipelining through many different stages. The KV values are not shared between layers. So why would it not help to be pipelining across multiple layers? Because then you don't have to store. Yeah, you only need to store like one layer rather than two layers of KVs, right? Yeah. So it helps from that perspective. You're right. um what's competing with that though is that you need to be keeping all of the racks usefully busy at a time and so the number of sequences that are in flight simultaneously has gone ah yeah yeah it makes sense makes sense makes sense so those exactly cancel and and you end up not getting a saving per gp right this is going back fundamentally the point of you're you're not able to amortize across kv caches well so first we did you can't amortize kv caches across batch size And now we're saying you also can't shard it across pipeline stages.
It sucks from both of those points. Yeah, yeah, yeah. Interesting. Okay, so then what is that during inference? So, I mean, like, DeepSeq paper reports what they do, which is, like, they just do a lot of expert parallelism. You should, in effect, you should increase your expert parallelism up to your scale-up domain size, and then do very little pipelining. Maybe none at all, maybe two, just enough to make the weight storage not too big of an issue. Those are the only two parallelisms that really make sense. In the past, there was tensor parallelism, which was cutting up within an expert, but the experts are so small now that that is not a profitable optimization.
So this goes back to the question, does that mean that frontier labs, when they're doing inference, are just basically within a single scale up? Yes. Yeah, I mean, you can look at how it depends on model size, um, like you could have a very large model, like, um, like one that exceeds the memory of a rack, um, and, and there you should be doing a bit of pipelining. Um, maybe, maybe it's extremely sparse, for example, and that would be a reason to do it. Um, so I guess this goes back to the question about, uh, or this goes back to the promise at the beginning of the lecture, which was, this will actually tell you about AI progress as well. Um, to the extent it is the case that model size scaling has been slow until recently because let me make sure I understand the claim the claim would not be you could have trained across more more racks it was just that it would not have made sense before like we didn't have the ability to do inference for a bigger model easily actually I mean so pipelining doesn't help with context length it totally helps with model size.
And so because of the ability to do pipelining, at least a rack should not be a constraint on your ability to fit the model parameters. I guess the other consideration you're asking, like, why hasn't it scaled up more and why did bigger scale-up domains help? So we talked through one aspect of that, which is we kind of said it's not because of memory capacity. We have a solution to the memory capacity, at least with respect to model size, not with respect to KV cache size, but at least with respect to model size, we have a solution to memory capacity. The other issue that shows up is latency. I was just about to ask, so what is the, going from rack to rack, what is the latency cost per hop?
This is very much dependent on the hardware. It's, I would, I can't say with a lot of authority. I think it's probably on the order of a few milliseconds, but it could be off by an order of a few seconds there. Is four a realistic number of how many pipelining stages you might have? Yeah, yeah. Okay, so that's not that much. On a small number of pipelining stages, this is not a huge latency impact. I mean, I guess it's 10 milliseconds per token. That's right. Two times four-ish. I don't know how many you said, but... Yeah, yeah. 10 milliseconds per token is actually a lot. Yeah, if it goes from 20 to 30, right?
Or something like that, yeah. This is... So Like, just to chart the path that it goes through, here you're going from your GPU or TPU or whatever to a network card, which then goes to, like, a top-of-rack switch and then hops over to the other rack and does the same thing in reverse. So you sort of have to sum up the latencies of these different things. Sorry, this is the same thing as the DC switch? Yeah, it may, in fact, go up to a data switch and back. Depends on deployment configuration. Got it, yeah. And because it's decoded in sequential, it's also not the, like, they stack up across the stages.
Yes, they do. You can't do them at the same time. That's right, yeah. Okay, so I guess this brings us back to the question then. Is the size of the scale-up at all relevant to why AI model sizes or whatever have been what they have been over the last few years, whether through training or through inference? Yeah, so, I mean, we talked about latency of the hop, of this hop. There is also just the same Tmem latency, the memory time latency is actually substantially, like massively improved by a larger scale of domains. So I'll recall Tmem down here. Tmem for the weights, T mem of weights. This was equal to the number of total parameters divided by the memory bandwidth.
Which memory bandwidth are we talking about here? Is it just one GPU? Or it's in fact it is the number of GPUs that I can use in parallel to load these weights. So I can't use different pipeline stages in parallel because they're not running at the same time but I can use all the GPUs in my scale up domain in parallel to load the weights and so this is actually extremely effective so basically I end up with a term here, this memory bandwidth term itself is equal to like scale up size times memory bandwidth per GPU yeah, times GPU bandwidth bandwidth. And so this term doesn't increase a lot. It maybe increases 1.5 or 2x per generation, but this one increased by like a factor of 8 from Hubbard. So the reason the bigger scale of matter is not the memory capacity of the whole scale up, but really the memory bandwidth.
Yeah. Pipelining totally solves the capacity problem, but scale up size helps solve the bandwidth problem. And the bandwidth problem helps you do longer context lengths, which is more and relevant as these models get more energetic. Yeah. It lets you just run the model at lower latency as a first thing. If I just do a very sparse model and it's on like a little like H100 box, the latency will be really high. Yeah. Okay. A super tangential question. There's chinchilla scaling, which tells you how big should a model be relative to the amount of data you're going to train it on. But now, obviously, you're not just trying to optimize for the highest quality model you can get with training compute, you want the best results a user can get with a mixture of training and inference compute.
So then there's a question of how much should you over-train a model such that that compute amortized over training and inference is minimized to get a certain performance. But now with RL inference, or RL, there's another consideration, which is you're going to do some on a pre-training. That pre-training will be used both for RL generation and then for inference for the final user. And by overtraining here, I mean, while it would have been more efficient just from a training computer perspective to have a bigger model that you train for less time because it can learn faster, maybe you get a smaller model, you spend more computer training.
than you otherwise would have, but now it's cheaper to give it to users. Basically, okay, maybe, but let me give a question more concrete. How much more than chinchilla optimal are models overtrained? Yeah. And has that changed as a result of RO generation? This is a place where we have to do a bit of guesswork because like the updated scaling laws and the model traffics are not reported. And so we have to guess there. But one way to look at it, um let me first just make a sort of a general heuristic claim if i am if i have some like cost and i've got a total cost which is a sum of like cost a and cost b like maybe this is the training cost and this is the inference cost yeah um and so i want to minimize this sum for many uh for many curves that tend up being the case the minimum tends to be where these are where the costs are equalized um that's something of a heuristic claim but uh you can you can it tends like there are many examples where it's true like uh where one is one over x and the other one is is x for example um they tend to be uh minimized at at the point where uh they equal each other um it's also true for like um e to the x and like e to the minus x and all kinds of other things um uh like
So basically, I've got some curve that's going down, some other curve that's going up, and they tend to be minimized at this equal point. Heuristically, I will conjecture that that is true for the setup you described as well. Actually, showing that that would be true would require looking at the scaling laws and fitting these weird exponents, but things that do follow power laws tend to have this property. So I'll just make that claim and move on. So we're going to say that the cost of training plus the cost of inference, we want to equalize these. We'll do pre-training only first because it's a little...
Well, actually, we can do all of it in general. So actually, we'll cost it as cost of pre-training. So, number of active params times the data on pre-training. So that's the cost of pre-training. There's a factor of six out here, which is the number of flops. There's the famous 6ND formula. And then in RL, we have approximately the same thing. We've got the same number of active parameters, but now the amount of data is the RL data. there's this extra like efficiency multiplier, which is, or inefficiency, like the inefficiency. Which is the fact that you're not training on all your rollouts. Well, yeah, there's that.
And then the other, perhaps even bigger inefficiency is that this involves a substantial amount of decode and often decode runs at less MFU than training. Okay, so if you're doing a backward pass on every single generation in RL, it would be 6 and D. Yeah, so this could be a smaller number, right? Like this could be somewhere, so... It would at least be 2. Yeah, somewhere in the range of 2 to 6. So we'll just like, we'll say somewhere in the range of 2 to 6 and leave it at that. Yeah. And then we can add in the inference cost. The inference cost is 2, number of active times the data in inference.
I think the way I said it was super garbled, just for the audience, maybe. Forward plus backwards per parameter is six. Forward alone is two. That's why RL, where you might, you're definitely going to generate all the trajectories, but you might or might not train all the trajectories is two to six. Yes. Yeah. Thank you. And then inference is just two. Yeah. We're going to solve for essentially maybe a quality of all three of these terms. That is ballpark where people are going to be. Like labs have more information on what is productive in doing more RL, for example, than versus doing more pre-training.
I don't have that information. But I think a good ballpark is 30, 30, like 33% split between each of them. Actually, I'm not sure I understand the intuition for that.
“the number of inference tokens should be about the same as the number of pre-training tokens”
to the extent this is in the right ballpark, just by thinking about, okay, you kind of want everything to be equal in terms of compute.
Here's, if that OpenAI also realizes that and they're serving a certain amount of tokens per second, that tells you how much data went into the pre-training of GPT-5. Even if it's like 50% off or something, that is sort of wild that you can sort of first principles for these kinds of numbers. There's also, I mean, this is why you should just like approximate everywhere because like there's so big error bars on this, but yeah, it's kind of like empowering to just like set A equal to B and figure it out. Yeah, yeah. That's super cool. Okay, so in the spirit of trying to deduce things, we can publicly look up the prices of the APIs of these models.
And maybe you can learn something from that. So first, with a longer context, Gemini 3.1 is 50% more expensive if you go over 200K tokens than if you're below 200K tokens. I mean
“we can solve for the number of bytes per token if we sort of make some assumptions about the number of active parameters”
because otherwise someone could scoop you. Maybe we can learn something about the difference in input versus output prices. Yeah. And what that tells us about decode versus pre-fill in these models. And I think, last day I checked, it's like 50% more expensive or something like that? I don't remember. What I've seen in the past is like three or five times more expensive. Oh, yeah, that makes more sense.
So let's say it's five times more expensive. Okay. this is the compute to process the next token in decode suppose you're doing prefill where you're not just processing the most recent token you're processing all the tokens in parallel so i want to say that it would be this times len um len prefill or the pass in general yeah if we say like if we can think of decode as being a pass with one and then prefill being a pass with many Okay, yeah, yeah. So maybe like prefix, whatever. Okay, memory. So you're not storing the KV cache if you're for the tokens that are the pre-fill tokens. I think maybe, maybe sort of let's draw actually how pre-fill shows up here.
If I may clarify. So we do a bit of decode like this. We may actually come back and do more pre-fill. Like if you think this is a chat session, The user says something, the AI generates response, and then the user says something else, and we pre-fill this. So maybe this is the more common, like this is the general case rather than this. In fact, this is like you read a file or something. Read a file or just like the AI is responding to a user input or a tool call or anything that's not AI generated. Yeah, okay. Okay, so suppose we're here. So you will need to load. basically you will have calculated all of this previously so just the kv of everything that came before but what is the memory cost of this well memory bandwidth cost of this if you're doing flash attention it's basically temporary it doesn't even go to my memory just ignore it Okay, so then it would just be everything that came before.
So, is it not just that then? Yeah, there's actually no adjustment at all to the minimum time. Okay, great. Oh, so it's a very trivial change to accommodate. So, this term is... making it 5x more expensive. Now, why would that be? Or what does that tell us about... What are we trying to learn here? What does that actually tell us? What variable does it help us clamp? Well, the compute has presumably gotten 5... Like, the only thing that could have changed is the compute is 5x more expensive as a result. So, yeah, there's the time for one pass, but actually the amount of tokens is that much larger.
So I guess we want the cost per token, in fact, or the time per token. Sorry, I'm not sure I understood. Good. The, this is, this is for processing the next token in prefix. Well, actually for processing the entire batch. So in this, like at this cost, we have processed this many tokens, like len, let it pre-fill. Yeah. Well, I guess pre, yeah, like the, of the paths, yeah, not, not this prefix, but it's this cost. Okay, let's see if it doesn't pass. So this is 5x more expensive. Input is 5x more expensive? No, output is more expensive. Output is 5x more expensive. So the result we want to work towards is that pre-fill is compute limited and decode is memory bandwidth limited.
Why don't we do this? Why don't we have, why don't we just chart it with, like, len pass on the x-axis? Yep, yeah. And a T on the y-axis. T, we want the cost per token, so it'll be T over some stuff. T over length of the pass. Mm-hmm. Yeah, that'll be right. Okay, so... okay it just made me confused about this length pass is the it seems like this should be higher when you're doing pre-fill pre-fill has a bigger length pass yeah right but then why is it why is it cost higher yeah yeah um so i mean we're gonna it's this division by length pass that That actually makes it all, so this is going to divide out, this is going to divide out, but then we're going to get, all of this is going to divide the length of pass and it's going to make the memory cost cheaper.
Okay, yeah, let me think about this then. Okay, so let's do one line for, basically we'll have four different lines. Let's do the, let's do pre-fill first. And so, actually let's do decode first. Oh, so actually, length of the pass, when it's one, that is decode. When it is bigger, that is pre-five. Okay, I see, I see, I see. That makes sense. Okay, getting back to it. So t compute, if you have, basically just this divided by length pass is just this amount. So this actually does not vary based on t, so it'll just be some flat value like this. And this is t compute. and then this is like this is that's decode decode right now tmem if you have this whole thing divided by the line pass well it doesn't really matter what's up there it'll just be something that looks like this right yeah let's say this is tmem this is decode again so as the length of the prefix goes up or pass your memory bandwidth time declines and that means that to the extent that you were bottlenecked on memory bandwidth before, you can avoid being bottlenecked on memory bandwidth.
The fact that they are charging 5x less for pre-fill than decode does suggest that they are bottlenecked on memory bandwidth to quite a degree, such that for them at least, because T is equivalent to cost, right? It's the cost of renting a compute. This is actually like, this would be at one and this would be at five. That's right. That's right. Yeah. So it is, in fact, tremendously memory-banded with bottleneck. The real graph looks something like that. Yeah, I mean, still it crosses, but... Yeah, exactly. Yeah, let me do it this way. Yeah, that's right. um and then the this is the gap on decode between the memory and the compute time yeah yeah interesting another interesting one would be why cache hits are so much cheaper yeah okay so i think if i remember correctly cache hits are like 10x it's more expensive to write to cache according to the pricing on all these models.
But if you do hit a cache, it's 10x cheaper. So what is going on with... Presumably, this is the cost of keeping something in HBM rather than just evacuating it. But if you do keep it in HBM, then it's cheaper to load again? Right. So there's two ways you can produce tokens or the KVCache for a token. You can just produce it from scratch by computing it from the underlying, like, token IDs, which are tiny. Or you can previously have produced it and stored it in a memory somewhere. So the cost ratio is really talking about the ratio between those two mechanisms of producing it. A cache miss means you've deleted it from all your memories and you have to recompute it from the tokens directly.
In fact, you can maybe even take that a step further and think about which memory tier do you store it in. So you could store it in HBM. There are other slower and cheaper memories than HBM, like DDR on your host or Flash as well. And so one of the things you can do is a calculation of where it makes sense to be in each memory tier. And this is related to how long you're going to store for. So we want to look at the cost of storage in a few different memory tiers and also the cost of rematerialization. So remat means the cost to rebuild all of the KB cache from scratch after you deleted it. So we rematerialize it.
And so basically, this is going to cost the length of the context. Actually, we'll look at cost per token so that we don't need to carry around this length of context everywhere. So to rematerialize one token of KVCache, I just need to run a forward pass on the whole model. And then, so this is going to be the compute time. I have to rerun the compute at whatever speed my GPU does it. And then I multiply it by my GPU dollars per second. I was very extremely naive question. Why is there not a quadratic term? Yeah, so there is a quadratic term. It shows up in the compute. As an approximation, I chose to remove it.
I'll just show you sort of quickly what that looks like. It's because, so you have the, if you look at the cost per token, or the number of flops per token, there There's the flops that are coming from doing the weight matrix multiplies as a function of context lengths. And then there is the number of multiplies that comes from doing the kvcache, which goes up linearly with the amount of stuff you attend to. The slope on this is so low that when you draw it like this, it's very well approximated by a flatline. So you start to notice the effect of the quadratic or the linear term up in the millions of tokens
“the primary thing that limits you to have really large contexts are memory bandwidth and memory capacity”
resynthesizing the kv cache? Computing it from scratch is based on my GPU time. I have to do a certain amount of multiplies in order to, of GPU time that I spend in order to produce it.
um storing hbm um this really goes as my um i think i had a number here which was the bytes per token um so i need to i need to have some number of bytes per token and then i need to store this in the uh hbm so it's going to use up some of my hbm capacity Uh, so a way to think of this is that like, if I have too many of these things sitting in my HBM, like if I fill up my HBM with just KV caches that I'm not using, I can't use that GPU. And so how do I price that? Maybe I say that the cost of it is proportional to the fraction of the HBM I'm using. So, so there's also times GPU dollars. Um, uh, um, and then let's just do one more memory tier and say something like, uh, DDR, um, store in DDR instead.
The same kind of thing, it goes up for flash and for ddr. I put these in the wrong columns, actually. I meant to make two columns. The distinction I want to make is that there is the cost to retrieve, and then there's a cost to store, cost to hold on. and so this is like this is a cost per second whereas this is like an instantaneous cost so rematerialization has a cost to retrieve and has zero cost to store it because we've deleted it this is the one that I put in the wrong location this is actually the cost just to hold on so I will rewrite it Okay, so we have, this is the, like, if we're just storing it in HBM, it has this sort of cost profile.
And then if we store in DDR, it's actually going to take some time. So it's, like, we get the same thing here, bytes per token over a DDR capacity. times DDR cost a second, but now this has a cost to retrieve that is higher than the HPM because we need to copy it into the HPM. And so this is a token over DDR bandwidth, and then this consumes some amount of the DDR as well. And every scale-up has DDR and Flash? There's really a deployment question, and so you can choose that. NVIDIA does deploy in this form. It has both. Why isn't the cost to retrieve HBM the memory bandwidth, or the bytes to write a memory bandwidth?
Yeah, I mean, it depends on what you define a retrieve to be. Here I'm defining retrieve to be move it into HBM so that you can start actually doing inference on it. And so, sort of by definition. Because if it's already in HBM, you can be doing compute while you're getting it from HBF to HBF? Yeah, for example. So these are three things, and I guess I ordered them wrong. In general, if you're balancing two costs and you've got different tiers in the memory hierarchy, you should expect as this cost goes up, this cost should go down. So you can kind of see where the zeros are, and I should have ordered them this one first, this one second, and this one third.
So if you're going to hold onto it for a very short amount of time, then all of this is multiplied by the hold time. This one is, and so is this one. And interestingly, they have different prices to write for, and you specify this in the API, for five minutes versus an hour. Yeah, right. Which suggests that the five minutes is HBM and the hour is DDR. I think that's a pretty good assumption. It could, if you look at the numbers, it might also turn out that it's one tier down and it's DDR versus flash. Yeah, okay, interesting. Price difference, I think, was... I'll look it up. Okay. So, the base...
Base input tokens is five per million tokens. Base, which means rebound. Yeah, that's five. This is five? Ooh, five dollars. To, like, retrieve, quote-unquote. And then the... To write to... Uh... presumably HBM, right for five minutes, is 6.25. So actually, we might actually be able to determine which memory tier it is by the durations, actually. The durations probably tells it to you, actually. Five minutes versus one hour. Yeah, exactly. I think this will probably end up being, it's going to be the drain time of the memory tier that you're in. And so what that means is, It's like, given that I know I'm going to be holding something for five minutes, I would like to pick a memory that I can read every five minutes.
Like, I can read the whole memory once per five minutes, ballpark. So that is the drain time of the memory. So if I take the storage capacity over storage bandwidths, I would like this to be equal to five minutes or something like that. And so actually we did this calculation for HBM. For HBM, we know that this number is 20 milliseconds. So HBM is much too short, like much too small. DDR could be about an order of magnitude or two off from this. And so this is probably in the order of like, actually I think it might even be in the seconds, like one to 10 seconds. And then this is really, I don't have these numbers memorized, But generally, as you go to slower tiers, flash is plausibly in the order of one minute.
And then like spinning disk, which is massively different, I think is on the order of one hour. So this might actually identify that the tiers are probably flash and spinning disk. Sorry, why is this the calculations and the storage cap divided by the bandwidth? So you've got a bunch of different memory tiers, like we've listed four of them. um uh the your choice like your choice of which memory tier is like you want to minimize the cost yeah um and so you are like what fraction of the device are you using you're using some fraction of the device for the holding onto it and then using some fraction of the device to retrieve it um and so let's say i'm using like 10 of the device um and i want to equalize those two fractions uh that's a sign that i've hit the right um the right thing so let's say i've got some runtime here like i'm going to hold on for all of this time um uh and then so this is the time hold uh and then there's going to be some amount of time here which is time retrieve uh and i want i mean basically to equalize the costs these two costs um i want the retrieval time to be equal to the hold time times the fraction of capacity.
Because this is the retrieval time. Yeah, I mean, this is how many other things I can hold simultaneously. Basically, just like, hey, you want to store things in there for so long such that the amount of time it's in there is kind of the time to get all your things in there and out. Yeah, basically. It makes sense, yeah. I think that probably indicates that this is the two tiers of Flash and spinning disk. I'm kind of shocked to see spinning disk being used at all because it's such an old technology. Yeah. I mean, it's also crazy that it's so slow that it takes an hour to load its full capacity into it and then...
It's a really unattractive technology, but it's useful. So we're sitting down because I want to ask you some questions that I guess don't need a blackboard. You have this extremely interesting blog post where you talk about how at a high level, the architecture of different cryptographic protocols looks a lot like neural networks. And there's this conversion evolution where they both need to jumble information across all their inputs for cryptographic protocols. It's to make sure that there's like each new input into a hash function will totally scramble what happens for neural networks. Of course, they need to consider how this piece of information changes what you should make of this other piece of information.
And that is an extremely interesting point. I guess at a high level, the difference in what they're trying to do, in some sense, they're trying to do the inverse thing. Right. Which is cryptographic protocols are trying to take information which has structure and make it look indistinguishable from randomness. And neural networks are trying to take things which look like random, protein sequences, DNA, garbled text, and extract higher level structure from it. So they have similar high level mechanisms, but they're actually kind of trying to do the opposite things. I wonder what you're making of that.
Yeah. So, I mean, like the mixing, like I try to look for other examples where mixing, like scrambling, mixing shows up as well. There's actually almost even like a physical example where like you're stirring something, you're making a cake and you want to stir the batter. And like literally the idea, like first stir it this way and then stir it this way is like actually not too bad of an approach. But beyond that, like, back to the digital world, there are some differences, and the one you call out is a pretty strong difference. The way it shows up, like, what makes neural nets, like, if you just randomly initialize a neural network, actually, maybe it's a reasonable cryptography, like, cipher as well, because, like, the random initialization is going to jumble stuff in a complicated way.
It may even, like, do what you want. Who knows? the thing that makes it interpretable is the gradient descent. So you can differentiate a neural network and get a meaningful derivative. And we do a lot of work to, like, not overcomplicate the derivative. So the residual connection keeps it, like, contained and simple. And so does, like, the layer norm stuff that we do. One of the biggest attacks against cryptographic ciphers is also to differentiate the cipher. ciphers run in a different number field they run in the field of two elements so just binary whereas neural nets run like in theory in the field of real numbers and so you have to differentiate with respect to like binary numbers but you can absolutely differentiate a cipher and this is called differential cryptanalysis and like basically what it says is that if you take a small difference of the input how like uh it's quite difficult to make uh the difference of the output be small like oh like uh the whole job of a of a well-designed cipher is to make the difference in output very large um so i guess the distinction is that the the optimization goals at that point are about complexifying they don't have the same residual connections or um or like
layer norms though yeah i mean i guess a place where the the two merge is back doors um okay so with a backdoor nllm you're trying to hide um what do you consider an input it's not an input into the forward pass or just an input into the backward pass but you're trying to hide an input into the backward pass like you're like this is like an adversarial uh yeah yeah yeah so yeah i I mean, in fact, this is like, this is actually a place where you get exactly the sort of avalanche property that ciphers have as well. Like adversarial attacks on... typically like image classification models, right, are can I find a perturbation of the image that a very, very small perturbation of the image that totally changes the classification, totally changes the output.
That is the common case in ciphers, whereas that's the undesired case in neural nets, for sure. Okay, so I was asking you, have neural networks actually been used for cryptography? And you realize it might be better if you just do this on the blackboard? Yeah. So I'm curious. Are they actually being used for cryptography?
“because it's invertible, I don't need to store this at all. I can completely rematerialize it when I'm running my backwards pass.”
Actually, it's kind of the opposite of what you're doing with the KVCache. The KVCache, you're spending more memory to save compute. Yeah. Spending more memory to save compute is generally profitable, given where hardware is at. Yeah, interesting.
Cool. That was super fun. Thank you so much for doing it. I feel like it really vindicated the vision behind the studio and the Blackboard. Cool. Thanks so much for doing it.


