[SPEAKER_1]: I mentioned before, my name is Dewan Lightfoot. I'm a developer advocate at Akamai, and this is my colleague. I'm Khadja Omer. I go by Omer. I'm a senior software engineer at Akamai. We're going to be talking agents that own their own inference, building production AI agents on dedicated GPUs. Now, why are we here? Things are changing, and for me, I started building agents before tool calling. Back in January 2023 is when I built my first agent. I would take a prompt that context was about 8,000 tokens at the time, and I would parse that prompt and then make a tool call with Python and then give the response back to an LLM. But as I was doing that, I found something interesting. It can get really expensive. And then I started using local models to figure out, okay, how can I do this? And then I learned something else. There's another challenge around that because if I'm using a smaller model, it may not be as capable. And then I may be compute bound. That memory in that GPU may not handle the larger context. So that's the inputs and outputs. And then the multiple turns in the tool calls. How do we get the most, either the GPUs, the costs, the latency that we need in production or just for our own use cases? Right? So the reason why we're here, we're going to talk about agents that are running their intelligence and then how you can take back that control on it.
When it comes to an agent, it's just a loop. You invoke an LLM, it has access to tools, it has access to an environment, makes it a decision, a reasoning decision on what actions to take once you invoke it or give it a prompt. And then those actions are being performed by your tools, your Python code, your other programming languages, and then given back to a model. The model evaluates the actions, the results, and then updates the plans, takes additional actions, or the goal is achieved. Right? But all that requires tokens to be generated. Right? And depending on your application can lead to latency challenges. So we're going to talk about how you can actually manage all of that on dedicated GPUs. So what does it mean to own your inference?
First, when it comes to owning your inference, you actually own the GPU or rent the GPU. So when you do that, that means that you have access to the GPU, the hardware for that AI to be run on, for the models to live on. Which means then you have access to control where it goes. So the data never leaves your cluster, never leaves your data center, never leaves your laptop. Right? You now own that intelligence and what's happening with the model. And if you're in the cloud, you can also do something like private VPC endpoints or have it in the VPC so it never leaves your VPC. Right?
I know we all have different environments, have different ways to set up our infrastructure. We can talk about all of those. Now, what's the difference? When do you own? When do you rent? Well, first, if your usage is high and steady. Why is that? Yes. Yes. At the end of the talk, I'll have a link to the slide and everything that we showed, code, everything, you can download it and take it with you. So thank you.
Now, when do you own? If the usage is high, right? If you're constantly have a workload running. Because if you're paying for a GPU, you're renting a GPU, what does that mean? That GPU should always be working. Otherwise, what are you paying for? So that's something you got to think about. Then, when it comes to the data, if you need that data to stay private, if you need to own the data, you care about your intellectual property, or you have some governance and compliance reasons why you can't use a public provider when it comes to AI, that's another reason you want to own.
And then, the hardware. That's something we got to think about. Your hardware, if you can afford the capacity, and you have the capacity, why not run those models? Right? For your use cases. Because then you have that full control.
Now, when do you rent? If your traffic is low, bursty, you just need intelligence sporadically. It might not be efficient for you to own some GPUs. Next. Well, we started talking about intelligence. The more capable models, they're going to cost for those GPUs. And oftentimes, those providers will provide that intelligence on the GPUs, because they have the infrastructure for that. So it may make more sense to use those providers to get that intelligence, to get those benefits. And then, the next part, which is often the challenge, is that your teams may not have the knowledge or the expertise to support dedicated or self-hosted AI.
Now, today's agenda. We're going to start out discussing some of the foundations you need to understand, like the infrastructure stack we'll be using, units and memory budget. We'll look at pre-filled decode and KB cache, and what that looks like. And then, from there, we'll look at dense models versus mixture of experts. So you understand what that actually looks like on the GPU, and why you would pick one or the other. From there, Omar will discuss how to optimize your inference. Right? Once you figure out, okay, we want to do self-hosted, how can we optimize this to get the most out of our GPUs, the inference engine that we run, and just our entire workload.
And then, finally, from there, we'll take that agent and deploy it into our own dedicated cluster. With that being said, I'm going to pass it off to you, Omar.
[SPEAKER_2]: All right. Thank you. So next, we'll talk about the environment that each of you is going to get for this workshop. We have a Kubernetes cluster with around 200 plus GPU nodes. Each of you gets a single GPU. And we have set it up in such a way that each of you gets your own namespace. And within that namespace, you will have your Jupyter notebook running. And then you will have your VLLM inference endpoint running as well that you'll be playing around with. And then we're also going to be deploying the agent on there as well.
The cool thing here is that the VLLM endpoint that we have running in your namespace, you're going to be optimizing it as part of after the first four modules. And I think that'll be pretty interesting. We're going to look at different techniques that we're going to be using there to do so. And you're going to redeploy this VLLM endpoint over and over again until you have optimized it to increase the throughput, reduce the latency, and make sure you're meeting all your SLAs.
And then the other thing I want to talk about is GPUs on LKE. So I work on the Kubernetes side of things at Akamai. So this is my wheelhouse. So if anyone has any Kubernetes related questions, feel free to ask anytime.
But I want to talk about what Akamai has. So we have the, we're going to be using the RTX 4000 ADA GPUs. We also have other GPUs available, but these are dedicated GPUs. EGPU has 200, EGPU has two gigabytes of VRAM with 260 gigabytes per second memory bandwidth. So the decode will be pretty quick because of that. We have high performance in TFLOPs, a large amount of CUDA cores. So the pre-fill will be pretty quick as well because of that. Currently for your workshop, we will be using a single GPU, but that doesn't mean when you want to deploy this at the end on your own, you can have different plans that we offer as well, where you can have up to four GPUs in a node. So that goes up to 80 gigabytes of VRAM on a single node. So you can deploy decently sized models on there as well. And everything is orchestrated by LKE. So setting up the node, deploying the drivers, setting it all up for you. So that way you don't have to do anything manually. Everything is one click. You click a button, everything gets deployed and you're off to the races.
You know, for more information, we have a link here as well. And at the end, you'll definitely get all these slides. So you'll be able to get to the pages. And then I'll give it back to Dewan.
[SPEAKER_1]: All right. So for the inference engine, we're going to be using VLLM. Now, some of you may have heard of OLLAMA, which is great for local, but VLLM offers some benefits that are better for production. One of those being continuous batching out of the box, the other being page detention. Now, it also supports the OpenAI compatible API. So if you're using whatever SDK that supports OpenAI, you can use it with VLLM. It also allows you to do some really interesting tweaks when you're setting up inference for your endpoints and for your applications.
Now, I mentioned continuous batching. For those of you that don't know what it is and how it actually works, this happens at the pre-fill stage. So you'll be able to get to the pages. And then I'll give it back to Duan. All right. So for the inference engine, we're going to be using VLLM. Now, some of you may have heard of OLLAMA, which is great for local, but VLLM offers some benefits that are better for production. One of those being continuous batching out of the box, the other being page detention.
Now, it also supports the OpenAI compatible API. So if you're using whatever SDK that supports OpenAI, you can use it with VLLM. It also allows you to do some really interesting tweaks when you're setting up inference for your endpoints and for your applications.
Now, I mentioned continuous batching. For those of you that don't know what it is and how it actually works, this happens at the pre-fill stage, right? The prompts come in. And normally with static batches, let's say you have a school bus full of kids. Well, in order for you to get new kids with static batching, you have to drop off every kid one at a time. And then once all the kids are dropped off, you go back and get the rest of the kids and then start the next batch. But with continuous batching, you can drop off a kid and pick a kid all at the same time. This is way more efficient when it comes to the KV caching that happens during the pre-fill stage.
Now, when it comes to page detention, page detention is when you think about the KV cache and you think about what's actually happening, there's memory space that happens. So the prompt comes in and the longest prompt is going to take up memory space. Without page detention, that memory space gets allocated even for smaller prompts, right? But with page detention, now that is all managed with the VLLM that ensures that you can continuously process, generate, and batch those requests as they come through VLLM. So it has a scheduler that kind of manages the batching, but it makes this really efficient.
Now, there are other service engines that are out there, and we'll talk about some of those in this workshop. With that being said, some of the metrics you're going to want to care about is going to be throughput, right? To understand how your GPU is performing, that time to the first token. Understand that, okay, you sent a prompt, how long does it take to get the first token back? From there, that KV cache utilization. We're going to look at these metrics and show you how to get all of that out of the VLLM and then the QDEP. So these are some of the metrics as we're going through this workshop. You'll see and be able to better understand.
And with that being said, we're going to access the environment. So if you can scan this QR code, pull out your laptops if you want to follow along. If not, you can follow us as we go through the workshop. In this Jupyter Notebook, we have nine different labs that we'll cover. And all of the resources and dependencies are loaded into this environment. Now, if you want to look at the code and try this on your own at home, I do have the repo public on Akamai's developers. I'll have this link along with the presentation and everything that we share available with one QR code that you can download. And if you need me to make a short link, I will.
With that being said, we're going to start with the first module in the workshop if everyone is connected. Yeah, it was slow for me too, which is why I went to my own league shortener, because I made that really fast with Russ. So, yeah. Hopefully, if you do have a hot spot, I would use your hot spot. But we'll try to make the best out of the experience. Sound good?
Awesome. All right, so in the first module, we're going to talk about the inference stack. We're going to connect to our LLM endpoint, understand it, see how it generates tokens. We'll also look at building our first agent, some things that we need to know, look at some metrics, and then understand the model that we'll connect to.
The model that we'll use is going to be QUIN 3-4B, but we have several models that sit on a PVC that you can actually load and unload for this endpoint. Now, when we talk about VLLM, one of the things about it is when you serve an endpoint, it just has one model, right? So if you want to serve two models, you're going to need another VLLM endpoint, right? Which means you may need some model routing, a gateway in front of it to kind of handle that.
Now, it does support authentication, but there's no authorization. So you may need a gateway around that, right? So agent gateway is often. KServe is another one. Any others? There's LLMD, there's all sorts of open source tooling out there that lets you do that. But the main one is like KServe is what we use a lot, and it's pretty good at doing the scaling, doing the routing, and the authentication as well, right. Another thing it doesn't have is rate limiting, right? If you're processing requests, you may want to rate limit. So again, you want to find a gateway to put in front of it to manage those requests and also handle the routing.
I mentioned that when it comes to the runtime, there are other service endpoints that are service runtimes that you can actually use for the server. SGLang is one. Tensor RT is another. And LLMACPP, which we do go over this later with a little bit more in depth so you can understand it. Now, in this environment, you are connected to a Jupyter notebook that lives in the namespace. You also have the VLLM server endpoint that you will see here in a moment. And all of this is in its own pod. And then you will have another pod, another pod that you can launch for the agent, and we'll see that too.
So let's go ahead and install our dependencies. So we'll install our dependencies. I've already ran through this, so some of this is already loaded in my runtime. I figured we don't know how the internet will be, right? But the good thing is once you send a request, it happens within the cluster. So once we send our first request to understand how we're configured in VLLM, you can notice the model that we have, the name of your namespace inside of the cluster, the kube config is just for your namespace. So that way nobody can access anyone else's namespace in the environment. And then we don't have an API key set, but you can set one with VLLM.
Now, from here we're going to use the OpenAI API compatible endpoint to be able, or API, to connect to the VLLM Q-QUIN3-4B, 4 billion parameter model. I believe we're using that at FP8, meaning that it actually sits at 8 billion parameters. Is it 8 billion parameters? No, no, 4 billion parameters. 4 billion parameters. We're using BF16. Oh, that's what it is. Full precision. Yeah, so we're using BF16, full precision, so you times the bits or bytes or parameters by 2. So it's 4 billion, which means it's 8 gigs on the GPU.
Now, once we invoke, we got our response for the model, and we can see what it was actually served by. Now, this was all within our cluster. That was pretty fast, right? It lives within our cluster. So hopefully with this experience, since we're not hitting the public API, we're already connected to this HTTP, it's going to happen right inside of the cluster. The response should come back a little faster. Now, we're going to send a trace in the end so we can actually understand how this actually looks like when it goes through the prefill, the KV cache, and the decode phase.
So here we have our stream that we're going to configure. We're going to look at the chunks and do some calculations. We'll get that time to first token so we can understand that. We'll see how all of this is generated here in a moment. So if we run this, I ran that one again. We'll come down here and run that. This may take a little bit to go through. But we should see time to first tokens took 37 milliseconds. And time output token, the decode phase, which means every token after the time to first token, that's going to be that interleaved latency, right? That inner latency that happens when those tokens are processed.
So we're calculating that and we're getting about 40 tokens per second. Which is probably going to be our cap. But when we start talking throughput, that changes because this is just one request. But imagine if we had hundreds of requests or 16 requests. That throughput is going to be a lot higher, but they're still going to be capped at that 40 tokens per second, right? Or it could go down, but we could still get more on that throughput. And I believe Umar will go deeper into that. So one of the things that I want to showcase is the question is around why don't you just run this on CPU? But we should see time to first tokens took 37 milliseconds.
And time output token, the decode phase, which means every token after the time to first token. That's going to be that interleave latency, right? That inner latency that happens when those tokens are processed. So we're calculating that and we're getting about 40 tokens per second. Which is probably going to be our cap. But when we start talking throughput, that changes because this is just one request. But imagine if we had hundreds of requests or 16 requests. That throughput is going to be a lot higher, but they're still going to be capped at that 40 tokens per second, right? Or it could go down, but we could still get more on that throughput.
And I believe Umar will go deeper into that. So one of the things that I want to showcase is the question is around why don't you just run this on CPU? I didn't want to do CPU on environment because this pod for this container for the Jupyter Notebook is only one gig. So trying to run a local model on this is just going to crash. So I simulated what that would look like. But if you're trying to run a local model on CPU, it's going to be a lot slower. It can't do the complex multiplication in those matrices the way a GPU can. That's the purpose of the GPU. It does all that math in parallel, which makes it a lot faster. So we simulate this on the CPU.
And then from there, we actually look at this on the GPU to see how that looks. We got 45 tokens per second. And one of the things about this, which is interesting to me, is that I do a lot of local models running them. But 45 tokens or 39 tokens per second isn't that bad for an application if you're running it for a specific use case. If you have a specific use case and you don't care about the latency, you don't care about those. If you have a chat bot, you want that first token to come fast. But for a standard application where you just kick off a job in the background, that 39 tokens per second may not be that bad.
Right? So sometimes a lower token per second or a lower time to first token may not be as important depending on the application and the latency that you care about. Right? You may care more about the intelligence in the job getting done than you do about how fast it actually happens. Especially, as I said, if it's a background process. Now here we're going to build our first agent. Now for those of you that when we talk about agents, there are no tools in this agent. So it's actually just a request. But just the foundation of the agent, we're giving it a system prompt so it knows its role when we do give it to us later on in the course.
But right now, we're just giving it a single prompt and we're giving it a role of a solutions architect agent for Akamon. And you can see that it was able to generate the response. Now, this response, pretty fast, it works. But then, the question is, if we're trying to do this at scale or we're trying to build an agent that does more than just take a prompt and generate a response, it may need to make multiple tool calls. Right? So that's where you start to think about things like the KVCache. You start to think about how much context. Because when we start talking about that KVCache, that's actually how much context you can actually fit on that GPU. Right?
And so, with continuous batching, what happens is you send a prompt to the model where you may have 100 users trying to send prompts at the same time. Right? Well, continuous batch, they're all going to be different sizes.
So, a smaller GPU can actually handle a bunch of requests if you're using something like VLM.
Now, if you're using something like OLAMA, you'll see you'll get throttled a lot faster because it doesn't process those requests the same way. But VLM actually handles that with their scheduler a lot better.
And so here we're going to set up our agent and invoke it and we're actually going to look at the steps. Now, the code that we're using for this is inside a common.
And you can actually look at all the code that we actually are importing that is custom code. So, here we have this foundation.py that allows us to do some measurements from Prometheus from VLM. Right? We can look at those metrics. Now, speaking of metrics, you can use Prometheus and you can use Grafana. Right? At home, I always use Grafana. Also, when I'm building my agents outside, I'm just looking at the metrics. Another thing that I always build, one of the first things I build into my agents, is observability. Right? LaneFuse. That's something I commonly use. How many of you have heard of LaneFuse? Now, there are other tools out there, but it's open source.
You can run that in your cluster as well, right beside your agents. And then have access. Now your observability is private as well. Right? And you can see every step, every trace, every span in your agent with how many tokens, what was the latency, not just for the time to first token, but for every tool call. Right? If you're trying to troubleshoot or you're trying to evaluate, now you can see all of the latency steps in the spans, but then you can see, okay, I'm using a smaller model and it's making way more tool calls. It's taking way more time than it should.
Why is that? Well, that's where evaluations come in. And Omer will talk more about that, but it's important to have that visibility into your agents so you can understand when you're using a smaller model how to optimize. And that could be something as simple as a prompt, removing tools, or making the agent just a little bit more specialized. And so we'll run this. And so we're looking at the steps. We're going to look at the max tokens. And we should see the time to first token. So you can see as we increase the tokens, what happens to the time to first token in milliseconds as we increase the prompt. Right?
As the prompts get larger, that time to first token takes longer. Right? So the question is, what do you optimize on? Do you optimize on the median or the largest? Right? The one that took the most time during the latency. Well, you're going to optimize on the one that takes the most time rather than the median. Right?
And then that way you can increase your median by doing that. Now here we talk about renting versus owning. We're going to look at tokens. How much are being generated? This is where I mentioned that if you're using Burstee, where you're not using, invoking a model as much with the provider versus if you have an agent or some agentic applications that are always working, you can compare that cost. So here we generate a response just to get those tokens. And now we're going to actually look at the billing and compare which one would actually be more efficient.
So if you're processing, let's say, 200,000 tokens per day on a hosted bill, rent it, that's going to be about 1,500 per month.
Right? But if you're renting a GPU, that's going to be about 1,000 per month. Now, it does matter the size of the GPU, the size of the model, if it actually performs the way you need. But these are some of the things you think about when you're trying to compare should I rent versus own. And you can actually do the math on that to break that down. And we already talked about these with the data resiliency, the compliance and security, the controls, and all of those good things when it comes to renting locally.
Now, before we go, the runtime landscape, I mentioned that we're using VLL, but you can also use SGLane, which is good if you have requests that share long prefixes, multi-term chats. So for agents, a lot of organizations are using SGLane for that. When it comes to Tensor, well, this is about that peak throughput on NVIDIA hardware. It really specializes in providing you that.
And then LLAMA CPP for that edge, that really fast processing. It can help you with those heavily quantized models, right, on the ARM server. So we're going to invoke one more time here. And we're looking at our client just to verify that we're still good. We're verifying that we can connect. We can see the model serve, and we can see the ID. And I believe I can print the entire. So we can see how that request actually looks when it comes back. So I'm going to print this whole thing as well. And now you can see, and actually let's print it so we can see it even better. There we go. And so when that request comes back, you can see the ID.
You can see the max model length, which that context length, you can control that, right? You can tweak those parameters, of course, when you work with a model. But we can see everything about the model itself. Now we're going to move on to the next session. It can help you with those heavily quantized models, right, on the ARM server. So we're going to invoke one more time here. And we're looking at our client just to verify that we're still good. We're verifying that we can connect. We can see the model serve, and we can see the ID. And I believe I can print the entire. So we can see how that request actually looks when it comes back.
So I'm going to print this whole thing as well.
And now you can see, and actually let's print it so we can see it even better.
There we go. And so when that request comes back, you can see the ID. You can see the max model length, which is that context length, you can control that, right? You can tweak those parameters, of course, when you work with a model. But we can see everything about the model itself. Now we're going to move on to the next session. This will have some taking it further. When you can explore the cluster, explore VLM, you can feel free to do that in this notebook. So I'm going to close that out, we'll discard that, and we'll move on to units and memory. Now the next section, and I'm going to go faster so Omar can have some time.
Now when it comes to units and memory, we're going to talk about the ceiling when it comes to token per second on using a model. We're also going to look at the model's real config and understand how a model actually sits and how it actually looks when it comes to a GPU. So here, as Omar mentioned, we are using, and I'm going to make that a little smaller. Let's see if we can get more of that on there. All right, so when we talk about the model actually sitting on the GPU, you have the model weights.
For the 4 billion parameter model, that model weights at BF16 is going to be 8 gigs. So we have 8 gigs, and the rest of the room is going to be for KV cache, meaning how much context can you fit on that GPU? Because it all has to fit within there. Now when your prompt comes in, when we talk about pre-fill, the model is going to read that entire prompt and store it in the KV cache. And then every time it generates a new token, it's going to update that pre-fill, so that pre-fill is going to grow. So just because your prompt that goes in is one size, as it goes through and is processed through the model, it's going to increase as it generates.
And then imagine the tool calls, the system prompt. All of these go to the model, and all of that has to fit on the KV cache in order for it to be able to handle your request efficiently. And so we're also looking at, if we're using FP8, which Omer is going to talk about quantization, and what that actually looks like to shrink a model, and to still get the efficiency that you're looking for. Now we're going to install our dependencies. And then from here, we're going to connect to verify what we have loaded. So again, we have the QUIN3, 4 billion parameter model, our workshop namespace, the cluster, API key. Now, when it comes to models, we have the config.json.
What is actually that file?
When you download a model, you get the config.json. Let's say you go to Hugging Face, you download the model, you're going to get a collection of files. All of those files are needed, right? You're going to get the config.json, you're going to get the save.tensors. Those tensor files are the model weights, right? But the configuration is what tells VLLM how to handle that model, right? So you can actually look at this and explore those files to understand what they actually look like. So here, we're showing what that configuration file looks like. So we have 128 layers, the size is 1024, the attention head. There are 16 attention heads. The values are eight.
Vocabulary size, right? How does the model train? What is the vocabulary size of that model? Right? You can actually look at these configurations. Can you modify them? No, right? These files cannot be modified. But you can fine tune, right? You can use LoRA. You can do all these things to adapt the model, but to modify these files, if you try to do that, it's just going to crash. It's not going to load. Now here, we're going to look at the bytes per weight and where it comes from. And we calculate here. We're looking at a smaller model at BF16 for the .6 billion parameter model. And the parameters, you multiply by two, 1.5 gigs.
And for the 8 billion parameter models, what those parameters look like, and it's going to be 8 gigs. And if we compare the BF16 versus FP8. Now when we talk about precision, most models, when they're trained, they're going to be at sometimes FP32, but you'll often get it at FP16, full precision.
Meaning that you multiply whatever the model size by what?
Four? By four. Right? So this 4 billion parameter would be 16 gigs at full precision. Right? On your GPU. When you quantize it down to, let's say, FP8, you kind of lose a little bit capabilities of the model, but not much. Right? But that's when you start to evaluate. Right? If you're compute constraint, you have this larger model, maybe 70 billion parameters, that maybe you can do it at FP8, or maybe with int4. Right? All the way down to where now, that 70 billion parameter models is rather than 32, it's 16 gigs. Right?
If that's possible. Right? I don't know how much you're going to lose for the precision, but you'll have to evaluate that. And so evaluation harnesses are important. So we'll look at the GPU, where the weights live. So here, at BF16, you multiply by 2.
FP8, you multiply by 1. We're looking at this for Quinn. And then we have another model that we're going to use in this course, where it's at 8 billion parameters, it's 5 gigs on the GPU. Which, you can see how much you save with the still intelligence that works for the use cases that we're discussing, if you decide to quantize down. So we're looking at this card, the gigabytes per second. You take the, where we're actually calculating, okay, we know how the speed of the GPU is 360, and we're showing how to calculate to get the tokens per second. And where we're actually bound. So we're going to be bound by the speed of the actual GPU, on how fast it can go.
And we're showing the math for the KV cache here. And I'm trying to go a little faster, so we can get into the quantization and the optimization. But if you go through these, you can read through it and understand how the KV cache formula works. Oftentimes, we may not have to go through this and figure it out, but you will have to, when you're trying to calculate, for example, you have 100 users you want to serve, you have a smaller GPU. The question is, I got the smaller GPU, let's say, I'll give you a perfect example.
I had to do a workshop, and I had to figure out how to serve 80 students and perform inference for all the students with about three or four GPUs that were about 20 gigs. Right? Do I need that many? Is it going to fit? Well, how big is my context for the workload? What if everybody is invoking at the same time?
Will the GPU, will the cluster support that? Will continuous batching work? So you set up an evaluation to evaluate the entire workload and to determine, okay, is it going to fit, or do you hit that roof line? Do you start to have spill over the CPU? Does your application slow down? The memory weights, memory budget versus KV pool. So we'll look at that. And then here's how you can actually get the math.
So here's our, we can get 37,000 tokens on this GPU, right? On a single GPU, there's eight gigs for the model weights. And then the room that you have is going to be 37,000 tokens, right? And so if we have multiple users sending requests, right? Well, this will show how many users in their context list.
So if we have four users, they can all send 8,000 tokens, right? For input, output, tool calls, this is going to add up to 8,000 tokens at the same time on that GPU. And now we're showing the text. As this increases the different requests and the generation of that request.
And this kind of shows how to do that math when you're trying to understand your compute constraint, your GPU, and then the workloads that you're performing. So you can take all this code and apply it and be able to take your use cases and do the math on it so you can see if it fits on your GPUs. So we'll go to the pre-fill and decode.
And then the room that you have is going to be 37,000 tokens, right? And so if we have multiple users sending requests, right? Well, this will show how many users in their context list. So if we have four users, they can all send 8,000 tokens, right? For input, output, tool calls, this is going to add up to 8,000 tokens at the same time on that GPU. And now we're showing the text. As this increases the different requests and the generation of that request. And this shows how to do that math when you're trying to understand your compute constraint, your GPU, and then the workloads that you're performing. So you can take all this code and apply it and be able to take your use cases and do the math on it so you can see if it fits on your GPUs. So we'll go to the pre-fill and decode. So going a little bit deeper into the pre-fill and the decode and the KV cache. Again, we're using the QIN3 model. But we're actually going to dive in to see how this looks. So we have the pre-fill, which as I mentioned is going to be focused on that time to first token, right? From the time you press send, how long does the first token, if you're streaming, right? Because if you're not streaming, you're just going to get the whole response back. But if you're streaming, how long does it take to get that first token back, right? And that's going to be that pre-fill stage. And then the decode is going to be that token, every token after that. That's all measured. And if you're looking at the metrics inside of Vita LL, you send that to Grafana, you can actually view that on the dashboard and you can watch, okay? As I increase my prompts, you can watch it increase, you can watch it decrease, right? And really understand what's actually happening on that GPU when you're sending requests. So we'll go through here, we'll install our dependencies. Then from there, we'll look at our environment, make sure we're connected. Yes, and we're still using the QIN3-4B. And we're going to look at the self-attention, meaning how does that KV cache get processed? So this is the actual formula, so you can look at that softmax to really understand how that KV cache is being handled within a model. We're just doing it by hand just so you can see the math on that. And so when it comes to the KV cache, there's the naive approach and there's the KV cache approach that I would say is handled. So the naive approach is you take a prompt, the model looks at the whole prompt, and then one by one stores that prompt in the KV cache and generates a response. What KV cache does, it says, okay, I'm going to take the prompt, I'm going to learn from it, and I'm going to store it, right? In parallel. And so the KV cache allows you to learn from the prompt to be able to reference the information rather than just doing the fixed sequence of the naive caching approach when it comes to handling that KV cache. And so if we generate this, we can look at how it computes the reduction of how much have you used the KV cached approach rather than the naive approach. And we're just showing all that by hand in code so you can really break it down and understand. And now we're going to look, okay, using KV caching, and we'll measure the turn of the first token. And so here we have 57 milliseconds, and then the decode was 25 milliseconds. And so we'll continue on. And we can see what VLM is actually exposing. So we can actually look at those metrics, and we're just showing some of the metrics that are actually being exposed and how you would view that in VLL. Now we're going to invoke the prompt, and we're going to increase it, and you can watch that KV cache fill. And you can see this is going to take a little while. So we'll give it a couple minutes while this processes. We're increasing it so we can see the KV cache usage, and we can look at the metrics. So we have usage running, and then the KV usage after it's finished. And this will be the math on how you would process that. Again, the worker that we're using for this code is in the foundation.py. So that's going to be the helper for this code. Now we're going to look at the WARM, the code against the WARM prefix caching. Now prefix caching is an interesting thing. Don't confuse it with prompt caching. And that's something I should have mentioned before. If you're using a provider, and you're paying by the token, prompt caching, especially if you have a continuous application that's running within every five minutes, prompt caching is a must. You can decrease the cost by up to 75%, depending on who you're using. So there is some ways you can use a provider and save on costs. But when we're talking about prefix caching, this is caching that prefix for the KV cache. And so when we do this, we can see how this actually is handled here. So the code is going to be 220 milliseconds, and it's down to 41 milliseconds. And this all shows you how to do that in the code. So you can go through that. And I'm trying to go a little faster so Omar can get to his part, and hopefully we can deploy. All right, so we'll go back and we'll go to the fourth section where we talk about dense model versus the mixture of experts on the GPU. Now, when it comes to a dense model, what is a dense model? Well, a dense model, when it sits on a GPU, that whole model is used to generate tokens, right? So if it's 30 billion parameters, or let's just use the model we're using now. So the QUIN3, 4B at BF16, 8 gigs on the actual GPU. Well, when that actually generates tokens, when it actually is working, that whole entire model is working, right? So it's going to be a little slower than if you use a mixture of experts. A mixture of experts may be a larger model. Maybe it's 30 gigs, but when it actually generates inside of the model, it takes a collection of experts, and only that section of experts does the generation. So even if it's 30 gigs, it may be 1.5 gigs just to do the generation. So it's going to be a lot faster. So that's one of the benefits. Even though it's a larger model when it's a mixture of experts, it actually can be performed a lot better within an application or a lot faster within an application. And so here we talk about memory, and why decode is memory bound. Meaning that when we talk about the generation phase, after that time to first token, when that generation actually happens, that's actually going to be bound by the memory. So when we looked at the speed of this GPU, that's bound. You can't go any faster than that, right? There's nothing we can do to tweak that to make it go any faster. But there are some things we can do to help this at scale. So we're going to look at our roof line and plot that so we can actually see it. So we'll make sure that we have our model loaded. So we had a QUIN3, 4 billion parameter, right? And it's going to be compute bound. So it's going to hit that roof line. So we're going to look at the flops. We're going to look at this. So the ridge line is 297 flops per byte, right? And where this is bound by the memory. Now, if we look at the mixture of experts, now we're just going to look at this as code, so we can actually understand it. So at this 30 billion parameter models, right? 128 experts and only eight active per token. That's 48 layers, 2048 hidden. And so now the mixture of expert, this is the weights. This is the share weight. So this is how much is being used when it generates. That would be a lot more efficient than using a smaller model. It can actually be faster when it actually does the generation. And so here we're looking at the dense model, right? It's nine times fewer bytes than a dense model, right? So it decodes a little bit faster. So that's breaking down the two when you're actually trying to figure out, okay, do I want to use something like Mistral, right? Or do I want to use a Quim model? We compare the dense sizes. So here we're going to look at the rate. We'll look at the bandwidth, the GPU server. So measured Quim 4B is about 40 tokens per second, right? The smaller model of the Quim, the 0.6. Now this isn't done on the CPU, but we're just showcasing 300 tokens per second, right? But we're looking at the ceiling. So this is actually looking at the bandwidth and it's doing the math here to get that the max that we can get, the ceiling that we have on the GPU is going to be 45 tokens per second.
It's nine times fewer bytes than a dense model. Right? So it decodes a little bit faster. So that's breaking down the two when you're actually trying to figure out, okay, do I want to use something like Mistral? Right? Or do I want to use a Quim model? We compare the dense sizes. So here we're going to look at the rate. We'll look at the bandwidth, the GPU server. So measure Quim 4B is about 40 tokens per second. Right? The smaller model of the Quim, the 0.6.
Now this isn't done on the CPU, but we're just showcasing 300 tokens per second. Right? But we're looking at the ceiling. So this is actually looking at the bandwidth and it's doing the math here to get that the max that we can get, the ceiling that we have on the GPU is going to be 45 tokens per second. Now if we enable reasoning on that model, we can look at that. Now when it comes to these Quim models, if you're wanting to do any type of agent and the model needs to reason, meaning that maybe the prompt comes in, you have tools, and it needs to make multiple tool calls, well, you're going to enable thinking.
So now when it makes the tool call, if it gets the results and it needs to make another tool call, or verify the results to make the accurate tool call, you're going to have to enable thinking on these models. And that's just a parameter that you can adjust in the model. But with thinking on, it just generated a response, it was 35 tokens. But with thinking on, now it had to think about it and it costs about 600 tokens. Now with some of the models, like provider models, you can actually set a token budget for thinking. So that's one of the things you can save on costs with a provider model. And maybe some of the open models, you can do that too. I'm not sure.
Yeah, you can. Yeah, you can also adjust that token budget on thinking as well. So more tokens on thinking isn't always good, but sometimes it can help the model better troubleshoot and better get to that end result that you're looking for. And so when we talk about inference, there's a lot of things to think about. But one of the things we want to think about is that memory bound limit for the actual card, and then how to apply that for the agent. So we look at all of the models, we talk about that KB cache, the prefix caching, the attention heads, as well as quantization, which I'm going to cover here in a minute. And then from there, that continues batching.
We also discussed that. So if we split the pre-fill from the decode, you have the pre-fill, GPU pool, and the decode, which is memory bound. So the pre-fill, compute bound, right? So it needs to go from your memory to the GPU, and it needs to be cached, right? There's that phase, you can do a lot of optimizations, but when it comes to the decode phase, there's nothing you can really do because you're bonded by the GPU. And so we show this in code rather than actually showing it because, again, we only have so much limitation in this workshop.
Now with that being said, I am going to make sure that we are good to go here.
I don't think I need to switch them out. I think you should be good, Omar. I'm going to turn it over to you. All right. And then, yeah, we should be good to go. You can talk about quantization. Thank you. All right. Thank you, Duan. Yep. All right. So let me close that. That's yours, actually. Okay, cool. So I'll be talking about a whole different optimization techniques I think you can use to deploy these models on Kubernetes. My background is in Kubernetes. I develop a lot of Kubernetes stuff at Akamai and I work on the managed Kubernetes platform there. So a lot of the stuff that we do is we want to make sure that we're able to use GPUs on Kubernetes really well.
Use all the different features that they have. And we deploy a lot of these models using some of these techniques that I'm going to be talking about. So there's different techniques. So we're going to talk about quantization. I think this one's the main big one. It's super important. We're going to talk about speculative decoding.
This is a pretty cool technique. It can give you quite a big performance boost in your throughput. We're going to talk about how do you tweak your LLM, VLM config to make sure that you're getting max performance out of it. And you're meeting your SLAs. And then we're going to actually do some tuning and evaluating. So I'm going to leave you guys with some sort of framework that you can use to figure out what exact configuration you need to use for your specific workloads and specific use cases.
So I'll dive into quantization. Let's see. And if we have time, we can definitely go. We can have a quick Q&A as well. But I think we have 30 minutes. I'm going to run through it at a good pace. So in quantization, there's a whole lot of different types of quantizations you can do. There's the BF16, the one that the model is going to start off with. That's the full precision model that Quint provides you. And then there's a lot of other quantizations on top of that. People have created FP8. That's one of the models that we're going to look at in this particular module. There's INT4. There's AWQ, GPTQ. These are different types of ways you can quantize the model.
There's NVFP4, which is NVIDIA's proprietary quantization technique that they use. It's hardware accelerated on Blackwell GPUs and more. That one is pretty cool.
But let's see. Let's dive into it. Make this... Hopefully we can fit that in there. All right. So as you can see, if you have the BF16 weights, it's going to take a lot of your memory. In this particular use case, we have 20 gigs of VRAM. And we want to maximize how many requests we can serve with these 20 gigs. So we want to make sure we have enough space for KV cache. Reason being, the more requests, the more KV cache you can have on the memory, the more requests you can process in parallel, thereby increasing your throughput. So that's super important.
So that's why we essentially want to do quantization. We want to reduce the size of the model so that way you can fit more KV cache and essentially increase your throughput. So that's one reason. The other big reason, I think, is also because you're shrinking the weights essentially by in half, you don't have to do that memory movement between the different memory hierarchies, resulting in essentially faster decode as well.
So we will see you'll go from, you know, 40 tokens per second, which is the base model, will probably go up to 60 tokens per second, if not more. So let's look into this. Let's install the dependencies. And then I'm just going to make sure that the model is still available and everything is running. So yeah, we do have the model running, the same 4 billion parameter model, and it's running in the namespace. Again, as I said, a high level overview, there's a whole different source of different techniques you can do quantization with. For example, Lama CBP is a pretty popular one for running a lot of these models at a lower precision. That uses GGUF format.
That format is pretty cool. You can have, you know, 5-bit, 3-bit, 2-bit, 1-bit quantizations, which is pretty interesting and pretty cool. But the downside of that is you lose a lot of quality trying to get a lot of performance out of it. So there's a tradeoff there. But for the most part, going from BF16 to FP8 is a very negligible drop in quality and performance. And it will result in more performance while keeping the quality exactly the same. So that's what we want to showcase. And that's one of the assumptions that we're making.
Obviously, when you're doing this for your particular workload, depending on what you're using it for, I highly encourage people to have their own evals. So that way, if you're switching from, you know, BF16, your evals are saying, okay, everything is good. Everything is running well for our workload. You switch to FP8, you might have issues where some things are breaking here. Sometimes it's hallucinating. Sometimes it's going in a loop. So a lot of those things can happen for very specific use cases. And in those scenarios, it's very important that you have your own eval set and you're running your own evals to make sure any changes you make are okay to make.
And also, you don't have any degradation in performance. Again, we'll run and make sure that we have the BF16 base. And then we're going to measure the performance.
When you're doing this for your particular workload, depending on what you're using it for, I highly encourage people to have their own evals. So that way, if you're switching from BF 16, your evals are saying, okay, everything is good. Everything is running well for our workload. You switch to FP8, you might have issues where some things are breaking here. Sometimes it's hallucinating. Sometimes it's going in a loop. So a lot of those things can happen for very specific use cases. And in those scenarios, it's very important that you have your own eval set and you're running your own evals to make sure any changes you make are okay to make. And also, you don't have any degradation in performance. Again, we'll run and make sure that we have the BF 16 base. And then we're going to measure the performance. So we have a little load test utility package that we use to do some testing. Essentially what we're doing, if you look at the levels where these are like different concurrencies, we're making this request. Each request is going to have about 256 tokens and the output is roughly going to be about 128 tokens. So this is trying to simulate how many requests you can process at one time. And we're going to use this as a baseline to see what the baseline performance is. So for 32, we're getting aggregate performance of 714 tokens per second, which is pretty good. At single concurrency, we're getting 37.5 tokens per second. So that's important to note down. And also we're getting 61 milliseconds for time to first token. And then you'll notice the time to first token goes up, right? The jump between 32 and 64 is quite large. We're going for 277 milliseconds to 1300 milliseconds. That's quite a big jump. And you might not necessarily want to make that trade off. Meaning you might want to potentially stop at only 32 concurrent requests that you're processing and not go higher than that. So that is an important thing to notice there. Again, as I was saying, evals are extremely important. Again, reason being, you can have performance degradation when you do quantization. And you can lose some intelligence. Reasoning can not work as it should. There's going to be a lot of issues. So you want to essentially simulate here at a very basic level what kind of evals you might want to think about. You want to think about if the JSON is being generated correctly, if the JSON is being corrupted when you reduce the quantization. You know, at BF 16, you might have good responses. But when you go to FP8, maybe potentially your function calls are failing. Why is that? It's probably because it's not generating the JSON correctly. So there's a lot of these eval cases that are already out there that you can find in the open source. Hugging Face has a lot of evals. You can go on GitHub, you can find a lot of these. But you want to come up with your own for your own use case. But then, so the next thing what we're going to do is we're going to switch from BF 16 to an FP8 model. So we are going to essentially reduce the size of the model in half. And once we do that, we'll see what the performance differences are, and are they worth it, and are we losing any quality over it. So to do this, you will need to be in the root, and then click on manifest. And in there, you will see VLLM.yaml. So I'll go over this. So this is a typical manifest configuration file that you have for Kubernetes deployments. How many of you have used Kubernetes before or have knowledge of Kubernetes? Okay, quite a few. Okay, great. So this will be quick. I don't have to go over all the details. But essentially we have a PVC, which is essentially our cache where all of our models are living. And we have a simple deployment with VLLM with a lot of different arguments and flags here. So you can see we're using the Qwen 3-4 billion parameter model. And then we're going to switch it to this FP8 version from Red Hat. One more quick thing I want to quickly mention is you see the dynamic at the end. This is pretty important. This means that not everything in this model is quantized to FP8. In a lot of cases, in a lot of different quantization techniques, you might want to quantize the model, only specific parts of the model and not the others to make sure the performance stays the same. And you don't have a lot of issues there. So that's one of the reasons why you'll see dynamic. You'll see all kinds of things. You'll even see quantizations where certain heads of the model are going to be 4-bit and then some are going to be 8-bit and some are going to be full precision. And it's interesting that people are doing that and finding a lot of performance there. They're finding the performance gain while making sure the quality stays the same. So once this is changed, we're going to save it and then we'll just go through and run it and apply it. So this is just making sure that the diff is good. We're not causing any issues here. That should be fine. And then we'll just go ahead and, where's the file? Right here. We'll just go ahead and apply and roll out. It's going to take a little bit of time. Let me save that. But another thing you guys can also do is you can open up a terminal tab as well. If you just click on the plus sign and then you will see a terminal option. And then that will also let you see what's in your namespace and what you can do here. So if you see, the VLLM endpoint is still coming up. This pod is essentially your Jupyter notebook running within your namespace. Let's see. This will take a little bit of time to come up. While this is coming up, does anyone have any questions? We can probably have one question.
[SPEAKER_01] It's pre-quantized, right? [SPEAKER_00] Huh? [SPEAKER_01] It's pre-quantized, right? The model is pre-quantized.
[SPEAKER_00] Yes. It was pre-quantized. Yeah. You can quantize your own models. There is LLM compressor. It's provided by VLLM, I believe. LLM compressor. So there is tooling out there for you to do this on your own if you would like. But yeah, the one that we're using currently is already pre-quantized that we downloaded off of Hugging Face. All right. I think that should be up. Again, it's taking a little bit of time, mainly because it's taking all the weights out of the VRAM and loading the new weights in. So it's going to take a little bit of time to do that. Anyone else have any questions? [SPEAKER_01] I'm sorry? [SPEAKER_00]
Look at your YAML file. Look. Looked like they had two flags on the model. [SPEAKER_01] Oh, they did. Oh. That's a good call out. Thank you for that. Did not see that. All right. We're going to go through it again. Let's rerun that. Okay. That's probably why it didn't come up as quickly as it should. Oh, I can't do that. All right. Any other questions while this is going through? [SPEAKER_01] Go ahead. How do you choose between FP8 and int8? [SPEAKER_00]
How do you choose between FP8 and int8? That's a good question. So it depends, right? int8 is going to be slightly less precision than FP8. That's essentially the reason. The difference is FP8 is floating point. So you get a little bit more precision out of it. And then int8 is integer. So you could use either or. Again, these are all the other options that you have. You can choose based on your workload and where your constraints are. But, yeah, you could totally go int8 as well and it should be fine. Where does it say that? Not very good for it. [SPEAKER_01]
Oh, yeah. I mean, oh, that's the other good call. It depends on the GPU as well. Some of the GPUs might not necessarily support it. [SPEAKER_00]
Oh, GPU. Yeah. So GPU support is important. That's another good call out. So some of the GPUs might support it, but it might not be accelerated by the GPU. Meaning you might not get the full performance that you would be expecting out of it. For example, the GPUs that we're using, we're using RTX 4000 ADAS. They support FP8 and we're going to get the full precision, full performance out of it. And it's able to hardware accelerate all those calculations. But if we, let's just say, use FP4, it won't be able to do that. And we would actually not see a whole lot of performance gains. And we would actually see performance go down instead of it going up. So that's another thing to keep in mind. All right. Where is it? All right. It has successfully rolled out. So we'll take a quick look.
GPU. Yeah. So GPU support is important. That's another good call out.
So some of the GPU might support it, but it might not be accelerated by the GPU. Meaning you might not get the full performance that you would be expecting out of it. For example, the GPUs that we're using, we're using RTX 4000 ADAS. They support FP8 and we're going to get the full precision, full performance out of it. And it's able to hardware accelerate all those calculations. But if we, let's just say, use FP4, it won't be able to do that. And we would actually not see a whole lot of performance gains. And we would actually see performance go down instead of it going up. So that's another thing to keep in mind. All right. Where is it? All right.
It has successfully rolled out. So we'll take a quick look. So now we can see it's actually using the FP8 model now.
And then we'll also quickly go through and do another load test. It's going to be the exact same. We're going to do it at concurrency 1, 4, 8, 16, and 32, I believe, over here. It's going to be exactly the same. So. And then once that is up, we can compare and see the performance differences and why you would want to quantize. Okay. The performance is in. And if we compare it before and after, you can see, let me make this a little bit bigger. You can see even at concurrency 1, we're going from 37.5 tokens per second to 53.4 tokens per second. So we're seeing considerable jump in performance here.
And then at peak throughput, we're seeing at 64 concurrency, we're going from 800 to 1140. So that's about 1.42 times, which is quite a big performance jump. But again, keep in mind, the time to first token is going up considerably as well compared to 32 and 64. But then, yeah, you can. And then again, you want to run evals. We can quickly run through this and it probably won't have any differences. So, yeah, again, BF16 versus FP8.
There's not a whole lot of performance degradation you should expect.
It's going to work out of the box for the most part. But for specific use cases, it might not. But for simple eval cases that we had here, it's working fine. I think that is it for this module. We'll jump into next is speculative decoding, which I think is a pretty interesting one. Let's see. Jump in here. All right.
So how many of you have heard of speculative decoding before? Okay. Quite a few people. That is good. For those who don't know what speculative decoding is, let me make this smaller. It's essentially we're using another draft model, which is going to be a much smaller model than the main model that we're using. And it's going to generate multiple tokens ahead of time. And then our main model, which is the 4 billion parameter model, is going to look at those generated tokens. And it's going to either say it looks good, it's going to verify it and say it's going to look good or it's not going to look good.
So in this diagram, you can see the draft model generated four tokens ahead of time. And then the verifier model, which is our 4 billion parameter model, is going to say, oh, only the first and second token makes sense. The other two don't. So it's going to discard it. And it's essentially going to do this each time it's generating new tokens. So it's going to go in a loop there. And for this workshop, we're going to be using the 0.6 billion parameter model from Quen as a draft model. And see if that is going to either help us or not help us. In a lot of cases, it can also not help you and reduce the performance.
And there's a multitude of reasons for that. And we'll go into that shortly. How are we doing our time? Good. Just make sure we are good here. The target model. Okay. Before we get into it, I also want to talk briefly about all of the different ways you can do speculative decoding. There's a lot of different ways. And there's more ways coming out every few months. But the draft model is one way. A lot of new ways of doing it is actually using a diffusion drafter model, which I think is really cool. I personally use that for one of my home lab machines. And that gives you a huge performance.
The difference between that and this is because it's a diffusion model, it's going to be generating a lot of data. It's going to be a lot of tokens at once rather than doing what we do sequentially with LLMs. And then the verifier model is able to verify X amount of tokens out of that. But there's a lot of different types of methods you can use. You can use suffix decoding. There's a lot of times model would come with a built-in drafter model as well. So those are like the native models that are trained along with the main model. So you don't have to import another model to do this.
There's Medusa, Eagle, again like Diffusion, D-Flash is a big one that has kind of been going viral. And it's working pretty well. So there's a configuration you set for figuring out how long, how much it generates before the verifier comes in and verifies it.
So you can set that. You can set it to two tokens, four tokens, and five tokens. And it's important that you set it correctly. Because if there are, for example, let's just say you set it at four and the model verifier comes in, it's like, okay, I only accept two. That's 50% acceptance rate. And that is pretty bad. That's actually going to have a negative impact. Because not only are you running, you're running two models, so you're spending compute to run two models, and then you're only getting 50% acceptance rate. And that's essentially going to result into a decrease in throughput. So that's not something you want.
So that's something you have to tweak and play around with and see how many tokens do I want to generate ahead of time. So, technically you could generate 15 tokens, but you probably don't want to do that. You probably want to do two, maybe three, maybe four. It also depends what type of method you're using. Again, I use D-Flash for a lot of my home labbing, and that works pretty well if I set it to eight. And if I set it more than eight, I actually get a lot less acceptance rate. And that causes my performance to go down or be very flaky. All right, so we will next. We've got one more question. One more question? Hey, sorry.
This is from the last module, but how does dynamic compression work in a sentence or two? So the way it works is if you understand the different heads of the model? Because there's different layers within an LLM. So if you look at the model.json, you'll actually see there's a lot of different parts to an LLM, and there's a whole pipeline that pushes the tokens from one thing to another. And a lot of times when you see a dynamic thing, it essentially is saying, okay, I'm going to only quantize the attention heads to FP8, but I'm going to leave everything else as is. I see. So that's the reasoning.
And if you remember from previous modules, you saw that the FP8 version is not exactly half in size. It's not going four gigabytes, it's like 5.1 gigabytes. That's because not every part of the model has been quantized to FP8. So that's like the dynamic part of it. I see. Is the same math applicable to all the models or it depends model to model? Depends model to model. Every model has a different architecture. So architecturally speaking, it depends what parts of the model you quantize. There's people who quantize some parts of the model to int4, but leave other parts to FP8 and then leave some parts to BF16. Thank you. Yeah. All right. We'll run through this.
Again, I'm just confirming that our baseline is good. We're using FP8 model here. And then we'll do another load test quickly to get another baseline of what it would look like. Before we implement and add speculative decoding to this particular deployment in VLLM. And then while that is running, I'm just going to make sure to let me actually copy this correctly. There's people who quantize some parts of the model to int four, but leave other parts to FP8 and then leave some parts to BF16. Thank you. Yeah. All right.
We'll run through this. Again, I'm just confirming that our baseline is good. We're using FP8 model here. And then we'll do another load test quickly to get another baseline of what it would look like before we implement and add speculative decoding to this particular deployment in VLLM. And then while that is running, I'm just going to make sure to let me actually copy this correctly.
I'll rate as draft tokens. So in this particular scenario, we're setting it to four. Again, this is something you have to do a lot of testing on. You have to try out, do I want to set it to four, do I want to set it to two, do I want to set it higher? It all depends on the acceptance rate and how much performance you're getting out of it. And then once you set this flag and we will redeploy this, we go back in here. We got our baseline. And then let me make sure that it's good. Okay. Things look good here. And then we'll go ahead and apply and roll this out. And this is probably going to take another couple minutes. So does anyone have any questions? Go ahead.
Oh, one second. I noticed that you set the GPU memory utilization to 0.7, which leaves a lot of your VRAM unused. Is there any particular logic to that choice?
In this particular scenario, there could be a lot of reasons. Sometimes you might have multiple deployments on the same GPU. And you want to make sure that you have enough VRAM for something else, and then you keep enough VRAM for this. But in this particular scenario, not really. We're going to bump it up in a following module. It's one of those knobs, right? Like you have to make sure that you're setting the utilization correctly. If you set it too low, you're leaving performance on the table. If you set it too high, you're going to kill your node. And that's not good.
Yeah, so I'm going to see the one. Is this up? There's another tab. Yeah, I don't have a number. Okay, it's still coming up. This is taking a little bit more time. Go ahead. The bump that we see from 32 to 64 parallelization, it's because of the key value cache just blowing out? Or I mean?
Yeah, yeah. Essentially the key value cache is blowing out, and it hit its max limit. And it can't go above that. So there's a lot of reasons. There's that part. And then there's also the continuous batching. And a lot of times what will happen if you don't set the configuration to a level where the continuous batching is not optimal, it can also cause you to see high tokens per second or high latency as well. Yeah, in this scenario, we're essentially hitting a ceiling in terms of how much VRAM we can use there. That's why we're seeing that. But in the following modules, we'll see how we can improve that scenario and hopefully make it better. Okay. All right. We're rolled out. So we now have speculative decoding set up correctly. So what we'll do is we'll do a quick load test again. It's the same exact test that we ran up here. Where, you know, just keep in mind we're getting 58.2 tokens per second for concurrency one and then 42 milliseconds of latency. So this is our baseline before we do speculative decoding. But what I want to showcase here is not a happy path where you will automatically get a crazy improvement in performance. You'll actually see the performance went down drastically. You're seeing 16 tokens per second, whereas the baseline was 58. And then even the time to first token is going up a little bit as well. And we want to figure out why is this happening? So there's a big difference and a big decrease in performance. Even if you look at concurrency 16, we're going from 700 tokens per second to 240 tokens per second. So that's a considerable decrease in our performance.
So the way to interpret this is there's a lot of different reasons. One is, as I was talking about earlier, it's the low acceptance rate. If your acceptance rate is very low and the verifier model is going to keep rejecting those tokens that are generated by draft model, you're wasting a lot of compute to generate those draft tokens. And then the verifier is coming in and saying, hey, I don't want to take this work. This is bad work. So that's one. It could be because we set the speculative tokens too high, meaning in our current config, we set it to four. Maybe we need to set it down and see if that actually helps improve the acceptance rate. There's a lot of things with the scheduler as well with VLLM, depending on how it's scheduling these requests in, that could be leaving some performance out on the table. So it also depends on compatibility and things like that. And then again, same GPU contention. You're using the same GPU to do this work. So it could be resulting in the resource not being used correctly.
So in a lot of cases, usually this works, but in our scenario, it didn't work. The main particular reason for that is this particular draft model is not trained correctly for this particular model. So that's the reason we're seeing a very low acceptance rate. So when you are doing this for your own models and for your own deployments, you have to make sure that the draft model that you're using is going to be compatible with the model that you want to use it for. If you don't do that, you will run into the scenario that I'm showcasing here where your performance is going to tank and there's not a whole lot you can do about it. I can tell you from the resource perspective, this GPU has enough headroom to support all of this. But the reason for us seeing this decrease in performance is because the models are not trained correctly. And that is something you want to keep in mind and test for as well. And you want to make sure the speculative tokens are set to the right number as well. But yeah, when you have your own time, I would definitely implore everyone to play around with that number. Meaning change this from four to two to six to one and see what kind of performance gain you see, what kind of performance decrease you see, and why is that happening? But yeah, that's it for speculative decoding. It is not going to help us in this scenario. So I'm just going to go ahead and comment that out and then we'll redeploy this. So we are back to our baseline.
I got one question. Hey, um, so I know there's probably some nuance depending on model architecture, but in general, from what you've seen, is there a massive hit to acceptance rate if you use mixed precision, essentially run the main model at FP8 and then quantize the draft model down to Q2? If I'm really memory constrained, is it often even worth doing that? Or what have you seen in general?
Yeah, that's a good question. A lot of times it doesn't matter as much. Most of the time what you want to do is you want to keep the draft model and the main model at the same precision. But let's just say the draft model is at BF16 and then the main model is at FP8. The mismatch can cause the acceptance rate to be very low. So the main part of it is you have to train the draft model correctly so that way it's able to generate the right tokens. In our particular scenario, the draft model was not trained correctly. And then it was also quantized down to FP8. So there was probably some issues with that recipe when they trained this model, which resulted in us taking a massive performance hit.
Or what have you seen in general? Like does that have a bad?
Yeah, that's a good question. A lot of times it doesn't matter as much. Most of the time what you want to do is you want to keep the draft model and the main model at the same precision. But let's just say the draft model is at BF 16 and then the main model is at FPA. The mismatch can cause the acceptance rate to be very low. And then the main part of it is you have to train the draft model correctly so that way it's able to generate the right tokens. In our particular scenario, the draft model was not trained correctly. And then it was also quantized down to FPA. So there was probably some issues with that recipe when they trained this model, which resulted in us actually taking a massive performance hit.
So a lot of times when a lab releases a model, they release a draft model along with it. So you want to use those draft models that come with the model. There's also third party labs that do their own draft models. So you can try out a lot of different options that are out there and see which one works for you. And in some cases, depending on the use case, let's just say you're using it for coding, the draft model might work perfectly fine. But if you're switching that to maybe some English writing, very specific academic writing, it might not necessarily work well. And you're going to see a decrease in acceptance rate. So it also depends a lot on your use case as well. So it's not universally applicable.
Gotcha. Cool. Makes sense. Thanks. Yeah. All right. Let's jump onto the inference side of things. But before you make another jump, any other questions? Oh yeah, I can put that on there. Yeah. Okay. So the fact that we have speculative decoding, presumably is because for a model, it's faster to verify rather than decode. Yeah. Can you just give a little bit of a mental model for what a model does underneath the hood to verify such that it's faster than decoding? You know, it can't be decoding and then comparing against what the draft model produces.
Yeah. So essentially, when a typical LLM is decoding, you have a set of vocabulary. It's a huge array of bunch of numbers and it's representing a confidence score for each of those items. So instead of doing that one token at a time, when you run with speculative decoding, you're running it for a lot of different things. So with continuous batching as well, you're running a lot of different requests in parallel. So you're doing the same calculation for everything and you're doing it at once for a lot of different requests. In the same way, you're doing the same thing for speculative decoding. You're checking the confidence score for the speculated tokens and making sure that this is a high confidence, so we're going to go for it. This is 0.95 and this one is like 0.9. And then you accept that. And then the other ones you reject those. That's the mental model: you are in parallel running through the layers and making sure that each of the tokens that the draft model outputs has a high confidence.
Yeah. Hopefully that answers your question. Oh, one more question. Do you have any examples where that is?
Yes, I do. That's a good call out. There's actually a few links in here. Where did I leave those? Interpreting the results. Yeah. So there's a lot of different write-ups on speculative decoding. In general, if you do it right, you do see quite a bit of increase in performance. VLM has actually done a big report on this and they've seen about 1.5X increase in token generation if you set it up correctly with the right model and with the right drafter and the right settings. So yeah, this does excel. It's just a matter of getting it right and tuning it correctly and making sure you have the right things in place for it.
But yeah, from my personal experience, for my home lab, I used Qwen 3.6, 35 billion MOE model. And along with that, I use a D-Flash drafter model. And I get roughly around 2 to 3X token generation performance improvement, depending on the use case. So it does work. It's just a matter of getting the right models to work together. How do you choose the model size for the drafter?
For the drafter, you want to figure out the smallest model that you can run that doesn't take as much GPU power because the main model is the model that has all the knowledge. That's the model that you really care about that has everything that you need. But you don't want draft model to take a lot of those resources away from the main model. So you want it to be small, but not so small that it's dumb, but big enough where it's going to actually give you results. 3B is too big. The reason why is a lot of MOE models, like I was talking about, Qwen 3.6, 35 billion. So it has a mixture of experts model and each expert is about 3 billion parameters. So the experts can be around that and you would get good performance out of it. But for the drafter model, you probably want to be less than 1 billion parameter just to make sure that it also depends on the main model you're using. Like if you're using a model that's like 400 billion parameters, you could probably get away with using a bigger drafter model to make sure that you get higher acceptance rate. So you got to find the right balance essentially.
Yeah. Cool. Do we have any other questions over there? One more before you jump in. Yeah. I just had a question. How is the draft model trained? Is it distillation or something else?
It's essentially distillation. So you take the big model and you distill all of its capabilities. You create a dataset and then you train the drafter model using that. And a lot of times what you'll see is different techniques to do this. The other techniques you'll see is the drafter model is trained alongside the main model so that way that's another way of doing it. And a lot of labs will actually give you a drafter model inside the same package. So you don't have to essentially download a second model and run it. So there's a couple of different ways of doing it. But probably the best way is train alongside it. And then that way you don't have a lot of issues and acceptance rate stays high.
Cool. We'll jump into module seven. So here I want to talk about some of the different flags that you should care about when deploying using VLLM and how you want to get the saturation to be as high as possible. Saturation meaning we want to get the GPU to work as hard as possible, as long as possible. And because you want to get your money's worth. If you're renting a GPU or if you're buying a GPU, you want to run it as much as possible.
So we will stop here. So one of the concepts I want to talk about, if you remember previously, we were looking at the 34, 32 concurrency and 64 concurrency. We saw a steep increase in the latency. And the reason for that is essentially you, the throughput at some point is going to flatten out. But the latency can keep increasing if you keep increasing the concurrency. So you essentially want to find the sweet spot. And that is something that VLLM sort of lets you tweak and make sure that you find that sweet spot. And once you do find it, you can set the right settings for it.
But essentially you want to find the point right before where the throughput gets to a flat state, but the latency is still acceptable enough. It's the point you want to get to. We will do a setup.
We saw a steep increase in the latency. And the reason for that is essentially you, the throughput at some point is going to flatten out. And the latency can keep increasing if you keep increasing the concurrency. So you essentially want to find the sweet spot. And that is something that VLLM lets you tweak and make sure that you find that sweet spot. And once you do find it, you can set the right settings for it. But essentially you want to find right before where the throughput gets to the flat state, but the latency is still acceptable enough. It's the point you want to get to.
We will do a setup. And then let's make sure our settings are all good still. Serving model is up. Let me just double check if it's up. Should be. Yeah. And then here we're again going to do another load test. So that way we know the data and then we can, based on that, figure out where that point is essentially. We call it the knee, where things are flattening, but also based on concurrency, the time to first token is acceptable.
Once that is, oh, I think, should be fine. So the throughput is slowly increasing as concurrency is increasing. That's acceptable. And then you also see the latency go up. That is also acceptable, but it's not going up drastically. But we should shortly see the big jumps with more concurrency here. But while this is running, any other questions for anyone? Go ahead. Over there. So my question was again on the previous speculative decoding. Just wanted to know, based on your experience with drafter model, what kind of use cases you have seen it to work really bad? Like for example, with agent loops, with tool call or with coding, what kind of use cases?
Agent loops. It's really good at tool calling. It's really good at browser use. That's the one particular use case that I use it for. I want to automate a lot of browser tasks. Because there's still, you don't necessarily get APIs for everything. And so you want to bridge that gap. And the drafter model helps you generate more tokens faster. So you see your browser agent essentially run around and do things faster. So in a lot of ways it does help. I will say for browser use, I probably see around 1.5x increase. Whereas for coding, I see closer to 3x. So depending on your use case, you may see more or less.
And a follow up on that one. Are there any benchmarks like coding fireshift? There's definitely brand benchmarks out there. I'm personally a little skeptical of benchmarks. Whenever I see them, I never get the same results. I don't know if people agree with that here. So for the most part, you want to do your own testing and see what works for you. Because it very much depends on your use case. Because the acceptance rate is going to be different depending on your use case, what you're using it for. Thank you. Yeah. Any other questions? Mic check, mic check. How's it going? Do big models like Codex or Claude, do they use this type of coding? Like have they published that they use this pattern? Or is this more for open source if you're training your own stuff or running inference?
I don't know if they do it or not. I would imagine they do for the free performance. But for the open source, yeah. This is particularly for the open source. All the open source big models that you want to use, all the Qwen models, the GLM models, they all have speculative decoding drafter models available that you want to use.
Is there a main drafting model that they use for example, for Deep Seek or GLM? Deep Seek actually came out with a new thing yesterday, I believe, or the day before. It's called Spark. It's their own technique for doing speculative decoding in a more dynamic way. Essentially they're figuring out how, so here are configurations static, right? Like we say we're going to generate four tokens at a time. But with Deep Seek's way of doing it, they are making it dynamic, meaning it on the fly decides, oh, I'm going to generate only two tokens. Oh, I'm going to generate four tokens or five tokens, depending on the acceptance criteria, depending on the GPU load and all sorts of metrics. So every model, every lab has their own way of doing it as well. And you probably want to stick to that, but you can also experiment. For example, the Qwen models, Qwen Lab doesn't release the D-Flash models for drafting, but these are released by a third party lab, but they work quite well with them. So you have to test it out and see. Thank you. Yeah. I think this is hanging, right? Yeah. I would check the pod. Yeah. Might've killed the cluster here. I can't type. This was working well. Refresh. Let me create the tab again. Okay. Well, something is wrong. Copy the URL and open it in the tab, see what happens. Let me open a new tab. I wouldn't close that one. You know, in all the testing that has not happened, but it happened today. Can I at least go through different things? Okay. At least I can scroll through.
You know, since the cluster decided to take a vacation, I'll go through the content that I was going to cover. The main point of running this benchmark here was to show where that knee is, meaning where you see the max throughput. If we go back to this diagram where you see the max throughput while making sure you are seeing the lowest latency for token generation. And that essentially limit was at 32 concurrency. Because anything above 32 concurrency, you'll see the token generation is going to be the same. It's not going to change much. The throughput is going to be the same, but the latency is going to go drastically up and you don't want that. So that's the limit you are hitting. And that is important information that we need to keep in mind and look at when we are deploying these things.
And if... Yeah. You can go to 100. Go to look at the spreadsheet. 100? Yeah. Go to 100. And then just continue from 7 to 8. Where is it? There you go. All right. Well, this one is working. That's good. All right. Cool. So we'll jump into 8. Let me also open up. Who's doing it? Okay. So for module 8, we're going to talk quickly through what flags and knobs you can tweak to make sure that you can get above that limiting point that we were talking about at 32 concurrency, you're seeing that limit and how do we get beyond that and what things you need to keep in mind when thinking about this.
So for this one, I'm going to give you a thinking model. Essentially you want to measure and that's why with a lot of different cells, I keep running load tests and it's super important to run those load tests to see what your performance is and any changes you're making, how is that changing the performance? Is it making it better? Is it making it worse?
Is it if the throughput keeps going up or stays the same but the latency is changing, something is either correct or wrong there. So that's something we have to keep in mind. And there's a bunch of different knobs you can tweak in VLLM to make it better. But the main four ones are again the GPU memory utilization. You want to make sure that you're setting that correctly depending on your use case. Again, if you are running multiple models on the same GPU, you might want to keep it low and that's a trade off you're making. But if you're only running a single model and you want to make sure that it's getting the best performance possible, you want to bump that up to 0.9 or even 0.95.
The other thing is you want to make sure that the max num sequences is set to a good limit as well. This is something you have to figure out by testing. In our particular deployment, if you look at the VLLM.yaml, we start with 32 sequences. Something is either correct or wrong there. So that's something we have to keep in mind.
And there's a bunch of different knobs you can tweak in VLLM to make it better. But the main four ones are again the GPU memory utilization. You want to make sure that you're setting that correctly depending on your use case. Again, if you are running multiple models on the same GPU, you might want to keep it low and that's a trade off you're making. But if you're only running a single model and you want to make sure that it's getting the best performance possible, you want to bump that up to 0.9 or even 0.95.
The other thing is you want to make sure that the max num sequences is set to a good limit as well. This is something you have to figure out by testing. In our particular deployment, if you look at the VLLM.yaml, we start with 32 sequences. So what that is doing is telling VLLM that it can only process 32 requests at a time and not more than that. And if you do more than that, you're going to see some performance degradation there.
So there's a lot of different flags, but those are the key ones that you want to keep in mind. You want to make sure that you're setting the model length to the correct length as well. And then you want to make sure the batch tokens are also set to the correct length. You don't want to keep it bigger if you want to do pre-fill faster if your GPU can handle it. You want to do it smaller if your GPU is on a slower side and you can't handle it.
But the idea is you want to change one flag at a time. You don't want to change multiple things. And when you change things, run the benchmarks and see what performance you're seeing. Measure it and then make assumptions on what you should do next. We have about 10 minutes left. I think we lost the PVC. I think that's what happened. Oh, it got a different one. Yeah, I need to actually change this. Re-run this, I think. Let me actually just change this in here. This was supposed to be sequential, but the other Jupyter notebook died. So change that. And then that should work. There you go.
Again, as I talked about, there's different knobs that you want to tweak and see what happens. But we'll measure the baseline and then we'll change a couple of flags and see what happens next. Does it work? Okay, cool. There you go. It's working. While this load test is running, does anyone have any other questions? I noticed that there's a definite fall off when we're optimizing the model like here, the 32 to 64, huge fall off. Is that when you would decide that maybe we should scale the hardware? Or is that something that you're confident you can still tune it further? Essentially, is this the ceiling?
Yeah, you figure out the ceiling by doing mathematics. I think in some of the previous modules, Duan covered what the max ceiling can look like for tokens per second, what the throughput looks like, and what sort of expectations you should have for the deployment. And if you are seeing those max expectations, that's probably the maximum limit of your hardware. And then you probably have to get additional hardware or better hardware to do so. So there is a limit. You know, there's only so much you can tune, but you're trying to squeeze as much out of the GPU as possible.
I'm going to share the slides real quick. I can leave it up for a couple of hours. I'm not going to leave it up just because you do have access to GPUs. But what I am going to give you, if you scan this QR code, you'll get access to the PowerPoint, as well as the repo if you want to spin this up in your own Akamai Cloud account, or if you want to run it on your laptop, you can do that.
So if you scan this QR code, it'll take you to a site that has all the resources. And if you don't have an Akamai Cloud account, you can sign up and you get $300 in credits with a free account. So that's everything you need. And if you all have questions, both of our contacts information is here. Omer, I'm Dewan Lightfoot. Yeah, and with that being said, if you all scan the QR code, I'll let Omer finish it up. I just want to make sure you all get this before people start to leave. Thank you. We'll leave it up there for a couple more minutes once everyone gets it. So you can use Llama, it depends on your hardware. I think that's the first thing I would look at.
Oh, you have both? For the sake of the argument, let's just say you have the best GPU. Let's just say you have the latest Blackwell GPU. Yeah, I think for testing and doing, figuring out what model you want to use for your use case, I think it's good to use Ollama and Llama CPP to quickly spin it up and try it out and see what happens. But once you have a model that you know I'm going to use for sure for this use case, and this is working great, you probably want to switch to VLLM, SGLang, or one of these other model runtimes.
Reason being, they allow you to run at higher concurrency and give you more performance out of it. So if you have a single agent running, I think it's fine to use Ollama. It's not a big deal because you only have one request going in at a time. But if you're running 20 agents and you want to run it parallel. Yeah, you can set up speculative decoding with VLLM. I don't think Ollama supports speculative decoding as far as I know, but I could be wrong. But when you want to get the max performance out of your hardware, you definitely want to do that. Yeah, I don't know if there's a diffusion LLM. Is there an open source diffusion model right now available?
Yeah, Lana. Yeah, I mean, I think VLLM supports it. So I think you would be able to run it on VLLM. Ollama, if Ollama supports it, you can as well. Yeah, that's definitely possible. Okay, we'll switch back to the module and go through it. Again, as I was saying, at 32, you're seeing good performance. But at 64, the throughput is staying the same if not going up. But we're seeing a significant increase in latency.
And to get around it, one of the things I want to talk about is the maximum sequence. Again, this is how many requests VLLM is able to process at one time. It's setting that flag. If you want to have a lot of requests being processed in parallel, then you want to increase this amount. So currently, I believe it's set up at 32. So we can bump this up to 128. And then we can run this, deploy it, and see how that changes the performance.
It changed a lot of things here. Once this comes up, we can do another test. And you'll see the limitation that we're seeing here at 32 is going to go away. And you'll actually see the latency be manageable again at higher concurrency levels as well. So this is the loop you want to go in. You want to find the right flags for wherever the bottleneck is. Find the bottleneck. Figure out why that is happening. What flag you can tweak to make sure that you're overcoming that bottleneck. That's going to take a little bit of time. Any questions? One more over there. Is there such a thing as bursting to serverless? Is that the domain of model routing, or what is the pattern for?
Yeah, I mean auto scaling is one of the patterns. Specifically, in LKE you can have dynamic auto scaling so it can scale up depending on your needs, depending on bursty traffic. It can scale up to maybe use a node that has four GPUs instead of one because that handles it better. So you can automate a lot of those things to make sure that you're doing well. And the other part of it is you can also build statistical models to make sure that you understand your traffic patterns over a long horizon. And then the cluster can also dynamically predict your burstiness in some ways and scale based on that too. If you got your browser, I can show you where it's at. Any questions?
One more over there. Is there such a thing as bursting to serverless? Is that the domain of model routing, a layer on top? What is the pattern for?
Yeah, auto scaling is one of the patterns. Specifically, in LKE you can have dynamic auto scaling, so it can scale up depending on your needs, depending on bursty traffic. It can scale up to maybe use a node that has four GPUs instead of one because maybe that handles it better, right? So you can automate a lot of those things to make sure that you're doing well. And the other part of it is you can also build some statistical models to make sure that you understand your traffic patterns over a long horizon, and then the cluster can also dynamically predict your burstiness in some ways and then can also scale based on that too.
If you got your browser I can show you where it's at.
Browser? Yeah. If you open your browser. Okay, so this one is successfully rolled out and then we'll do a quick load test and once that is run we can see more. All right. Any other questions? Most folks are gone but yeah. Lightfoot. H. 32. That's where we saw the limit last time. Once we get to 64 we should see that it should improve.
Okay, so there was a big drastic improvement. The throughput actually went up quite a bit. It's at 1100 tokens per second, whereas previously if we look at it over here at 64 we were at 800 tokens per second and then the latency was 2000 milliseconds. But now after the change that we made it is 1100 tokens per second and then the latency is 800 milliseconds. So the latency has gone down quite drastically and then we have also increased the throughput quite drastically. So these are the tuning you can do over time to make sure that things are running well. Once you have it up and running you can do this for your particular use case. Maybe you're not going to have 64 concurrent requests coming in for a particular use case but maybe you are. So you have to decide based on your use cases.
Your concurrency one higher than four? Like was that a trade off you just did? Concurrency one?
I mean it can be a little higher or lower. It's not going to be the same all the time but for example before it was 37 but now it's 35. So it's a little bit of deviation that happens with running models. But it should be plus minus two tokens there. We're also running the full precision model now. We're no longer running the FPA because we have to switch the notebook. So that's the other reason why you're seeing it go from 50 something tokens to 30 something tokens. So that's the performance hit we're seeing there. But that is all I have. That is one flag you can tweak. There's also all sorts of other flags that I implore everyone to take a look at. The workshop goes through it as well. But I think we're on time and I'll give it back to Duan.
Yeah, thank you all for attending our session today. If you have not scanned the QR code, the repo, the powerpoints are available on this site. Feel free to start a free Akamai cloud account. My name is Duan Lightfoot and I'm joined by my colleague Omer and we thank you all for joining us today. Feel free to ask us questions after this session. Thank you. Thank you. So you can see we're using the QN 3-4 billion parameter model. And then we're going to switch it to this FP8 version from Red Hat.
One more quick thing I want to quickly mention is you see the dynamic at the end. This is pretty important. This means that not everything in this model is quantized to FP8. In a lot of cases, in a lot of different quantization techniques, you might want to quantize the model, only specific parts of the model and not the others to make sure the performance stays the same. And you don't have a lot of issues there. So that's one of the reasons why you'll see dynamic. You'll see all kinds of things. You'll even see quantizations where certain heads of the model are going to be 4-bit and then some are going to be 8-bit and some are going to be full precision.
And, you know, it's sort of interesting that people are doing that and finding a lot of performance there. They're finding the performance gain while making sure the quality stays the same. So once this is changed, we're going to save it and then we'll just quickly go through and run it and apply it. So this is just making sure that the diff is good. We're not causing any issues here. That should be fine. And then we'll just go ahead and, where's the file? Right here. We'll just go ahead and apply and I'll roll out. It's going to take a little bit of time. Let me save that. But another thing you guys can also do is you can open up a terminal tab as well.
Like if you just click on the plus sign and then you will see a terminal option. And then that will also let you see sort of like what's in your namespace and what you can do here. So if you get, you see the VLM endpoint is still coming up. This pod is essentially your Jupyter notebook running within your namespace. Let's see. This will take a little bit of time to come up.
While this is coming up, does anyone have any questions? We can probably have one question.
It's pre-quantized, right? Huh? It's pre-quantized, right? The model is pre-quantized. Yes. It was pre-quantized. Yeah. You can quantize your own models. There is LLM compressor. It's provided by VLM, I believe. LLM compressor.
So there is tooling out there for you to do this on your own if you would like. But yeah, the one that we're using currently is already pre-quantized that we downloaded off of Hugging Face. All right. I think that should be up. Again, it's taking a little bit of time, mainly because it's taking all the weights out of the VRAM and loading the new weights in. So it's going to take a little bit of time to do that. Anyone else have any questions?
I'm sorry? Look at your YAML file. Look. Looked like they had two flags on the model. Oh, they did. Oh. That's a good call out. Thank you for that. Did not see that. All right. We're going to go through it again. Let's rerun that.
Okay. That's probably why it didn't come up as quickly as it should.
Oh, I can't do that.
All right. Any other questions while this is going through? Go ahead. How do you choose between FP8 and int8? How do you choose between FP8 and int8? That's a good question. So it depends, right? Like int8 is going to be slightly less precision than FP8. That's essentially the reason. The difference is FP8 is floating point. So you get a little bit more precision out of it. And then int8 is integer. So you could use either or. Again, these are all the other options that you have. You can choose based on your workload and where your constraints are. But, yeah, you could totally go int8 as well and it should be fine.
Where does it say that? Not very good for it.
Oh, yeah. I mean, oh, that's the other good call. It depends on the GPU as well. Some of the GPUs might not necessarily support it. Oh, GPU. Yeah. So GPU support is important. That's another good call out. So some of the GPU might support it, but it might not be accelerated by the GPU. Meaning you might not get the full performance that you would be expecting out of it. For example, the GPUs that we're using, we're using RTX 4000 ADAS. They support FP8 and we're going to get the full precision, full performance out of it. And it's able to hardware accelerate all those calculations. But if we, let's just say, use FP4, it won't be able to do that.
And we would actually not see a whole lot of performance gains. And we would actually see performance go down instead of it going up. So that's another thing to keep in mind. All right. Where is it?
All right. It has successfully rolled out. So we'll take a quick look. So now we can see it's actually using the FP8 model now. And then we'll also kind of quickly go through and do another load test. It's going to be the exact same. We're going to do it at concurrency 1, 4, 8, 16, and 32, I believe, over here. It's going to be exactly the same. So.
And then once that is up, we can compare and see the performance differences and why you would want to quantize.
Okay. The performance is in. And if we compare it before and after, you can see, let me make this a little bit bigger. You can see even at concurrency 1, you know, we're going for 37.5 tokens per second to 53.4 tokens per second. So we're seeing considerable jump in performance here. And then at peak throughput, we're seeing at 64 concurrency, we're going from 800 to 1140. So that's about, you know, 1.4, 42 times, which is quite a big performance jump. But again, keep in mind, the time to first token is going up considerably as well compared to 32 and 64. But then, yeah, you can. And then again, you want to run evals.
We can quickly run through this and it probably won't have any differences. So, yeah, again, BF 16 versus FP8. There's not a whole lot of performance degradation you should expect. It's going to work out of the box for the most part. But for specific use cases, it might not. But for simple eval cases that we had here, it's working fine. I think that is it for this module. We'll jump into next is speculative decoding, which I think is a pretty interesting one. Let's see. Jump in here. All right. So how many of you have heard of speculative decoding before? Okay. Quite a few people. That is good.
For those who don't know what speculative decoding is, let me make this smaller. It's essentially we're using another draft model, which is going to be a much smaller model than the main model that we're using. And it's going to generate multiple tokens ahead of time. And then our main model, which is the 4 billion parameter model, is going to look at those generated tokens. And it's going to either say it looks good, it's going to verify it and say it's going to look good or it's not going to look good. So in this diagram, you kind of see the draft model generated four tokens ahead of time.
And then the verifier model, which is our 4 billion parameter model, is going to say, oh, only the first and second token makes sense. The other two don't. So it's going to discard it. And it's essentially going to do this each time it's generating new tokens. So it's going to go in a loop there. And for this workshop, we're going to be using the 0.6 billion parameter model from Quen as a draft model. And see if that is going to either help us or not help us. In a lot of cases, it can also not help you and reduce the performance. And there's a multitude of reasons for that. And we'll go into that shortly. How are we doing our time? Good.
Just make sure we are good here. The target model. Okay. Before we get into it, I also want to talk briefly about all of the different ways you can do speculative decoding. There's a lot of different ways. And there's more ways coming out every few months. But the draft model is one way. A lot of new ways of doing it is actually using a diffusion drafter model, which I think is really cool. I personally use that for one of my home lab machines. And that gives you a huge performance. The difference between that and this is because it's a diffusion model, it's going to be generating a lot of data.
It's going to be a lot of tokens at once rather than doing what we do sequentially with LLMs. And then the verifier model is able to verify X amount of tokens out of that. But yeah, there's a lot of different types of methods you can use. You can use suffix decoding. There's a lot of times model would come with a built-in drafter model as well. So those are like the native models that are trained along with the main model. So you don't have to import another model to do this. There's Medusa, Eagle, again like Diffusion, D-Flash is a big one that has kind of been going viral. And it's working pretty well.
So there's a configuration you set for figuring out how long, like how much it generates before the verifier comes in and verifies it. So you can set that. You can set it to two tokens, four tokens, and five tokens. And it's important that you set it correctly. Because if there are, for example, let's just say you set it at four and the model verifier comes in, it's like, okay, I only accept two. That's 50% acceptance rate. And that is pretty bad. That's actually going to have a negative impact. Because not only are you running, you're running two models, so you're spending compute to run two models, and then you're only getting 50% acceptance rate.
And that's essentially going to result into a decrease, like, throughput. So that's not something you want. So that's something you have to, like, kind of tweak and play around with and see how many tokens do I want to generate ahead of time. So, yeah, technically you could generate 15 tokens, but you probably don't want to do that. You probably want to do two, maybe three, maybe four. It also depends what type of, what's it called, let me go back, where is it, what type of method you're using. Again, like, I use dflash for a lot of my home labbing, and that works pretty well if I set it to eight. And if I set it more than eight, I actually get a lot less acceptance rate.
And that causes my performance to go down or be very flaky.
All right, so we will next. We've got one more question. One more question? Hey, sorry. This is from the last module, but how does dynamic compression work in a sentence or two, I guess? So the way it works is if you, do you understand the different heads of the model? Because there's different layers within an LLM. So if you look at the model.json, you'll actually see there's a lot of different parts to an LLM, and there's a whole pipeline that sort of, like, pushes the tokens from one thing to another.
And a lot of times when you see a dynamic thing, it essentially is saying, okay, I'm going to only quantize the attention heads to FP8, but I'm going to leave everything else as is. I see. So that's the reasoning. And if you remember from previous modules, you saw that the FP8 version is not exactly half in size. It's not going four gigabytes, it's like 5.1 gigabytes. That's because not every part of the model has been quantized to FP8. So that's like sort of the dynamic part of it. I see. Is the same math applicable to all the models or it depends model to model? Depends model to model. Every model has a different architecture.
So architecturally speaking, it depends, you know, what parts of the model you quantize. There's people who quantize, you know, some parts of the model to int four, but leave other parts to FP8 and then leave some parts to like BF16. Thank you. Yeah.
All right. We'll run through this. Again, I'm just confirming that our baseline is good. We're using FP8 model here. And then we'll do another load test quickly, sort of to get another baseline of what it would look like. Before we implement and add speculative decoding to this particular deployment in VLLM.
And then while that is running, I'm just going to make sure to... Let me actually copy this correctly. Let me...
Let me...
Let me... Oh, I'll... I'll... I'll... I'll... I'll... I'll... I'll... I'll... I'll... I'll... I'll... I'll... I'll... I'll... I'll...
I'll...
I'll... rate as draft tokens. So in this particular scenario, we're setting it to four. Again, this is something you have to do a lot of testing on. You have to try out, do I want to set it to four, do I want to set it to two, do I want to set it higher? It all depends on the acceptance rate and how much performance you're getting out of it. And then, yeah, once you set this flag and we will redeploy this, we go back in here. We got our baseline. And then, let me make sure that it's good. Okay. Things look good here. And then we'll go ahead and apply and roll this out.
And this is probably gonna take another couple minutes. So does anyone have any questions? Go ahead.
Oh, one second.
I noticed that you set the GPU memory utilization to 0.7, which leaves a lot of your, essentially leaves 30% of the VRAM unused. Is there any particular logic to that choice? In this particular scenario, there could be a lot of reasons. Sometimes, you know, you might have multiple deployments on the same GPU. And you want to make sure that you have enough RAM for something else, VRAM for something else, and then you keep enough VRAM for this. But in this particular scenario, not really. We're gonna bump it up in a following module, actually. It's one of those knobs, right? Like, you have to keep, you have to make sure that you're setting the utilization correctly.
If you set it too low, you're leaving performance on the table. If you set it too high, you're gonna kill your node. And that's not good. Yeah, so, um, I'm going to see the one. Uh, is this up? There's another tab. Yeah, I don't have a number. Okay, it's still coming up. This is taking a little bit more time. Go ahead.
The bump that we see from 32 to 64 parallelization, it's because of the key value cache just blowing out? Or I mean... Yeah, yeah. Essentially, the key value cache is blowing out, and it's sort of hit like its max limit. And it can't go above that. So there's a lot of reasons. So there's that part. And then there's also the continuous batching. And a lot of times will happen if you don't... If you set the configuration to a level where the continuous batching is not optimal, it can also cause you to see, like, high tokens per sec... Uh, you can see high latency there as well.
Um, yeah, in this scenario, we're essentially hitting, like, sort of like a ceiling on us, uh, for us, in terms of how much VRAM we can use there. That's why we're seeing that.
But in the following modules, we'll see how we can improve that scenario and hopefully, like, make it better. Uh, okay. All right. We're rolled out. So we now have speculative decoding, uh, set up correctly. So what we'll do is we'll do a quick load test again. It's the same exact test that we ran up here. Where, you know, just keep in mind we're getting 58.2 tokens per second for concurrency one and then 42 milliseconds of latency. So this is our sort of baseline before we do speculative decoding. Uh, but what I want to showcase here is not a happy path where you will automatically get a crazy improvement in performance.
You'll actually see the performance went down drastically. You're seeing 16 tokens per second, whereas the baseline was 58. Um, and then even the time to first token is sort of going, uh, up a little bit as well. Uh, and, you know, we want to figure out, like, why is this happening? So there's a, there's a big difference and there's a big, uh, decrease in performance. Like, even if you look at concurrency 16, we're going from 700 tokens per second to 240 tokens per second. So that's a considerable decrease in our performance. So the way to interpret this is there's a lot of different reasons. Um, one is again, as I was talking about earlier, it's the low acceptance rate.
Uh, if your acceptance rate is very low and the verifier model is just, it's going to keep rejecting those tokens that are generating by draft model, you're wasting a lot of compute to generate those draft tokens. And then the verifier is coming in and then saying, hey, I don't want to take this work. Like this is bad work. Um, so that's one, um, it could be because we said the speculative tokens too high, meaning in, in our current config, we set it to four. Maybe we need to set it down, uh, and see if that actually helps improve the acceptance criteria or acceptance rate.
Uh, there's a lot of things with the scheduler as well with VLM, uh, depending on how it's scheduling these requests in, uh, that could be leaving some, uh, performance out on the table. So it also depends on compatibility and things like that. Um, and then, yeah, again, same GPU contention. You're using the same GPU, uh, to do this work. So it could be, uh, resulting in, uh, the resource not being used correctly. Um, so in a lot of cases, usually this works, but in our scenario, it didn't work. Uh, the main particular reason for that is, um, this particular. Uh, the other drafter model is not trained correctly for this particular model.
So that's the reason we're seeing a, a very, very low acceptance rate. Um, so when you are doing this for your own models and for your own deployments, you have to make sure that the model, the draft model that you're using is going to be compatible with the model that you want to use it for. If you don't do that, you will run into scenario that I'm showcasing here where like your performance is going to tank and, um, there's not a whole lot you can do about it. I can tell you from the resource perspective, this GPU has enough headroom to support all of this. But the reason for us seeing this decrease in performance is because the models are not trained correctly.
And, uh, that is something you want to keep in mind and test for as well. And you want to make sure the speculative tokens, uh, are set to the right, uh, number as well. Um, but yeah, when you, in your own time, I would definitely implore everyone to play around with that number. Meaning change this to from four to two to six to one and see, uh, what kind of performance gain you see, what kind of performance decrease you see, and why is that happening?
But yeah, that's, that's, that is it for speculative decoding. It is actually not going to help us in this scenario. So I'm just going to go ahead and comment that out and then we'll redeploy this. So we are back to our baseline. I got one question. One question. Hey, um, so I know there's probably some nuance depending on model architecture, but in general, from what you've seen, is there a massive hit to acceptance rate if you use like mixed precision, essentially like run the main model at FPA and then quantize the draft model down to Q2. If I'm like really memory constrained, is it often even worth doing that? Uh, or, you know, what have you seen in general?
Like does that have a bad? Yeah, that's a good question. Um, a lot of times it, you, it doesn't matter as much. Um, most of the time what you want to do is you want to keep the draft model and the main model at the same precision. But let's just say the draft model is at BF 16 and then the main model is at FPA. The mismatch can cause the acceptance rate to be very low. So, and then the, the main part of it is you have to train the draft model correctly. So that way it's able to generate the right tokens. In our particular scenario, the draft model was not trained correctly. Um, and then it was also quantized down to FPA.
So there was probably some issues with that recipe when they trained this model and which resulted in us actually taking a massive performance hit. Um, so a lot of times when you, when, uh, a lab releases a model, they release a draft from model along with it. So you want to use those draft remodels, uh, that come with the model. Uh, there's also third party labs that do their own draft remodels. So you can try out a lot of different options that are out there and see which one works for you. And in some cases, depending on the use case, let's just say you're using for coding, the draft remodel might work perfectly fine.
But if you're switching that to maybe some English writing, very specific academic writing, and it might not necessarily work well. And you're going to see like decrease in acceptance rate. So it's also, uh, it also depends a lot on your use case as well. So it's not universally applicable. Gotcha. Cool. Makes sense. Thanks. Yeah.
All right. Let's jump onto the inference side of things. But before you make another jump, any other questions? Oh, yeah, I can put the on there. Yeah. Yeah. Okay. Um, so the fact that we have speculative decoding, uh, presumably is because, um, for, for a model, it's faster to verify rather than decode. Yeah. Can you just give a little bit of a mental model for like what it's, what a model does underneath the hood, um, to verify such that it's faster than decoding? You know, it can't be decoding and then comparing against what the draft model produces. Yeah. Yeah. What is it doing exactly so that it's faster? Yeah.
So essentially, uh, when a typical LLM is, you know, decoding, you have a set of vocabulary. It's a huge array of bunch of numbers. And it's representing, um, a confidence score for each of those items, right? So instead of, um, instead of doing that one token at a time, when you run with speculative decoding, you're running it for a lot of, you're running the model for parallel things. So with continuous batching as well, you're running a lot of different requests in parallel. Uh, so you're doing the same, uh, you're doing the calculation for everything, uh, and you're doing it at once for a lot of different requests.
In the same way, you're doing the same thing for speculative decoding. You're checking the confidence score for the, uh, the speculated tokens and making sure that, oh, this is a high confidence, so we're going to go for it. This is, you know, 0.95 and this one is like 0.9. And then you, you accept that. And then the other ones you, you know, uh, you reject those. That's sort of roughly the mental model is like you are in parallel running, uh, through the layers and making sure that each of the tokens that the draft for model, uh, outputs is, has a high confidence. Yeah. Hopefully that answers your question. Oh, one more question. Do you have any examples where that is?
Uh, yes, I do. That's a good call out. Um, there's actually, I left a few links in here. Um, where did I leave those? Interpreting the results. Yeah. So there's a lot of different, uh, write-ups on speculative decoding. In, in general, if you do it right, you do see quite a bit of increase in performance. Uh, VLM has actually done a big report on this and they've seen about 1.5 X increase in token generation if you set it up correctly with the right model and with the right drafter and the right settings. Um, so yeah, this, this does excel. It's just a matter of getting it right and tuning it correctly and making sure you have the right, uh, things in place for it.
Um, but yeah, like it, from my personal experience, um, for my home lab, I used, uh, Quinn 3.6, 35 billion MOE model. And along with that, I use a D-Flash, um, um, um, drafter model. And I get roughly around 2 to 3 X token generation, uh, performance improvement, uh, depending on the use case. So, it, it does work. It's just a matter of getting the right models to work together. How do you choose the model size for the, uh, is there some kind of like speed spot? For the drafter? Uh, you want to, you basically want to figure out, uh, the smallest model that you can run. That doesn't take as much GPU power because you, the main model is the model that has all the knowledge.
That's the model that you really care about that has everything that you need. But you don't want draft model to take a lot of those resources away from the main model. So you want it to be small, but not so small that it's dumb, but big enough where like, it's going to actually give you.
3B is too big. Uh, the reason why is a lot of MOE models, like I was talking about, Quinn 3.6, uh, 35 billion. So it has, it's a mixture of experts model and each experts is about 3 billion parameters. So the experts can be around that, uh, and you would get good performance out of it. But for the drafter model, you probably want to be less than 1 billion parameter just to make sure that it also depends on the main model you're using, I guess, right? Like if you're using, if your main model is like 400 billion parameters, you could probably get away with using a bigger drafter model to make sure that you get higher acceptance rate.
So it's, you got to find the right balance essentially. Yeah.
Cool. Um, do we have any other questions over there? One more. Before you jump in. Yeah. I just had a question. How is the draft model trained? Like, is it distillation or something else? It's essentially distillation. Uh, so you take the big model and, you know, you distill all of its capabilities. You create a dataset and then you train the, uh, drafter model using that. And a lot of times actually what's, there's different techniques to do this. Uh, the other techniques you'll see is the drafter model is trained alongside the main model. Uh, so that way, that's another way of doing it.
And a lot of labs will actually give you a drafter model, uh, inside the same package. So you don't have to essentially download a second model and run it. Uh, so there's a couple of different ways of doing it. Uh, but probably the best way is train alongside it. And then that way you don't have a lot of issues and acceptance rate sort of stays high. Cool. Um, we'll jump into module seven. So here I want to talk about some of the different flags that you, uh, should care about when deploying using VLLM and what, and how you want to get the saturation to be as high as possible. Saturation meaning we want to get the GPU to work as hard as possible, as long as possible.
Uh, and because you want to get your money's worth. If you're renting a GPU or if you're buying a GPU, you want to run it, uh, as much as possible.
So, uh, we will stop here. So, uh, one of the concepts I want to talk about, uh, if you remember previously, we were looking at the 34, uh, 32 concurrency and 64 concurrency. We saw a steep increase in the latency. And the reason for that is essentially you, the throughput at some point is going to flatten out. And, but the, uh, but the latency can keep increasing if you keep increasing the, uh, concurrency. So you essentially want to find the sweet spot. And, uh, that is something that VLLM sort of lets you kind of tweak and make sure that you find that sweet spot. And once you do find it, you can set the right settings for it.
Um, but, but essentially you want to find the inner, not, sorry, not the intersection, but essentially right before where the throughput gets to like the flat state, but the latency is like still acceptable enough. It's sort of like the point you want to get to.
Um, we will do a setup. And then let's make sure our settings are all good still. Serving model is up. Um, let me just double check if it's up.
Should be. Yeah.
And then here we're again going to get, uh, another, we're going to do another load test. So that way we know the data and then we can, based on that, figure out where that, uh, where this point is essentially. The, we call it the knee, um, where things are flattening, but also the concurrent, uh, based on concurrency, uh, the time to first token is acceptable. Um, once that is, oh, I think, uh, should be fine. Um, so, you know, the throughput is slowly increasing as concurrency is increasing. That's acceptable. Um, and then you also see the latency go up. That is also acceptable, but it's not going up drastically.
Uh, but we should shortly see the big jumps, uh, with more, um, concurrency here. But while this is running, any, any other questions for anyone? Go ahead. Oh, over there. So my question was again on the previous speculative decoding. Uh, just wanted to know, based on your experience, um, with like drafter model, uh, what kind of use cases you have seen it to work really bad? Like for example, with agent loops, with tool call or with coding, like what kind of like use? Uh, agent loops. It's really good at tool calling. It's really good at, um, browser use is the one particular use case that I use it for. I want to automate a lot of browser tasks.
Um, cause there's still, you know, you don't necessarily get APIs for everything. And so you want to bridge that gap. Uh, and, uh, yeah, the drafter model helps you generate more tokens faster. So you see your browser agent just essentially run around and do things faster. Uh, so in a lot of ways it does help. Uh, I will say for browser use, I probably see around 1.5x increase. Whereas for coding, I see like closer to 3x. So depending on your use case, you may see more or less and things like that. Uh, and a follow up on that one. Are there any benchmarks like more trust me bro mentions? Like coding fireshift? There's definitely brand benchmarks out there.
I, I'm, I'm personally a little skeptical of benchmarks. Whenever I see them, I never get the same results. I don't know if people agree with that here. Um, so, um, yeah, for the, for the most part, like, you know, you want to do your own testing and see what works for you. Cause it very much depends on your use case. Cause the acceptance rate is going to be different depending on your use case, what you're using it for. Thank you.
Um, yeah. Yeah. Any other questions? Mic check, mic check. How's it going? Um, do like big models like codex or cloud, like, do they use this type of the coding? Like have they published that they use this pattern source? Or is this more like for open source if you're training your own stuff or the running inference? I don't know the question to if they do it or not. Um, I would imagine they do. Sort of like free performance, but, uh, for the, for the open source. Yeah. This is particularly for the open source. All the open source, big models that you want to use all the Quen models, the GLM models,
they all have speculative decoding, uh, drafter models available that you want to use. Is there like a main drafting model that they use for example, for like deep seek or GLM? Deep seek actually came out with a new, uh, thing yesterday, I believe, or the day before. It's called the spark. It's like their own technique for doing speculative decoding in a more dynamic way. Essentially they're figuring out how, so here are configuration static, right? Like we say we're going to generate four tokens at a time. Uh, but with deep seek's way of doing it, they are making a dynamic meaning, you know, it on, on the fly sort of decides, oh, I'm going to generate only two tokens.
Oh, I'm going to generate four tokens or five tokens, depending on the acceptance criteria, depending on the GPU load and all sorts of metrics. So yeah, every, every model, uh, every lab has like their own way of doing it as well. And you probably want to stick to that, but you can also experiment. For example, the Quinn models, uh, Quinn lab doesn't release the D flash models for drafting, but these are released by a third party lab, but they work quite well with them. So you sort of have to test it out and see. Thank you. Yeah. I think this is hanging, right? Yeah. I would check the pot. Yeah. Might've killed the cluster here. Uh oh, I can't type. Uh oh.
This was working well. Refresh.
Let me create the tab again. Okay. Um, well, something is wrong. Copy the URL and open it in the tab, see what happens. Let me open a new tab. I wouldn't close that one. I'm sure.
You know, in all the testing that has not happened, but it happened today.
Can I at least go through and go through different things? Okay. At least I can scroll through.
You know, since the cluster decided to take a vacation, I'll sort of go through the content that I was going to cover. The main point of running this benchmark here was to kind of show where that knee is, meaning where you see the max throughput. If we go back to this diagram where you see the max throughput while making sure you are seeing the lowest latency for token generation. And that essentially limit was at 32 concurrency. Because anything above 32 concurrency, you'll see the token generation is going to be kind of the same. It's not going to change much. The throughput is going to be the same, but the latency is going to go drastically up and you don't want that.
So that's sort of like the limit you are hitting. And that is important information that we need to keep in mind and look at when we are deploying these things. And if... Yeah. You can go to 100. Go to look at the spreadsheet. 100? Yeah. Go to 100. And then just continue from... Yeah. ...7 to 8. Where is it?
There you go. All right. Well, this one is working. That's good.
All right. Cool. So we'll jump into 8. Let me also...
Open up. Who's doing it?
Okay. So for module 8, we're going to talk quickly through what sort of flags and knobs you can tweak to make sure that you can sort of get above that limiting point that we were talking about at 32 concurrency, you're sort of seeing that limit and how do we kind of get beyond that and what things you need to keep in mind when thinking about this. So for this one, I'm sort of going to give you guys a thinking model is essentially you want to measure and that's why with a lot of different cells, I keep running load tests and it's super important to run those load tests to see what your performance is like and any changes you're making, how is that changing the performance?
Is it making better? Is it making it worse? Is it making worse? Is it making worse? Is it if the throughput keeps going up or stays the same but the latency is changing, something is either correct or wrong there. So that's something we have to keep in mind. And there's a bunch of different knobs you can sort of like tweak in VLLM to make it better. But the main four ones are again the GPU memory utilization. You want to make sure that you're setting that correctly depending on your use case. Again, if you are running multiple models on the same GPU, you might want to keep it low and that's a trade off you're making.
But if you're only running a single model and you want to make sure that it's getting the best performance possible, you want to bump that up to 0.9 or even 0.95. The other thing is you want to make sure that the max num sequences is set to a good limit as well. This is something you have to figure out by testing. In our particular deployment, if you look at the VLLM.yaml, we start with 32 sequences. So what that is doing is telling VLLM that it can only process 32 requests at a time and not more than that. And if you do more than that, you're going to see some performance degradation there.
So there's a lot of different flags, but those are the key ones that you want to keep in mind. You want to make sure that you're setting the model length to the correct length as well. And then you want to make sure the batch tokens are also set to the correct length. You don't want to keep it bigger if you want to do pre-fill faster if your GPU can handle it. You want to do it smaller if your GPU is on a little slower side and you can't handle it. But yeah, the idea is you want to change one flag at a time. You don't want to change multiple things. And when you change things, run the benchmarks and see what performance you're seeing.
See, measure it and then make assumptions on what you should do next. Kind of go through it quickly here. We have about 10 minutes left.
Uh-oh.
I think we lost the PVC. I think that's what happened. Oh, it got the different one. Yeah, I need to actually change this. Re-run this, I think.
Let me actually just change this in here. This was supposed to be like sequential, but other Jupyter notebook died. So, change that. And then that should work. There you go. Again, like I talked about, there's different knobs that you want to tweak and see what happens. But we'll get sort of the measure, we'll measure the baseline and then we'll change a couple of flags and see what happens next.
Does it work? Okay, cool. There you go. It's working. While this load test is running, any other questions anyone has? Excuse me.
I noticed that there's a definite fall off when we're optimizing the model like here, the 32 to 64, huge fall off. Is that when you would decide that maybe we should scale the hardware? Or is that something that you're confident you can still tune it further? Essentially, is this the ceiling? Yeah. You figure out the ceiling by doing mathematics. I think in some of the previous modules, Duan covered like what the max ceiling can look like for tokens per second, what the throughput looks like, and you know, what sort of expectations you should have for the deployment. And if you are like seeing those max expectations, that's probably the maximum limit of your hardware.
And then you probably have to get additional hardware or better hardware to do so. So yeah, there is sort of a limit. You know, there's only so much you can tune, but you're trying to squeeze as much out of the GPU as possible. I'm going to share the slides before you continue. I'm going to share the slides real quick.
The server? I can leave it up for a little bit, a couple of hours. I'm not going to leave it up just because you do have access to GPUs. But what I am going to give you, if you scan this QR code, you'll get access to the PowerPoint, as well as the repo if you want to spin this up in your own Akamai Cloud account, or if you want to run it on your laptop, you can do that. So if you scan this QR code, it'll take you to a site that has all the resources. And if you don't have an Akamai Cloud account, you can sign up and you get $300 in credits with a free account. So that's everything you need. And if you all have questions, both of our contacts information is here.
Omer, I'm Dewan Lightfoot. Yeah. And yeah. With that being said, if you all scan the QR code, I'll let Omer finish it up. I just want to make sure you all get this before people started to leave. Thank you. We'll leave it up there for a couple more minutes once everyone gets it.
Yeah, go ahead. So, kind of like being able to work for AI tools, with the users, personal assistant. Personal assistant? Okay. So, So, you can use Lama, it depends on your hardware. I think that's like the first thing I would look at. Thank you. Oh, you have both? For the sake of the argument, let's just say you have the best GPU. Let's just say you have, Yeah. Yeah. You have the latest black world GPU. You know, I think for testing and doing, like, figuring out what model you want to use for your use case, I think it's good to use Olama and Lama CPP to quickly spin it up and try it out and see what happens.
But once you have a model that you know I'm going to use for sure for this use case, and this is working great, you probably want to switch to VLM, SGLang, or one of these other model runtimes. Reason being, they allow you to run at higher concurrences and give you more performance out of it. So, if you have a single agent running, I think it's fine to use Olama. It's not a big deal because you only have one request going in at a time. But if you, let's just say you're running like 20 agents and you want to run it parallel.
Yeah. Yeah. You can set up speculative decoding with VLM. I don't think Olama supports speculative decoding as far as I know, but I could be wrong. But yeah, when you want to get the max performance out of your hardware, you definitely want to do that.
Yeah.
I actually don't know if there's a diffusion LLM. Is there an open source diffusion model right now available?
Yeah. Lana. Yeah. Yeah, I mean, I think VLM supports it. So, I think you would be able to run it on VLM. Olama, if Olama supports it, you can as well. Yeah. That's definitely possible. Okay. We'll switch back to the module and kind of go through it. Again, like I was saying, at 32, you're seeing, you know, good performance. But at 64, we're going at, you know, the throughput is sort of staying the same if not going up. But we're seeing a significant increase in latency. And to kind of get around it, one of the things I want to talk about is the maximum sequence. Again, this is sort of how many requests VLM is able to process at one time. It's sort of setting that flag.
If you want to have a lot of requests being processed in parallel, then you want to sort of increase this amount. So, currently, I believe it's set up at 32. So, we can bump this up to 128. And then we can run this, deploy it, and see how that changes the performance.
Okay. It changed a lot of things here.
Yeah. Once this comes up, we can do another test. And you'll see the limitation that we're seeing here at 32 is going to go away. And you'll actually see the latency be manageable again at higher concurrency levels as well. So, this is sort of like the loop you want to go in. You want to find the right flags for wherever the bottleneck is. Find the bottleneck. Figure out why that is happening. What flag you can tweak to make sure that you're kind of overcoming that bottleneck.
That's going to take a little bit of time. Any questions? One more over there.
Is there such a thing as bursting to serverless? Is that the domain of, you know, model routing, layer on top. like what is the pattern for? Yeah I mean auto scaling is one of the patterns like specifically I'll tell you in LKE you can have dynamic like auto scaling so it can scale up depending on your needs depending on bursty traffic it can scale up to you know maybe use a node that has four GPUs instead of one because maybe that handles it better right so you can automate a lot of those things to make sure that you're doing well and the other part of it is like you can also build like some statistical models to make sure that you kind of understand
your traffic patterns over a long horizon and then the the cluster can also dynamically like sort of predict your burstiness in some ways and then can also scale based on that too. If you got your browser I can show you where it's at. Browser? Yeah. If you open your browser. Okay so this one is successfully rolled out and then we'll do a quick load test and once that is run we can see more.
All right. Any other questions? Most folks are gone but yeah. Lightfoot. H.
32. That's where we saw the limit last time. Once we get to 64 we should see that it should improve. Okay so there was a big drastic improvement. The throughput actually went up quite a bit so it's at 1100 tokens per second whereas previously if we look at it over here at 64 we were at 800 tokens per second and then the latency was 2000 milliseconds. But now after the change that we made it is 1100 tokens per second and then the latency is 800 milliseconds. So it's gone down the latency has gone down quite drastically and then we have also increased the throughput quite drastically.
So these are the sort of the tuning you can do over time to make sure that things are running well. Once you have it up and running and you can do this for your particular use case. Maybe you're not going to have 64 concurrent requests coming in for a particular use case but maybe you are. So you have to decide based on your use cases. Your concurrency one higher than four? Like was that a trade off you just did? Concurrency one? I mean it can be a little higher or lower. It's not going to be the same all the time but for example before it was 37 but now it's 35. So it's a little bit of deviation that happens with running models.
But it should be plus minus two tokens there. We're also running the full precision model now. We're no longer running the FPA because we have to switch the notebook. So that's the other reason why you're seeing it go from like 50 something tokens to 30 something tokens. So that's the performance hit we're seeing there.
But yeah that is all I have. That is one flag you can tweak. There's also all sorts of other flags that I implore everyone to take a look at. The workshop kind of goes through it as well. But I think we're on time and I'll give it back to Duan. Yeah thank you all for attending our session today. If you have not scanned the QR code the code the repo the powerpoints are available on this site. Feel free to start a free Akamai cloud account. My name is Duan Lightfoot and I'm joined by my colleague Omer and we thank you all for joining us today. Feel free to ask us questions after this session. Thank you. Thank you.