Go back

Reiner Pope – The math behind how LLMs are trained and served

133m 50s

Reiner Pope – The math behind how LLMs are trained and served

Reiner Pope presents a detailed analysis of AI inference efficiency using a "blackboard lecture" format, focusing on batch size, compute, and memory bandwidth as core factors. The key insight is that batch size determines the trade-off between latency and cost: larger batches reduce cost per token through amortization of weight and KV cache fetches, with an optimal batch size of approximately 2,000 tokens driven by the ratio of active to total model parameters (sparsity). This balance occurs when memory bandwidth and compute time are equal, and the result is remarkably consistent across models. Sparse architectures like Mixture of Experts reduce compute load but increase memory demands and batch size requirements. Communication limits significantly impact scalability—especially across racks, where inter-rack links are 8× slower than intra-rack links, making full connectivity within a single rack preferable. Pipeline parallelism across racks reduces memory per rack but offers no latency benefit in inference and introduces training complexity due to micro-batching. Ultimately, the physical constraints of data center design—such as cable density, power, and cooling—limit how far AI models can scale. The analysis shows that cost and performance are fundamentally tied to hardware architecture and model sparsity, with large-scale inference requiring massive scale-up domains to store weights and KV caches efficiently. This explains why leading AI providers invest heavily in rack-level and interconnect innovations.

Transcription

21651 Words, 115376 Characters

