AI Infrastructure Explained (GPUs, vLLM, and LLM-D) — Transcript
Full transcript
- 0:00This is an introduction to the
- 0:02infrastructure behind AI, which means
- 0:04the GPUs, the servers, and the systems
- 0:07that sit behind every product you've
- 0:09ever used. If you're an SRE, a systems
- 0:12administrator, or a DevOps engineer,
- 0:14this course is for you. And there's
- 0:16never been a better time to learn it.
- 0:19Companies like Amazon, Google,
- 0:20Microsoft, and Meta together are
- 0:22spending over $700 billion on AI
- 0:25infrastructure this year alone. That is
- 0:28four times what they were spending just
- 0:304 years ago before ChatGPT launched, and
- 0:32it grew nearly 80% in the last year
- 0:35alone. McKinsey expects close to $7
- 0:38trillion to go into data centers by
- 0:402030. Now, somebody has to build all of
- 0:42that and keep it running, and the people
- 0:44who can are some of the most
- 0:46sought-after engineers in the industry
- 0:48today. So, let's start with a question.
- 0:51What actually happens when you type
- 0:52something into ChatGPT and press enter?
- 0:56Behind that answer is a solution that is
- 0:58unreasonably hard to build. And in this
- 1:01course, we're going to take that
- 1:02solution apart piece by piece. So, we'll
- 1:05start with a single GPU and build it up
- 1:07into a real model server. We'll learn
- 1:09how a model writes its answers one word
- 1:12at a time, and we'll find the hidden
- 1:14cache that makes it fast. Then, we'll
- 1:16pack many users onto one GPU, and we'll
- 1:18split models that are too big for any
- 1:20single card across several of them, and
- 1:23we'll see why ordinary load balancing
- 1:25falls apart the moment you run a cluster
- 1:27of GPU servers. We'll see how LLMD
- 1:31LLMD is an open-source project that's
- 1:34built by companies like Red Hat, Google,
- 1:36IBM, and Nvidia, and its job is to run
- 1:39the whole fleet of servers, routing
- 1:41every request to the right server,
- 1:43moving caches around, sharing the GPUs
- 1:45fairly, and scaling them down when
- 1:47traffic stops. Now, you don't need any
- 1:49machine learning background for this. If
- 1:51you can follow a request through a
- 1:53system, you can follow everything in
- 1:55this course. My name is Mumshad Man Robb
- 1:57I'll be walking you through this course.
- 1:59And this is the part of AI that nobody
- 2:02shows you.
- 2:05So, you open ChatGPT, you type in a
- 2:07question, you hit enter, and a moment
- 2:09later an answer comes back. Now, let's
- 2:11pull that apart, starting with the name,
- 2:13because the name is really two things
- 2:14stuck together. So, you have the chat
- 2:16part, which is the application, that's
- 2:18the website, and the GPT part is the
- 2:20model, which is the thing that's behind
- 2:22the scenes, that's actually reading your
- 2:24question and working out the answer.
- 2:27And GPT is only one model. There's
- 2:29Claude from Anthropic, Gemini from
- 2:30Google, and Llama from Meta, along with
- 2:33plenty more. Now, they have different
- 2:34names, but the same idea sits underneath
- 2:36all of them, which is a model doing the
- 2:39thinking with an application wrapped
- 2:41around it.
- 2:42But, what is one of these models? And
- 2:44before we get technical, let me show you
- 2:45the simplest possible version of a
- 2:47model. So, forget about AI for a second.
- 2:50Picture a tiny machine where you drop a
- 2:52number, and and a different number comes
- 2:54out. You drop in three, and out comes
- 2:56six. You drop in 10, and out comes 20.
- 3:00Every time it doubles whatever you gave
- 3:01it.
- 3:02That little machine is a model. It takes
- 3:05an input, it does some math, and it
- 3:07hands you an output. And the whole
- 3:09behavior, the doubling, comes down to
- 3:11one number hiding inside it,
- 3:13which is times two.
- 3:15So, if you look closely, there are
- 3:17really two things in that one line.
- 3:19First, there's the formula, which is the
- 3:21shape of the calculation, an
- 3:22[clears throat] input, a multiply, and
- 3:24an output.
- 3:25That part is fixed, and it's the
- 3:27structure.
- 3:29Second, there's the number sitting
- 3:30inside it, the number two, which is the
- 3:32part the machine actually learned. That
- 3:34number has a name, and we call it a
- 3:36weight.
- 3:37So, you change the weight from two to
- 3:39three, and the very same formula now
- 3:41triples instead of doubles. So, it's the
- 3:44same structure with a different number
- 3:46and completely different behavior.
- 3:48Now, one weight and one multiplication
- 3:50won't get you very far. So, let's make
- 3:51it do something real. So, you want to
- 3:54guess the price of a house. A house has
- 3:56few things that you can measure, like
- 3:58its size, how many bedrooms it has, and
- 4:00how old it is, and each one pushes the
- 4:02price by some amount.
- 4:04So, it's still just multiply and add,
- 4:09the same math as doubling the box, but
- 4:11now there are several weights. So,
- 4:13there's 350,000,
- 4:141,000, 25,000. Each weight says how much
- 4:19that one thing matters. And where do
- 4:21these numbers come from?
- 4:22You don't make them up. You show the
- 4:24formula thousands of real houses with
- 4:26their sizes, bedrooms, ages, and the
- 4:28price each one actually was sold for,
- 4:30and it works out the weights that fit
- 4:32best. So, that working out of the
- 4:35weights from examples is what training
- 4:37is. So, now the picture is clear because
- 4:40a model is a formula, and its weights
- 4:42are numbers that are learned from
- 4:44examples.
- 4:46Now, we just keep going. A house price
- 4:48needed a handful of weights, but
- 4:50understanding a sentence needs far more
- 4:52than that because language is far more
- 4:54tangled than just bigger houses and
- 4:56higher prices. So, the formula grows.
- 4:58So, you get more inputs, more
- 5:00multiplications, and more weights.
- 5:02That's all stacked in layers where the
- 5:04output of one becomes the input of the
- 5:07next. Now, if you keep growing that, and
- 5:09in one very particular arrangement, you
- 5:11arrive at the shape behind every modern
- 5:14language model. And that shape has a
- 5:15name, and it's called the transformer.
- 5:18Now, don't worry about how it works
- 5:19inside because what matters is what it
- 5:21is. So, it's the same idea as doubling
- 5:23the box with inputs, multiplications,
- 5:25weights, and an output. It's just that
- 5:27it's enormous and wired in a specific
- 5:30pattern. So, the transformer is the
- 5:32formula. It's written once in code, and
- 5:35it's broadly the same across GPT,
- 5:37Claude, and LLaMA.
- 5:39What makes each of them different isn't
- 5:41the formula, it's the weights.
- 5:44Which brings us to the The part. The
- 5:46formula, the transformer, is only a page
- 5:48of code, and all of the knowledge is in
- 5:50the weights. A real model doesn't have
- 5:52four weights or 400, because it has
- 5:55billions of them. And these billions of
- 5:57numbers are what training produced, and
- 5:59they have to live somewhere, so they sit
- 6:01quite literally as a file on a disk.
- 6:04It's simply a very large file that's
- 6:06full of numbers waiting to be poured
- 6:07into the formula. And if you open one
- 6:09up, that's all genuinely that you would
- 6:12see inside.
- 6:14And they come in wildly different sizes.
- 6:15So, a small model may be 2GB in size. A
- 6:17mid-size model may be 16GB. A large
- 6:21model with 70 billion parameters would
- 6:23be 140GB.
- 6:25And the giants, like 500 plus billion
- 6:27numbers, uh would be several hundred GB.
- 6:30To actually use one of these files, you
- 6:32load it off the disk into a memory, and
- 6:34you hand it your question as input, and
- 6:37you let the formula run all those
- 6:38numbers over uh what you gave it, and
- 6:40out comes the answer that you read on
- 6:42screen. You load the file into memory,
- 6:45you feed it text, you get text back.
- 6:48That's basically at its simplest form,
- 6:51a model running. Now, that brings us to
- 6:53the obvious question. So, if model is
- 6:55just a file, and running it is only a
- 6:57matter of loading it into memory and
- 7:00doing some math, then why can't you just
- 7:02run one on your own laptop? So, take one
- 7:05of the smaller models, the kind that
- 7:06fits in your computer's memory just
- 7:08fine. Uh you've got a perfectly good
- 7:10machine sitting right in front of you.
- 7:12So, why can't you just run thing? To see
- 7:15why, we need to look at the computer a
- 7:17little bit closer. So, think about any
- 7:20computer you've ever used, whether it's
- 7:22your laptop or a server in a data
- 7:23center.
- 7:25On the inside, there are two
- 7:27important parts that we care about.
- 7:28There's the CPU, the processor, and
- 7:30that's the part that actually does the
- 7:32thinking, the calculations, the logic,
- 7:34and the work. And then there's the RAM,
- 7:35the memory, which is where the computer
- 7:37keeps the data and the instructions the
- 7:39CPU is currently working on.
- 7:41Now, here's the thing I wanted you to
- 7:42notice because it comes back later.
- 7:45These two parts sit separately. The CPU
- 7:47is one place and the memory is in
- 7:49another and they are connected by a
- 7:51channel between them.
- 7:53Now, if you take the smallest
- 7:54calculation there is, you punch 6 * 7
- 7:57into a calculator app and those two
- 7:58numbers land in the memory first. So,
- 8:01the CPU then reads them out, does the
- 8:04multiplication, and writes the result,
- 8:06which is 42, back into the memory. So,
- 8:08every single calculation is the same
- 8:10round trip, which means the computer and
- 8:13memory are always
- 8:15tightly paired.
- 8:16The processor here, there's the memory
- 8:18there, and there's like a small road, a
- 8:20bus that's
- 8:22between these two.
- 8:23Now, that is kind of the same way that
- 8:26every type of computing works.
- 8:27So, the CPU is a brilliant generalist.
- 8:30It has a handful of very powerful cores.
- 8:33It works through complicated tasks
- 8:35one after the other.
- 8:36It's extremely fast and for almost
- 8:39everything that you do on your computer,
- 8:40like running your browser, your
- 8:42applications, your operating system,
- 8:43that's exactly what you want.
- 8:45So, what is a model actually doing under
- 8:48the hood? Now, at its core, running a
- 8:50model comes down to billions of very
- 8:53small multiplications. And here's the
- 8:55important part because these
- 8:56multiplications don't depend on each
- 8:58other. They can all happen at the same
- 9:01time, in parallel.
- 9:02Now, a CPU is really a few powerful
- 9:05cores one after another. So, when we
- 9:07hand it billions of independent little
- 9:10multiplications, it works through them
- 9:12mostly in sequence, a few at a time. It
- 9:14gets every single one right and you'll
- 9:16be waiting a very, very long time.
- 9:19And that's our first problem. So, the
- 9:21work is massively parallel with billions
- 9:23of things that could all happen at once,
- 9:25but the CPU is built to do things in
- 9:28sequence and we need a different kind of
- 9:30processor. And that's where the GPU
- 9:32comes in. Now, the GPU is a processor
- 9:34that's built the exact opposite way.
- 9:36Instead of a handful of powerful cores,
- 9:38it has thousands of small, simple cores,
- 9:41and they all do math at the same time.
- 9:43So, if you take a modest GPU like the
- 9:45Nvidia T4, which has around 2,500
- 9:48of these little cores,
- 9:50and if you put some numbers on the
- 9:52difference, a CPU manages roughly 10
- 9:54trillion operations per second, while a
- 9:57GPU can get closer to a thousand
- 10:00trillion operations per second. So, it's
- 10:02about a hundred times more math every
- 10:05second.
- 10:06So, the GPU solves our math problem, but
- 10:09uh it also creates a new one.
- 10:11Because if you remember how a computer
- 10:12is built that we just spoke about, a
- 10:14processor needs memory to feed it data.
- 10:17And the same thing is true for a GPU. A
- 10:19GPU needs something to feed it all of
- 10:22this data that it needs to compute.
- 10:24In the case of a model, it's the
- 10:25weights. So, all those billion numbers
- 10:28of billions of parameters that we spoke
- 10:30about earlier,
- 10:31they need to be stored somewhere, and
- 10:33they need to be delivered to the CPU.
- 10:35So, where do they live? If we leave them
- 10:37sitting on the computer's regular RAM,
- 10:41there's a problem because the system RAM
- 10:43sits far off the card, down a narrow
- 10:45pipe that carries about 64 Gbps, and
- 10:49that's roughly 50 times slower than what
- 10:52the core actually can eat. That was fine
- 10:54for a CPU doing a few things at a time,
- 10:56but for thousands of GPU cores all
- 10:58demanding data at once, that far away
- 11:01memory simply can't deliver fast enough.
- 11:03So, the cores end up sitting idle,
- 11:05waiting for numbers that arrive too
- 11:07slowly. So, how do we feed these
- 11:10thousands of cores fast enough? The
- 11:12answer to that is to give the GPU its
- 11:14own memory that's built right onto the
- 11:17card and sitting right next to its core.
- 11:19And this is called VRAM.
- 11:21And here's where I wanted to bring back
- 11:23that picture from the very beginning.
- 11:25So, on a computer, the CPU and the RAM
- 11:28sit apart, connected by a road. The GPU
- 11:31uses the same idea of a
- 11:32and its memory, but it packs them
- 11:34tightly together on a single board
- 11:37that's right next to each other. So, the
- 11:39data never has to
- 11:41travel far and is the same pairing that
- 11:44you already know that's just moved kind
- 11:46of close together. Now,
- 11:49the VRAM has a much wider pipe uh that's
- 11:51measured in terabytes a second rather
- 11:53than gigabytes. So, now the models
- 11:55weights live right beside the map and
- 11:58the cores can be fed. But, this solution
- 12:00comes with a catch and the catch is
- 12:02size. So, VRAM is fast, but it's small.
- 12:05So, a card like the T4 has 16GB only.
- 12:08And
- 12:09remember the model sizes from the start
- 12:11of the lessons that we spoke about? That
- 12:13a large model
- 12:15some of them are with 70 billion numbers
- 12:17and needs around 140GB of weights just
- 12:20to sit in the memory.
- 12:22So, space in the VRAM is precious and
- 12:24keep that in mind because later we'll
- 12:26see how
- 12:28GPUs tackle
- 12:30loading large models with hundreds of
- 12:32GBs in size
- 12:34onto multiple GPUs. So, with all of
- 12:37that,
- 12:38there are three numbers that size every
- 12:40AI workload. So, you have the compute,
- 12:42which is how much math the card can do.
- 12:46Then there's the capacity, which is how
- 12:49much fits in that memory.
- 12:52And then there's the bandwidth, which is
- 12:53how fast it can read its own memory. So,
- 12:57every card that you're ever going to
- 12:58meet is described by these three numbers
- 13:01and each generation adds more of all the
- 13:05three.
- 13:06So, those three numbers describe every
- 13:07card that you're ever going to meet. So,
- 13:09here we have a list of cards
- 13:12and a comparison between the three. So,
- 13:14at first we have the desktop and we know
- 13:17that uh typically you have anywhere from
- 13:19one to three TFLOPS
- 13:21uh processing power on a desktop.
- 13:24The The and memory is usually 32GB or
- 13:2764GB and the bandwidth between the
- 13:30memory and the compute is about 0.09
- 13:33TBps. Now, if you compare that against a
- 13:36rack server, which typically does about
- 13:385 to 10 TFLOPS computing power and
- 13:41usually has really high RAM,
- 13:44the
- 13:45bandwidth between the RAM and the CPU is
- 13:47around 0.5.
- 13:49But, if you compare these to the Nvidia
- 13:52data center cards, for example, so A100,
- 13:55H100, H200, and B200, A100, the smallest
- 13:59of them all, has about 312 TFLOPS
- 14:02capacity or computing power, and the
- 14:04memory has 80GB in capacity. The
- 14:07bandwidth is around 2 TBps. The H100 and
- 14:11H200 are the comparatively higher level
- 14:13of cards. They each have 990 TFLOPS
- 14:18computing power, but if you look at the
- 14:20difference is mainly in the memory. So,
- 14:23H100 is 80 VRAM capacity and H200 has
- 14:27141 GB of capacity.
- 14:29Uh the B200s are comparatively much
- 14:32higher and they have about 2,250
- 14:36TFLOPS computing power and has a really
- 14:39high VRAM of about 192GB
- 14:43and also has higher bandwidth between
- 14:45the memory and the compute of about 8
- 14:47TBps. Now, a chip on its own does
- 14:50nothing at all because something has to
- 14:52drive it. So, that something, the
- 14:54software, is called PyTorch, which is
- 14:56the uh software that loads the model
- 14:58onto the GPU and puts all of these cores
- 15:00to work. So, in just few lines of code,
- 15:02as you can see here, in about
- 15:04six to seven lines of code, you're
- 15:05importing the torch package and then
- 15:08you're uh loading the Llama model. In
- 15:11this case, it's a Llama model. And then,
- 15:13all you do is uh you're calling the gen
- 15:15command that actually sends a request or
- 15:18a question to the model and it res-
- 15:20sends back a response. You when you look
- 15:22at the generated text in the response,
- 15:25that would be what model actually
- 15:27generated. So, here's the super simple
- 15:28example to load a simple model on your
- 15:31laptop. So, if you download really small
- 15:33models on your laptop, you can actually
- 15:34try this right away. Now, that's just a
- 15:36script. It runs once for one person and
- 15:38then it's done. Real users are out on
- 15:40the internet, thousands of them that are
- 15:42all at once. So, you need something
- 15:44that's always on, that's listening for
- 15:46requests and running the model
- 15:47efficiently. And that's a model server.
- 15:50And the one that we'll keep coming back
- 15:52to is uh vLLM, which is built right on
- 15:54top of PyTorch. It wraps the model into
- 15:57a service with a normal web API. So, now
- 16:00it's a real product. And that raises a
- 16:02question that we're going to pick up
- 16:04next. What is that server actually doing
- 16:06every time a request comes in?
- 16:10Okay, so we'll now look at the model
- 16:12server itself. So, say I want to serve a
- 16:14model and it's really just one command.
- 16:17So, I run the vLLM serve and point it at
- 16:19the model. And vLLM then reads
- 16:21[clears throat] the model weights off
- 16:23the disk and loads them into the GPU
- 16:25memory. That's about 16 GB to move, so
- 16:28you'll be waiting for a minute or two.
- 16:31Now, after that, the server is up and
- 16:33running and it stays up and it waits for
- 16:35requests. So, how do you talk to it? You
- 16:37send it a normal web request, the same
- 16:39way that you would talk to any other web
- 16:41service.
- 16:42vLLM speaks the exact same format that
- 16:44the OpenAI API uses. So, any tool that
- 16:47already talks to OpenAI, any script that
- 16:49you've already built that talks to
- 16:50OpenAI can talk to your own server
- 16:53instead without changing a single line
- 16:55of code. Now, let's notice what we have
- 16:57actually got here. So, this one server
- 16:59is holding the entire model in its GPU
- 17:00memory.
- 17:01The whole time that it's running.
- 17:03Now, so if one server isn't enough, a
- 17:05second one is not cheap at all because
- 17:08it means another full copy of the model
- 17:10on another expensive GPU. So, a model
- 17:13server is a heavy beast. Uh it's
- 17:15expensive to run on, it's slow to start,
- 17:17and it's costly to copy. Okay, so now
- 17:20that we've got a real server that's
- 17:21answering real questions, everything
- 17:23that's actually matters is happening
- 17:25inside those few seconds. So, what is
- 17:26the model really doing in there? Like,
- 17:28between reading a prompt and handing
- 17:30back the output?
- 17:32That's what we'll see next.
- 17:35Now, before we go any further, there's
- 17:37one word that you'll need, and this is
- 17:40something that you have heard a lot of
- 17:42times.
- 17:43Tokens. So, language model doesn't read
- 17:46and write whole words the way we do.
- 17:49Instead, it breaks it into little pieces
- 17:51called tokens.
- 17:52So, a token is roughly 3/4 of a word.
- 17:55So, sometimes it's whole word, and
- 17:56sometimes it's only part of a word. If
- 17:59you take a sentence like serving LLMs is
- 18:01not like serving web apps, which is
- 18:03eight words, but it comes to about nine
- 18:05tokens. And everything here gets counted
- 18:07in tokens. So, what a model can read,
- 18:09what you pay, and how fast it goes, and
- 18:12how fast it gets generated, all of these
- 18:15happen in terms of tokens.
- 18:17Now, the model has exactly one trick.
- 18:19So, it's basically predicting machine,
- 18:22right? Which is, given all the text so
- 18:24far, it predicts the next word or the
- 18:26next token. So, then it takes that
- 18:29token, adds it to the original text, and
- 18:31then it takes that again, the output of
- 18:33that, and then pens it to the original
- 18:37text, and it does that again and again
- 18:39and again until it generates the entire
- 18:41output that makes sense to the user. So,
- 18:44a 100 token answer or 100 word answer
- 18:47isn't like one big calculation, it's the
- 18:49model running that loop a 100 times
- 18:51over, like one token per lap. And that's
- 18:54exactly why the answer types itself out
- 18:57word by word when you watch ChatGPT,
- 19:00because you're watching each lap finish.
- 19:02Uh, so, the streaming comes as a free
- 19:03feature.
- 19:04So, there's two things that fall out of
- 19:06this, and both of this we'll talk about
- 19:08later. The first is that these requests
- 19:11take a long time, because a normal web
- 19:13request is over in maybe a few
- 19:15milliseconds, but a few hundred tokens
- 19:17means a few hundred laps of that loop.
- 19:20Now, the second one is a big one. It's
- 19:22that there are no two requests that are
- 19:24the same. So, you're asking for, say,
- 19:26capital of France is a few tokens in and
- 19:29maybe one or two tokens out, but uh if
- 19:31you were to say, "Summarize this
- 19:33100-page contract,"
- 19:35that's like tens of thousands of token.
- 19:37So, both of these kind of hit the same
- 19:39server, through the same API, but one is
- 19:42a thousand times more than the other.
- 19:44So, that is one thing that we'll look at
- 19:46uh later. So, we spoke about the loop,
- 19:49which generates one token at a time.
- 19:51Now, let's take a deeper look at what
- 19:54that loop does. So, we'll now go into
- 19:56the loop and uh try and see uh the two
- 19:58halves of that loop. So, there's the
- 20:01initial pause half, and then there's the
- 20:04streaming half, and that is what we will
- 20:05look at next.
- 20:08So, what are the two halves of a loop?
- 20:11So, you paste a big chunk of text into
- 20:13ChatGPT and you hit enter. And there's
- 20:16this pause initially for a second or or
- 20:18two, where nothing happens.
- 20:20And then the answer comes out, and it
- 20:23streams out word by word steadily. So,
- 20:26there's the pause, and then there's the
- 20:28stream. So, the pause and stream are the
- 20:30two halves, and we'll see exactly what
- 20:32happens in each of these. So, let's
- 20:34start with the pause. Now, before the
- 20:35model can write a single word, it has to
- 20:38read everything that you give it, which
- 20:40is your whole prompt.
- 20:42Because
- 20:43it reads all of it at once. So, your
- 20:45prompt is already there in full, so
- 20:48there's nothing to wait on, and every
- 20:50token goes through the whole model
- 20:52together in one big burst. So, the whole
- 20:55model gets loaded out of the VRAM once,
- 20:57and thousands of cores fire at the same
- 20:59time to chew through the entire prompt
- 21:01in a single pass, and that pass ends by
- 21:04producing the first token of your
- 21:06answer. And that's the moment the pause
- 21:08ends and the typing or the streaming
- 21:11begins. So, the pause comes down to one
- 21:13thing, which is how much you gave it to
- 21:15read. Asking for the capital of France
- 21:17is about, say, seven tokens. So, that's
- 21:19only one tiny pause and no pause would
- 21:23be noticed. But, if you paste a 100-page
- 21:25contract and that's like tens of
- 21:27thousands of tokens that's pushed
- 21:28through at once, and that single burst
- 21:31becomes a real weight. So, this first
- 21:33phase has a name and it's called
- 21:35prefill. So, it's not called pause,
- 21:37that's just something I just came up
- 21:38with, but it's called prefill, that's
- 21:40the technical term. The weight it causes
- 21:42has a name, too. So, which is
- 21:45the time to first token. So, TTFT, time
- 21:48to first token means the time that it
- 21:50takes for the prefill process, the
- 21:53initial computing process, to complete.
- 21:55And how much time does it take to get
- 21:57that first token, the first word of the
- 22:00response generated? That's TTFT or time
- 22:03to first token. Now, let's look at the
- 22:04second phase, which is the writing the
- 22:07answer part, the streaming part. Now,
- 22:09this is the token-by-token loop that we
- 22:11spoke about earlier. So, each token is
- 22:13one full pass through the model and
- 22:16because this phase has completely
- 22:17different bottleneck, to produce each
- 22:19new token, the GPU has to read the
- 22:21entire model out of its memory. So,
- 22:23writing a 200-token answer means you
- 22:26load the entire model out of the memory
- 22:28200 times over. And each of those loads
- 22:31buys you exactly one token. So, the
- 22:34cores barely do any work at all in this
- 22:36phase. So, this second phase is called
- 22:38decode and the speed is limited by how
- 22:41fast the GPU can read its own memory.
- 22:44So, how fast the entire
- 22:46model loads from the memory into the
- 22:48GPU.
- 22:49So, why is the reading
- 22:51that's limiting the speed?
- 22:53So, the cores are tiny and they can't
- 22:55hold the entire model. So, the weights
- 22:58live in VRAM, which is something we
- 22:59spoke about earlier, and the cores have
- 23:01to be fed from it's constantly. That
- 23:03means for every single token, the entire
- 23:05model streams out of the VRAM into the
- 23:07cores, gets used, and makes way for the
- 23:09next one. And that stream has a speed
- 23:12limit. So, a high-end GPU reads its own
- 23:14memory at about 3 TB per second, which
- 23:18sounds enormous. And this is something
- 23:20we discussed earlier, different GPUs
- 23:23have different speed limits.
- 23:253 TB a second against a 16 GB model
- 23:28means the GPU can only read the whole
- 23:30thing about 200 times a second. So, if
- 23:32you do a simple math, you'll see that
- 23:33that's one read per token, so it's 200
- 23:36tokens a second, and that's the maximum
- 23:39limit.
- 23:40So, the benchmarks usually flip that
- 23:42number around and call the gap between
- 23:44one token and the next, which is about 5
- 23:46ms. So, that's like one token every 5
- 23:49ms. So, that gap per token is called as
- 23:53TPoT. So,
- 23:55the TPoT stands for time per output
- 23:58token. And every serving benchmark
- 24:00you'll ever read is built on these two.
- 24:02So, there's the initial pause, that's
- 24:05the TTFT, and then then you have the
- 24:08TPoT, which is the time per output
- 24:11token.
- 24:12Okay, so to summarize, we have seen two
- 24:14phases. You have the prefill phase,
- 24:16which is when the original prompt gets
- 24:18processed, so that's the initial pause,
- 24:21and that is compute heavy. And then
- 24:22there's the decode phase, which writes
- 24:24the answer by rereading the model over
- 24:26and over. And that's the stream that we
- 24:29see, and that is a memory bandwidth
- 24:32heavy. So, those are the two kind of
- 24:34different
- 24:35computing and memory requirements for
- 24:37the two different phases.
- 24:39One is one-time calculation, the other
- 24:41is a long, steady grind against memory.
- 24:43And right now, they're both happening on
- 24:45the same GPU. So, the same GPU takes
- 24:47turns to process both of these different
- 24:49kinds of operations.
- 24:52So, with the prefill and decode phases,
- 24:55every new token generated has a prefill
- 24:57phase that processes everything until
- 25:00then and then the decode phase that
- 25:01generates the new word.
- 25:03With that approach, every word would
- 25:05have a gap before the new word is
- 25:07generated. So, that's a fresh pause
- 25:09before every single word and the chat
- 25:12would be too slow to use. But, that's
- 25:14not what happens. We know that with chat
- 25:16applications like ChatGPT, the words
- 25:18come out like really fast, one after the
- 25:20other with no repeated stall. So, how
- 25:22does that happen?
- 25:24The prefill step is the real work and
- 25:26it's expensive because it consumes a lot
- 25:28of GPU power. But, instead of throwing
- 25:30it away the moment it's done, the model
- 25:33saves it right there in the GPU's
- 25:35memory. And that saved work has a name.
- 25:37That's called KV cache. So, prefill runs
- 25:40once right at the start and save the
- 25:42output in the KV cache. From then on, as
- 25:45the model writes the answer one token at
- 25:46a time, it does not repeat prefill for
- 25:49each new token. It just reaches into the
- 25:51cache, reuses everything it already
- 25:53worked out, and adds the one new token
- 25:55on top. So, you pay for that pause only
- 25:58once
- 25:59and not before every word.
- 26:01So, now everything above covers exactly
- 26:04one message.
- 26:05One question in and one answer out. So,
- 26:08the moment your reply finishes, that
- 26:10request is done and the cache gets
- 26:12cleared. So, what happens the moment you
- 26:15send a second message in the chat? The
- 26:18model remembers nothing between
- 26:19messages. So, your chat app resends the
- 26:22entire thread every single time. So,
- 26:24your first question, your first answer
- 26:27that you receive from the model, and now
- 26:29your new message. This is all bundled
- 26:31into one request. And because last
- 26:33time's work is already gone, the server
- 26:35has to reread every word of that from
- 26:37the very beginning before it can reply.
- 26:40And every turn rebuilds all that work
- 26:42from scratch and then throws it away.
- 26:44So, the longer you talk, the longer you
- 26:46wait. So, the cost of a conversation
- 26:48grows with every message because it has
- 26:51to do the prefill for every message.
- 26:54So, what if instead of throwing that
- 26:56cash away the moment the request ends,
- 26:58you just kept it? You hang on to those
- 27:00saved blocks and you label each one by
- 27:03the exact text that produced it. Now,
- 27:05turn two arrives. The model looks at
- 27:07your thread and realizes it has already
- 27:09done the work on all of it except your
- 27:11newest message. That's the only part it
- 27:14actually has to prefill.
- 27:16Turn 10 now costs about what turn two
- 27:18costs. So, the pause stays small no
- 27:20matter how long the conversation gets.
- 27:23This idea has a name and is called
- 27:25prefix caching. If you go to the
- 27:27Anthropic console
- 27:29in the API console, you would see that
- 27:30there's something called as prompt
- 27:32caching. And a cached input
- 27:35token only costs about 10th of what a
- 27:38fresh one does. So, if you have prefix
- 27:40caching enabled, you can actually save a
- 27:42lot of
- 27:43cost for input tokens. Okay, and once
- 27:45you're holding onto that saved work,
- 27:47something else falls out of it for free.
- 27:49The saved work for any stretch of text
- 27:52depends only on the text before it and
- 27:54doesn't know or care whose conversation
- 27:56it's coming from. So, say I've built an
- 27:58assistant that is like a central
- 28:00assistant in my company and every single
- 28:02conversation that opens with the same
- 28:04long block of instructions,
- 28:07that's the same text every time. So,
- 28:09under the hood, it's the same saved work
- 28:11every time. The model does that work
- 28:13once and reuses it for every person who
- 28:15talks to it. So, it's really the same
- 28:16mechanism as your own next turn to the
- 28:19cache, but in both cases,
- 28:21it just looks at matching beginning of
- 28:24the call, which is in this case the
- 28:25system prompt.
- 28:27We'll now look at how a single GPU
- 28:29serves many users at the same time.
- 28:32And the one thing that limits how many
- 28:34users it can actually serve.
- 28:37So, if you think back to the expensive
- 28:38part of writing an answer, so for every
- 28:40single token it produces, the GPU has to
- 28:43read the entire model out of its memory
- 28:45and that read is the real cost. So, if
- 28:47the GPU already has to read the whole
- 28:49model just to produce one token for one
- 28:51user, why not use that same read to
- 28:54produce the next token for a lot of
- 28:56users at the same time?
- 28:58One read of the model gives you one
- 28:59token for one user or 50 tokens for 50
- 29:03users because it's the same single read
- 29:05either way. So, that's the idea and it
- 29:07has a name and it's called batching. You
- 29:09pack many people's requests together and
- 29:11run them through the GPU as one group.
- 29:13Each person's own answer still comes out
- 29:16at roughly the same speed it would on
- 29:18its own.
- 29:20But, look at what happens to the server
- 29:21as a whole once you add up everyone's
- 29:23tokens. It's total output, the number of
- 29:26tokens it produces every second, what we
- 29:28call its throughput, shoots up. So, you
- 29:31end up serving 50 people for something
- 29:33close to the cost of serving just one.
- 29:35Without batching, you'd be pulling the
- 29:37entire model out of the memory for one
- 29:39person at a time and nobody could afford
- 29:41to run that hardware that way.
- 29:43So, why can't we batch like a million
- 29:45users with the same approach? The answer
- 29:47comes down to memory and that's the
- 29:49ceiling on how far batching can go. So,
- 29:52you remember the scratchpad that we
- 29:54talked about earlier, the KV cache? So,
- 29:56every single user sitting in that batch
- 29:59needs their own scratchpad and it has to
- 30:01sit in the GPU's memory for as long as
- 30:04they're being served. So, that memory is
- 30:06small to begin with and most of it is
- 30:08already taken because it's busy holding
- 30:10the entire model. So, the model's
- 30:12weights are fixed, so they're always
- 30:14there taking their share of memory and
- 30:17whatever is left over is the only room
- 30:19you have for everyone's scratchpads.
- 30:21So, now fill that space up and
- 30:25that's it because the server is full.
- 30:27And at that point, new users have to
- 30:29wait in line or somebody else's
- 30:30scratchpad gets thrown out to make room
- 30:32for them and that's exactly why ChatGPT
- 30:34sometimes tells you that it's at
- 30:36capacity. So, notice what isn't the
- 30:38problem here. It's not the processor of
- 30:40runs out because there's plenty of math
- 30:42left in those cores uh sitting idle.
- 30:44It's the memory that runs out, and it's
- 30:46the memory that decides how many people
- 30:48one GPU can actually serve. And this is
- 30:51also where a lot of money gets wasted in
- 30:53the real world. Teams end up buying far
- 30:55more GPUs than the math can actually
- 30:58calls for, and those expensive GPUs just
- 31:00sit there half idle.
- 31:02But memory does more than decide how
- 31:04many people fit on a GPU. It also
- 31:07decides whether the model fits on the
- 31:08GPU at all. So far we've assumed that
- 31:11the whole model sits on one GPU, and for
- 31:13the very biggest models we know that it
- 31:16won't because they're just simply too
- 31:18large for any single GPU to hold. And
- 31:21that's what we will look at next.
- 31:24Now, so far every server we've talked
- 31:26about holds the whole model by itself.
- 31:29For a lot of models, that works fine.
- 31:31But it doesn't work for the very biggest
- 31:34models, because some of them are too
- 31:36large to fit on a single GPU.
- 31:38Now, remember the sizes of the models
- 31:40that we looked at earlier in the course,
- 31:41like a large model came in at about 140
- 31:44GBs, and the giants with 500 billion
- 31:46parameters or more comes at several
- 31:49hundred GBs on disk. Now, what if the
- 31:51GPU holds only about 80 GBs? So, it
- 31:54doesn't fit.
- 31:55What do we do? Now, you bring in several
- 31:57GPUs instead. So, you take the giant,
- 31:59you slice it into pieces, and put one
- 32:01piece on each of the many GPUs. No
- 32:04single GPU can hold the whole thing, but
- 32:07together they can hold the entire model.
- 32:10So, VLLM, the model server that we've
- 32:12set up earlier, can split a model across
- 32:14GPUs on its own. You point it at a giant
- 32:17model, tell it how many GPUs it has, and
- 32:20it takes care of the rest. Now, before
- 32:22we cut the model up let's look at
- 32:24exactly what we're cutting. And let's
- 32:26super simplify this.
- 32:28So, a model is a stack of layers, and
- 32:30each layer is a formula, which in
- 32:32practice is just a large sum of numbers.
- 32:35Your prompt enters at the top and flows
- 32:37through the stack one layer at a time.
- 32:40Each layer adds up its numbers and
- 32:42passes the result to the layer below it
- 32:44until the very last one produces the
- 32:46token. So, how do you actually split
- 32:48those layers across GPUs? Now, there are
- 32:50two ways to do it. The first is by
- 32:52layer. You hand the first whole layers
- 32:55over to GPU uh one and the next ones to
- 32:57GPU two. The second way works within
- 33:00each layer. So, you take a single
- 33:01layer's sum and split its stream. So,
- 33:04GPU one adds the first half and GPU two
- 33:07adds the second. And the two halves
- 33:09combine into that layer's answer.
- 33:11Now, where you physically put those GPUs
- 33:14decide which way you slice, and it comes
- 33:17down to one thing, the speed of the wire
- 33:19between them. So, inside a single
- 33:21machine, the GPUs are joined by a
- 33:23special ultra-fast link called NVLink,
- 33:26far quicker than any ordinary network.
- 33:28So, the chatty method, which is
- 33:30splitting within each layer, works well
- 33:32there because the GPUs can afford to
- 33:34talk to each other constantly.
- 33:36Now, if you pack eight GPUs into one box
- 33:39on that fast link, and they serve a
- 33:40giant as if they were one machine,
- 33:43then that works perfectly. Now, this is
- 33:45how most large models run today. Now, if
- 33:47you go bigger than a single box where
- 33:49the GPUs are sitting in different
- 33:51machines, and they only have the
- 33:53ordinary network between them, which is
- 33:55a lot slower, so across machines, you
- 33:57switch to the light method instead. So,
- 34:00you hand out whole stretches of layers,
- 34:02and each machine passes just one small
- 34:04result onto the next. So, the rule then
- 34:07is simple. So, you keep the chatty talk
- 34:09inside a box, and you keep the light
- 34:12talk between boxes. So, this technique,
- 34:15splitting a model across GPUs, has a
- 34:17name, and that's called sharding, and it
- 34:18solves the the fitting problem. So, a
- 34:21giant too uh big for one GPU now runs
- 34:23across a machine's worth of uh GPUs or
- 34:26several machines worth of GPUs acting as
- 34:30one logical server. So, sharding makes
- 34:32it possible to run the giant model, but
- 34:34it still does not make one server serve
- 34:37the entire world.
- 34:40Okay, so what happens when you have a
- 34:42fleet of these servers? So, a real
- 34:45service is never run on a single server
- 34:48because you want to serve the entire
- 34:49world. So, you need a whole fleet of
- 34:52them, and each one is its own expensive
- 34:55GPU that's carrying its own copy of the
- 34:57model. So, how does my request get to
- 35:01one of these servers? Now, if you've
- 35:02worked in the infrastructure space
- 35:04before, you probably already have a fix
- 35:06in mind that you put a load balancer in
- 35:09front of the fleet, and it spreads the
- 35:10incoming request evenly across every
- 35:13server round and round one to each in
- 35:16turn.
- 35:17And we've balanced web traffic this way
- 35:19for decades, so it feels like the
- 35:20obvious move here. But, for serving
- 35:23large language models, it turns out to
- 35:25be the wrong one for two reasons.
- 35:27So, say I send my first message, and it
- 35:31lands on server two, which reads my
- 35:33conversation and saves its work in
- 35:36memory.
- 35:37And that's basically the KV cache that
- 35:39we spoke about earlier. And a little
- 35:40later, I send a second message, but the
- 35:43load balancer's whole job is to spread
- 35:45traffic evenly, so it sends the this one
- 35:48to server five instead.
- 35:50And uh server five has never seen me
- 35:52before, so it has nothing saved, and it
- 35:54has to read my entire conversation again
- 35:57from scratch, which means the pre-fill
- 35:59behavior that we spoke about happens all
- 36:01over again.
- 36:02So, a load balancer treats every server
- 36:04as interchangeable, but we already know
- 36:07they're not. So, it throws away saved
- 36:09work that was perfectly good, and it
- 36:11does that on the most expensive hardware
- 36:14you own.
- 36:15Now, the second reason, this has nothing
- 36:17to do with where your saved work lives.
- 36:19So, a load balancer assumes that every
- 36:22request is roughly the same size, so
- 36:24spreading them out evenly also spreads
- 36:26the load out evenly. But, we know that
- 36:29no two large language model requests are
- 36:31the same size. So, one of them might be
- 36:33just a quick hello message, and the next
- 36:36one is probably a request to summarize
- 36:3950 pages of text. So, to the load
- 36:42balancer, these two requests look
- 36:44identical because all it sees is the
- 36:46same address and the same kind of
- 36:48traffic. So, it might send that 50-page
- 36:50request to a server that's already busy
- 36:53streaming answers to 30 other people,
- 36:55and all 30 of them slow down. And that
- 36:58one big request takes far longer than it
- 37:01should.
- 37:01Now, the load balancer can't tell any of
- 37:04this apart because everything it would
- 37:05need to know is inside the servers,
- 37:08where it has no way of seeing in. So,
- 37:11how full is each server's memory right
- 37:13now? Whose saved work is sitting where?
- 37:16And how long is each queue? So, serving
- 37:18large language models need a much
- 37:20smarter way to route requests than
- 37:23anything that we have ever used before.
- 37:27So, why is serving models so hard? The
- 37:29model barely fits in memory to begin
- 37:31with. Every token forces the server to
- 37:34reread the whole thing from scratch.
- 37:36Whatever saved work a server has done
- 37:38for you is stuck on that one server, and
- 37:41memory also caps how many people that
- 37:43server can handle at once. And if you
- 37:45get the routing wrong on top of all of
- 37:47that, you waste your most expensive
- 37:49hardware, which is your GPU cycles.
- 37:52So, that same wall stopped everyone in
- 37:54the industry, which is why Red Hat,
- 37:55Google, IBM, and Nvidia decided to solve
- 37:59it together out in the open. And what
- 38:02they built is called LLMD. And LLMD is
- 38:05what we're going to discuss next. So,
- 38:07what is LLMD?
- 38:09At its heart, it's a smart router that
- 38:11sits in front of your entire fleet of
- 38:14servers. And when a request comes in, it
- 38:16doesn't just throw it at whichever
- 38:18server happens to be free next, it stops
- 38:21and thinks about where that request
- 38:23should go, then sends it to the server
- 38:25that is best equipped to handle it. To
- 38:27make that call, it looks at three
- 38:29things: the saved work each server is
- 38:31holding, how much memory it has free,
- 38:33and how long its queue is.
- 38:36So, start with the first one. LLMD keeps
- 38:38track of which server holds which saved
- 38:40work. So, when your next message comes
- 38:42in, instead of scattering it across the
- 38:44fleet, LLMD sends it straight back to
- 38:46the server that already has your
- 38:48conversation. So, that server skips the
- 38:50reread and your reply comes back
- 38:52instantly. Now, routing that way,
- 38:54instead of spreading requests evenly,
- 38:56gives you around three times the
- 38:57throughput and a first response that is
- 39:00twice as fast on the same hardware.
- 39:03The second thing LLMD does is look
- 39:05inside its server at details a plain
- 39:08load balancer never checks.
- 39:09How full is the server's memory right
- 39:11now? How long is its queue? It uses that
- 39:14to send your request to a server that
- 39:16genuinely has room instead of piling
- 39:18work
- 39:19into one that's already full.
- 39:21The third comes from noticing that a
- 39:23request has two very different halves.
- 39:25So, there's the prefill phase that we
- 39:27spoke about earlier, which is
- 39:28compute-heavy, and that's the one-time
- 39:30job of reading a prompt, and then
- 39:31there's the decode phase, which is the
- 39:33slow token-by-token job of writing the
- 39:35answer.
- 39:35On one shared GPU, those two take turns.
- 39:38So, when someone pastes in 50 pages,
- 39:41that one big prefill makes everyone's
- 39:44answer wait midstream. So, LLMD can
- 39:46split them onto separate pools, where
- 39:48one pool does nothing but prefill and
- 39:51the other does nothing but decode.
- 39:53Prefill is all compute, decode is all
- 39:56memory, so each pool runs the hardware
- 39:58that fits its job.
- 40:00For example, you could have the H100
- 40:02type of GPUs for the prefill pool and
- 40:04the H200 that has higher memory for the
- 40:07decode GPUs. And when a prefill server
- 40:10finishes reading a prompt, it hands the
- 40:12saved work across a fast link to a
- 40:14decode server, which streams the
- 40:16response. So, that's up to 70% more
- 40:19tokens per second on the same hardware.
- 40:22Now, the best part is that LLMD runs on
- 40:24top of something you're almost certainly
- 40:26using. It's the platform you've built
- 40:28applications on all decade. It's the
- 40:30platform that 60% of organizations
- 40:33hosting GenAI use to manage inference
- 40:35workloads. It's a platform that your ops
- 40:37team already runs, and it is the
- 40:39platform that is now becoming the de
- 40:42facto standard for AI inference. And
- 40:44that platform is none other than
- 40:47Kubernetes.
- 40:48Now, one of the recent CNCF blogs named
- 40:50The Future of AI is community-driven and
- 40:52open mentions that 66% of organizations
- 40:55hosting generative AI use it to manage
- 40:58some or all of their inference
- 40:59workloads. So, if you ask teams running
- 41:01generative AI in production, what they
- 41:04run it on, about two out of three say
- 41:06Kubernetes. And LLMD sits right on top
- 41:09of it.
- 41:11So, if you actually wanted to run this
- 41:13yourself, where would you start? One of
- 41:15the challenge teams face starting their
- 41:17LLMD implementation is how to tune it.
- 41:19So, everything we've talked about has a
- 41:21real tunable knob behind it. So, how
- 41:25much the router should favor a server
- 41:27that already holds your saved work over
- 41:30one that's simply less busy. Whether you
- 41:32split the servers that read prompts from
- 41:34one the ones that write answers, that's
- 41:36the prefill versus decode split, and how
- 41:39many of each do you run? How many GPUs
- 41:42one copy of the model spans when it's
- 41:43too big for a single machine. How many
- 41:45requests each server batches before it
- 41:47starts falling behind? And every one of
- 41:50these moves your speed and your cost.
- 41:52And the right answer depends on your
- 41:54model, your hardware, and your traffic.
- 41:56So, tune them all by hand, and you could
- 41:59just spend weeks at it and still get
- 42:02several of them wrong. So, LLMD hands
- 42:04you what it calls the well-lit paths.
- 42:06So, these are ready-made recipes where
- 42:08every knob is already set, and each one
- 42:11measured on real hardware.
- 42:14So, there's a whole menu of these paths
- 42:15by now, but let's look at the three that
- 42:18carry almost the whole story and you
- 42:20already know the idea behind each one.
- 42:22So, the first one is the optimized
- 42:24baseline. So, that's one pool of plain
- 42:26identical servers with cache aware
- 42:28routing switched on and nothing else
- 42:30changed.
- 42:31The second path splits the work in two.
- 42:33One pool of servers reads prompts. This
- 42:35is your prefill pool and another writes
- 42:38answers. So, these are the decode pool
- 42:40and they save workflows between them.
- 42:42So, you size each pool for your own
- 42:44traffic, which makes it the path for
- 42:46long heavy prompts. The third spreads a
- 42:49single model across a group of GPUs that
- 42:51act as one server, which is what the
- 42:53giants need. The router stays exactly
- 42:56the same across all three and the only
- 42:58thing that changes is the shape of the
- 43:00fleet behind it. So, most people start
- 43:03with the first path because it's the
- 43:04smallest change you can make and the
- 43:06biggest
- 43:08payoff.
- 43:10Let's dive into the details now. To set
- 43:12it all up takes two commands. So,
- 43:14there's a helm install router command
- 43:16that installs the LLM D router itself
- 43:19and sets up the vLLM servers. And you
- 43:22have the helm install model
- 43:24command that installs the model itself.
- 43:27So, let's try to understand what they
- 43:28build and how you use it.
- 43:31So, we start with what you already have,
- 43:33which is a Kubernetes cluster with some
- 43:35worker nodes and right now nothing is
- 43:37running on any of them. So, first come
- 43:39the model servers and every one of them
- 43:41is a vLLM instance. So, this is the same
- 43:44server that we set up at the start. So,
- 43:47on Kubernetes each vLLM instance runs as
- 43:50a pod landing on whichever node has room
- 43:52for it and a group of identical pods we
- 43:54know is called a deployment. So, that's
- 43:57your prefill pool and then you have your
- 43:59decode pool, which is a few different
- 44:02pods on a few different servers.
- 44:04Next, out front comes a gateway, which
- 44:06is kind of the same gateway that you
- 44:08would put in front of any web service,
- 44:10and it gives you one address for the
- 44:12whole fleet.
- 44:13And right behind it sits the LLMD
- 44:16scheduler, which is a small brain
- 44:17holding the cache aware and the load
- 44:19aware logic. And the gateway takes the
- 44:22request, and the scheduler picks the
- 44:24pod. So, this is a very high-level
- 44:26overview of the architecture. Later in
- 44:29the full course, we will dive more
- 44:31deeper into what are the different
- 44:33subcomponents of these.
- 44:35Now, what happens to the giant models?
- 44:38The giant large language models. So, say
- 44:39a model is too big for a single machine,
- 44:41it has to span several of them. So,
- 44:43Kubernetes needs a way to treat that
- 44:45whole group of pods as one unit. So, if
- 44:47you already know Kubernetes, you're
- 44:49probably already aware of stateful sets,
- 44:51because that's the first thing that came
- 44:52to my mind
- 44:53when I thought how you would deploy a
- 44:55model.
- 44:56Now, does LLMD use stateful sets here?
- 44:59So, a stateful set gives each pod a
- 45:01stable name and starts them in a fixed
- 45:03order, like 0 1 2 3, etc. And this is
- 45:07especially useful for, say,
- 45:09databases like MySQL that needs to power
- 45:12up in a particular sequence. But, it
- 45:14still treats every pod as its own
- 45:16separate replica. Now, this works for
- 45:19databases like MySQL, but in case of
- 45:21LLMs that are split across different
- 45:23pods, they're not separate servers or
- 45:25replicas because together they are one
- 45:27server that is simply split into
- 45:30different pieces. So, scaling
- 45:33should add another whole group of them,
- 45:35and not just like one pod, which would
- 45:38just be hanging. And if a single
- 45:40part of that, if a single shard of that
- 45:42fails, the whole group has to restart
- 45:44together because a model missing a piece
- 45:46can't answer anything at all. So,
- 45:49Kubernetes built a new kind of object
- 45:51that can say these pods belong together,
- 45:54and it's called the leader worker set.
- 45:57So, it's a leader pod plus its workers
- 45:59scaled and healed as a single unit. Now,
- 46:02every box in that architecture is a
- 46:04standard Kubernetes object. So, how do
- 46:06you describe it all to Kubernetes? And
- 46:07it comes down to the values.yaml file
- 46:10that you pass to help when you deploy
- 46:12the model. Now, this is where you
- 46:14describe the URI to the llama model.
- 46:16That's the location where the model file
- 46:18exists. And then you define how many
- 46:20pods serve prefill and how many serve
- 46:22decode. And when you swap that one file
- 46:25with another file with another values,
- 46:27you get a completely different fleet of
- 46:29servers and and pods. And when you apply
- 46:32them, LLMD creates the prefill pods and
- 46:34the decode pods, puts the gateway and
- 46:36the scheduler out front, and wires it
- 46:39all together. So, a minute later, you
- 46:41ask cluster what's running, and then
- 46:44there it is. You see a few lines of
- 46:46text, which tells you exactly what's
- 46:48running in your inference system.
- 46:51Now, once it is up,
- 46:53how do you keep it running? Now, this is
- 46:55kind of the uh best part of this because
- 46:57it's deployed on Kubernetes. Now, every
- 46:59server here is just a pod. So, the
- 47:01normal Kubernetes loop looks after all
- 47:04of them, and that's the part your ops
- 47:06team already trust. So, a pod crashes,
- 47:08and Kubernetes restarts it. A whole
- 47:10machine dies, and Kubernetes moves those
- 47:12pods somewhere else. And because the
- 47:15readers and the writers are separate
- 47:17pools, you grow each one independently.
- 47:20And adding decode pods when answers
- 47:22start backing up, and when you have the
- 47:24prefill pods when the prompts get heavy.
- 47:27So, Kubernetes keeps the servers alive,
- 47:29and LLMD keeps them smart.
- 47:31So, how do you actually use it? So, when
- 47:33LLMD comes up, it hands you a single
- 47:35address, the inference gateway, and that
- 47:37one endpoint sits in front of your
- 47:39entire fleet. So, you're in front of
- 47:41your entire prefill pod, your every
- 47:43decode pod, and and even in front of the
- 47:46entire sharded giant models. So, you
- 47:49never call a pod directly as you
- 47:50wouldn't in the case of web app, either.
- 47:54You would instead look at the URL that's
- 47:57the given by the IP address in the URL
- 47:59that's for the gateway and you would
- 48:01route your request there. So, just to
- 48:03summarize, when you send a request to
- 48:06our cluster now, the request hits the
- 48:08gateway, the scheduler picked the pod
- 48:11that already held your saved work, a
- 48:13pre-filled pod read your prompt, and a
- 48:15decode pod wrote the answer one token at
- 48:18a time, streaming the model straight out
- 48:20of memory. And if the model happened to
- 48:22be a giant, a whole group of GPUs spread
- 48:24across several machines did that work
- 48:26together as one. If you want to read up
- 48:28further on this, the project lives at
- 48:30llm-d
- 48:32.ai. That's llm-d.ai.
- 48:34So, look it up.
- 48:37Now, before we close, I want to talk
- 48:39about you and about where you go from
- 48:41here. If you take a look at everything
- 48:43we just walked through, we spent this
- 48:45whole course on pods and deployments, on
- 48:48routing and load balancing, on caching,
- 48:50auto scaling, memory, and networking.
- 48:52And almost none of it was machine
- 48:53learning. It was infrastructure work
- 48:56from the first lesson to the last. The
- 48:58models may be new, but the discipline is
- 49:00one you already have. So, if you're a
- 49:03systems administrator or an SRE or a
- 49:05DevOps engineer, you're closer to this
- 49:07world than you might think. Linux
- 49:09containers, Kubernetes, and monitoring
- 49:11are the foundation that every AI
- 49:13platform stands on, and they're exactly
- 49:15the skills teams are struggling to hire
- 49:18for right now. So, every company racing
- 49:20to ship AI needs somebody who can keep
- 49:23the GPUs busy, keep the latency down,
- 49:25and keep the bill under control. And
- 49:27that person looks a lot like you. And
- 49:29this is not some small corner of the
- 49:31industry. Remember the trillions of
- 49:33dollars we saw pouring into data centers
- 49:36at the start of this course? Because
- 49:37every one of those data centers need
- 49:39people to build it and run it, and
- 49:41that's why the World Economic Forum
- 49:43lists AI and big data as the fastest
- 49:45growing skills of this decade, and why
- 49:47LinkedIn named AI engineer the fastest
- 49:50growing job in the United States.
- 49:52Now, you don't need to become a data
- 49:54scientist, and you don't need to train
- 49:56models. You need to point the skills you
- 49:59already have at a new kind of workload.
- 50:01So, keep your foundation and add that ER
- 50:03layer on top of it. How GPUs work, model
- 50:06servers like vLLM, and orchestration
- 50:08with LLMD, which is the exact stack we
- 50:11took apart in this course. So, we've
- 50:13laid all of that out step-by-step as a
- 50:15learning path on Code Cloud. So, it
- 50:17starts from the foundations. You can
- 50:19jump in whenever you're ready, and it
- 50:20runs all the way to serving models at
- 50:22scale. So, you'll find it at
- 50:23codecloud.com/learningpath/ai.
- 50:27The hard problems in AI are
- 50:29infrastructure problems now, and nobody
- 50:32is better placed to solve them than you.
- 50:35Now, it's time to try the um vLLM lab.
- 50:38First of all, uh you don't need to worry
- 50:40if you're not um feeling confident for
- 50:42the lab because this lab comes with a
- 50:44lot of hints and solutions. In this lab,
- 50:46you'll get um a model server that
- 50:48answers one request at a time, and users
- 50:51are waiting. And by the end of the lab,
- 50:52your goal will be to build a real vLLM
- 50:55server handling multiple users at once.
- 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.