KV Cache-Aware Routing and P/D Disaggregation on Kubernetes — Yuchen Fama & Ashish Kamra, Red Hat
AI Engineer · 21 min · 166 sentences · from YouTube's caption track
Each timecode opens YouTube at the start of that sentence. Line anchors (#s42) are the cue ids in the WebVTT, and every line carries its start and end seconds. All transcripts has every talk, and the whole corpus as one file.
- 00:12All right.
- 00:13Um, welcome everyone to yet another inference talk.
- 00:17I hope you have had a good conference so far.
- 00:20And u, so in this session, I mean I'm sure you people who have been in the room uh must have heard these terms many times by now.
- 00:28So we're going to do a little bit more deep dive into the challenges of LLM deployments for agentic workloads and uh in this session we'll focus specifically on KV cache away routing and
- 00:40uh PD disagregation um and also you know when you when you look at public inference uh benchmark results you are typically looking at very steady state isolated highly sanitized numbers and what those benchmarks actually don't show you
- 00:55u is the chaotic reality of multi-turn interactions, massive context fluctuations which are very typical of agentic workloads.
- 01:04So we'll also try to pull the curtain back on some of those complexities.
- 01:09Um by by way of introduction uh my name is Ashish Kamra.
- 01:13I'm a senior manager of performance engineering at Red Hat.
- 01:17And with me
- 01:18hi I'm Yuch Chen.
- 01:19I'm the product manager at Red Hat Inference working closely with VLM and AMD core maintainers.
- 01:25also a contributor myself.
- 01:28So here is the agenda for the next 20 minutes or so.
- 01:31Um Euchen will start with an analysis of inference behavior in the agentic era and some of the core characteristics and challenges.
- 01:41Uh next we next you will walk us through the KV cache um utilization and management strategies.
- 01:48I will break down the mechanics of pre-fill decode disagregation and walk you through some some results and then Euchen will again bring it all back together with our ongoing case study on our favorite
- 02:01open coding model GLM 5.2. Um and just a couple of uh sources from our side if you are more interested in learning more about open source inference we have a free course
- 02:12free course on deep learning.ai AI uh by Cedric and with Andrew Ning.
- 02:17Um and the other is a series of blogs on the Red Hat developer portal on distributed inference concepts uh troubleshooting and deployment patterns.
- 02:27Uh and for those who may not be aware since Red Hat is better known as the Linux company for enterprise Linux and uh the Kubernetes company for Open Shift
- 02:39uh but more recently we are also a major player in open source AI inference with uh us being the top contributor in VLM LLMD and the case of projects and also
- 02:51uh having incubated guide LLM for benchmarking LLM compressor for model quantization and speculators for uh speculative uh decoding models and we also bring it bring all of that together in a
- 03:06optimized model hub on hugging phase under the Red Hat AI arc.
- 03:12Um and we are also building the platform for the next wave of agentic inference workloads and with that I will hand over to you to uh walk you through more of it.
- 03:25So we are currently um at this inflection point moving from the era of classic inference to the agentic era.
- 03:33So when we look at the real world agentic work workloads such as uh sweet bench and also watrices from real world cloud code sessions they fundamentally break many assumptions we made with classic LM serving.
- 03:47uh as you heard actually many times in previous sessions for example multi-turns and new standard we found from a few turns all the way to 3,000 turns and also because agent frequently reuse the uh system prompt and the total definitions
- 04:01we usually see super high cash hit rate um oftentimes well exceeding 90%.
- 04:07Uh another thing is input output ratio is uh is massive oftentimes over a 100 ratio and even higher and in many cases and on top of that the context management is is incredibly
- 04:20complex due to this high variance because we can't just simply take the average and oftentimes we need to look at the distributions and the P90 numbers especially when you do uh capacity planning
- 04:32and also we observe really interesting patterns like sub Asian panel which is which further complex uh complicates scheduling.
- 04:41So to help communities study um this patterns we collaborate with Google thank you and also IBM our parent company to add uh a a trace replay tool in the inference perf you heard from earlier sessions
- 04:53u from Ashoken and Jason.
- 04:55Um so yeah feel free to check it out and the link is here.
- 05:01Uh next slide.
- 05:03Oh, so transition from the class uh the characteristics um we just saw for agentic workloads.
- 05:08We're no longer chasing this um this this raw throughput in a steady state.
- 05:13We often need to optimize uh for example interactive latency and they're very um highly volatile and client-driven context because user and you know client define the prompt structure.
- 05:25So this introduced several critical challenges.
- 05:28First of all, KV cache management becomes super volatile because the context is client determined as I said.
- 05:34So oftentimes we face this like you know frequent evictions and rewrites and secondly we also need to tune um the engine like VM with upper layer uh scheduling and routing.
- 05:47It needs that coordination such as prefix routing especially when latency becomes a primary uh scheduling matrix rather than like a secondary or afterthought.
- 05:57And thirdly, we also need to rethink our metrics.
- 06:00For example, we need to measure cats throughput separately.
- 06:03Why?
- 06:03Because on the right, it's really clear that economic stakes is very high.
- 06:08So, this is the uh anthropic API pricing.
- 06:10You also heard from earlier sessions.
- 06:12There's 10x cost difference between cash and non-cash tokens.
- 06:16So, 10x difference on your um token balance sheet is is pretty serious impact on your business.
- 06:23So next let's let's look at how the KV cache is um both utilized and managed in LMD.
- 06:29So LMD router has this really flexible um endpoint picker plugins we call the EP that can route the request to the optimal pods and that meet the KV cache locality
- 06:40and also the load criteria.
- 06:42So the EP continue probe each pods like VM pod matrix to score each pod on like the running for example running and waiting request and then the KV cache utilization
- 06:52also prefix uh cache availability and so we can schedule requests to the optimal pod with the lowest load and also highest possibility to um to of a cache hit.
- 07:03So um going down from to the KV cache management layer actually you also heard from earlier session right before this.
- 07:10So for agentic sessions when you have u hot warm and cold cache our current effort focus on for example um more offloading tiers like NVME SSD and also uh file system XF
- 07:22along with KV ccentric store um like uh moon cake and also implementing smarter and session a wire eviction policies such as priority and also session pinning to uh ensure this uh really important you know the the context persists
- 07:37exactly when and where it's needed.
- 07:41So, I'm gonna play this um video really quick.
- 07:44Uh it's a it's a short demo.
- 07:46Stand here so you can look at it.
- 07:48Okay.
- 07:52So, okay.
- 07:55So, this is a example of a KV cache bar routing.
- 07:57As you see, when we send the very first request and it populate the KV cache, it takes roughly 3 seconds.
- 08:04And when we actually look at where it's you know the KV cache uh is going there's no KV cache hit because it's the very first turn.
- 08:11And then when we have the second turn the request actually reuse a KV cache because as you see the system prompt is the same and this time takes about one seconds.
- 08:20And then when you actually look at the uh pod address exactly the same because we define the KV cache.
- 08:25Now going to the third turn a new request with different system prompt.
- 08:29Now it takes about three uh seconds and as you see you know right now and we don't find any KV cache here because you can tell it's different pod address
- 08:40and then if you just change the user prompt and keep the same system prompt and the next turn you you reuse the KB cache and in this in this time it takes roughly about uh one second.
- 08:50Yeah.
- 08:51So it's a pretty intuitive demo and um I'll turn it to Ashish to talk about the next side but before that what does problem does it solve?
- 08:58So often times the prefix routing KB cache routing helps you solve the TTFD problem and of course you'll improve your lat uh your your throughput but oftentimes for agentic workload is not just a TTFT your throughput is about your inter token latency
- 09:13how do we solve that so preview decode disagregation is a really uh powerful technique but there are times there work at times it doesn't work so I'll turn it to Ashish to give you a preview of um of the PD
- 09:25uh disregation So before we dive into PD, let's just uh look at what LLMD is.
- 09:33So LLMD is a high performance Kubernetes native and actually now works on non-cubernetes environments as well.
- 09:39Distributed LM LLM inference framework hosted under the CNCF umbrella.
- 09:44LLMD provides a unified intelligent control plane designed specifically for agentic era of inference workloads.
- 09:52Well, Euchin already talked about the router and the EP at the top of the slide.
- 09:57Um, the other aspects are workload APIs such as leader worker set and disagregated set that orchestrates complex multi- multi-node model execution and then autoscalers that monitors capacity bounds and real-time traffic mixes
- 10:13to independently scale up and scale down uh your pods depending on the system load.
- 10:19So now look now let's look at uh prefill decode disagregation in detail.
- 10:23Um uh okay so why does PD exist in the first place?
- 10:29So one of the most powerful patterns implemented by LLMD is prefill decode disagregation and you must have heard from some of the previous talks as well.
- 10:37So what happens is in in a nonPD situation in aggregated serving one pod is responsible for optimizing both your time to first token and your inter token latencies.
- 10:49Uh but in PD prefill and decode become independently scalable inference pods.
- 10:54But to understand why we actually need this we have to look at the physics of LLM execution.
- 11:00colloccating uh both prefill and decode tasks on the same GPU creates something called as phase interference.
- 11:07Prefill phase is the phase that creates the KV caches for your initial prompt.
- 11:12It wants high compute.
- 11:14It's highly bursty uh utilizes GPUs at uh high flops and and thrives on large batch parallelism to process the prompts and builds the initial KV cache.
- 11:27The decode phase on the other hand is generating one token at a time and it's more me memory bandwidth hungry.
- 11:33It's highly latency sensitive and requires high heavy cache residency.
- 11:38So in a in a in a traditional aggregated pod if you if there's a sudden influx of a long prefilled palm, it will completely stall the ongoing decode token generation process
- 11:50causing massive problems and jitter in user streaming latency.
- 11:56So, so how does PD actually work in practice in LMD?
- 12:00So, LNMD uses um uh you know like okay, we'll start with step one.
- 12:05A incoming request hits the gateway router which dynamically evaluates cluster states using something known as the endpoint picker you talked about and schedules the request to use PD disagregation
- 12:18selecting the optimal prefill and decode workers.
- 12:21The router then coordinates the transaction directly with the designated pre-fill worker.
- 12:25The pre-fill worker processes the prompt, construct the initial KV cache of the prompt and outputs the standard KV transfer metadata.
- 12:34Um, and the target decode worker actually pulls the computed KV caches um, uh, across the network fab fabric utilizing uh, the KV transfer metadata that the uh, uh, prefill pod had generated.
- 12:49Um okay so with that yes that's kind of how uh PD is implemented in practice in LMD and next I would like to show you some uh experimental results on where PD actually shines.
- 13:02So in this graph you can see that um uh in in in the standard aggregated deployment which is the top red line uh the P99 ITL uh hovers roughly around 900 milliseconds and you can you can see some fluctuations
- 13:19um up and down and but the the bottom blue line is the P99 uh inter token latency on a PD deployment and you can see that it's drastically almost nine times better at 100 millconds and it's also much smoother
- 13:34uh than the aggregated serving and uh this is some of our own internal results at Red Hat.
- 13:44So for a GPOSS 12B model uh 16 H100s uh the aggregated config is four replicas tensor parallelism 4 and the disagregated is two prefilled 2D code all with tensor parallelism 4. It's a highly multi-turn workload with a 10,000 token prefix and 128 tokens
- 14:04for every turn every turn.
- 14:07So, so this is a great chart like you can see at the bottom most line is a standard aggregated config that's uh is doing the default Kubernetes scheduling and uh and it's aggregated.
- 14:17So that's kind of our baseline and then the middle blue line is still aggregated but with the LLMD uh KV cache aware routing and you can almost see the gains just just based on the routing and the red line is actually the PD
- 14:33uh the pre-fill decode config with two pre-fill and two decode workers and you can actually see that like it's very similar to the aggregated config at the lower concurrency regimes
- 14:43and uh even and and very similar at the higher concurrency regimes but it's actually the middle part of the concurrency regime that PD actually shines and and these are some of the the classic parita curves that we see when you actually do PD and uh aggregated side by side.
- 15:02So these results are again from the GPTOSS 12B model 64 H100s aggregated is eight replicas TP8 and this a is uh three prefilled 5D code again TP8 and a pre-filled heavy workload with like 5,000
- 15:17average input sequence length and 500 output sequence length and you can actually see the blue line is the the PD curve and the red line is the aggregated curve and the PD curve kind of dominates
- 15:28um uh the aggregate curve across the entire interactivity spectrum.
- 15:37Okay, but I don't want to leave you guys that PD is the answer to everything and it's a magic bullet.
- 15:42But um it's uh it's essentially a separation phase separation trade-off and not a magic bullet.
- 15:47So we created this uh matrix to help you decide when PD might be uh good for you.
- 15:53So if you're managing long context uh with high ISL OSL ratios and you if you have a large model that you're serving that can that you can apply rich model parallelism techniques
- 16:07um you're facing that middle concurrency regime uh that I I showed you in the previous graphs and and the very important part is that if you want uh strict ITL streaming requirements like you want the you want the token generation to be uh much more smooth
- 16:22um then you want to consider PD but we also saw that it requires transfer of KV caches from your pre-filled workers to your decode workers.
- 16:30So you must pro process an advanced uh high-sp speeded network fabric like uh RDMMA or rocky to support that KV cache transfer.
- 16:38And if you do not have such requirements, short moderate context, any model size, low concurrency regimes or uh if you have strict TTF requirements because you can actually tune them on an aggregate serving
- 16:53um and you the biggest point is like if you don't have the network fabric to support those KV cache transfers.
- 16:58So you might actually just want to stick with aggregated.
- 17:02So here is my key takeaway from all of this.
- 17:04So architecting this complex platform requires balancing a lot of u knobs and a highly multi-dimensional design space all of which is supported in LLMD.
- 17:14As you saw the scheduler must support or constantly evaluate SLO targets uh QEPs KV cache locality metrics PD ratios and network topologies to be able to route the request to the optimal
- 17:27FOD.
- 17:28While in while the PD design space you you need dynamic PD rate matching to adapt to PD ratios because you know you can start with a static PD ratio but it needs to evolve with the autoscaler
- 17:40as the traffic changes um and you need uh yeah autoscaling to scale PD pools independently um and constantly tweaking model parallelism techniques like tensor parallelism data parallelism uh to meet your SLOs's.
- 17:56So um I think with these uh I will hand it over to Euchen to anchor some of the concepts that we showed with the real world case study of serving the GLM 5.2 model
- 18:08uh which is uh still ongoing as we speak.
- 18:11Yeah, still ongoing.
- 18:12You probably have seen tons of uh impressive numbers of GLM 5.2 on B200 when we talk to our customers and they usually don't have you know the luxury of B200.
- 18:22They have a lot of H200.
- 18:24So we have to figure out how to like put all the knobs together and make GM 5.2 work really well for cluster of of H200.
- 18:32So uh we let's anchor all the concept together.
- 18:35Um we went through for example the uh KV cache routing PD disagregation.
- 18:40We kind of call them a wildl path in LMD and also we combine with different parallelism strategies to so we can uh independently uh scale prefuel paths because for agentic workload is super uh long you know like heavy prefill.
- 18:54So uh in this case we designed the prefuel pool using up to three workers optimized for uh high throughput uh with deep and then for decoup we use uh one dedicated worker and um that's optimized for for low latency.
- 19:07So we use Nixo for efficient KV transfer between the pools and also with the each worker we have the leader worker set group uh with TP1 DP8 and also uh EP8
- 19:18uh expert parallelism 8. So the architecture is just highly modular because you can uh actually scale the throughput by simply adding uh preview workers without reconfiguring and um the decoup.
- 19:29So uh this highlights how AMD effectly effectively managed the complexity of combining like PB and DB and EPI scale.
- 19:38And also we found some interesting fun fact actually a couple days ago.
- 19:42Um B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B B Bf6 uh BF16
- 19:44KV cache actually is faster than using like FPA uh KV cache for longer preview.
- 19:50Um this is also like we continue to explore and found like more interesting patterns, but more importantly uh we want to kind of just show the result really quick.
- 19:58So um for this uh data set agentic workload data set the ISO OSL ratio is pretty high 45 to1 ratio preview is uh is really the constraint you can tell um with 2P even 1D
- 20:10we have um 4x passer TDFT and also 60 uh% more requests and this is continuous like work in progress so the next step is we need to also put the upper layer
- 20:22lower TTFT and also adding more more preview replicas so um I know we're running out of time really quick.
- 20:28Uh we um the fundamental shift for agentic workload we're continuing to uh have this um uh agentic north uh northstar uh with session graph orchestration program award scheduling uh state reuse life cycle and also
- 20:43the uh agentic benchmark um we're working on.
- 20:46So you can find them uh in AMD upstream AMD and also you know feel free to join the SIG group and uh and contribute and um this is the very last slide.
- 20:57So distri distributed inference is not challenge uh every single comp a single company can solve along.
- 21:03We're proud to be uh building this uh future in the open alongside our incredible ecosystem collaborators uh core wave Google IBM Nvidia growing list of launch partners and industry adopters.
- 21:16So if you're passionate about the future of opensource inference, we invite you to join us.
- 21:20We do have a booth downstairs.
- 21:22Feel free to stop by, ask us any questions.
- 21:24And uh thank you so much for your time.
- 21:27[applause]
- 21:44[music]