English
Today I'm interviewing Reiner Pope who is CEO of Maddox which is a new ship startup. Previously he was doing TPU Architectural and many other things at Google. This is a very different format for my usual interviews. This is going to be a blackboard lecture running it up in a second. We in fact build this whole new studio with specifically this format in mind. And so it's a pleasure to get to inaugurate it with you. We're going to be talking about model architecture, ML and for many other things. And the reason I think it's an important topic is because once you actually understand how creating an inference actually work in a cluster, as we'll see a lot of things about why AI is the way it is, why AI architectures are the way they are, why API prices are the way they are, fundamentally also how why AI progress is the way it is, a start making sense. And you need to understand the details to get there and you need a blackboard to understand the details. So Reiner, thank you so much for doing this. Yeah, very happy to be here. Just a heads up, this is a lecture with brass and equations and all that stuff. So if you can, I would really recommend watching it on a video platform like YouTube. Okay, full disclosure, I am an angel investor in Maddox, but that's under the list of this podcast. Reiner, maybe to kick us off, ask this question. So we have a couple of companies like Claude and Codex and cursor are offering something like fast mode, where for 6x the price, they'll give you streaming tokens at 2.5x to speed. Mechanically, I'm curious what's going on here. Well, why is it the case that 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 Claude 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, to jump to 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 coding or multi-doken 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 the two principles of analysis. Firstly, we're going to look at a roofline analysis of how a runner transformer model on a cluster of chips will take a sort of let's say a black well 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 of the KB cache. So let's jump in. What we're going to try and do is we're going to try and 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 fetches, and then the time it takes to do the compute. 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 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 smoothing comparison to this. So we'll be honest. Maybe I'll just interrupt from time to time to ask some very name 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. Yes, 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 we'll turn out to be the cases that if you do not batch together many users, the cost and the economics you get is can be like a thousand times worse than if you do batch many two years together. And we'll be able to see that quite clearly. And then a number of active parameters, this is saying, like if I look at it, for example, a deep seek model, the deep seek V3 model has about 37 billion active parameters, and then 700 billion total parameters. So this is, we're focusing on just the ones that are active for a single token. Okay, so we're modeled computer 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 they'll be sometimes 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 weight fetch time, and then in addition, there's a KV cache fetch time. So there is, this actually depends on batch size. So for every element of the batch, we have to fetch an entire context length, worth the tokens, and then there's a size per token. So like bytes, bytes for one token. And so there's a model parameter. And maybe just back in, let's just explain what the KV caches real quick. Yeah, so when I do a forward pass, let me draw actually a, how the autoregressive inference works. So this is during decode. So if I think I have a bunch of tokens, text, I'm growing a tensor, because ultimately the tokens are represented as some like tensor of in some embedding dimension. And then in this direction, I have the sequence like the work of running a decode is, I have to run each token through a whole bunch of my checks, all the buys 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 up here. Yep. And so what I'm going to do there is I'm going to run a full forwards pass of qualifying by all of the white matrices in the entire model. But then I've got this attention mechanism where this token sort of it's like looking at all of the pass tokens in this way. And what is it looking at specifically? It is looking at some internal representation where the model is produced of the tokens. And we call that the KV cache. 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 patches from it and then makes a database. So we've got the amount of memory that we're fetching, showing over here. And then there's of course, just then divided by the memory bandwidth. So so the memory bytes 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 will draw separately to context links. So we said that the big big effect you can get is like some trade-off in latency versus 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 shop. So let's first look at this compute time. This is just purely linearly linear in batch size with no offset. So it is some I'm kind of like this is this is t compute. And then on the memory side, we've got some portion here that that is just this constant that's that is you know constant in some base offset here, which is the weight fetch. And then finally we have this toe here, which is the kb fetch, which we're going to draw as there's the kb fetch, which is a linear in batch size. 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 and I'm looking on this curve to look like this. And then we get a the overall maximum is I'll draw a little figure here is the maximum of these two curves. 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 us off in a amount of time. If I use all of my memory bandwidth, I can't do any better than that. It's even like the way you've drawn the slopes for compute time and how the KB grows. And what implication the KB has on memory time? That as a matter of size-- What if this were above a low or-- Yeah, or is that necessarily the case? Because if this is always true, then this batch size grows. Compute always dominates. KB, which suggests that if you have a 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 will cause a transition from compute limited to memory limited. Is there something especially significant about the slope being exactly the slope of the compute time? Yeah, whenever we have balanced points, it kind of says that you're getting it exactly right. And so for the particular context length, where the slope's match, that says I am equally memory bound and compute bound, which is a really desirable place to be. But suppose it's like this is a very simple algebra problem, but suppose the optimal is 100K context length. And you go to 200K context length. Does your MFU go down to like 50%. Does it have a humongous impact on MFU? Yeah, it does. To be slightly outside of context length, the optimal range will go to the lock zone. That's right. So that is true as modeled here. There's a key point here that I'm modeling this context length, or I'm modeling the memory fetch as linear in context length. That actually depends on model architecture. It is true for all of the model architectures with dense attention. There's a sparse attention actually scales much better than that. And is sparse attention a number of reasons in practice? I'm pretty excited about sparse attention. It's hard to know the labs are using. DeepSeq has published a sparse attention, but can it say? I'll just put a plug in that sparse attention. Some of the deepSeq papers that have published sparse attention end up putting a square root in this term. OK, so far 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 run this inference. I'm going to use the GPU for a certain number of seconds, like 1 millisecond or 20 milliseconds or something like that. And I have to pay the rental time for that time. So it's $2 an hour per GPU or something like that. So that's the cost of this inference. But 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. We have to imagine dividing each of these three curves by b. So multiplying by this reciprocal. And so what we end up with is there is the compute curve is going to-- it was linear. We divide by b. That makes it a constant here. This is t compute. The kv fetch was linear. Now it becomes a constant as well. kv fetch. And then the weight fetch was constant. And now we're divided by b. And so it becomes this hyperbola. 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 kv fetch and the weight fetch gives us 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, we see some limiting behavior. The cost initially starts very high at batch size of 1. Actually, it almost goes to infinity. Because we've got so many weight fetches which are not amortized over a large batch size. But then as we increase the batch size, the weight fetches 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 lower bound on cost, which is this one here. Yeah. So cloud code slow or code X slow or whatever would just live on this line and it wouldn't help much. Because you're not able to amortize the kv values over a much bigger batch. Yeah, their 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 at this point, where you are no longer memory bandwidth bound, what practically-- how big a batch do you need to-- 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 are 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 multiplies time. I'm going to disregard the kv fetch 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. Yeah. 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 so that we have the hardware parameters on the other side. So this is equivalent to-- well, so the 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. 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 one, hfp4, is half a byte. And so I can actually make this end up ending up being dimensionless. And this ends up being on most GPUs around 300, somewhere around 300. And so has that ratio changed over time as we've got from model generation to model generation or the flops keeps increasing? To what extent has the hardware changed? So from, like, A100 to A100 to A100 to B100, the flops has increased substantially. The memory bandwidth has also increased substantially. And it has remained reasonably stable. 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 sizing total. We end up with-- so we're 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 a 100, like, I activate in deep-seq, I activate 32 out of 246 experts. So this would be, like, 8 for deep-seq. Got it, OK. So this actually gives you a bullpuck, 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 the refined analysis would say. But like, take this and maybe double it or triple it. OK. So basically, it's like 2 to 3,000 tokens per batch. but then if you're 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 workloads. 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, um, keep in mind that I'm talking about the number of tokens that I'm generating one more token for. So, so it's like, it's actually 2,000 unique sequences. Okay, we're just talking about the, a single forward pass on these sequences. This is like the, do you think about like the batches, the number of sequences, rather than like, that's right. That's cool. Yeah. When I'm prepping for interviews, I often talk to experts in the field. So, for Reiner, I chatted with two of James Wies engineers, Clark and Axel. Clark, who works at low latency trading systems, walked me through why James Wies uses FPGA's to make sure that they have predictable nanosecond latencies. You can just build these like giant grids of compute very easily. They do exactly what you need, the touch, 100 megabytes of SRAM, and then get your response back in tens of nanoseconds very easily. And that's basically impossible on some PEO. 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 1,500 byte packet. They say, "Okay, this packet is ready. Here we go. CPU, you can start thinking about it now." FPGA is allowed 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, Jainstreet is hiring. You can check out their open roles at jainstreet.com/vorkash. 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. 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 about it as like, when does the train depart as a model. Let's say I've picked a batch size that I'm going to run at. Maybe I pick this batch size. By the way, this intersection point is the same intersection point here. I picked 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 uplanding. 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. So each of this is 20, this is 40. I guess. 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 and they wait to the next train, if the train is not full, the train is going to go anyway. So in terms of what that means for queuing latency, it means that the worst case is that you're like 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 like it says 40 milliseconds. How is a train miles against 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 store the weights or the KBs. 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 into the chip. And so that is capacity divided by bandwidth. That tends to be 20 milliseconds on on many different generations of HBM. The units make sense. You would have a a byte divided by bytes per set. Yeah. So for example, I mean on on I think the Ruben generation, it is something like 288 kicker bytes divided by 20 terabytes per second. And this looks like it comes out to about 15 milliseconds. Let me make sure I understand what to say. I mean, I understand how wide the units can be in the sort of unit analysis. But what is it saying is we can evacuate and replace HBM in this amount of time. And so we don't want to mean the situation where the HBM is not big enough that we're not actually able to keep writing everything you want to it or take everything out of it. Or we don't want a new 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. It's like almost all reads because the weight matrices are read only. And then almost all of the KV cache access. So in like let's say around 30 milliseconds, I can read all of HBM twice. But what's the point of that? I don't want to read the weight matrices twice. I don't want to read the KVs twice. Yeah, it makes sense. It makes sense. Okay, so a couple of actual quick questions. One, if it is the case that the optimal batch size is something like 2000 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. Yeah, scale. Well, that's very interesting result. And that seems to imply that you can, one question is how much of a push towards centralization is that you would have these economies of scale from inference for batching. Yeah. But it seems like it's not that big deal. Like I don't know, it's 2000 years into the same time a lot. It doesn't seem like a lot. So 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 or 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. So every time and 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 2000 times 64. So like 128, 128, tokens per second. So this is sort of in more digestible units. It's hard to reason about consumer 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 without like this is 1000th of that. But I mean, I mean, Gemini is big. So that's actually 1000th of Gemini is a lot to actually be like to be competitive at scale. You need to be able to serve at least 1000th of Gemini. Yeah, that's interesting. Cool. Okay. So the more sparsity you have, the less compute you need. And it does seem that as batch size is getting bigger, computing is 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 or other total parameters, how much is performance of the model degrading? And is it degrading faster than your saving compute by increasing the sparsity factor? Yeah. So equality of the ultimately, rather than speed of the model. Yeah. So unfortunately, we're not able to answer that analytically. That's, that is an empirical question of model quality. Best I can just pull up a paper and answer that empirically. Should we follow the paper an hour or so? Yeah. So this paper, this is unified laws for router 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 maybe back in 2017, but the techniques have changed a lot. Deepseek mixture of experts was a big change in how it worked. There have been older papers which are G-sharge 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 go like expert count here, the quality keeps increasing. And then if you imagine drawing a horizontal line from 1.3B dents across, you end up seeing that, for example, in this case, the 64-experts 370 million activated parameters model is as good as a 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 a parameter count for a modest increase in condition. Yeah. So in this case, actually, what is it? 64x. 64x for 4x. Yeah. Well, it is true, I guess, that you get this benefit of being able to economize on your compute time if you increase sparsity. Naively would seem like, oh, that's a tradeoff worth making. But if this increasing this by 2x and then having this go up by 8x, every time you double sparsity. Yeah, absolutely. 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 out larger batch size. From the point of view of the analysis we've done here, this is pure wind. 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 smarter 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 when we bound it with it, but it's a reasonable amount of capacity. So let me just make sure I understood. You're saying we want this one less time computing, therefore we do more sparsity to make that work. We need bigger batch sizes, which means we need more memory capacity. Yeah, so that's how we're sparse. Yeah, so maybe this would be a good point to actually talk about how a mixture of exposed layer is typically led out on a rack of GPUs, doesn't make sense. Yeah, we're really sparse mixture of experts, maybe how we lay that out on a GPU. So let's zoom in on the mixture of exposed layer first and sort of draw what that looks like. So we typically will have a some kind of a router layer, which is making the decision of where we route the experts to the tokens to tokens coming in here, they go through a router layer and then we have a bunch of different experts draw a few more to line some up. And then the router will make a decision on 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 a 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. We're going to move, bring in them in like this. And then finally, we have our residual connection, the token is also passed through here and it gets added to the result of the MLP layer. So this is a normal MLP layer. What I want to talk through is how this is mapped to a GPU rack and what this means for communication. Because I think this will start to show some of the limits of how fast we can go. So the standard practice here, and the best solution is to use expert parallelism. So that means different experts go on different GPUs. So if we take something like a deep seek model, they have 256 experts. Let's say we want to run that on a like well rack, so there are 72 GPUs. We have a divisibility problem, this is not a power of two. So we'll just simplify and say we're only going to use 64 of them. Just ignore the other age. It's not a big deal. And so we have four experts per GPU, very simple. For the sake of the diagram, I'll actually just say let's say we have two experts per GPU. So we end up just putting, these are the GPU boundaries. Every pair of experts is on its own GPU. And then we can look at the communication cost. We had some experts stored, some tokens stored centrally here. They get routed to all of these experts. And so there is some communication cost paid here. There's the same communication cost paid on the output. And then the hope is that this does not become communication committed. Now what is the traffic pattern here? The traffic pattern here is that any GPU in fact will be talking to any other GPU depending on the decisions made by the model. So this is an all-to-wall traffic pattern. So we're going to say any GPU in the pretense. The router is more than one GPU. So I drew this as one router. In reality, you would actually have many copies of the router. So you would have as many routers as GPUs, in fact, as the incoming traffic. So these are 64 GPUs. These are 64 GPUs. It's actually the same GPUs. We just draw them as separate because they're serving different purposes. So at this point, any GPU can be sending to any GPU. So this all-to-wall pattern of communication that shows up and how the black wall racks are configured is a perfect fit for the communication pattern that the MOE actually wants to do. However, if you think maybe one rack is too slow when I want to do two racks, then I have this challenge that maybe I've got some rack boundary drawn outside here like this. And I no longer in fact have all-to-wall communication between all the GPUs in two racks. And so the rack-to-rack communication ends up being a substantial bottleneck. This sort of like the fundamental thing here is that one rack is actually the bounds the size of an expert layer you can do. And so this has been part of what's been driving towards larger, larger interconnect domains. Yeah. But before we, it may be worth your explaining what exactly a rack is, the differences in bandwidth between a rack and within a rack and the all-to-all versus not all-to-all nature of communication within a versus outside. Yeah. This where it starts to be very different, in fact, between Nvidia, for example, and Google and then others including us. So generally a rack is a, it is a physical structure. It's a few meters tall, a meter or two wide, it depends on configuration. And it stores some number of GPUs or XPUs, which is typically about 64. So what constraints are being a certain size is power delivery, weight, and cooling ability. It ends up being about the sizing in many cases because of these physical constraints. So then when I deploy a data center, a data center may have thousands of these racks. So I've got one of these tall racks, it's got a bunch of GPUs in it, and so on. And then I put another rack next to it. You make it sounds so easy. Yeah. Drop them in. In Nvidia's case, the communication topology is actually, they put the GPUs on the outside of the rack, and then they push these switches on the inside of the rack. So what this ends up being is that there's a set of switches in here. These are the envy switches. And then they run a bunch of cables, and every single GPU has cables going to the switches in the middle. So every GPU goes to the switches in the middle, and then the switches have connection to all the GPUs. So all of the GPUs can talk to all the other GPUs in just like two hops, going to switch, going to the other GPU. Now when I want to leave the rack, I end up going via a different path. The GPUs have also a much slower connectivity, which is typically about eight times slower, which is, so the green that I drew here in GPU cases is the envy link. More generally, it's called the scale up network. This is the scale up network. You will typically also have a scale out network, which allows you to connect to like some data center switch, so data center switch. And then all of the GPUs will have some connectivity up to some data center switch somewhere. Well, this is our times, like this is the scale out, and it tends to be about eight times slow in bad weather. So the challenge, if you want to, for example, lay out a mixture of expert layer across two racks is that half of the GPUs here are going to be wanting to talk to the GPUs of GPUs. use here. And so, like, just on average, like, when I look at where the tokens on these GPUs want to go, how are the tokens that want to go inside the rack? That's great. They can use the fast scale up network. But half the tokens are going to want to leave the rack and go to the other rack. And that's not as good. They can need you as a much slower network. And so that becomes the bottleneck on the all-to-all battery. The different choice would be, well, why don't I, like, have a big switch here and sort of, like, and connect everything to some big switching, like, much bigger switch that actually combines the two racks together? There are many ideas in this direction, but in general, it becomes the reason you have this sort of hierarchy of switches rather than one big switch is to manage the cabling congestion. You just need to run a lot of server capings. So, is that question you just asked basically, why isn't it a bigger scale up? Yeah, exactly. Why not, why not just, like, have, like, a million chips in scale up? What has changed that is allowed in video to go from Hopper was eight, then Blackwell is 72, and now Ruben will be, as if 500 or something. Yeah, 500 or something. 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 is a tray just switching to racks as the form factor. That's a product decision. Yeah. There wasn't a substantial technical barrier there. Switching from, from the, like, 64 to 500 or so, there's a bit of Jensen 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, the, the, the cost figuring out which cable hops to which, or like, which you signal, I mean, 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, but if a cable is that look like this, running onto 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, yeah, these as well. Excuse me, now you 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 like really big. Yeah. So, there is space outside the rack. Inside the rack, like these racks are like, I mean, because they become more optimized, these racks are very tight. So, there's a connected density going from the tray into the rack and the rack's back plane. And then the back plane itself has a really high density. There are other physical constraints, including bend radius of cables, like you don't want to start the little sound. Okay, so it's literally the physical space to put a cable. Yeah. That's constraining it now. I had no idea. Interesting. It seems surprising, but like the rack is so big, we can't just stuff more cables in there. Yeah, so I mean, rack design is not my expertise, but when I talk to folks in one of the constraints they're up against, it's a combination of, so one of the big physical things you're optimizing for space, weight of the rack. It's actually really heavy and so you need enough metal top to not sag and fall, but then you 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 inputs. 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 it back and forth in the Netherlands. 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 GPT4 released again? It was 2022 or 2023? It was rumored to be over one trillion parameters. It seems like only now, within the last six months, have models been getting released that are significantly more parameters than a model of at least three years ago. When supposedly there should have been this scaling in the meantime, is the reason that we are just waiting for racks with enough memory to hold the five trillion parameter model along with its KV-K-ash for enough users for a full for a lot of sequences or if you're doing RL, kind of a similar consideration of actually holding the KV-Kash for all the batch problems you're trying to solve. So if you look at LeCopper, you had eight hoppers and I think that's 640 gigabytes as of 2022, with Blackwell finally, which was deployed by 2020 very recently, maybe last year. You finally have a scale up with on the order of like 1020 terabytes, which is then now for like a 5T model plus KV-Kash. Yeah. Deploying in larger scale up domains is a huge unlock. I mean, I've drawn here the sort of in video Blackwell deployment. The Google deployment has actually had a very large scale up to domains. And that also explains why Gemini seemed to be ahead. Gemini 2.5 was a successful or it just seems like Gemini has that successful reach rate for 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 high-espacity ratios, which could be. It could also be, I mean, there's a whole bunch of actual modeling things of like specifically, how do you do the mixture of experts? I've seen the deep seek, like the deep seek mixture of experts has said actually activate more experts but find a great 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 watch 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 is 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 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. Okay, so to answer that question, we're going to need to talk about the communication patterns. We've talked about the mixture of expert communication pattern. That is this all to all. It's all to all. All to all. All to all, very strongly favours full connectivity, which is what we've kind of just shown here and favours 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 up 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, let's just sort of visualise it out and sketch the path. So we're going to have a bunch. This is another MOE layer. I'm going to have another MOE layer at the Apple someone. So let's say I change rack here and then some number of layers later, I change rack here as well. So our methodology that we're going to use to determine whether we have a communication bottleneck in this point where we change rack is we're going to compare this, this is the scale out, scale out bandwidth requirements to the scale up bandwidth requirements. So let's try this. 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 that's so that's going to be the What makes the difference? Can I try to guess? Yeah, just have a 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 a number of activated GPUs, right? So like I don't send to this GPU at all, right? So there's an explosion from one to like Three times larger here in this diagram. Yeah 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 it. 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 scales 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 There's the quantity we're talking about And the first consideration is that the scale up is like Scale up is 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-rate, which is coming from bandwidth Bandwits But then we have some amount of Expansion in in in how much data we're sending so if one token comes in here And this one token gets routed to in the deep-sea case it'll get routed to maybe 32 experts or six Teen experts gets routed to some number of experts. So this is the number of activated experts number of activated Experts And then it also This the same thing applies on multiple different layers. So maybe I'm going to run two layers. So there's also multiple times Number of layers Our stage And there's need to multiply the whole thing by two for the For the off-and-down. Yes. Yes, and as a factor of two. 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 in precious resource And so we just we want this one. We would like this number to be greater than or equal to one And this really doesn't seem hard like we've 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 8 Typically we have a fairly large number of activated experts. It could be 8 by itself And then we can increase the number of layers per stage a lot until until we satisfy this And 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 like I can do another layer. It's interesting to me that the best parallelism Uh, strategy and practice ends up being one which physically resembles The actual architecture. It's not some galaxy brain thing. You know, it's like oh, we have experts We're gonna put them on different GPUs. Oh, we have different layers. We're gonna put them on different racks Isn't that I feel that's interesting that the physical and the model architecture matches like the the counting matches about luck Yeah, exactly. Yeah, it could have been something wackier with a 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 um Like what are all the different dimensions in which a model is scaled up Um, and so there is uh, it is scaled up by layers. It is scaled up by the like demodeled dimension is scaled up by the dff dimension and is scaled up by the number of experts Um, every single one of those numbers you can choose to cut along Um, and if those numbers are big enough it eventually becomes profitable to get along there um, and we have selected two of them the other two In the way typical models are typically sized are not profitable. Um, so there's um Talk about Ilia where he says today we know not to do pipeline parallelism and Ahoracy give my friends and me I hate that it's not like a bachelor's quote But he gave us a lecture on uh, these different kinds of parallelisms and he said the problem pipeline parallelism is that it Other than the bubbles that constrain it creates these architectural constraints. Yes on um Like Kimmy for example has these uh, residuals were attention attends to The a few of back or something. Yeah, there's a few back and so that it becomes hard to implement in this way Yeah, um, so and I guess we didn't really articulate even what is the benefit that we're getting from pipelining. Yeah Uh, and So these complexities are real. It's pipelining is a massive hassle. It's uh, but it does give you some benefits um The uh, and then you can then decide whether those benefits are the worth of costs um the The biggest benefit that shows up so it can has some benefits in inference maybe bigger benefits in training Um, in inference what are we saving on are we saving on um memory time or computer time not really we're just moving the memory time from one chip to another chip Um, or one rack to a different rack. There's no actual benefit in runtime um However, what we are saving on is that the memory capacity is uh The amount of memory used per rack if we think that the memory in a rack is a bottleneck then there's a constraint on how sparse we can go um It pipelining allows us to massively reduce that bottleneck. I guess but the opposite connotation to this Which actually before this i was tragic before this interview i was chatting with them Axel was a gpu performance engineer uh jane straight and he he was explaining Well, to do pipelining you had to do micro batches rather than full batches. Uh-huh 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 out 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. I mean, it's worth explaining why you had to do micro batches because yeah So we draw the mic with a pipeline bubble um yeah Okay, so so why do we do um uh what what is this micro batching that shows up in shows up in pipeline parallelism so um The uh i'll focus on inference first. It's just slightly simpler a problem um So and i'm going to draw uh, so this is time um, and then this is which rack uh rack um where on and so the idea is that maybe i'll have like four rack So i've got um uh an inference that is going to like step through these four racks in some time like this So great this is inconsistent number zero um Uh it runs at a certain batch size uh and it steps through all 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 Try like um like three quarters of the time each of the racks is doing that. So um so so we don't actually run inference one here We we run it as soon as we can which is immediately after um inference zero finishes like this um So uh and we keep um so if we hadn't filled this in we would call this the pipeline bubble Um when i've drawn it in this inference context where we're only going in a forwards-ass It's like obvious like why would you do the stupid thing? But in a training context uh, it's maybe less obvious But in the inference context it's it's sort of really natural to to make this change. I was just saying so This sort of virus but um The difference between micro batch and batch doesn't matter all in inference because You can just call whatever you want whatever yeah, it only matters in training because There is in 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 have 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 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 do some number of uh batches in the forwards pass And then we're going to transition to the backwards pass for everyone all like one go So the the inference part is the same uh here, but then we do a hard stop at this point and then transition every under backwards pass um Similar number 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 backward step um and then there is an optimal size for how big that batch should be Yeah, I mean smaller is always better actually is is is a way to put it, but uh it's such like from a [BLANK_AUDIO] 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 training time perspective, it's like smaller is worse from a system's perspective, and so the optimum is the tradeoff between us. So you pick a batch size, and then for that batch size you do some around forwards and then some around backwards. You ask why is there even a hard stop? The pipeline parallelism, because of the fact that you've got this idle time here, which is the bubble, there are so many techniques in the literature for how to lay this out differently and avoid that. There are more complicated schemes called zero bubble, or one forward, one backward, which interleave the forwards and the backwards in complicated ways, but you can mind bitcoin in that bowl. Right, right. So you just fully can do the 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 you were pipelined versus if you were all on one rack, if you 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 you can extend the sense. So basically, no brainer is pipelining during inference, but there's this hard work trade off during training. So even in inference, in fact, it's not used a ton. Say 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 of, if that's much bigger than, like, a trillion-parameter model, a trillion-parameter model is 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. It does say that theoretically, maybe you had too much memory, and maybe you could have done a different, like, build a different hardware that has less memory, in fact. If you were designing your hardware, like, 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, put GPU. Last week, Porecy 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'd made during the lecture. And I asked it to visualize a specific hierarchal collective that Horus 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. The first composer-to-fast 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 this kind of iterative design flow for yourself, go to cursor.com/thoracash to get started. So macro question, everybody's talking about the memory wall right now, where he's getting super expensive. There's not enough memory. Smart phone volume will go down 30% because there's not enough memory. Hyper-scalers are spending, this is shocking. Dylan said they're spending 50% of their CapEx this year on memory. That's believable. Yeah. Like, what is hyper-scaler CapEx? It's like a high-hundreds of billions, maybe a trillion, and they're spending half of that on memory. Okay. That is a 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, what Jet says is shoving all this memory into these racks if you don't need it. Yeah. So we've, like, in the equations we had here before we raised them, we were doing memory time. So memory bandwidth and compute bandwidth. 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, like, 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, um, times, uh, turns the bytes, bytes per bytes paycheck, um, okay. So, um, what I was arguing about in this context and the case I was making, uh, for pipelining is that, um, 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, let's consider. So we're going to run this on some number of GPUs and we're going to say, um, we're going to have one extend, which is, um, uh, E is going to be the expert parallelism. So how many, when we had this charting of, uh, expert layer across many GPUs, how much of that, uh, to what extent do we do that? How many GPUs? Um, so we're going to say that this is fact, for example, 64. And then P is going to be the extent of pipelining, pipelining, um, and so this is the number of racks, which, who knows, maybe it, maybe we'll, um, maybe we'll pick four or something. Well, we want to calculate. So this is the, this is like the total, um, total memory requirement across the system. Um, but now I'm going to calculate a, um, a memory requirement per GPU. So per, per GPU memory requirement, uh, we're going to have, I guess I'll use a love a case, see, mem, um, and well, obviously we just take all these numbers and divide it by ENP really easy. So, um, uh, it's this end total, um, plus the batch times length of context times bytes, uh, token, um, all of this is divided by E and speed. Okay. So this is like, why is this correct as divided this way? Um, well, we're, we're saying, we knew that the parameters were perfectly divided amongst all the, the GPUs in a rack, the layers are perfectly divided amongst the, the, the different racks. So that works here. And somehow we can do a range, I'll hand away if exactly how, somehow we can arrange the same perfect shouting of, of the contexts across GPUs in a rack and, and, and, and then based on a layer across, uh, racks, and it's a four is a number of racks. Uh, yeah, for example, um, so, um, this is the place where we actually need to go back and analyze this batch size B. And you're making this comment that there's micro batching versus global batching. So, um, let's come back to this pipelining diagram here, um, 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, um, 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 us in. We'll have the. Oh, uh, yes. Um, yeah, so we've got the two, three, uh, two, 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 four zero, one, two, three, um, and then the batch size per, um, like, the micro batch size, this is still this, like, two thousand dish number. Um, this is the one that is like, um, this is the, like, two thousand time sparsity. Uh, sorry, uh, no, this is the three hundred times sparsity, uh, three hundred times sparsity. This is the, how big the train that takes up a 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, um, well, the number of micro batches is as small as possible such that we can like wrap around, uh, and not leave any idle time when we wrap around. So if we like, if we had fewer, we would have had 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, sort of proofed by visual here, like it is for, and it's for 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, sorry, very basic question. This is what is actually done. Okay, as in Frontier model today, we'll actually have, during inference, have pipeline. For sure, during massive scale training, this is done, 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 kx. Yeah, the big challenge is, so like, let's fill this in. The micro batch size here ends up being equal to the number of pipeline stages. When we go back and substitute this, that's all of that into here. We get a number of pipeline stages, times this little b, trying up in here. And then when we factor this out, I'm going to split this into, like, 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, if 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 KV cache becomes the dominant term. Yeah. I know this is wrong. I'm just trying to think about why we're trading 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. 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 off. Yeah, it makes sense, it makes sense. So those exactly cancel. And you end up not getting a second for a GPU. Right. And this is going back fundamentally at the point of you're not able to amortize across KV caches. Well, so first we did, you can't amortize KV caches across batch size. Yeah. And now we're saying you also can't charge it across pipeline stages. It sucks from both of those points of view. Yeah, yeah, yeah. Interesting. Okay, so then what is starting during inference? So, I mean, a, like, deep-seek paper reports what they do, which is like, they just do a lot of exot parallelism. You should, in effect, you should increase your exot parallelism up to your scale up to main size. Yeah. And then do very little pipelining. Maybe not 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 making cutting up within an expert. But the experts are so small now that that is not a profitable organization. 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. Like, you could have a very large model. Like, one that exceeds the memory of a rack. And there you should be doing a bit of pipelining. Maybe it's extremely sparse, for example, and that would be a reason to do it. So I guess this goes back to the question about, 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. 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 made the clip. So pipelining doesn't help with context links. It totally helps with model size. And so, because of the ability to pipelining, at least a rack should not be a constraint on your ability to fit the model. 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 is 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. 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. Is for a realistic number of how many pipelining stages you might have? Yeah. On a small number of pipelining stages, this is not a huge latency impact. I guess it's 10 milliseconds per token. That's right. Two times four-ish. I don't know how many said, but 10 milliseconds per token is actually a lot. If it goes from 20 to 30, something like that. Just to chart the path that it goes through, here you're going from your GPU or GPU or whatever to a network card, which then goes to a top of rack switch, and then hops over to the other rack, and does the same thing in reverse. You have to sum up the latency of these different things. This is the same thing as the DC. It may in fact go up to an ascension back. It depends on deployment configuration. Because it's decode-int sequential, it's also not like they stack up across the stage. You can't do them at the same time. I guess this brings us back to the question. 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 they're through training or through inference? We talked about latency of the hop of this hop. There's also just the same TMM latency. The memory time latency is actually substantially massively improved by a large scale of domains. I'll recall TMM down here. TMM for the weights, TMM 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? It is the number of GPUs that I can use in parallel to load these weights. 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. This is actually extremely effective. Basically, I end up with a term here. This memory bandwidth term itself is equal to scale up size. That's a memory bandwidth for GPU. Yeah, times GPU bandwidth. And so this term doesn't increase a lot. It may be increases 1.5 or 2x per generation. But this one increased by a factor of 8 from these from Hopper 2. So the reason the bigger scale up matter is not the memory capacity of the whole scale up, but really the memory bandwidth. Pipeline entirely solves the capacity problem, but scale up size helps solve the bandwidth. The bandwidth for the problem helps you do longer context lengths, which is more and more relevant as the models get more energetic. Yeah, it lets you just run the model at low latency as a first thing. If I just do a very fast model and it's on a little H100 box, the latency will be really high. Yeah, okay. It's 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 trading compute. You want the best results a user can get the 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 inferences minimize to get a certain performance. But now with RL inference, there's or RL there's another consideration, which is you're going to do some other pre-training that pre-training will be used both for RL generation and then for inference for the final user. And by over training here, I mean, well, it would have been more efficient just from a training compute 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 compute. trading it than you otherwise would have, but now it's cheaper to give it to users. They basically, let me question more concrete. How much more than Chinchilla optimal are models or a trend? And has that changed as a result of our own generation? - This is a place where we have to do a bit of guesswork, because like the updated scaling laws and the model traffic is not reported, and so we have to guess there. But one way to look at it, 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, you know? And so I want to minimize this sum for many curves that tend up being the case, the minimum tends to be where these are, where the costs are equalized. That's something of a heuristic claim, but you can, it tends to, like there are many examples where it's true, like where one is one over X, and the other one is X, for example, they tend to be minimized at the point where they equal each other. It's also true for like each of the X, and like each of the minus X, and all kinds of other things. So basically I've got some curve that's going down, some other curve that's going up, and they tend to be minimized up at this equal point. Heuristically, I will conjecture that that is true for the setup you described as well. Like actually showing that I would be true would require looking at the scaling laws and like fitting these like weird exponents, but things that do follow power will always 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 we can do all of it in general, so actually we'll cost over those. Cost of pre-training, so number of active pre-empts, 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 six and D formula. And then in RL, we have approximately the same thing. We've got like the same number of active parameters, but now it's 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 roll outs. 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 six and D. Yeah, so this could be a smaller number, right? Like this could be somewhere, so it would at least be two. Yeah, somewhere in the range of two to six. So I'll just say somewhere in the range of two to six, and then we can add in the inference cost. The inference cost is two, number of active times the data in inference. And sorry, 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'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. So we're going to solve for essentially, it may be a quality of all three of these terms, but that is bullpock 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 retraining, I don't have that information, but I think a good bullpock is 33% split between each of them. Actually, I'm not sure if there's anything more intuition for that. Another naive model could have been that RL plus pre-training would be 50% and inference would be 50%. That's also a valid answer as well. Because this is heuristic, I can't really argue for one of us the other. They don't differ by that much, like 33 versus 25 is on the estimate of a trough. So let's pick one of them. All equals seems simple enough. And so we're just going to solve for a quality of them. It's pretty straightforward. We can immediately see that the number of activated parameters totally disappears. And so let's factor that out. And we're going to just say that data in pre-training, I decided to do it your way. It's a little bit nicer, actually. So data in pre-training plus this-- oh, I didn't have the inefficiency over here either. inefficiency, data in pre-training plus some multiple of alpha times the data in RL is just going to be end up equal to the sum of beta times the data in inference. And then let's just roughly size the alpha. So this alpha, it's going to be-- this is like the-- it's maybe somewhere in the range of 2 to 6, 2 to 6, over 6, from this term compared to this term. And then we've got an inefficiency term, which I would say is maybe in the range of 30% to submit that. So this alpha is going to be something like 1 on 10, 1 over 10, let's say. Then this beta here is actually the same. It's a third, it's one third, times 30%. So it's also equals 1 in 10, something bigger. If you both of them are 1 in 10, the kind of implies that there's never a backward path on RL? Yeah, OK. We can make this like 2 in 10, make it a bit bigger. So yeah, like just write it out once more. Like this is 2 over 10. This is 1 over 10. So the number of inference tokens you have-- and this is just a function of like-- I've got hundreds of millions of tokens per second, times my model is deployed for, I don't know, two months before I shift to the next version. That should determine the number of tokens in RL. And pre-training-- and then I guess we didn't do the equivalence between pre-training and RL sort of that here-- data, pre-training should be equal to like 2 over 10 times daily in RL, but not to be a cost equivalent. Sorry, this 1 over, I got a backwards. We pay more cost when it's inefficient, so this needs to be 1 over. So this-- tracing this backwards-- four projects. This thing ends up actually being, as written here, it's like 1.5, and this is one. Billions of dollars is the compute just for the other direction. Yeah, right. I think if you do it with a spreadsheet, it actually won't work out. You might notice when the money's going down the drain. So all of these end up being close as modeled here. The study percent may have been a little bit too generous. So let's say something like 1.5 here, and update this as a 1 here. So I think at this point, you can always read it off. Like, the number of inference tokens should be about the same as the number of pre-training tokens should be about the same as the number of RL tokens within-- in fact, it's the way we're not able to reason about. But then it looks-- Sorry, I'm making a basic algebraic second. It seems like there should be less RL tokens than pre-training tokens. Yeah, so that's in general, right? Because RL is less efficient in terms of machine time. And so if you're trying to equalize the RL and pre-training time, then you should have fewer tokens in order to have the same wall time. This is quite interesting that I never thought about it in terms of how much equalizing in terms of data. I mean, I think starting with equalizing in cost is right. But it depends on how you model the cost. It comes close to equalizing in data. That if every single user who uses-- basically, if you forge a GBT to be trained optimally, every single user who uses GPT-5, the total amount of tokens of the stream should be the amount total amount that I've got into pre-training. And the total amount of tokens that I've got into pre-training is the sum of all human knowledge. So like, each model should generate the sum of human knowledge on the output that it gets on the input. Yeah. So I mean, which way are people going to err? If you think that people's power of predictions are perfect, and also you run the risk that you make a model that is not a frontier model. And then you just throw it away. Then that kind of changes the cost to trade off because there's some probability that applies to the inference. And you should derate the inference token by some amount. Right. And then can we back out how much more compute-- yeah, compute the general optimal for a given size? So I think we just have to make some real-world assumptions here in order to do that. So the inference tokens we should totally be able to count. So let's say a few times. I don't know, maybe it's like 500 million tokens a second now, I don't really know. A 500 million tokens a second times a model is deployed for two months before it becomes obsolete. I don't really know. I can't do this in my head. Can you type it into a computer? 2.6 times 10 to the 15th. This number is probably too large because this is going to be multiple models in a family. Let's make it like 5 times smaller or 10 times smaller or something like that. So we're estimating maybe 50 million tokens per second, per specific model. The model is live for two months and so this comes out to around 200 trillion tokens. And then we want to compare that to active parameters on a frontier model. I don't actually know the latest rumors but do you know somebody thought we 150 trillion active brands? So I mean that tokens. Train you down 150 trillion tokens. Interesting, which is similar. Yeah, that's actually similar. So data on pre-training, this is not well cited but you'll be to not remove it. That's right, that's right. And I think often active parameters, number of active parameters, could be in the range of like 100 billion. Maybe a little larger. So I'm assuming active frames are about 100 billion and so multiple by 20 together, chinchilla token count. So chinchilla, the chinchilla, would be around two trillion. And yeah, and we see like we're at 100 times larger than that. What does the chinchilla actually mean? Like the token counts for pre-training for the chinchilla scaling model would recommend, I guess. Oh, I see. So how much is it over-trained? Got it. So yeah, it's like the ratio of this 200 trillion or 100 trillion parameters over the like the chinchilla optimal of two trillion. That's the amount that's over-trained. Which is like the factor of 100 out of a train. That's whatever. Okay, so if you consider this right here, to the extent this is in the right wallpark, just by thinking about, okay, you kind of want everything to be equal in terms of compute. Here's if that opening I also realize is that underserving our certain amount of tokens per second, that tells you how much data went into the pre-training of GPD-5. Even if it's like 50% off or something, that is the sort of wild you can sort of first principles, these kinds of numbers. This is also, I mean, this is why you should just like approximate every way because like there's so big air miles on this. But yeah, no, it's kind of like empowering to just like set AA equal to bay and figure it out. Yeah, yeah, that's super cool. Okay, so it's weird of trying to do 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 longer context, Gemini 3.1 is 50% more expensive if you go over 200 K tokens than if we're bullet 200 K tokens. I mean, at a high level, I understand why that might that be, but why specifically 50%? Yeah, so I mean, why specifically 50% let's sort of, so the high level even in the first place is there is some amount of increasing cost with context links. And we can bring that back up. That was the the memory time, this is the compute time. So we've put up these same occasions from before of the time for memory fetches, which is the weights and the kb cache, and then the time for the compute, which is just the matrix multiplications for the weights. I will also draw the the cost curve. But this time, I'll do it as a function of context like instead of as a function of patch size. So this time over, yeah, just time. So this is the cost curve as a function of context links. We'll draw the compute. The cost of the compute is actually constant as a function of context links. There's no dependence here on context links. In reality, there is some dependence, but it is very mild dependence, so we'll ignore it. So this is the time for the compute. This one. And then we'll also draw the dependence of the memory fetch on context links. And this starts at a large number for the weights and then grows gradually with the context links. So maybe here and then go gradually with context links. And so you take the maximum and you see there is this inflection point here. So now, so this is the costs that that, for example, Gemini might be paying. And then you think how, how, how might you put a pricing structure on top of that? You would like to ensure that no matter what the context length is, you are, you are still profitable. So interesting. And so we've got a two tier pricing structure. Maybe we've got something that looks like this up to size context. Fascinating. So I think it says something about given that the bump is at 200k, it probably means that this is somewhat aligned with this cross over point, maybe not exactly aligned with. Fascinating. So we can actually probably even complete that calculation just to see where it lands out. We can solve for the number of bytes per token if we sort of make some assumptions about the number of active parameters. So solving for the number of bytes per token, we're going to assume like the point where we equalize the time of memory and the time of compute is at let's say 200k tokens. So we equalize these two. We're also going to just assume that the batch size is large enough that the memory time spent on weights is negligible. So we'll forget about this and we'll focus on the actual memory time spent on kb cache. So that ends up saying copying this term over batch times length context times bytes. The token over them bandwidth is going to be equal to now we're activated parameters over the flux. And then we're going to solve for bytes per token. The batch size was missing here. It shows up here. And then it cancels out by the time we get to you. And I drop the length context. So we can plug in numbers. This number, this is the reciprocal of the number we saw before it's, yeah, this is like 1 over 300, which is reasonably stable across many different hardware platforms. We conjectually said that maybe number of activated tokens is like 100 billion. And length of the context we said was 200k. Something is wrong here. The length of the context should be under the denominator, not the new writer. 1667, make about 1k, almost 2k. That is plausible actually. So we said around 2k. Let's just do a sanity check for this, what this could be. There are two mechanisms that people do attention with a small number of bytes per token. One is dense attention with a lot of reuse across layers. So character AI has a blog post talking about that, alternating long and short context. And like in the character AI kind of model, which also showed up in the Jemma models, the global context, which is really what we're talking about here, global context, was shared across all the layers. And so to get this two kilobytes, you could get that, for example, as a d head of 128, is typical. And then like the number of bytes is typically number of attention layers times two times d head times a number of q heads. So this is the number of unique contexts per layer. Do you share the context across many layers or do you do it only once? So in the character AI-like models, this number is one, we said this is 128 and this is a choice which typically ranges from one, sorry, this is KV heads, I meant. There was written a head in a KV head is that the KV heads of the heads that are stored in memory, like store the contents of the previous circles, the Q heads are the retrieval heads there, they're only used temporarily and they're used by the attending token, so in this border-aggressive context, I've got KV heads associated with all of the contacts, and then Q heads associated with this new token here. But this had the 128. Oh, this number is actually the same for, oh, so this D head is the dimension of the vector. A number of KV heads is typically in the range of one to eight, so it is totally plausible to get this by, for example, having eight KV heads and a D head of 128, that gives you exactly this number, or you could have fewer KV heads, but more layers. So this is one way to get that via dense attention, there's also a way to get that via sparse attention, where you increase all of these numbers, but then you have like a one or the sparse attention. So yeah, I mean, I think this number is plausible if maybe a little bit small. It's funny that they would leak so much information through their API pricing. I mean, you are incentivized to price close to your costs, because otherwise, someone could skip 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 year, 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. That makes more sense. So let's say it's five more times more expensive. Okay. This is the compute to process the next token in decode. Suppose you're doing pre-fill, but 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 lend pre-fill. Try all the lines of the past in general. Yeah. If we say like, if we can think of decode as being a past with one and then pre-fill being a past with many. Okay. Yeah. Yeah. So maybe like prefix, chop, whatever. Okay. Memory. So you're not storing the kvcache 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 say this is a chat session, the user says something, the AI generous response, and then the user says something else. Yeah, we pre-fill this. So like 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 user input or full call or anything that's not. Yeah, exactly. Yeah. Okay. Okay. Suppose we're here. So you will need to load basically the, you will have calculated all of this previously. So just the kv of everything it 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? Yeah, there's actually no adjustment at all to the memory time. Great. Oh, it's a very trivial change. Yeah. I could accommodate. So this term is making it 5x marksman set. Now, why would that be? Well, 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 like the only thing that could have changed is the compute is 5x marksman set as a result. So yeah, there's the time for one pass. But actually the amount of tokens is that that much larger. So I guess we want the cost per token. In fact, all the time they're token. So I'm not sure I understood that 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 then let it refill. Yeah. Well, I guess it's pretty yeah, like the of the past. Yeah, not not not this prefix, but it's this cost. Okay, let's just do the math. So this is 5x more expensive input is 5x more expensive 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 turn it with like a length pass on the x-axis? Yep, yeah, T on the t-axis. T we want the cost per token. So it'll be t over some stuff t over length at the pass. Yeah, that'll be right. Okay, so. Okay, excuse me to introduce one of this. The length pass is the, it seems like this should be higher when you're doing pre-fill. Pre-fill has a big length pass. Yeah, right. But then why is it cheap? Why is it cost higher? Yeah, yeah. So we're going to, it's this division by length pass. That actually makes it all so. Okay, yeah, this is going to divide out. This is going to divide out, but then we're going to get a div, 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 let me 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 let's do decode first. Oh, sorry, actually, length length of the pass when it's one, that is decode when it is bigger, that is pre-fill. Okay, yes, yes, yes, yes, 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 to compute. And then this is like, this is, let's decode, right? Now, tmem, if you have this whole thing, divided by length 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 remember bottleneck on memory bandwidth before, you can avoid being bottleneck on memory bandwidth. The fact that they are charging 5x less for pre-fill than decode does suggest that they are bottleneck on memory bandwidth to quite a degree such that for them at least, because t is equivalent to cost, right? It's a cost of writing a compute. This is actually like, this would be at one, and this would be at five. That's right. Yeah. So it is, in fact, tremendously memory bandwidth on like, like, the real graph looks something like, the real graph looks something like, like that. Yeah, I mean, it's still cost us, but yeah, exactly. So yeah, let me do this. Yeah, that's right. And then this is the gap on decode between the memory and the compute time. Yeah. Yeah, interesting. Another interesting one would be why caches are so much cheaper? Yeah. Okay. So if I remember correctly, caches are like 10x. It's more expensive to write a 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 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 memory somewhere. So the cost ratio is really talking about the ratio between those two mechanisms for producing it, a cache missed, means you've deleted it from all your memories and you have to re-comput it on the tokens directly. In fact, you can maybe even take that a step further and think about which memory tier do you store? So you can 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 HBM. 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, having it after you've deleted it. So we rematerialize it. And so basically it is going to cost the length of the context. Actually, we'll look at cost per token so we don't need to carry around this length of context everywhere. So to rematerialize one token of KB cache, I just need to run I need to run a forward pass on the whole model. And then so there's going to be the computer. I have to rerun the compute and whatever speed my GPU does it. And then I multiply it by my like GPU dollars per second. I was very extremely naïve question. Why is there not a quadratic term? Yeah. So there is a quadratic term in it shows up in the compute. As an approximation, I chose to remove it. I will 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 is the flops that are coming from doing the weight matrix multiplies as a function of context length. And then there is the number of multiplies that comes from during the KB cache, which goes up linearly with the amount of stuff you attend to. The slope on this is so low that when you draw like this, it's very well approximated by a flat line. So it starts to, you start to notice the effect of the quadratic or the linear term up in the millions of tokens or so. So just not super relevant. So what is the reason that there's no company which has over a million token context length if there's this rule? Yeah. So there are two costs of long context. One is the memory bandwidth cost, which we've spent a lot of time analyzing. That's this thing. And then the other one is the compute cost. The compute cost is almost always and sort of actually forced by fundamental principles to be a much smaller slope than the memory bandwidth cost. And so the primary thing that limits you to have really large context memory bandwidth capacity, which is exactly this effect like. And so there's this idea that Dario said on the podcast and others have said, which is, we don't need continual learning for BGI in context learning is enough. And if you believe that, then you have to think that we had to get to 100 million token, 100 million billion context length to have an employee that is the equal into working with you for a month. Now, maybe that's no longer true, it's for us attention or something. Yeah. If you think that, then some ML info thing would have to change to allow for 100 million, like the memory bandwidth to allow for 100 million token context lengths. I mean, response attention gives you a get out for sure because you get this square root, like gives you a big improvement. But I think it's like, if you look at the history of context lengths of models, from like earlier models like GPT-3, maybe to GPT-4, I don't remember when the transition happened exactly, like they shot up from like about 8k to 100k to 200k. And then for the last year or two, they've all been hovering around there. I think that actually indicates that that's sort of the reasonably balanced cost point and going massively beyond that would be cost prohibitive. Not because of the compute cost, because the memory bandwidth cost, yeah. So, I actually don't see a very good path to solving that. The HPM is where it is. It's not getting hugely better. And why it isn't supposed to have to solve it? The space attention is a big improvement. Maybe that is priced in already, perhaps. It's not an infinite improvement because if you go to Spars, you'll lose too much quality. But yeah, I mean, the empirical result is that the context lengths haven't been increasing that much. And I think it's because there is no solution to the memory wall there. Like, so going to Spars just means like you're attending to a very small subterm of the tokens and the quality will get worse. So, what is the cost of these different ways of producing recenterizing the kV cache? The community 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. Storing HPM this really goes as my, I think I had a number here, which was the bytes per token. So, I need to, I need to just have some number of bytes per token. And then I need to store this in the HPM. So, it's going to use up some of my HPM capacity. So, a way to think of this is that like, if I have too many of these things sitting in my HPM, like if I fill up my HPM 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 HPM I'm using. So, there's also times cheaper your dollars. And then let's just do one more memory tier and say something like DVR, store in DVR instead. The same kind of thing goes up for flash and for DVR. 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 time to cost to retrieve. And then there's a cost to store. Cost to hold on. Yeah. And so, this is like, there's 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 to hold on. So, I will rewrite it. Okay. So, we have, this is the, like, if we're just storing it in HPM, it has this sort of cost profile. And then, if we store in DVR, it's actually going to take some time. So, it's, like, we get the same thing here, but it's, right, it's prototyped over a DVR capacity, times DVR 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 by token over DVR bandwidth, bandwidth. And then, this consumes some amount of the DVR as well. And every scale up has DVR and flash. There's really a deployment question. And so, you can choose that. In video, it does deploy in this form. It has, it has both. Whereas in the cost to retrieve HPM, the memory bandwidth, where the bytes have had been memory bandwidth. Yeah, I mean, it depends what, what you define a retrieve to be. Here, I'm defining a retrieve to be, move it into HPM so that you can start actually doing it. And so, like, sort of by definition. Because if it's already in HPM, you can be doing compute while you're getting it from HPM. 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 memory, different tiers in the memory hierarchy, you should expect as, as this cost goes up, this cost should go down. So, you can kind of see where the zeros are. And like, 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 the, all of this is like multiplied by the hold time. Yeah. This one is, and so is this one. And interestingly, they have different prices to write for, and is it you specify this in the API for five minutes versus an hour? Yeah, which suggests that the five minutes is HPM 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, - All right, and it's TDR, bro, so it's Flash, isn't it? - Yeah, okay, interesting. and the price difference I think was I'll look it up. Okay, so the base in Potokins is five per million tokens. Which means, yeah, that's five. This is five. Two to like, retrieve, quote-unquote. And then, to write to presumably HBM, write for five minutes is 6.25. So actually, we might actually be able to determine the, which memory territory it is by the durations, actually. The direction probably tells it to actually, it was six of 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 like, given that I know I'm going to be holding something for five minutes, I would like to have 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 was the memory. So if I take the storage capacity over storage bandwidths, I would like this to be equal to five minutes also. 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 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 calculation? This is the storage cap we're divided by the bandwidth. So you've got a bunch of different memory tiers, like we've listed four of them. Your choice, like your choice of which memory tier is like you want to minimize the cost. 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 you're using some fraction of the device to retrieve it. And so let's say I'm using like 10% of the device. And I wouldn't utilize those two fractions. That's the sign that I've hit 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. And then so this is the time hold. And then there's going to be some amount of time here, which is time retrieve. And I want, I mean, basically to equalize the costs, these two costs, I want the retrieval time to be equal to the whole time times the like fraction of capacity. Because like this is the retrieval time. Yeah, I mean, this is how many other things I can hold simultaneously. Yeah. Basically just like, hey, you want to, 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. Yeah. I think that probably indicates that this is the two tiers of fraction and spending disk. I'm kind of shocked to see spending disk being used at all because it's such an old technology. Yeah. Yeah. I mean, it's not so crazy that it's so slow that it takes an hour to load its full capacity to it. And like it's really on the structure of technology, but it's just full in some places. So we're sitting down because I want to ask you some questions that I guess don't need to play for it. 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 information how this piece of information changes what you should make of this other piece of information. And that has an extremely interesting point. I guess at a high level, the difference in what they're trying to do is sometimes they're trying to be 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 are 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. They are underage to make of that. Yeah. So I mean, like the mixing, like I tried 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 at this way and then stir at this way is like actually not too bad of an approach. But beyond that, like in 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 cryptographer, like a cypher 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 integral 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 the, and sort of 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 binary, whereas neural nets run like in theory and 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 encryption analysis. And like basically what it says is that if you take a small difference of the input, how like it's quite difficult to make the difference of the output be small, like like the whole job of a well designed cypher is to be the difference in output pretty large. So I guess the distinction is that the optimization goals at that point are about complexifying. They don't have the same residual connections or like layer norms. Yeah, I mean, I guess a place where the the two merge is back doors. Okay, so with the back door no 11, you're trying to hide. What do you consider an input? It's not an input into the forward pass, but it's 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. Yeah, yeah, yeah, yeah. So yeah, 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? Or 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 like undesired case and we can neural nets for sure. Yeah. Okay, so I was asking you has have neural networks actually been used for cryptography and you realize it might be better to just do this in the blackboard. Yeah. So I'm curious. Are they actually being used for cryptography? Yeah. So using neural nets for cryptography, well, in general, cryptography like creating a new cipher is a very, very dangerous proposition. Like almost all of them are broken, like 99% of them are broken. So probably a bad place to start, but the other direction has been very like in at least one very clear case, quite productive. So there is this construction in, so a construction that exists in ciphers and then was imported into neural nets called a Fistle cipher, Fistle network. So the idea is that you may have some some some function F, which is not incredible. But you like the function because it like does interesting things like it, it does, it doesn't MLP, for example, or it mixes in an interesting way. You'd like to build something out of this that is invertible. So the construction we're going to make is going to actually be a true input function rather than a one input function. And we're going to apply F of X. We need to actually remember what X was. So we're going to stick X over here so that we can work backwards. And then we also can't drop Y. So we're going to remember Y, and we're going to add them together. And so we form this tuple. So the the way to invert this, like if you think I have this output and I want to recover X and Y, well, I can easily recover X. That's right there. I just read it off. And then to recover Y, I like if this thing was called Z, I can recover Y by Z minus F of X because I've already recovered X. So that means that this construction is invertible. This was used in Cypher's, like a ton, still is used. It's one of the main mechanisms of constructing Cypher's, often you want Cypher's to be invertible, especially the layers of Cypher's, you want to be invertible because that has been hercaptographic properties. This has actually been floored over into neural nets. There's a 2017-18 paper called Rev Nets, Reversible Networks. And what it does is it actually makes the entire, like you can apply it to any network, like a transformer network. You can make, I do it forwards pass, but then I can actually run the entire pass backwards as well. So the whole neural network is invertible. With exactly this construction. And so this paper reversible networks, like applied to some layer, like a transformer layer, for example, we've got this function F, which is our transformer layer. Now normally we would have just an input and then a residual connection coming out. I think it's added like this over here. But now the variation of this is going to be we've got two inputs x and y. So we've got x and y inputs, x goes through the function, gets added to y. And then this becomes the new x, the output x. And then this x becomes the output y. So really what this is doing, this is like this is actually sort of doing, if you think of two layers back, this is actually the thing you mentioned before. It's actually doing the residual connection for two layers back, like this y came from the previous layer and what's the residual connection there. But because of this construction, the whole thing is invertible. Why do I care? What does invertible matter for? The big thing that it can be interesting for is for training. If I think of a forward pass of training, so I will, let's say I have four layers, I run them in zero, one, two, three, order. I have to write all of the activations to hbm. And so I get an hbm footprint here that is kind of like linear, linear in a number of layers. So this actually can be the largest memory footprint during training. And so this is normal training. And then I run the backwards pass, and I read it kind of in reverse, like I run them sort of forward pass goes forward, backward pass, backwards, backwards, and I have to read the back out. The idea of this Revanette's paper is that 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. So I run my forwards pass. And then when I'm running my backwards pass, I'm simultaneously in lock step, undoing all of the forwards pass steps that I did in order to have the activations that I need here. So this ends up being a memory saving, which is an idea. Interesting. And in some sense, you're spending more compute to save memory. That's right. Interesting. 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. Interesting. Cool. That's 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. Thanks.

