YouTube2Text

AI Infrastructure Explained (GPUs, vLLM, and LLM-D) — Transcript

by KodeKloud · 9,360 words · 1,376 segments · language en · Watch on YouTube

Full transcript

  1. 0:00This is an introduction to the
  2. 0:02infrastructure behind AI, which means
  3. 0:04the GPUs, the servers, and the systems
  4. 0:07that sit behind every product you've
  5. 0:09ever used. If you're an SRE, a systems
  6. 0:12administrator, or a DevOps engineer,
  7. 0:14this course is for you. And there's
  8. 0:16never been a better time to learn it.
  9. 0:19Companies like Amazon, Google,
  10. 0:20Microsoft, and Meta together are
  11. 0:22spending over $700 billion on AI
  12. 0:25infrastructure this year alone. That is
  13. 0:28four times what they were spending just
  14. 0:304 years ago before ChatGPT launched, and
  15. 0:32it grew nearly 80% in the last year
  16. 0:35alone. McKinsey expects close to $7
  17. 0:38trillion to go into data centers by
  18. 0:402030. Now, somebody has to build all of
  19. 0:42that and keep it running, and the people
  20. 0:44who can are some of the most
  21. 0:46sought-after engineers in the industry
  22. 0:48today. So, let's start with a question.
  23. 0:51What actually happens when you type
  24. 0:52something into ChatGPT and press enter?
  25. 0:56Behind that answer is a solution that is
  26. 0:58unreasonably hard to build. And in this
  27. 1:01course, we're going to take that
  28. 1:02solution apart piece by piece. So, we'll
  29. 1:05start with a single GPU and build it up
  30. 1:07into a real model server. We'll learn
  31. 1:09how a model writes its answers one word
  32. 1:12at a time, and we'll find the hidden
  33. 1:14cache that makes it fast. Then, we'll
  34. 1:16pack many users onto one GPU, and we'll
  35. 1:18split models that are too big for any
  36. 1:20single card across several of them, and
  37. 1:23we'll see why ordinary load balancing
  38. 1:25falls apart the moment you run a cluster
  39. 1:27of GPU servers. We'll see how LLMD
  40. 1:31LLMD is an open-source project that's
  41. 1:34built by companies like Red Hat, Google,
  42. 1:36IBM, and Nvidia, and its job is to run
  43. 1:39the whole fleet of servers, routing
  44. 1:41every request to the right server,
  45. 1:43moving caches around, sharing the GPUs
  46. 1:45fairly, and scaling them down when
  47. 1:47traffic stops. Now, you don't need any
  48. 1:49machine learning background for this. If
  49. 1:51you can follow a request through a
  50. 1:53system, you can follow everything in
  51. 1:55this course. My name is Mumshad Man Robb
  52. 1:57I'll be walking you through this course.
  53. 1:59And this is the part of AI that nobody
  54. 2:02shows you.
  55. 2:05So, you open ChatGPT, you type in a
  56. 2:07question, you hit enter, and a moment
  57. 2:09later an answer comes back. Now, let's
  58. 2:11pull that apart, starting with the name,
  59. 2:13because the name is really two things
  60. 2:14stuck together. So, you have the chat
  61. 2:16part, which is the application, that's
  62. 2:18the website, and the GPT part is the
  63. 2:20model, which is the thing that's behind
  64. 2:22the scenes, that's actually reading your
  65. 2:24question and working out the answer.
  66. 2:27And GPT is only one model. There's
  67. 2:29Claude from Anthropic, Gemini from
  68. 2:30Google, and Llama from Meta, along with
  69. 2:33plenty more. Now, they have different
  70. 2:34names, but the same idea sits underneath
  71. 2:36all of them, which is a model doing the
  72. 2:39thinking with an application wrapped
  73. 2:41around it.
  74. 2:42But, what is one of these models? And
  75. 2:44before we get technical, let me show you
  76. 2:45the simplest possible version of a
  77. 2:47model. So, forget about AI for a second.
  78. 2:50Picture a tiny machine where you drop a
  79. 2:52number, and and a different number comes
  80. 2:54out. You drop in three, and out comes
  81. 2:56six. You drop in 10, and out comes 20.
  82. 3:00Every time it doubles whatever you gave
  83. 3:01it.
  84. 3:02That little machine is a model. It takes
  85. 3:05an input, it does some math, and it
  86. 3:07hands you an output. And the whole
  87. 3:09behavior, the doubling, comes down to
  88. 3:11one number hiding inside it,
  89. 3:13which is times two.
  90. 3:15So, if you look closely, there are
  91. 3:17really two things in that one line.
  92. 3:19First, there's the formula, which is the
  93. 3:21shape of the calculation, an
  94. 3:22[clears throat] input, a multiply, and
  95. 3:24an output.
  96. 3:25That part is fixed, and it's the
  97. 3:27structure.
  98. 3:29Second, there's the number sitting
  99. 3:30inside it, the number two, which is the
  100. 3:32part the machine actually learned. That
  101. 3:34number has a name, and we call it a
  102. 3:36weight.
  103. 3:37So, you change the weight from two to
  104. 3:39three, and the very same formula now
  105. 3:41triples instead of doubles. So, it's the
  106. 3:44same structure with a different number
  107. 3:46and completely different behavior.
  108. 3:48Now, one weight and one multiplication
  109. 3:50won't get you very far. So, let's make
  110. 3:51it do something real. So, you want to
  111. 3:54guess the price of a house. A house has
  112. 3:56few things that you can measure, like
  113. 3:58its size, how many bedrooms it has, and
  114. 4:00how old it is, and each one pushes the
  115. 4:02price by some amount.
  116. 4:04So, it's still just multiply and add,
  117. 4:09the same math as doubling the box, but
  118. 4:11now there are several weights. So,
  119. 4:13there's 350,000,
  120. 4:141,000, 25,000. Each weight says how much
  121. 4:19that one thing matters. And where do
  122. 4:21these numbers come from?
  123. 4:22You don't make them up. You show the
  124. 4:24formula thousands of real houses with
  125. 4:26their sizes, bedrooms, ages, and the
  126. 4:28price each one actually was sold for,
  127. 4:30and it works out the weights that fit
  128. 4:32best. So, that working out of the
  129. 4:35weights from examples is what training
  130. 4:37is. So, now the picture is clear because
  131. 4:40a model is a formula, and its weights
  132. 4:42are numbers that are learned from
  133. 4:44examples.
  134. 4:46Now, we just keep going. A house price
  135. 4:48needed a handful of weights, but
  136. 4:50understanding a sentence needs far more
  137. 4:52than that because language is far more
  138. 4:54tangled than just bigger houses and
  139. 4:56higher prices. So, the formula grows.
  140. 4:58So, you get more inputs, more
  141. 5:00multiplications, and more weights.
  142. 5:02That's all stacked in layers where the
  143. 5:04output of one becomes the input of the
  144. 5:07next. Now, if you keep growing that, and
  145. 5:09in one very particular arrangement, you
  146. 5:11arrive at the shape behind every modern
  147. 5:14language model. And that shape has a
  148. 5:15name, and it's called the transformer.
  149. 5:18Now, don't worry about how it works
  150. 5:19inside because what matters is what it
  151. 5:21is. So, it's the same idea as doubling
  152. 5:23the box with inputs, multiplications,
  153. 5:25weights, and an output. It's just that
  154. 5:27it's enormous and wired in a specific
  155. 5:30pattern. So, the transformer is the
  156. 5:32formula. It's written once in code, and
  157. 5:35it's broadly the same across GPT,
  158. 5:37Claude, and LLaMA.
  159. 5:39What makes each of them different isn't
  160. 5:41the formula, it's the weights.
  161. 5:44Which brings us to the The part. The
  162. 5:46formula, the transformer, is only a page
  163. 5:48of code, and all of the knowledge is in
  164. 5:50the weights. A real model doesn't have
  165. 5:52four weights or 400, because it has
  166. 5:55billions of them. And these billions of
  167. 5:57numbers are what training produced, and
  168. 5:59they have to live somewhere, so they sit
  169. 6:01quite literally as a file on a disk.
  170. 6:04It's simply a very large file that's
  171. 6:06full of numbers waiting to be poured
  172. 6:07into the formula. And if you open one
  173. 6:09up, that's all genuinely that you would
  174. 6:12see inside.
  175. 6:14And they come in wildly different sizes.
  176. 6:15So, a small model may be 2GB in size. A
  177. 6:17mid-size model may be 16GB. A large
  178. 6:21model with 70 billion parameters would
  179. 6:23be 140GB.
  180. 6:25And the giants, like 500 plus billion
  181. 6:27numbers, uh would be several hundred GB.
  182. 6:30To actually use one of these files, you
  183. 6:32load it off the disk into a memory, and
  184. 6:34you hand it your question as input, and
  185. 6:37you let the formula run all those
  186. 6:38numbers over uh what you gave it, and
  187. 6:40out comes the answer that you read on
  188. 6:42screen. You load the file into memory,
  189. 6:45you feed it text, you get text back.
  190. 6:48That's basically at its simplest form,
  191. 6:51a model running. Now, that brings us to
  192. 6:53the obvious question. So, if model is
  193. 6:55just a file, and running it is only a
  194. 6:57matter of loading it into memory and
  195. 7:00doing some math, then why can't you just
  196. 7:02run one on your own laptop? So, take one
  197. 7:05of the smaller models, the kind that
  198. 7:06fits in your computer's memory just
  199. 7:08fine. Uh you've got a perfectly good
  200. 7:10machine sitting right in front of you.
  201. 7:12So, why can't you just run thing? To see
  202. 7:15why, we need to look at the computer a
  203. 7:17little bit closer. So, think about any
  204. 7:20computer you've ever used, whether it's
  205. 7:22your laptop or a server in a data
  206. 7:23center.
  207. 7:25On the inside, there are two
  208. 7:27important parts that we care about.
  209. 7:28There's the CPU, the processor, and
  210. 7:30that's the part that actually does the
  211. 7:32thinking, the calculations, the logic,
  212. 7:34and the work. And then there's the RAM,
  213. 7:35the memory, which is where the computer
  214. 7:37keeps the data and the instructions the
  215. 7:39CPU is currently working on.
  216. 7:41Now, here's the thing I wanted you to
  217. 7:42notice because it comes back later.
  218. 7:45These two parts sit separately. The CPU
  219. 7:47is one place and the memory is in
  220. 7:49another and they are connected by a
  221. 7:51channel between them.
  222. 7:53Now, if you take the smallest
  223. 7:54calculation there is, you punch 6 * 7
  224. 7:57into a calculator app and those two
  225. 7:58numbers land in the memory first. So,
  226. 8:01the CPU then reads them out, does the
  227. 8:04multiplication, and writes the result,
  228. 8:06which is 42, back into the memory. So,
  229. 8:08every single calculation is the same
  230. 8:10round trip, which means the computer and
  231. 8:13memory are always
  232. 8:15tightly paired.
  233. 8:16The processor here, there's the memory
  234. 8:18there, and there's like a small road, a
  235. 8:20bus that's
  236. 8:22between these two.
  237. 8:23Now, that is kind of the same way that
  238. 8:26every type of computing works.
  239. 8:27So, the CPU is a brilliant generalist.
  240. 8:30It has a handful of very powerful cores.
  241. 8:33It works through complicated tasks
  242. 8:35one after the other.
  243. 8:36It's extremely fast and for almost
  244. 8:39everything that you do on your computer,
  245. 8:40like running your browser, your
  246. 8:42applications, your operating system,
  247. 8:43that's exactly what you want.
  248. 8:45So, what is a model actually doing under
  249. 8:48the hood? Now, at its core, running a
  250. 8:50model comes down to billions of very
  251. 8:53small multiplications. And here's the
  252. 8:55important part because these
  253. 8:56multiplications don't depend on each
  254. 8:58other. They can all happen at the same
  255. 9:01time, in parallel.
  256. 9:02Now, a CPU is really a few powerful
  257. 9:05cores one after another. So, when we
  258. 9:07hand it billions of independent little
  259. 9:10multiplications, it works through them
  260. 9:12mostly in sequence, a few at a time. It
  261. 9:14gets every single one right and you'll
  262. 9:16be waiting a very, very long time.
  263. 9:19And that's our first problem. So, the
  264. 9:21work is massively parallel with billions
  265. 9:23of things that could all happen at once,
  266. 9:25but the CPU is built to do things in
  267. 9:28sequence and we need a different kind of
  268. 9:30processor. And that's where the GPU
  269. 9:32comes in. Now, the GPU is a processor
  270. 9:34that's built the exact opposite way.
  271. 9:36Instead of a handful of powerful cores,
  272. 9:38it has thousands of small, simple cores,
  273. 9:41and they all do math at the same time.
  274. 9:43So, if you take a modest GPU like the
  275. 9:45Nvidia T4, which has around 2,500
  276. 9:48of these little cores,
  277. 9:50and if you put some numbers on the
  278. 9:52difference, a CPU manages roughly 10
  279. 9:54trillion operations per second, while a
  280. 9:57GPU can get closer to a thousand
  281. 10:00trillion operations per second. So, it's
  282. 10:02about a hundred times more math every
  283. 10:05second.
  284. 10:06So, the GPU solves our math problem, but
  285. 10:09uh it also creates a new one.
  286. 10:11Because if you remember how a computer
  287. 10:12is built that we just spoke about, a
  288. 10:14processor needs memory to feed it data.
  289. 10:17And the same thing is true for a GPU. A
  290. 10:19GPU needs something to feed it all of
  291. 10:22this data that it needs to compute.
  292. 10:24In the case of a model, it's the
  293. 10:25weights. So, all those billion numbers
  294. 10:28of billions of parameters that we spoke
  295. 10:30about earlier,
  296. 10:31they need to be stored somewhere, and
  297. 10:33they need to be delivered to the CPU.
  298. 10:35So, where do they live? If we leave them
  299. 10:37sitting on the computer's regular RAM,
  300. 10:41there's a problem because the system RAM
  301. 10:43sits far off the card, down a narrow
  302. 10:45pipe that carries about 64 Gbps, and
  303. 10:49that's roughly 50 times slower than what
  304. 10:52the core actually can eat. That was fine
  305. 10:54for a CPU doing a few things at a time,
  306. 10:56but for thousands of GPU cores all
  307. 10:58demanding data at once, that far away
  308. 11:01memory simply can't deliver fast enough.
  309. 11:03So, the cores end up sitting idle,
  310. 11:05waiting for numbers that arrive too
  311. 11:07slowly. So, how do we feed these
  312. 11:10thousands of cores fast enough? The
  313. 11:12answer to that is to give the GPU its
  314. 11:14own memory that's built right onto the
  315. 11:17card and sitting right next to its core.
  316. 11:19And this is called VRAM.
  317. 11:21And here's where I wanted to bring back
  318. 11:23that picture from the very beginning.
  319. 11:25So, on a computer, the CPU and the RAM
  320. 11:28sit apart, connected by a road. The GPU
  321. 11:31uses the same idea of a
  322. 11:32and its memory, but it packs them
  323. 11:34tightly together on a single board
  324. 11:37that's right next to each other. So, the
  325. 11:39data never has to
  326. 11:41travel far and is the same pairing that
  327. 11:44you already know that's just moved kind
  328. 11:46of close together. Now,
  329. 11:49the VRAM has a much wider pipe uh that's
  330. 11:51measured in terabytes a second rather
  331. 11:53than gigabytes. So, now the models
  332. 11:55weights live right beside the map and
  333. 11:58the cores can be fed. But, this solution
  334. 12:00comes with a catch and the catch is
  335. 12:02size. So, VRAM is fast, but it's small.
  336. 12:05So, a card like the T4 has 16GB only.
  337. 12:08And
  338. 12:09remember the model sizes from the start
  339. 12:11of the lessons that we spoke about? That
  340. 12:13a large model
  341. 12:15some of them are with 70 billion numbers
  342. 12:17and needs around 140GB of weights just
  343. 12:20to sit in the memory.
  344. 12:22So, space in the VRAM is precious and
  345. 12:24keep that in mind because later we'll
  346. 12:26see how
  347. 12:28GPUs tackle
  348. 12:30loading large models with hundreds of
  349. 12:32GBs in size
  350. 12:34onto multiple GPUs. So, with all of
  351. 12:37that,
  352. 12:38there are three numbers that size every
  353. 12:40AI workload. So, you have the compute,
  354. 12:42which is how much math the card can do.
  355. 12:46Then there's the capacity, which is how
  356. 12:49much fits in that memory.
  357. 12:52And then there's the bandwidth, which is
  358. 12:53how fast it can read its own memory. So,
  359. 12:57every card that you're ever going to
  360. 12:58meet is described by these three numbers
  361. 13:01and each generation adds more of all the
  362. 13:05three.
  363. 13:06So, those three numbers describe every
  364. 13:07card that you're ever going to meet. So,
  365. 13:09here we have a list of cards
  366. 13:12and a comparison between the three. So,
  367. 13:14at first we have the desktop and we know
  368. 13:17that uh typically you have anywhere from
  369. 13:19one to three TFLOPS
  370. 13:21uh processing power on a desktop.
  371. 13:24The The and memory is usually 32GB or
  372. 13:2764GB and the bandwidth between the
  373. 13:30memory and the compute is about 0.09
  374. 13:33TBps. Now, if you compare that against a
  375. 13:36rack server, which typically does about
  376. 13:385 to 10 TFLOPS computing power and
  377. 13:41usually has really high RAM,
  378. 13:44the
  379. 13:45bandwidth between the RAM and the CPU is
  380. 13:47around 0.5.
  381. 13:49But, if you compare these to the Nvidia
  382. 13:52data center cards, for example, so A100,
  383. 13:55H100, H200, and B200, A100, the smallest
  384. 13:59of them all, has about 312 TFLOPS
  385. 14:02capacity or computing power, and the
  386. 14:04memory has 80GB in capacity. The
  387. 14:07bandwidth is around 2 TBps. The H100 and
  388. 14:11H200 are the comparatively higher level
  389. 14:13of cards. They each have 990 TFLOPS
  390. 14:18computing power, but if you look at the
  391. 14:20difference is mainly in the memory. So,
  392. 14:23H100 is 80 VRAM capacity and H200 has
  393. 14:27141 GB of capacity.
  394. 14:29Uh the B200s are comparatively much
  395. 14:32higher and they have about 2,250
  396. 14:36TFLOPS computing power and has a really
  397. 14:39high VRAM of about 192GB
  398. 14:43and also has higher bandwidth between
  399. 14:45the memory and the compute of about 8
  400. 14:47TBps. Now, a chip on its own does
  401. 14:50nothing at all because something has to
  402. 14:52drive it. So, that something, the
  403. 14:54software, is called PyTorch, which is
  404. 14:56the uh software that loads the model
  405. 14:58onto the GPU and puts all of these cores
  406. 15:00to work. So, in just few lines of code,
  407. 15:02as you can see here, in about
  408. 15:04six to seven lines of code, you're
  409. 15:05importing the torch package and then
  410. 15:08you're uh loading the Llama model. In
  411. 15:11this case, it's a Llama model. And then,
  412. 15:13all you do is uh you're calling the gen
  413. 15:15command that actually sends a request or
  414. 15:18a question to the model and it res-
  415. 15:20sends back a response. You when you look
  416. 15:22at the generated text in the response,
  417. 15:25that would be what model actually
  418. 15:27generated. So, here's the super simple
  419. 15:28example to load a simple model on your
  420. 15:31laptop. So, if you download really small
  421. 15:33models on your laptop, you can actually
  422. 15:34try this right away. Now, that's just a
  423. 15:36script. It runs once for one person and
  424. 15:38then it's done. Real users are out on
  425. 15:40the internet, thousands of them that are
  426. 15:42all at once. So, you need something
  427. 15:44that's always on, that's listening for
  428. 15:46requests and running the model
  429. 15:47efficiently. And that's a model server.
  430. 15:50And the one that we'll keep coming back
  431. 15:52to is uh vLLM, which is built right on
  432. 15:54top of PyTorch. It wraps the model into
  433. 15:57a service with a normal web API. So, now
  434. 16:00it's a real product. And that raises a
  435. 16:02question that we're going to pick up
  436. 16:04next. What is that server actually doing
  437. 16:06every time a request comes in?
  438. 16:10Okay, so we'll now look at the model
  439. 16:12server itself. So, say I want to serve a
  440. 16:14model and it's really just one command.
  441. 16:17So, I run the vLLM serve and point it at
  442. 16:19the model. And vLLM then reads
  443. 16:21[clears throat] the model weights off
  444. 16:23the disk and loads them into the GPU
  445. 16:25memory. That's about 16 GB to move, so
  446. 16:28you'll be waiting for a minute or two.
  447. 16:31Now, after that, the server is up and
  448. 16:33running and it stays up and it waits for
  449. 16:35requests. So, how do you talk to it? You
  450. 16:37send it a normal web request, the same
  451. 16:39way that you would talk to any other web
  452. 16:41service.
  453. 16:42vLLM speaks the exact same format that
  454. 16:44the OpenAI API uses. So, any tool that
  455. 16:47already talks to OpenAI, any script that
  456. 16:49you've already built that talks to
  457. 16:50OpenAI can talk to your own server
  458. 16:53instead without changing a single line
  459. 16:55of code. Now, let's notice what we have
  460. 16:57actually got here. So, this one server
  461. 16:59is holding the entire model in its GPU
  462. 17:00memory.
  463. 17:01The whole time that it's running.
  464. 17:03Now, so if one server isn't enough, a
  465. 17:05second one is not cheap at all because
  466. 17:08it means another full copy of the model
  467. 17:10on another expensive GPU. So, a model
  468. 17:13server is a heavy beast. Uh it's
  469. 17:15expensive to run on, it's slow to start,
  470. 17:17and it's costly to copy. Okay, so now
  471. 17:20that we've got a real server that's
  472. 17:21answering real questions, everything
  473. 17:23that's actually matters is happening
  474. 17:25inside those few seconds. So, what is
  475. 17:26the model really doing in there? Like,
  476. 17:28between reading a prompt and handing
  477. 17:30back the output?
  478. 17:32That's what we'll see next.
  479. 17:35Now, before we go any further, there's
  480. 17:37one word that you'll need, and this is
  481. 17:40something that you have heard a lot of
  482. 17:42times.
  483. 17:43Tokens. So, language model doesn't read
  484. 17:46and write whole words the way we do.
  485. 17:49Instead, it breaks it into little pieces
  486. 17:51called tokens.
  487. 17:52So, a token is roughly 3/4 of a word.
  488. 17:55So, sometimes it's whole word, and
  489. 17:56sometimes it's only part of a word. If
  490. 17:59you take a sentence like serving LLMs is
  491. 18:01not like serving web apps, which is
  492. 18:03eight words, but it comes to about nine
  493. 18:05tokens. And everything here gets counted
  494. 18:07in tokens. So, what a model can read,
  495. 18:09what you pay, and how fast it goes, and
  496. 18:12how fast it gets generated, all of these
  497. 18:15happen in terms of tokens.
  498. 18:17Now, the model has exactly one trick.
  499. 18:19So, it's basically predicting machine,
  500. 18:22right? Which is, given all the text so
  501. 18:24far, it predicts the next word or the
  502. 18:26next token. So, then it takes that
  503. 18:29token, adds it to the original text, and
  504. 18:31then it takes that again, the output of
  505. 18:33that, and then pens it to the original
  506. 18:37text, and it does that again and again
  507. 18:39and again until it generates the entire
  508. 18:41output that makes sense to the user. So,
  509. 18:44a 100 token answer or 100 word answer
  510. 18:47isn't like one big calculation, it's the
  511. 18:49model running that loop a 100 times
  512. 18:51over, like one token per lap. And that's
  513. 18:54exactly why the answer types itself out
  514. 18:57word by word when you watch ChatGPT,
  515. 19:00because you're watching each lap finish.
  516. 19:02Uh, so, the streaming comes as a free
  517. 19:03feature.
  518. 19:04So, there's two things that fall out of
  519. 19:06this, and both of this we'll talk about
  520. 19:08later. The first is that these requests
  521. 19:11take a long time, because a normal web
  522. 19:13request is over in maybe a few
  523. 19:15milliseconds, but a few hundred tokens
  524. 19:17means a few hundred laps of that loop.
  525. 19:20Now, the second one is a big one. It's
  526. 19:22that there are no two requests that are
  527. 19:24the same. So, you're asking for, say,
  528. 19:26capital of France is a few tokens in and
  529. 19:29maybe one or two tokens out, but uh if
  530. 19:31you were to say, "Summarize this
  531. 19:33100-page contract,"
  532. 19:35that's like tens of thousands of token.
  533. 19:37So, both of these kind of hit the same
  534. 19:39server, through the same API, but one is
  535. 19:42a thousand times more than the other.
  536. 19:44So, that is one thing that we'll look at
  537. 19:46uh later. So, we spoke about the loop,
  538. 19:49which generates one token at a time.
  539. 19:51Now, let's take a deeper look at what
  540. 19:54that loop does. So, we'll now go into
  541. 19:56the loop and uh try and see uh the two
  542. 19:58halves of that loop. So, there's the
  543. 20:01initial pause half, and then there's the
  544. 20:04streaming half, and that is what we will
  545. 20:05look at next.
  546. 20:08So, what are the two halves of a loop?
  547. 20:11So, you paste a big chunk of text into
  548. 20:13ChatGPT and you hit enter. And there's
  549. 20:16this pause initially for a second or or
  550. 20:18two, where nothing happens.
  551. 20:20And then the answer comes out, and it
  552. 20:23streams out word by word steadily. So,
  553. 20:26there's the pause, and then there's the
  554. 20:28stream. So, the pause and stream are the
  555. 20:30two halves, and we'll see exactly what
  556. 20:32happens in each of these. So, let's
  557. 20:34start with the pause. Now, before the
  558. 20:35model can write a single word, it has to
  559. 20:38read everything that you give it, which
  560. 20:40is your whole prompt.
  561. 20:42Because
  562. 20:43it reads all of it at once. So, your
  563. 20:45prompt is already there in full, so
  564. 20:48there's nothing to wait on, and every
  565. 20:50token goes through the whole model
  566. 20:52together in one big burst. So, the whole
  567. 20:55model gets loaded out of the VRAM once,
  568. 20:57and thousands of cores fire at the same
  569. 20:59time to chew through the entire prompt
  570. 21:01in a single pass, and that pass ends by
  571. 21:04producing the first token of your
  572. 21:06answer. And that's the moment the pause
  573. 21:08ends and the typing or the streaming
  574. 21:11begins. So, the pause comes down to one
  575. 21:13thing, which is how much you gave it to
  576. 21:15read. Asking for the capital of France
  577. 21:17is about, say, seven tokens. So, that's
  578. 21:19only one tiny pause and no pause would
  579. 21:23be noticed. But, if you paste a 100-page
  580. 21:25contract and that's like tens of
  581. 21:27thousands of tokens that's pushed
  582. 21:28through at once, and that single burst
  583. 21:31becomes a real weight. So, this first
  584. 21:33phase has a name and it's called
  585. 21:35prefill. So, it's not called pause,
  586. 21:37that's just something I just came up
  587. 21:38with, but it's called prefill, that's
  588. 21:40the technical term. The weight it causes
  589. 21:42has a name, too. So, which is
  590. 21:45the time to first token. So, TTFT, time
  591. 21:48to first token means the time that it
  592. 21:50takes for the prefill process, the
  593. 21:53initial computing process, to complete.
  594. 21:55And how much time does it take to get
  595. 21:57that first token, the first word of the
  596. 22:00response generated? That's TTFT or time
  597. 22:03to first token. Now, let's look at the
  598. 22:04second phase, which is the writing the
  599. 22:07answer part, the streaming part. Now,
  600. 22:09this is the token-by-token loop that we
  601. 22:11spoke about earlier. So, each token is
  602. 22:13one full pass through the model and
  603. 22:16because this phase has completely
  604. 22:17different bottleneck, to produce each
  605. 22:19new token, the GPU has to read the
  606. 22:21entire model out of its memory. So,
  607. 22:23writing a 200-token answer means you
  608. 22:26load the entire model out of the memory
  609. 22:28200 times over. And each of those loads
  610. 22:31buys you exactly one token. So, the
  611. 22:34cores barely do any work at all in this
  612. 22:36phase. So, this second phase is called
  613. 22:38decode and the speed is limited by how
  614. 22:41fast the GPU can read its own memory.
  615. 22:44So, how fast the entire
  616. 22:46model loads from the memory into the
  617. 22:48GPU.
  618. 22:49So, why is the reading
  619. 22:51that's limiting the speed?
  620. 22:53So, the cores are tiny and they can't
  621. 22:55hold the entire model. So, the weights
  622. 22:58live in VRAM, which is something we
  623. 22:59spoke about earlier, and the cores have
  624. 23:01to be fed from it's constantly. That
  625. 23:03means for every single token, the entire
  626. 23:05model streams out of the VRAM into the
  627. 23:07cores, gets used, and makes way for the
  628. 23:09next one. And that stream has a speed
  629. 23:12limit. So, a high-end GPU reads its own
  630. 23:14memory at about 3 TB per second, which
  631. 23:18sounds enormous. And this is something
  632. 23:20we discussed earlier, different GPUs
  633. 23:23have different speed limits.
  634. 23:253 TB a second against a 16 GB model
  635. 23:28means the GPU can only read the whole
  636. 23:30thing about 200 times a second. So, if
  637. 23:32you do a simple math, you'll see that
  638. 23:33that's one read per token, so it's 200
  639. 23:36tokens a second, and that's the maximum
  640. 23:39limit.
  641. 23:40So, the benchmarks usually flip that
  642. 23:42number around and call the gap between
  643. 23:44one token and the next, which is about 5
  644. 23:46ms. So, that's like one token every 5
  645. 23:49ms. So, that gap per token is called as
  646. 23:53TPoT. So,
  647. 23:55the TPoT stands for time per output
  648. 23:58token. And every serving benchmark
  649. 24:00you'll ever read is built on these two.
  650. 24:02So, there's the initial pause, that's
  651. 24:05the TTFT, and then then you have the
  652. 24:08TPoT, which is the time per output
  653. 24:11token.
  654. 24:12Okay, so to summarize, we have seen two
  655. 24:14phases. You have the prefill phase,
  656. 24:16which is when the original prompt gets
  657. 24:18processed, so that's the initial pause,
  658. 24:21and that is compute heavy. And then
  659. 24:22there's the decode phase, which writes
  660. 24:24the answer by rereading the model over
  661. 24:26and over. And that's the stream that we
  662. 24:29see, and that is a memory bandwidth
  663. 24:32heavy. So, those are the two kind of
  664. 24:34different
  665. 24:35computing and memory requirements for
  666. 24:37the two different phases.
  667. 24:39One is one-time calculation, the other
  668. 24:41is a long, steady grind against memory.
  669. 24:43And right now, they're both happening on
  670. 24:45the same GPU. So, the same GPU takes
  671. 24:47turns to process both of these different
  672. 24:49kinds of operations.
  673. 24:52So, with the prefill and decode phases,
  674. 24:55every new token generated has a prefill
  675. 24:57phase that processes everything until
  676. 25:00then and then the decode phase that
  677. 25:01generates the new word.
  678. 25:03With that approach, every word would
  679. 25:05have a gap before the new word is
  680. 25:07generated. So, that's a fresh pause
  681. 25:09before every single word and the chat
  682. 25:12would be too slow to use. But, that's
  683. 25:14not what happens. We know that with chat
  684. 25:16applications like ChatGPT, the words
  685. 25:18come out like really fast, one after the
  686. 25:20other with no repeated stall. So, how
  687. 25:22does that happen?
  688. 25:24The prefill step is the real work and
  689. 25:26it's expensive because it consumes a lot
  690. 25:28of GPU power. But, instead of throwing
  691. 25:30it away the moment it's done, the model
  692. 25:33saves it right there in the GPU's
  693. 25:35memory. And that saved work has a name.
  694. 25:37That's called KV cache. So, prefill runs
  695. 25:40once right at the start and save the
  696. 25:42output in the KV cache. From then on, as
  697. 25:45the model writes the answer one token at
  698. 25:46a time, it does not repeat prefill for
  699. 25:49each new token. It just reaches into the
  700. 25:51cache, reuses everything it already
  701. 25:53worked out, and adds the one new token
  702. 25:55on top. So, you pay for that pause only
  703. 25:58once
  704. 25:59and not before every word.
  705. 26:01So, now everything above covers exactly
  706. 26:04one message.
  707. 26:05One question in and one answer out. So,
  708. 26:08the moment your reply finishes, that
  709. 26:10request is done and the cache gets
  710. 26:12cleared. So, what happens the moment you
  711. 26:15send a second message in the chat? The
  712. 26:18model remembers nothing between
  713. 26:19messages. So, your chat app resends the
  714. 26:22entire thread every single time. So,
  715. 26:24your first question, your first answer
  716. 26:27that you receive from the model, and now
  717. 26:29your new message. This is all bundled
  718. 26:31into one request. And because last
  719. 26:33time's work is already gone, the server
  720. 26:35has to reread every word of that from
  721. 26:37the very beginning before it can reply.
  722. 26:40And every turn rebuilds all that work
  723. 26:42from scratch and then throws it away.
  724. 26:44So, the longer you talk, the longer you
  725. 26:46wait. So, the cost of a conversation
  726. 26:48grows with every message because it has
  727. 26:51to do the prefill for every message.
  728. 26:54So, what if instead of throwing that
  729. 26:56cash away the moment the request ends,
  730. 26:58you just kept it? You hang on to those
  731. 27:00saved blocks and you label each one by
  732. 27:03the exact text that produced it. Now,
  733. 27:05turn two arrives. The model looks at
  734. 27:07your thread and realizes it has already
  735. 27:09done the work on all of it except your
  736. 27:11newest message. That's the only part it
  737. 27:14actually has to prefill.
  738. 27:16Turn 10 now costs about what turn two
  739. 27:18costs. So, the pause stays small no
  740. 27:20matter how long the conversation gets.
  741. 27:23This idea has a name and is called
  742. 27:25prefix caching. If you go to the
  743. 27:27Anthropic console
  744. 27:29in the API console, you would see that
  745. 27:30there's something called as prompt
  746. 27:32caching. And a cached input
  747. 27:35token only costs about 10th of what a
  748. 27:38fresh one does. So, if you have prefix
  749. 27:40caching enabled, you can actually save a
  750. 27:42lot of
  751. 27:43cost for input tokens. Okay, and once
  752. 27:45you're holding onto that saved work,
  753. 27:47something else falls out of it for free.
  754. 27:49The saved work for any stretch of text
  755. 27:52depends only on the text before it and
  756. 27:54doesn't know or care whose conversation
  757. 27:56it's coming from. So, say I've built an
  758. 27:58assistant that is like a central
  759. 28:00assistant in my company and every single
  760. 28:02conversation that opens with the same
  761. 28:04long block of instructions,
  762. 28:07that's the same text every time. So,
  763. 28:09under the hood, it's the same saved work
  764. 28:11every time. The model does that work
  765. 28:13once and reuses it for every person who
  766. 28:15talks to it. So, it's really the same
  767. 28:16mechanism as your own next turn to the
  768. 28:19cache, but in both cases,
  769. 28:21it just looks at matching beginning of
  770. 28:24the call, which is in this case the
  771. 28:25system prompt.
  772. 28:27We'll now look at how a single GPU
  773. 28:29serves many users at the same time.
  774. 28:32And the one thing that limits how many
  775. 28:34users it can actually serve.
  776. 28:37So, if you think back to the expensive
  777. 28:38part of writing an answer, so for every
  778. 28:40single token it produces, the GPU has to
  779. 28:43read the entire model out of its memory
  780. 28:45and that read is the real cost. So, if
  781. 28:47the GPU already has to read the whole
  782. 28:49model just to produce one token for one
  783. 28:51user, why not use that same read to
  784. 28:54produce the next token for a lot of
  785. 28:56users at the same time?
  786. 28:58One read of the model gives you one
  787. 28:59token for one user or 50 tokens for 50
  788. 29:03users because it's the same single read
  789. 29:05either way. So, that's the idea and it
  790. 29:07has a name and it's called batching. You
  791. 29:09pack many people's requests together and
  792. 29:11run them through the GPU as one group.
  793. 29:13Each person's own answer still comes out
  794. 29:16at roughly the same speed it would on
  795. 29:18its own.
  796. 29:20But, look at what happens to the server
  797. 29:21as a whole once you add up everyone's
  798. 29:23tokens. It's total output, the number of
  799. 29:26tokens it produces every second, what we
  800. 29:28call its throughput, shoots up. So, you
  801. 29:31end up serving 50 people for something
  802. 29:33close to the cost of serving just one.
  803. 29:35Without batching, you'd be pulling the
  804. 29:37entire model out of the memory for one
  805. 29:39person at a time and nobody could afford
  806. 29:41to run that hardware that way.
  807. 29:43So, why can't we batch like a million
  808. 29:45users with the same approach? The answer
  809. 29:47comes down to memory and that's the
  810. 29:49ceiling on how far batching can go. So,
  811. 29:52you remember the scratchpad that we
  812. 29:54talked about earlier, the KV cache? So,
  813. 29:56every single user sitting in that batch
  814. 29:59needs their own scratchpad and it has to
  815. 30:01sit in the GPU's memory for as long as
  816. 30:04they're being served. So, that memory is
  817. 30:06small to begin with and most of it is
  818. 30:08already taken because it's busy holding
  819. 30:10the entire model. So, the model's
  820. 30:12weights are fixed, so they're always
  821. 30:14there taking their share of memory and
  822. 30:17whatever is left over is the only room
  823. 30:19you have for everyone's scratchpads.
  824. 30:21So, now fill that space up and
  825. 30:25that's it because the server is full.
  826. 30:27And at that point, new users have to
  827. 30:29wait in line or somebody else's
  828. 30:30scratchpad gets thrown out to make room
  829. 30:32for them and that's exactly why ChatGPT
  830. 30:34sometimes tells you that it's at
  831. 30:36capacity. So, notice what isn't the
  832. 30:38problem here. It's not the processor of
  833. 30:40runs out because there's plenty of math
  834. 30:42left in those cores uh sitting idle.
  835. 30:44It's the memory that runs out, and it's
  836. 30:46the memory that decides how many people
  837. 30:48one GPU can actually serve. And this is
  838. 30:51also where a lot of money gets wasted in
  839. 30:53the real world. Teams end up buying far
  840. 30:55more GPUs than the math can actually
  841. 30:58calls for, and those expensive GPUs just
  842. 31:00sit there half idle.
  843. 31:02But memory does more than decide how
  844. 31:04many people fit on a GPU. It also
  845. 31:07decides whether the model fits on the
  846. 31:08GPU at all. So far we've assumed that
  847. 31:11the whole model sits on one GPU, and for
  848. 31:13the very biggest models we know that it
  849. 31:16won't because they're just simply too
  850. 31:18large for any single GPU to hold. And
  851. 31:21that's what we will look at next.
  852. 31:24Now, so far every server we've talked
  853. 31:26about holds the whole model by itself.
  854. 31:29For a lot of models, that works fine.
  855. 31:31But it doesn't work for the very biggest
  856. 31:34models, because some of them are too
  857. 31:36large to fit on a single GPU.
  858. 31:38Now, remember the sizes of the models
  859. 31:40that we looked at earlier in the course,
  860. 31:41like a large model came in at about 140
  861. 31:44GBs, and the giants with 500 billion
  862. 31:46parameters or more comes at several
  863. 31:49hundred GBs on disk. Now, what if the
  864. 31:51GPU holds only about 80 GBs? So, it
  865. 31:54doesn't fit.
  866. 31:55What do we do? Now, you bring in several
  867. 31:57GPUs instead. So, you take the giant,
  868. 31:59you slice it into pieces, and put one
  869. 32:01piece on each of the many GPUs. No
  870. 32:04single GPU can hold the whole thing, but
  871. 32:07together they can hold the entire model.
  872. 32:10So, VLLM, the model server that we've
  873. 32:12set up earlier, can split a model across
  874. 32:14GPUs on its own. You point it at a giant
  875. 32:17model, tell it how many GPUs it has, and
  876. 32:20it takes care of the rest. Now, before
  877. 32:22we cut the model up let's look at
  878. 32:24exactly what we're cutting. And let's
  879. 32:26super simplify this.
  880. 32:28So, a model is a stack of layers, and
  881. 32:30each layer is a formula, which in
  882. 32:32practice is just a large sum of numbers.
  883. 32:35Your prompt enters at the top and flows
  884. 32:37through the stack one layer at a time.
  885. 32:40Each layer adds up its numbers and
  886. 32:42passes the result to the layer below it
  887. 32:44until the very last one produces the
  888. 32:46token. So, how do you actually split
  889. 32:48those layers across GPUs? Now, there are
  890. 32:50two ways to do it. The first is by
  891. 32:52layer. You hand the first whole layers
  892. 32:55over to GPU uh one and the next ones to
  893. 32:57GPU two. The second way works within
  894. 33:00each layer. So, you take a single
  895. 33:01layer's sum and split its stream. So,
  896. 33:04GPU one adds the first half and GPU two
  897. 33:07adds the second. And the two halves
  898. 33:09combine into that layer's answer.
  899. 33:11Now, where you physically put those GPUs
  900. 33:14decide which way you slice, and it comes
  901. 33:17down to one thing, the speed of the wire
  902. 33:19between them. So, inside a single
  903. 33:21machine, the GPUs are joined by a
  904. 33:23special ultra-fast link called NVLink,
  905. 33:26far quicker than any ordinary network.
  906. 33:28So, the chatty method, which is
  907. 33:30splitting within each layer, works well
  908. 33:32there because the GPUs can afford to
  909. 33:34talk to each other constantly.
  910. 33:36Now, if you pack eight GPUs into one box
  911. 33:39on that fast link, and they serve a
  912. 33:40giant as if they were one machine,
  913. 33:43then that works perfectly. Now, this is
  914. 33:45how most large models run today. Now, if
  915. 33:47you go bigger than a single box where
  916. 33:49the GPUs are sitting in different
  917. 33:51machines, and they only have the
  918. 33:53ordinary network between them, which is
  919. 33:55a lot slower, so across machines, you
  920. 33:57switch to the light method instead. So,
  921. 34:00you hand out whole stretches of layers,
  922. 34:02and each machine passes just one small
  923. 34:04result onto the next. So, the rule then
  924. 34:07is simple. So, you keep the chatty talk
  925. 34:09inside a box, and you keep the light
  926. 34:12talk between boxes. So, this technique,
  927. 34:15splitting a model across GPUs, has a
  928. 34:17name, and that's called sharding, and it
  929. 34:18solves the the fitting problem. So, a
  930. 34:21giant too uh big for one GPU now runs
  931. 34:23across a machine's worth of uh GPUs or
  932. 34:26several machines worth of GPUs acting as
  933. 34:30one logical server. So, sharding makes
  934. 34:32it possible to run the giant model, but
  935. 34:34it still does not make one server serve
  936. 34:37the entire world.
  937. 34:40Okay, so what happens when you have a
  938. 34:42fleet of these servers? So, a real
  939. 34:45service is never run on a single server
  940. 34:48because you want to serve the entire
  941. 34:49world. So, you need a whole fleet of
  942. 34:52them, and each one is its own expensive
  943. 34:55GPU that's carrying its own copy of the
  944. 34:57model. So, how does my request get to
  945. 35:01one of these servers? Now, if you've
  946. 35:02worked in the infrastructure space
  947. 35:04before, you probably already have a fix
  948. 35:06in mind that you put a load balancer in
  949. 35:09front of the fleet, and it spreads the
  950. 35:10incoming request evenly across every
  951. 35:13server round and round one to each in
  952. 35:16turn.
  953. 35:17And we've balanced web traffic this way
  954. 35:19for decades, so it feels like the
  955. 35:20obvious move here. But, for serving
  956. 35:23large language models, it turns out to
  957. 35:25be the wrong one for two reasons.
  958. 35:27So, say I send my first message, and it
  959. 35:31lands on server two, which reads my
  960. 35:33conversation and saves its work in
  961. 35:36memory.
  962. 35:37And that's basically the KV cache that
  963. 35:39we spoke about earlier. And a little
  964. 35:40later, I send a second message, but the
  965. 35:43load balancer's whole job is to spread
  966. 35:45traffic evenly, so it sends the this one
  967. 35:48to server five instead.
  968. 35:50And uh server five has never seen me
  969. 35:52before, so it has nothing saved, and it
  970. 35:54has to read my entire conversation again
  971. 35:57from scratch, which means the pre-fill
  972. 35:59behavior that we spoke about happens all
  973. 36:01over again.
  974. 36:02So, a load balancer treats every server
  975. 36:04as interchangeable, but we already know
  976. 36:07they're not. So, it throws away saved
  977. 36:09work that was perfectly good, and it
  978. 36:11does that on the most expensive hardware
  979. 36:14you own.
  980. 36:15Now, the second reason, this has nothing
  981. 36:17to do with where your saved work lives.
  982. 36:19So, a load balancer assumes that every
  983. 36:22request is roughly the same size, so
  984. 36:24spreading them out evenly also spreads
  985. 36:26the load out evenly. But, we know that
  986. 36:29no two large language model requests are
  987. 36:31the same size. So, one of them might be
  988. 36:33just a quick hello message, and the next
  989. 36:36one is probably a request to summarize
  990. 36:3950 pages of text. So, to the load
  991. 36:42balancer, these two requests look
  992. 36:44identical because all it sees is the
  993. 36:46same address and the same kind of
  994. 36:48traffic. So, it might send that 50-page
  995. 36:50request to a server that's already busy
  996. 36:53streaming answers to 30 other people,
  997. 36:55and all 30 of them slow down. And that
  998. 36:58one big request takes far longer than it
  999. 37:01should.
  1000. 37:01Now, the load balancer can't tell any of
  1001. 37:04this apart because everything it would
  1002. 37:05need to know is inside the servers,
  1003. 37:08where it has no way of seeing in. So,
  1004. 37:11how full is each server's memory right
  1005. 37:13now? Whose saved work is sitting where?
  1006. 37:16And how long is each queue? So, serving
  1007. 37:18large language models need a much
  1008. 37:20smarter way to route requests than
  1009. 37:23anything that we have ever used before.
  1010. 37:27So, why is serving models so hard? The
  1011. 37:29model barely fits in memory to begin
  1012. 37:31with. Every token forces the server to
  1013. 37:34reread the whole thing from scratch.
  1014. 37:36Whatever saved work a server has done
  1015. 37:38for you is stuck on that one server, and
  1016. 37:41memory also caps how many people that
  1017. 37:43server can handle at once. And if you
  1018. 37:45get the routing wrong on top of all of
  1019. 37:47that, you waste your most expensive
  1020. 37:49hardware, which is your GPU cycles.
  1021. 37:52So, that same wall stopped everyone in
  1022. 37:54the industry, which is why Red Hat,
  1023. 37:55Google, IBM, and Nvidia decided to solve
  1024. 37:59it together out in the open. And what
  1025. 38:02they built is called LLMD. And LLMD is
  1026. 38:05what we're going to discuss next. So,
  1027. 38:07what is LLMD?
  1028. 38:09At its heart, it's a smart router that
  1029. 38:11sits in front of your entire fleet of
  1030. 38:14servers. And when a request comes in, it
  1031. 38:16doesn't just throw it at whichever
  1032. 38:18server happens to be free next, it stops
  1033. 38:21and thinks about where that request
  1034. 38:23should go, then sends it to the server
  1035. 38:25that is best equipped to handle it. To
  1036. 38:27make that call, it looks at three
  1037. 38:29things: the saved work each server is
  1038. 38:31holding, how much memory it has free,
  1039. 38:33and how long its queue is.
  1040. 38:36So, start with the first one. LLMD keeps
  1041. 38:38track of which server holds which saved
  1042. 38:40work. So, when your next message comes
  1043. 38:42in, instead of scattering it across the
  1044. 38:44fleet, LLMD sends it straight back to
  1045. 38:46the server that already has your
  1046. 38:48conversation. So, that server skips the
  1047. 38:50reread and your reply comes back
  1048. 38:52instantly. Now, routing that way,
  1049. 38:54instead of spreading requests evenly,
  1050. 38:56gives you around three times the
  1051. 38:57throughput and a first response that is
  1052. 39:00twice as fast on the same hardware.
  1053. 39:03The second thing LLMD does is look
  1054. 39:05inside its server at details a plain
  1055. 39:08load balancer never checks.
  1056. 39:09How full is the server's memory right
  1057. 39:11now? How long is its queue? It uses that
  1058. 39:14to send your request to a server that
  1059. 39:16genuinely has room instead of piling
  1060. 39:18work
  1061. 39:19into one that's already full.
  1062. 39:21The third comes from noticing that a
  1063. 39:23request has two very different halves.
  1064. 39:25So, there's the prefill phase that we
  1065. 39:27spoke about earlier, which is
  1066. 39:28compute-heavy, and that's the one-time
  1067. 39:30job of reading a prompt, and then
  1068. 39:31there's the decode phase, which is the
  1069. 39:33slow token-by-token job of writing the
  1070. 39:35answer.
  1071. 39:35On one shared GPU, those two take turns.
  1072. 39:38So, when someone pastes in 50 pages,
  1073. 39:41that one big prefill makes everyone's
  1074. 39:44answer wait midstream. So, LLMD can
  1075. 39:46split them onto separate pools, where
  1076. 39:48one pool does nothing but prefill and
  1077. 39:51the other does nothing but decode.
  1078. 39:53Prefill is all compute, decode is all
  1079. 39:56memory, so each pool runs the hardware
  1080. 39:58that fits its job.
  1081. 40:00For example, you could have the H100
  1082. 40:02type of GPUs for the prefill pool and
  1083. 40:04the H200 that has higher memory for the
  1084. 40:07decode GPUs. And when a prefill server
  1085. 40:10finishes reading a prompt, it hands the
  1086. 40:12saved work across a fast link to a
  1087. 40:14decode server, which streams the
  1088. 40:16response. So, that's up to 70% more
  1089. 40:19tokens per second on the same hardware.
  1090. 40:22Now, the best part is that LLMD runs on
  1091. 40:24top of something you're almost certainly
  1092. 40:26using. It's the platform you've built
  1093. 40:28applications on all decade. It's the
  1094. 40:30platform that 60% of organizations
  1095. 40:33hosting GenAI use to manage inference
  1096. 40:35workloads. It's a platform that your ops
  1097. 40:37team already runs, and it is the
  1098. 40:39platform that is now becoming the de
  1099. 40:42facto standard for AI inference. And
  1100. 40:44that platform is none other than
  1101. 40:47Kubernetes.
  1102. 40:48Now, one of the recent CNCF blogs named
  1103. 40:50The Future of AI is community-driven and
  1104. 40:52open mentions that 66% of organizations
  1105. 40:55hosting generative AI use it to manage
  1106. 40:58some or all of their inference
  1107. 40:59workloads. So, if you ask teams running
  1108. 41:01generative AI in production, what they
  1109. 41:04run it on, about two out of three say
  1110. 41:06Kubernetes. And LLMD sits right on top
  1111. 41:09of it.
  1112. 41:11So, if you actually wanted to run this
  1113. 41:13yourself, where would you start? One of
  1114. 41:15the challenge teams face starting their
  1115. 41:17LLMD implementation is how to tune it.
  1116. 41:19So, everything we've talked about has a
  1117. 41:21real tunable knob behind it. So, how
  1118. 41:25much the router should favor a server
  1119. 41:27that already holds your saved work over
  1120. 41:30one that's simply less busy. Whether you
  1121. 41:32split the servers that read prompts from
  1122. 41:34one the ones that write answers, that's
  1123. 41:36the prefill versus decode split, and how
  1124. 41:39many of each do you run? How many GPUs
  1125. 41:42one copy of the model spans when it's
  1126. 41:43too big for a single machine. How many
  1127. 41:45requests each server batches before it
  1128. 41:47starts falling behind? And every one of
  1129. 41:50these moves your speed and your cost.
  1130. 41:52And the right answer depends on your
  1131. 41:54model, your hardware, and your traffic.
  1132. 41:56So, tune them all by hand, and you could
  1133. 41:59just spend weeks at it and still get
  1134. 42:02several of them wrong. So, LLMD hands
  1135. 42:04you what it calls the well-lit paths.
  1136. 42:06So, these are ready-made recipes where
  1137. 42:08every knob is already set, and each one
  1138. 42:11measured on real hardware.
  1139. 42:14So, there's a whole menu of these paths
  1140. 42:15by now, but let's look at the three that
  1141. 42:18carry almost the whole story and you
  1142. 42:20already know the idea behind each one.
  1143. 42:22So, the first one is the optimized
  1144. 42:24baseline. So, that's one pool of plain
  1145. 42:26identical servers with cache aware
  1146. 42:28routing switched on and nothing else
  1147. 42:30changed.
  1148. 42:31The second path splits the work in two.
  1149. 42:33One pool of servers reads prompts. This
  1150. 42:35is your prefill pool and another writes
  1151. 42:38answers. So, these are the decode pool
  1152. 42:40and they save workflows between them.
  1153. 42:42So, you size each pool for your own
  1154. 42:44traffic, which makes it the path for
  1155. 42:46long heavy prompts. The third spreads a
  1156. 42:49single model across a group of GPUs that
  1157. 42:51act as one server, which is what the
  1158. 42:53giants need. The router stays exactly
  1159. 42:56the same across all three and the only
  1160. 42:58thing that changes is the shape of the
  1161. 43:00fleet behind it. So, most people start
  1162. 43:03with the first path because it's the
  1163. 43:04smallest change you can make and the
  1164. 43:06biggest
  1165. 43:08payoff.
  1166. 43:10Let's dive into the details now. To set
  1167. 43:12it all up takes two commands. So,
  1168. 43:14there's a helm install router command
  1169. 43:16that installs the LLM D router itself
  1170. 43:19and sets up the vLLM servers. And you
  1171. 43:22have the helm install model
  1172. 43:24command that installs the model itself.
  1173. 43:27So, let's try to understand what they
  1174. 43:28build and how you use it.
  1175. 43:31So, we start with what you already have,
  1176. 43:33which is a Kubernetes cluster with some
  1177. 43:35worker nodes and right now nothing is
  1178. 43:37running on any of them. So, first come
  1179. 43:39the model servers and every one of them
  1180. 43:41is a vLLM instance. So, this is the same
  1181. 43:44server that we set up at the start. So,
  1182. 43:47on Kubernetes each vLLM instance runs as
  1183. 43:50a pod landing on whichever node has room
  1184. 43:52for it and a group of identical pods we
  1185. 43:54know is called a deployment. So, that's
  1186. 43:57your prefill pool and then you have your
  1187. 43:59decode pool, which is a few different
  1188. 44:02pods on a few different servers.
  1189. 44:04Next, out front comes a gateway, which
  1190. 44:06is kind of the same gateway that you
  1191. 44:08would put in front of any web service,
  1192. 44:10and it gives you one address for the
  1193. 44:12whole fleet.
  1194. 44:13And right behind it sits the LLMD
  1195. 44:16scheduler, which is a small brain
  1196. 44:17holding the cache aware and the load
  1197. 44:19aware logic. And the gateway takes the
  1198. 44:22request, and the scheduler picks the
  1199. 44:24pod. So, this is a very high-level
  1200. 44:26overview of the architecture. Later in
  1201. 44:29the full course, we will dive more
  1202. 44:31deeper into what are the different
  1203. 44:33subcomponents of these.
  1204. 44:35Now, what happens to the giant models?
  1205. 44:38The giant large language models. So, say
  1206. 44:39a model is too big for a single machine,
  1207. 44:41it has to span several of them. So,
  1208. 44:43Kubernetes needs a way to treat that
  1209. 44:45whole group of pods as one unit. So, if
  1210. 44:47you already know Kubernetes, you're
  1211. 44:49probably already aware of stateful sets,
  1212. 44:51because that's the first thing that came
  1213. 44:52to my mind
  1214. 44:53when I thought how you would deploy a
  1215. 44:55model.
  1216. 44:56Now, does LLMD use stateful sets here?
  1217. 44:59So, a stateful set gives each pod a
  1218. 45:01stable name and starts them in a fixed
  1219. 45:03order, like 0 1 2 3, etc. And this is
  1220. 45:07especially useful for, say,
  1221. 45:09databases like MySQL that needs to power
  1222. 45:12up in a particular sequence. But, it
  1223. 45:14still treats every pod as its own
  1224. 45:16separate replica. Now, this works for
  1225. 45:19databases like MySQL, but in case of
  1226. 45:21LLMs that are split across different
  1227. 45:23pods, they're not separate servers or
  1228. 45:25replicas because together they are one
  1229. 45:27server that is simply split into
  1230. 45:30different pieces. So, scaling
  1231. 45:33should add another whole group of them,
  1232. 45:35and not just like one pod, which would
  1233. 45:38just be hanging. And if a single
  1234. 45:40part of that, if a single shard of that
  1235. 45:42fails, the whole group has to restart
  1236. 45:44together because a model missing a piece
  1237. 45:46can't answer anything at all. So,
  1238. 45:49Kubernetes built a new kind of object
  1239. 45:51that can say these pods belong together,
  1240. 45:54and it's called the leader worker set.
  1241. 45:57So, it's a leader pod plus its workers
  1242. 45:59scaled and healed as a single unit. Now,
  1243. 46:02every box in that architecture is a
  1244. 46:04standard Kubernetes object. So, how do
  1245. 46:06you describe it all to Kubernetes? And
  1246. 46:07it comes down to the values.yaml file
  1247. 46:10that you pass to help when you deploy
  1248. 46:12the model. Now, this is where you
  1249. 46:14describe the URI to the llama model.
  1250. 46:16That's the location where the model file
  1251. 46:18exists. And then you define how many
  1252. 46:20pods serve prefill and how many serve
  1253. 46:22decode. And when you swap that one file
  1254. 46:25with another file with another values,
  1255. 46:27you get a completely different fleet of
  1256. 46:29servers and and pods. And when you apply
  1257. 46:32them, LLMD creates the prefill pods and
  1258. 46:34the decode pods, puts the gateway and
  1259. 46:36the scheduler out front, and wires it
  1260. 46:39all together. So, a minute later, you
  1261. 46:41ask cluster what's running, and then
  1262. 46:44there it is. You see a few lines of
  1263. 46:46text, which tells you exactly what's
  1264. 46:48running in your inference system.
  1265. 46:51Now, once it is up,
  1266. 46:53how do you keep it running? Now, this is
  1267. 46:55kind of the uh best part of this because
  1268. 46:57it's deployed on Kubernetes. Now, every
  1269. 46:59server here is just a pod. So, the
  1270. 47:01normal Kubernetes loop looks after all
  1271. 47:04of them, and that's the part your ops
  1272. 47:06team already trust. So, a pod crashes,
  1273. 47:08and Kubernetes restarts it. A whole
  1274. 47:10machine dies, and Kubernetes moves those
  1275. 47:12pods somewhere else. And because the
  1276. 47:15readers and the writers are separate
  1277. 47:17pools, you grow each one independently.
  1278. 47:20And adding decode pods when answers
  1279. 47:22start backing up, and when you have the
  1280. 47:24prefill pods when the prompts get heavy.
  1281. 47:27So, Kubernetes keeps the servers alive,
  1282. 47:29and LLMD keeps them smart.
  1283. 47:31So, how do you actually use it? So, when
  1284. 47:33LLMD comes up, it hands you a single
  1285. 47:35address, the inference gateway, and that
  1286. 47:37one endpoint sits in front of your
  1287. 47:39entire fleet. So, you're in front of
  1288. 47:41your entire prefill pod, your every
  1289. 47:43decode pod, and and even in front of the
  1290. 47:46entire sharded giant models. So, you
  1291. 47:49never call a pod directly as you
  1292. 47:50wouldn't in the case of web app, either.
  1293. 47:54You would instead look at the URL that's
  1294. 47:57the given by the IP address in the URL
  1295. 47:59that's for the gateway and you would
  1296. 48:01route your request there. So, just to
  1297. 48:03summarize, when you send a request to
  1298. 48:06our cluster now, the request hits the
  1299. 48:08gateway, the scheduler picked the pod
  1300. 48:11that already held your saved work, a
  1301. 48:13pre-filled pod read your prompt, and a
  1302. 48:15decode pod wrote the answer one token at
  1303. 48:18a time, streaming the model straight out
  1304. 48:20of memory. And if the model happened to
  1305. 48:22be a giant, a whole group of GPUs spread
  1306. 48:24across several machines did that work
  1307. 48:26together as one. If you want to read up
  1308. 48:28further on this, the project lives at
  1309. 48:30llm-d
  1310. 48:32.ai. That's llm-d.ai.
  1311. 48:34So, look it up.
  1312. 48:37Now, before we close, I want to talk
  1313. 48:39about you and about where you go from
  1314. 48:41here. If you take a look at everything
  1315. 48:43we just walked through, we spent this
  1316. 48:45whole course on pods and deployments, on
  1317. 48:48routing and load balancing, on caching,
  1318. 48:50auto scaling, memory, and networking.
  1319. 48:52And almost none of it was machine
  1320. 48:53learning. It was infrastructure work
  1321. 48:56from the first lesson to the last. The
  1322. 48:58models may be new, but the discipline is
  1323. 49:00one you already have. So, if you're a
  1324. 49:03systems administrator or an SRE or a
  1325. 49:05DevOps engineer, you're closer to this
  1326. 49:07world than you might think. Linux
  1327. 49:09containers, Kubernetes, and monitoring
  1328. 49:11are the foundation that every AI
  1329. 49:13platform stands on, and they're exactly
  1330. 49:15the skills teams are struggling to hire
  1331. 49:18for right now. So, every company racing
  1332. 49:20to ship AI needs somebody who can keep
  1333. 49:23the GPUs busy, keep the latency down,
  1334. 49:25and keep the bill under control. And
  1335. 49:27that person looks a lot like you. And
  1336. 49:29this is not some small corner of the
  1337. 49:31industry. Remember the trillions of
  1338. 49:33dollars we saw pouring into data centers
  1339. 49:36at the start of this course? Because
  1340. 49:37every one of those data centers need
  1341. 49:39people to build it and run it, and
  1342. 49:41that's why the World Economic Forum
  1343. 49:43lists AI and big data as the fastest
  1344. 49:45growing skills of this decade, and why
  1345. 49:47LinkedIn named AI engineer the fastest
  1346. 49:50growing job in the United States.
  1347. 49:52Now, you don't need to become a data
  1348. 49:54scientist, and you don't need to train
  1349. 49:56models. You need to point the skills you
  1350. 49:59already have at a new kind of workload.
  1351. 50:01So, keep your foundation and add that ER
  1352. 50:03layer on top of it. How GPUs work, model
  1353. 50:06servers like vLLM, and orchestration
  1354. 50:08with LLMD, which is the exact stack we
  1355. 50:11took apart in this course. So, we've
  1356. 50:13laid all of that out step-by-step as a
  1357. 50:15learning path on Code Cloud. So, it
  1358. 50:17starts from the foundations. You can
  1359. 50:19jump in whenever you're ready, and it
  1360. 50:20runs all the way to serving models at
  1361. 50:22scale. So, you'll find it at
  1362. 50:23codecloud.com/learningpath/ai.
  1363. 50:27The hard problems in AI are
  1364. 50:29infrastructure problems now, and nobody
  1365. 50:32is better placed to solve them than you.
  1366. 50:35Now, it's time to try the um vLLM lab.
  1367. 50:38First of all, uh you don't need to worry
  1368. 50:40if you're not um feeling confident for
  1369. 50:42the lab because this lab comes with a
  1370. 50:44lot of hints and solutions. In this lab,
  1371. 50:46you'll get um a model server that
  1372. 50:48answers one request at a time, and users
  1373. 50:51are waiting. And by the end of the lab,
  1374. 50:52your goal will be to build a real vLLM
  1375. 50:55server handling multiple users at once.
  1376. 50:57Go give this lab a try.

About this transcript

This page contains the full transcript of AI Infrastructure Explained (GPUs, vLLM, and LLM-D) by KodeKloud, generated from the public captions YouTube serves with the video. The transcript has 9,360 words across 1,376 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.