How Inference Keeps Up with Our Insatiable Need for Tokens — Cerebras & Gimlet Labs

AI Engineer · 22 min · 241 sentences · from YouTube's caption track

Each timecode opens YouTube at the start of that sentence. Line anchors (#s42) are the cue ids in the WebVTT, and every line carries its start and end seconds. All transcripts has every talk, and the whole corpus as one file.

  1. 00:01[music]
  2. 00:12Hello everyone.
  3. 00:13My name is Daniel.
  4. 00:14I work on AI and AI agents here at Cerebras.
  5. 00:18What's your name?
  6. 00:19I'm Michelle.
  7. 00:20I'm a co-founder at Gimlet Labs where we're building a multi-silicon neo cloud to optimize inference at every layer of the stack.
  8. 00:28And we're really excited to bring you our talk, all the things we have to do to satisfy your insatiable need for tokens.
  9. 00:36As you know, AI spend is going kind of bananas right now.
  10. 00:39With this year we're slated to spend $765 billion on compute and in 2031 up to $1.6 trillion.
  11. 00:49The frontier labs are having a mad dash to secure as much compute as possible to buy across hardware vendors to do both training for the frontier models as well as to serve all of their users.
  12. 01:03And all of their compute is going to satisfy everyone's insatiable need for tokens.
  13. 01:09Google at their IO last year said that they were serving 480 trillion tokens per month.
  14. 01:15And last month they said that it jumped up to 3.2 quadrillion tokens per month.
  15. 01:21So all of this is happening at the same time as models are getting cheaper and faster.
  16. 01:28Lama 3.37 B when it was first released compared to now is now 25% cheaper whilst still being 3.6 times faster.
  17. 01:37So in today's talk we're going to talk about two things.
  18. 01:41One, what have we done so far to optimize inference to make it cheaper and faster.
  19. 01:46And what does the road map look like to juice perf and throughput even further?
  20. 01:52So to do this, let's take a little bit of a time jump to 2022 and learn about all the optimizations that led us to the point we're at now and hopefully what the future looks like.
  21. 02:03So, LLMs produce tokens one at a time in something called an auto-regressive loop.
  22. 02:10So, to generate one additional token, you need to read all of the weights from memory into compute.
  23. 02:17So, most of the time, the computer is sitting idle.
  24. 02:19It's just waiting for memory to be able to stream in all the weights necessary to do the compute itself.
  25. 02:25So, up to 90% of the time, the computer is just sitting there waiting on memory to load.
  26. 02:29So, how can we figure out how to optimize this so there's less idle time and you can make full advantage and serve tokens faster?
  27. 02:37So, what you can do is throw more compute at the problem.
  28. 02:40So, instead of streaming in the whole set of weights, what if you could split up the entire model into four and have each GPU take care of a fourth of the model each?
  29. 02:50Then, you could reduce, in theory, the amount of time it takes to serve a single token by four times.
  30. 02:56However, you have to pay a tax if you want to do this.
  31. 02:59Before the attention block and then the F So, after the attention block and then the FFM block, you have to do something called all-reduce, where you take each of the individual calculations from each GPU
  32. 03:10and you combine it all together.
  33. 03:12So, you can actually get a calculation because each of the GPUs doesn't have the whole picture.
  34. 03:16It only does 1/4 of the model.
  35. 03:18So, you need to do this across every layer twice, which can lead to only getting 2x speed up for getting 4x the amount of compute that you add on.
  36. 03:27If I were to graph this in a pretty graph, um you can see that throwing more GPUs at the problem does get you faster tokens, but it requires exponentially
  37. 03:37more energy to serve a single token as you put in more compute at the problem because of the communication overhead we just talked about.
  38. 03:45So, if we flip the Y axis here so it's throughput, you can see that this resembles something like a Pareto frontier, where you can see that you have to make some kind of sacrifice between throughput and speed
  39. 03:56when you're an inference provider.
  40. 03:58A great example of this is Claude code fast mode, where you can spend, I think, 6x the amount of tokens to serve a single token compared to regular Claude for twice the speed.
  41. 04:08So, for that product, they're really optimizing towards the right of the Pareto frontier, where they're getting the speed, but at the cost of not being able to serve as many tokens.
  42. 04:18So, during today's talk, we're going to talk about what are the innovations we have done in the past and in the future to be able to shift the Pareto frontier to the right.
  43. 04:27So, you all already know from our previous slides that to generate each token, you have to read the whole model.
  44. 04:34So, what if we could spend one pass that we already paid for to serve multiple requests?
  45. 04:40So, that is where the idea of batching and continuous batching comes in.
  46. 04:45The idea of batching is when you take a weight read that you've already done and be able to serve multiple user requests.
  47. 04:53However, the problem, though, is that some of these requests are longer than others, which means that there's all of these idle periods in the compute where nothing is happening.
  48. 05:02So, how can we solve this problem and squeeze out more performance?
  49. 05:06That's where continuous batching comes in.
  50. 05:09So, the idea here is that for every single idle slot, you slot in a new user request to be served during that same weight read to be able to serve as many requests as possible.
  51. 05:20However, this does come with a slight downside because every single token when you do inference requires you to save something into the KV cache because that's how the attention block works.
  52. 05:31You need to understand how every single token, like what the K and V vectors are.
  53. 05:37This can add up very quickly.
  54. 05:39So, if you are running a coding agent with very long context, for example, 128k context, you're going to save 42 gigabytes of KV cache that is needed to serve that individual request.
  55. 05:50So, the rule of thumb here for a 70 billion parameter model is that for every 3,000 tokens, you need 1 GB of additional KV cache.
  56. 05:57And that's for one user request.
  57. 05:59So, imagine you're doing batching and you're doing like eight different requests at the same time, then your KV cache is going to explode and you will not have enough memory to be able to serve all of your requests.
  58. 06:09So, what are some of the innovations we have done to be able to optimize how we use memory?
  59. 06:13So, that's where paged KV cache comes into play.
  60. 06:18So, how traditionally KV cache worked was that you would have physical memory that you would reserve to make sure that you could have enough room to be able to store all of the KV information
  61. 06:28from each request into memory.
  62. 06:30However, this came with a downside and a lot of inefficiency because you would just have a lot of memory blocks that would be reserved but wouldn't actually be used.
  63. 06:39So, the idea with a paged KV cache is we use something that's similar to like an OS or a virtual machine where you provision a whole memory block that's all virtual and you can store wherever there's free space
  64. 06:51KV cache for each request.
  65. 06:53So, this allows you to serve three times more requests than not having a paged KV cache and just doing what was before.
  66. 07:00And this really reduces the amount of wasted space where you are reserving memory slots without actually using them.
  67. 07:08This was right after followed by an innovation called prompt caching.
  68. 07:13So, the idea here is that if you have a coding agent or if you have a chat app that has a very long system prompt, you don't actually have to recalculate
  69. 07:22the KV cache needed every single time you have a request.
  70. 07:25What you can do is you can reuse the KV cache that you calculated already for the previous request for the next request.
  71. 07:31That way you can just pick up where you left off.
  72. 07:34Here, you can skip the very, very time-consuming prefill phase.
  73. 07:39And you might be wondering, what is prefill?
  74. 07:42So, during inference, you can split up what happens into two major phases, prefill and decode.
  75. 07:48So, the prefill phase consists of all the things that happen once the request arrives, and then ends when the first tokens gets generated.
  76. 07:57And here, you can see this when you type something into ChatGPT, and then it takes a couple seconds before it starts returning the first token, and then it goes kind of like
  77. 08:05smoothly from there.
  78. 08:06So, what's happening during the first couple of seconds where it's not returning anything is that it's computing K and V vectors for every single prompt token that you've inputted
  79. 08:15and produces the first output token.
  80. 08:17This is very compute bound because you can optimize the hell out of this.
  81. 08:20You can parallelize this extremely.
  82. 08:24However, after the first token is generated, what happens is uh that you decode one token at a time, reusing the KV cache you just built in the prefill phase.
  83. 08:33So, this is more reliant on memory.
  84. 08:36The reason I'm talking about this is because something happened lately that's really messing up a lot of inference pipelines, which is super super token hungry coding agents.
  85. 08:46So, let's say you have a coding agent that's using 200K context or 500K context or a million context, right?
  86. 08:51What happens is that it starts to clock up the pipeline.
  87. 08:54While prefill is running, no other prefill or decode request can get through.
  88. 08:59So, this is kind of catastrophic if you have a bunch of people that are sending in coding requests and a couple people that are just trying to figure out like math
  89. 09:06problems in chat mode.
  90. 09:09So, to avoid this clogging problem, there is an innovation called chunked prefill that kind of goes and solves this problem.
  91. 09:17And the idea is quite simple here.
  92. 09:20The idea is taking a very long piece of prefill, chopping it up into smaller bits, so you can interleave in different decode and prefill requests.
  93. 09:28That way, there's not one thing that's taking up a bunch of time and clogging the whole pipeline.
  94. 09:33So, now Michelle, tell us more about what else we can optimize.
  95. 09:38Yeah, so all of the optimizations that Daniel just talked about are run time level optimizations.
  96. 09:43So, that explains we explore how we make inference more efficient within a single worker.
  97. 09:49But, in order to to keep pushing that frontier, we really need to start looking at system level optimizations, which is how can we distribute these workloads across many different workers.
  98. 10:00And so, the first thing to recognize there is that every request is different.
  99. 10:04So, take for example a summarization use case.
  100. 10:07You're throwing the LLM a bunch of different documents, and you just really want a single question answered.
  101. 10:13And so, this workload is going to have a long prompt and short answer.
  102. 10:17And so, it's a dominated by that prefill phase, and so therefore compute bound.
  103. 10:22On the other hand, you might have a case where it's the opposite.
  104. 10:25Let's say you want to write a long story or book, you just want to pass it a few themes for it to go off of.
  105. 10:31And so, this is going to have a short prompt and long answer.
  106. 10:34And this is going to be dominated by decode because you have so many output tokens compared to the number of input tokens coming in.
  107. 10:41And this is going to be memory bound.
  108. 10:43And finally, you can have a case that's somewhere in the middle, right?
  109. 10:46It's both a long prompt, long answer, and you're seeing here that both the prefill and decode phases and therefore compute and memory both matter.
  110. 10:54And by looking at these different examples, you can really see that the resource requirements that you have for your hardware, it's pretty different depending on what your workload looks like.
  111. 11:04And so, how do you prevent yourself from getting, you know, bound by compute, bound by memory?
  112. 11:10And so, one way to do that is called disaggregation.
  113. 11:13So, splitting up your workload to different worker nodes.
  114. 11:17And so, the most common form is called prefill decode disagg, where you're actually splitting and disaggregating this workload by phase.
  115. 11:26And what that allows you to do is essentially have two pools.
  116. 11:29So, you have your prefill pool, that's going to be running the prefill part of your workload.
  117. 11:33The decode pool, that's going to be running the decode part of your workload.
  118. 11:36And taking the summarization use case for example, you know, you're going to want to scale up that prefill pool so you're not blocked by the compute and scale down your decode pool because
  119. 11:46you don't want to waste resources when you just really don't have that much decode work to do.
  120. 11:51And it's nice cuz now you can scale all these independently and neither part is stalling the other.
  121. 11:59And we can take that one step further, right?
  122. 12:01We said before, prefill, that workload itself is inherently bound by compute.
  123. 12:05Decode, that is bound by memory.
  124. 12:07And just walking through that really quickly again, the reason for that is as you're doing decode, you're stepping through each of these tokens one by one and for every decode step, you're re-reading
  125. 12:17the entire KB cache, right?
  126. 12:18That's going to be memory bound.
  127. 12:21So yeah, um the the thing that Michelle just said about this being memory bound, this can be clearly seen by what the hardware can actually do.
  128. 12:31So GPUs, right?
  129. 12:32Um the the speed at which you can transfer data from memory into compute is limited by something called memory bandwidth.
  130. 12:39So for an H100, this looks like 3.35 terabytes per second.
  131. 12:43However, Cerebras has 7,000 times the bandwidth of a H100 with 21,000 terabytes per second.
  132. 12:50This is because we have a very specialized SRAM based memory architecture on our chip.
  133. 12:56So this really means that Cerebras is really built for decode.
  134. 12:59So we can serve tokens at 3,000 tokens per second versus an H100 serving it at 600 tokens per second for decode.
  135. 13:08So we're really excited to partner with AWS to productionize this.
  136. 13:12So we are going to partner with AWS Trainium so they can serve prefill using their AWS Trainium chips, use their EFA service to transfer the KB cache to our Cerebras CS-3 systems
  137. 13:23to finally serve the the token.
  138. 13:26So this will lead us to give us 5x high-speed token capacity in the same footprint.
  139. 13:30So, this is one of the things that we're doing to try to make fast inference more accessible and cheaper for developers.
  140. 13:36So, we're really excited to really pursue this partnership.
  141. 13:39And at Gimlet, we're really generalizing that beyond just training them and Cerebras.
  142. 13:44What Gimlet is building is essentially a multi-silicon inference cloud, which takes your workload, breaks it down into finer-grain pieces, determines the resource characteristics of all of those different pieces,
  143. 13:55and then figures out the best way to map it to the underlying hardware, where that hardware can be really anything, right?
  144. 13:59Nvidia, AMD, Trainium, Cerebras, D-Matrix, Intel Gaudi.
  145. 14:03The list goes on and on.
  146. 14:05And by running those tasks on the machine that is most efficient for running it, we're actually seeing pretty crazy results.
  147. 14:11So, we're seeing three to 10 times faster inference compared to homogeneous systems that have the same power budget.
  148. 14:18And this is diving into more than just the pre-full decode disaggregation than before, and some of those techniques are, for example, disaggregating based on model instead of on phase.
  149. 14:29And so, that's called speculative decoding.
  150. 14:32So, just reviewing again the decode phase, typically you do a forward pass for each of the decode tokens that you're getting out.
  151. 14:39And that's the standard way of doing it.
  152. 14:41What speculative decode is is that you essentially have a draft model.
  153. 14:45And this is just a smaller form of the full model that um can generally approximate the results that you get out of it.
  154. 14:52And the nice thing there is because it's smaller, it runs a lot more quickly and also uses less resources.
  155. 14:57And so, in speculative decode, what you can do is, in order to get, you know, the nine next tokens, you will essentially run the decode on that draft model first.
  156. 15:06It's going to give you back what is called candidate tokens.
  157. 15:09So, you're not 100% sure all these tokens are right, but because, you know, often these have been fine-tuned or been trained off of the full model, it's it's approximately right.
  158. 15:18And you want to validate, okay, are these the tokens that I actually want to output?
  159. 15:22And so you'll actually run the next phase on that full model that's called the verify stage to validate, okay, which of these tokens are correct?
  160. 15:30And essentially you can keep doing this until, you know, you've validated all these tokens from the draft model.
  161. 15:35And at the end of the day you can see here on the top, the standard way of running it, you needed to run that forward pass on your full model nine times to get those nine tokens.
  162. 15:44On the other hand, with speculative decode, you actually only needed to run it three times on that full model.
  163. 15:49And if you can get that draft model to run really, really quickly, then that time is minimal and you can really shorten the amount of time it takes to get your tokens.
  164. 15:59And looking at some more concrete results, so this is essentially that Pareto frontier that Daniel was showing earlier where x-axis is the speed at which you're getting the tokens and the y-axis
  165. 16:09is the throughput.
  166. 16:10And so the baseline case we're comparing to here is prefill decode disagg across homogeneous GPUs.
  167. 16:16And you can see that, you know, throughput is pretty good, but as soon as you're pushing on that speed, that throughput drops pretty drastically.
  168. 16:23So what if you then run speculative decode across those same GPUs?
  169. 16:27So now you're running that draft model and you're able to see you're able to get that curve to the right.
  170. 16:32And the reason for that is because you're running the decode on that full model less times.
  171. 16:37But we can push that even further, right?
  172. 16:38Like going back to our theme of running those workloads on the hardware that can run it best.
  173. 16:45On something such as, you know, D Matrix or Cerebrus where you're able to run small models very, very quickly, you see drastic performance improvements.
  174. 16:53So here this is where you're seeing those numbers for that same throughput, right?
  175. 16:57You're able to get 10x the interactivity compared to if you're just running it on homogeneous machines.
  176. 17:05The final form of disagg we wanted to talk about is called attention FFN disagg.
  177. 17:09And this one gets pretty exciting when you think about serving large models.
  178. 17:13And I'm saying like 3 trillion parameter models where these models are so large that even just running one layer, it can be pretty resource-intensive.
  179. 17:22And so the concept is essentially the same thing, right?
  180. 17:24Like for that particular task that you need to do, whether it's that attention layer or the feedforward FFN network layer, then you are essentially trying to figure out, okay, what are the resource characteristics,
  181. 17:35then what is the best hardware to map it to?
  182. 17:37And so the attention layer, that's going to be more memory bound.
  183. 17:39It's doing a lot of KB cache accesses.
  184. 17:42The FFN layer, that's doing a lot of dense matrix multiplications.
  185. 17:45And so then it makes sense, right?
  186. 17:46You're going to run the attention on the machine that has memory bandwidth, the FFN layer on the machines that can run those matrix multiplications as quickly as possible.
  187. 17:55And essentially what happens here is even within the model, you're ping-ponging across, you know, many different machines in order to to get the inference from that model and just really disaggregating every single layer.
  188. 18:08And one thing that we really wanted to note here is that there is no best form of disagg.
  189. 18:12There is actually no best hardware.
  190. 18:15It really depends on the tradeoffs that you have for, you know, depending on what your model is, your workload, and what you need for latency, and what you need for throughput guarantees.
  191. 18:26And as we look towards the future, we see that agents are only becoming more and more incorporated into our everyday life.
  192. 18:33It's incorporated into our work.
  193. 18:35Everyone is using it.
  194. 18:36And it's continuing to push that need for more and faster tokens.
  195. 18:40Yeah, it's really getting geared to the right.
  196. 18:42I
  197. 18:42[laughter]
  198. 18:42told Daniel not to say that.
  199. 18:46But the good thing about this is that even though, you know, this seems like a crazy crazy target, we can actually use agents to help us solve these problems and keep pushing the frontier.
  200. 18:56And so one of the things that we're doing at Gimlet is actually using an agent to generate optimized kernels.
  201. 19:01Especially for our use case where we want to support such a wide range of different kinds of hardware, we need to figure out how do you make that problem a lot more tractable.
  202. 19:09Cuz right now, how people generate and how people optimize kernels is that there's a lot of people sitting there hand tuning and figuring out how to optimize these kernels.
  203. 19:19And the thing is that these optimizations can vary pretty drastically based on you know, the model that you're trying to run, the hardware that you're running on, even within generations of the hardware,
  204. 19:29and you know, the workload shape itself.
  205. 19:31And so what we do at Gimlet is we built KForge, which is an agent for generating these kernels.
  206. 19:36It takes in a bunch of information like your hardware profiles, your workload profiles, basically anything that you can use to figure out how to optimize kernels and we solve it as a brute force problem, right?
  207. 19:47And so here's an example, right?
  208. 19:49We have a forward pass and the kernel that um KForge optimized from it.
  209. 19:54And we're seeing pretty interesting results.
  210. 19:56So last week, you know, we were running the agent for probably less than the span of a week and within that time it was able to speed up GPT-OSS-120B
  211. 20:04on AMD hardware by 33% end-to-end.
  212. 20:07And the interesting thing to note here is that this is building on top of kernels that have already been optimized.
  213. 20:15And you can go and take, you know, agents to the next level and use them to help us build and design custom silicon that is hyper tuned for specific models or your specific workload.
  214. 20:27This can then be used to train even better and smarter and faster AI, which then can also be used then to design the next generation of that custom silicon.
  215. 20:35And you know, this loop keeps going on and on and it's a recursive loop.
  216. 20:38Like shout out to the folks at Recursive.
  217. 20:42And I want to end the talk by saying that we're just getting started in our journey to optimize throughput and speed on inference.
  218. 20:51Because at the very top of the stack, you don't think really about inference optimization when you talk about like incident response, right?
  219. 20:58But when you have agents that are making our systems much more reliable and increasing uptime, we're getting more throughput and we can get more tokens.
  220. 21:06Or you can apply agents to the problem of bringing up models.
  221. 21:09As soon as a model drops on the market, getting it running on all the different kinds of hardware on day one.
  222. 21:15You can even go a little bit crazier with compilers.
  223. 21:18Imagine a world where an inference that can be custom-built for your workload and the model that you're running.
  224. 21:24This is already being demonstrated by folks at Anthropic, right?
  225. 21:27That built a compiler in 2 weeks.
  226. 21:29So, I think there's a lot of optimizations that you can do when you're building just-in-time custom software to support the model you want to run, on the workload you want to run, on your custom hardware.
  227. 21:39And referring back to the previous slide, using agents to continue to help us to build, you know, more custom silicon and helping speed up the tape-out process.
  228. 21:49And finally, this is the non-very technical part, but all of the things that surround what takes to serve inference.
  229. 21:55All the procurement, all the legal, all of the things that are in the back office.
  230. 21:59All of these things combined with agentic workflows are able to be optimized.
  231. 22:04So, when we do all of this, I'm really optimistic about the future and all the things we can accomplish to serve tokens faster and cheaper.
  232. 22:11So, next slide, please.
  233. 22:13Thank you so much for coming to our talk.
  234. 22:15Uh we are working both very, very hard to give you faster and cheaper tokens.
  235. 22:19And yeah, let us know if you have any questions.
  236. 22:21We'll be around after the talk.
  237. 22:22Yeah, and go eat tokens.
  238. 22:24We're making more tokens for you so you can also generate GIFs like this.
  239. 22:27Yeah.
  240. 22:28[laughter]
  241. 22:44[music]