Podcast Summary

Key Points:

  1. Batch size is the primary driver of latency and cost in AI inference, with optimal batch sizes around 2,000 tokens due to a balance between compute and memory bandwidth.
  2. The latency of inference is bounded by memory bandwidth (for fetching weights and KV cache) and compute throughput, with the cost per token decreasing as batch size increases due to amortization.
  3. Sparse models (e.g., Mixture of Experts) reduce compute needs but increase memory usage and require larger batch sizes to maintain efficiency.
  4. A key insight is that optimal batch size depends primarily on sparsity (ratio of active to total parameters), not model size, and is roughly 300× sparsity.
  5. Communication overhead between GPUs in a rack limits scaling; all-to-all communication in MOE layers creates a bottleneck, especially across rack boundaries.
  6. Rack interconnects (scale-up links) are 8× faster than scale-out links, making intra-rack deployment more efficient.
  7. Pipeline parallelism across racks reduces memory pressure per rack but does not improve inference latency. It is neutral in inference but introduces micro-batching trade-offs in training.
  8. The physical architecture of data centers (rack design, bandwidth, cable density) directly constrains AI model scaling.
  9. The rise of large-scale models (e.g., 5T parameters) depends on scale-up domains with sufficient memory and bandwidth to store KV cache and weights for large batches.

Summary:

Reiner Pope presents a detailed analysis of AI inference efficiency using a "blackboard lecture" format, focusing on batch size, compute, and memory bandwidth as core factors. The key insight is that batch size determines the trade-off between latency and cost: larger batches reduce cost per token through amortization of weight and KV cache fetches, with an optimal batch size of approximately 2,000 tokens driven by the ratio of active to total model parameters (sparsity). This balance occurs when memory bandwidth and compute time are equal, and the result is remarkably consistent across models.

Sparse architectures like Mixture of Experts reduce compute load but increase memory demands and batch size requirements. Communication limits significantly impact scalability—especially across racks, where inter-rack links are 8× slower than intra-rack links, making full connectivity within a single rack preferable. Pipeline parallelism across racks reduces memory per rack but offers no latency benefit in inference and introduces training complexity due to micro-batching.

Ultimately, the physical constraints of data center design—such as cable density, power, and cooling—limit how far AI models can scale. The analysis shows that cost and performance are fundamentally tied to hardware architecture and model sparsity, with large-scale inference requiring massive scale-up domains to store weights and KV caches efficiently. This explains why leading AI providers invest heavily in rack-level and interconnect innovations.

FAQs

Faster responses are achieved by increasing batch size, which reduces latency. Larger batches allow better hardware utilization and amortize memory costs. Paying more enables faster processing because the system serves more users simultaneously, cutting per-token latency.

No, because the hardware and memory bandwidth are physical limits. Beyond a certain batch size, compute time becomes the bottleneck. Doubling or multiplying cost won’t yield faster speeds due to diminishing returns and hardware constraints.

Theoretically yes, but it wouldn’t significantly reduce cost. Each inference is unique, and KV cache and weight fetches aren’t shared across batches. Slower processing doesn’t reduce cost per token, as the fundamental cost is tied to compute and memory usage.

The optimal batch size balances compute and memory bandwidth. It’s approximately 300 times the sparsity ratio of the model. For example, with 32 active experts out of 246, the batch size is around 2,000 tokens, which minimizes cost per token.

Sparsity reduces active parameters, lowering compute cost. However, it increases memory usage per batch and may degrade model quality. Beyond a point, performance drops faster than compute savings, making the trade-off inefficient.

Large models have massive weight matrices and long context lengths, requiring frequent memory access. The KV cache grows linearly with context length, making memory bandwidth a critical bottleneck in inference speed and cost.

Chat with AI

Loading...

Pro features

Go deeper with this episode

Unlock creator-grade tools that turn any transcript into show notes and subtitle files.