Operating Distributed Inference Systems at Scale — Nishant Gupta & Naman Ahuja, Meta
AI Engineer · 19 min · 203 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:12Good morning everyone.
- 00:14Welcome to the first infants talk on the last day of AI engineer world fair.
- 00:18My name is Nishan Gupta and I'm joined today by my co-speaker Naman Auja.
- 00:23We work on building the efficiency training and inference infrastructure at Meta.
- 00:27Today we're going to be talking about how do you operate distributed infence systems at scale.
- 00:32As we all know, inference is no longer just a research artifact boiled to a product.
- 00:38It's a foundational hypers scale infrastructure workload which is growing at a tremendous rate.
- 00:43The infence traffic already outpaces the largest microservices in the world and the rate of growth is fastest of any workload we have ever seen.
- 00:54Let's rewind back to around 2008 and try to compare the AI era with the cloud era.
- 01:01In around 2008, the cloud started as virtual machine offerings.
- 01:05The interesting injuring was virtualization.
- 01:07Then over time, the value moved up to the stack to the scheduulers.
- 01:11Think bog, kubernetes, msos, then to service meshes, then to autoscalers, and then to various platforms that were built on top of it.
- 01:19The orchestation layer is what actually captured the value and the complexity.
- 01:24AI is on the exact same trajectory but just compressed into a last few years instead of a decade.
- 01:30We started with simple models running on GPUs.
- 01:33Then we saw the evolution of model serving frameworks like VLM to serve Triton and now we are watching the orchestration layer emerging in real time addressing the complex challenges of routing
- 01:45KV cache management prefield decode disagregation and multimodel multiplexing.
- 01:51In this next phase of AI era, it's not just about the best models or the kernels or the optimizations.
- 01:57It's about the whole ecosystem.
- 01:58It's about the control plane and the orchestration.
- 02:00And this is what we're going to be focusing in this today's talk.
- 02:06So let's talk a little bit about agentic demand explosion.
- 02:09In the classical web serving before the AI inference workloads kicked off the capacity scaled roughly linearly with users depending upon the workload type double the users mostly double the QPS
- 02:21double the infrastructure fleet if there are no optimizations and capacity planning was mostly a spreadsheet exercise.
- 02:28In this new agentic serving capacity is scaling with number of users time number of calls per users times number of tokens which varies depending on the model the optimizations
- 02:38the hardware SKU you have a chatbot can have one model call per turn which is evolving now with 10 to 20 for co-pilots and 50 for research agents and now it's
- 02:51thousands of such calls for autonomous workflows with no human in the loop.
- 02:54The key to take away that you cannot plan capacity for the agents the same way we did for microservices.
- 03:00We need to think about elasticity and implement workload aware scheduling and admission control.
- 03:09Now let's try to dive a little bit deep into the differences pros and cons differences between the traditional microser in serving versus the modern infence serving across these key dimensions.
- 03:19The request shape microservices assumes short uniform request wherever the LLM requests we are seeing in our workloads they can vary from 50 tokens to 100,000 tokens with vastly different compute profiles between prefill and decode stage
- 03:33for batching classical stacks for microservices was doing stacking batching mostly at the load balance layer if at all however LLM serving requires continuous inflight batching how otherwise the throughput collapses by an order of magnitude or
- 03:48state most of the classical microservices were stateless when we not talking about storage layer however LLM serving does require a huge per request state the KV cache which require which is very expensive to build and even more expensive to throw away
- 04:03scaling units when we think about traditional microservices we could run them in cheap CPUs in pods however for model inferencing we require to run on GPUs which are 100 times more expensive which are 10 times slower to acquire and we cannot overprovision them casually otherwise it will lead to a huge wastage.
- 04:23failure mode.
- 04:25When you think about traditional microservices like most of us have built over the last couple of years, we could even if a micro even if a host crashed or a bot crash, we could restart it.
- 04:34We could rebuild the state if needed be.
- 04:36However, for the model inferencing, it takes a huge amount of time to go from cold to hot startup and these if and if a GPU is mid decode, it can drop thousands of in-flight
- 04:47tokens and it can lead to a queue buildup.
- 04:50The takeaway is that the bottleneck is not just the model, it's the orchestration itself.
- 04:58Now, as we can see in these hidden decisions behind a prompt, when we go to any gentic application, it requires a bunch of steps which are behind the scenes.
- 05:06We have to authenticate.
- 05:07We have to choose a model depending on the request type.
- 05:09We have to select a region where it goes, we have to do admission control.
- 05:12We have to do caching lookup.
- 05:14We have to do the we have to run it on the GPU.
- 05:17We have to do batching.
- 05:18And there's a bunch of other steps involved.
- 05:19And as we can see out of all these steps only one step requires the model which is the pre-filled decode.
- 05:26If it's disagreed inference or just if it's not disagreed inference other steps require infrastructure.
- 05:31The intelligence might lie in the model but the economics the reliability and the user experience are all in the infrastructure.
- 05:38And this is why a lot of platform teams across a lot of companies are having much more impact on the product quality and the success ra much more than before.
- 05:50Now most of us in this room have a deep expertise across one or two or three layers.
- 05:54We might own kernels or kernel optimizations.
- 05:57We might own routing or the product itself or we might be operating the GPU infrastructure or the cluster itself.
- 06:03But very few of us have operated the whole stack or seen thought about it end to end.
- 06:08As you can see in these layers, these layers are not new.
- 06:11They have been around for 20 years or more.
- 06:14What is new is the combination and the coupling between them.
- 06:18A decision at the routing layer can change the cache hit rate at the model layer which can change the batch composition which can change the GP utilization which can change the autoscaling
- 06:29decision because of the change in GPUs simplization.
- 06:32So everything is entangled when we have any regressions in our inference workloads.
- 06:37It's not just about understanding what happened at the caching layer admission control.
- 06:41We need to think about the stack top to bottom.
- 06:43And when we see any bottleneck, it's very very important to understand at which layer is that bottleneck so that we can invest properly.
- 06:54Now diving a little bit deep into a how a prompt works when we have a prompt for any application be it just if you want to generate an image or if you have a research task or if you have complex multi-agent orchestration
- 07:05more or less it involves a bunch of these steps.
- 07:08The prompt goes to the gateway.
- 07:10Then it goes to the router after which it does the cache lookup if the request was already seen before.
- 07:17Then it goes to the scheduulers which decides on which GPU cluster it should run on which hardware it can be on Nvidia or AMD or your in-house silicon chip which then goes to the appropriate serving runtime VLM SD lang or whatever we have we are working on and then we stream the response back to the user
- 07:33according to the SLO profiles of time to first token and time between each token and while making sure the throughput is what the users desired.
- 07:41Now as we can see this inference behaves like a distributed transaction.
- 07:45Each arrow in this diagram is a network hop.
- 07:47Every of every one of these hops can retry.
- 07:50It can time out.
- 07:52It can fall back.
- 07:53It can even fail.
- 07:54And each of these hop will have an SLOs's and it will it it is streaming back to the user.
- 08:00So if it fails, the partial fail is mantics are much more harder to deal with than if for a regular RPC call.
- 08:06Think about what happens if we have already streamed 200 tokens back to the user and suddenly a GPU host is preempted due to a scheduled or a planned or unplanned maintenance event.
- 08:16We cannot just retry.
- 08:17We have to think about it holistically.
- 08:19This is where this is why reliability we cannot build reliability at the edge.
- 08:23It has to be a property of the control plane because the control plane is the one which sees the whole workflow.
- 08:31Now let's talk about scheduulers and some of the optimizations uh and how we can think about it.
- 08:37So for the traditional microservices we used to think about bin packing of traditional microservices across three four dimensions could be across resource utilization CPU memory or could be across all domains depending upon if you're using AWS if you're using your own in-house
- 08:51cloud providers but for inference the schedule needs to be aware AC of across at least seven access when we schedule a particular request it has to be aware of the GPU type there can be any number of heterogeneous
- 09:03hardwarees in your cluster H00 versus E00 versus B200 with different network topologies.
- 09:09It has to be aware of the HPM headroom, KV cache state, the model weights, whether they are already loaded, whether they're cold or we have to whether they have already warmed up, we have to cold start it.
- 09:20It has to be aware of the tenant priority.
- 09:22There can be any number of tenants running on that multi-tenant cluster with different SLO profiles.
- 09:27We have to also be aware of the workflow context.
- 09:30Are we in the third step of reasoning that has already spent X dollar or are we at the initial stages and we can terminate the workflow if it if we are overprovision.
- 09:39We have to also think about latency budget depending upon the type of agentic application we are building.
- 09:44So this brings us to the idea that we have to make sure that we implement agentic aware scheduling.
- 09:49We have to make sure that we place the work which will which will finish the in the fastest and the cheapest time as opposed to just placing it on a random GPU.
- 09:59A concrete example might be that the skiller needs to be aware that request R is at step three of a five in a workflow and it has already and step one and two has already spent X plus Y dollar.
- 10:09So if a step three fails the whole workflow will be terminated and we have wasted all that compute resources.
- 10:14That's why workflow aware orchestration is very very important because it it will change the admission decisions the priority and how we retry.
- 10:25Now let's talk about optimizations.
- 10:27I will not go too deep into a lot of optimizations.
- 10:29There's a lot of research which has already been done outside.
- 10:32But I would like to share a framework which at least I like to use when it comes to it.
- 10:37And uh we can place it into four quadrants.
- 10:40First, can we avoid the work?
- 10:42Meaning can we skip it entirely through caching through techniques like prefix caching, response caching, semantic caching.
- 10:48The second can we share the work?
- 10:51Can multiple requests share compute through batching?
- 10:54Think continuous patching, prefill decode, chunk prefill, specular decoding.
- 10:59Third, can we move away the work?
- 11:01Can we send it somewhere to a cheaper model or closer to the user through mostly routing?
- 11:07Can we route it to a smaller model or a cheaper region or some other techniques?
- 11:12And lastly, can we delay the work?
- 11:14Can we wait for a better moment through admission control and queueing which requires us to understand the priority classes of these requests and implement deadline aware scheduling.
- 11:25Now this framework is very powerful because it transfers to various stacks.
- 11:29You might be using VLM or SDG lang or tensor RT but every technique fits into one of these quadrants.
- 11:35So whenever we think about any optimization to our model we have to apply we have to do a comparison and contrast with the previous techniques and see how all these stack with each other.
- 11:47Now whenever we think about scale it's not just important to think about the performance of the model.
- 11:51We have to think about the cost economics as well.
- 11:54This is where it's important to understand what metric we're trying to optimize because the cost is not just the cost of the GPU or the model.
- 12:02It is the cost of all these parameters retries, storage, failures, network and of course the operational cost of development and all that stuff.
- 12:10What is important is to understand what is the key key performance indicator for your product which will add value to the users.
- 12:17So it's not important to optimize just cost per token or cost per request.
- 12:22We have to optimize cost per successful task because this is what actually users care about.
- 12:26And if you're able to optimize that, the cost for the overall product decreases and the users are much more happier.
- 12:36Now let's talk about reliability a little bit about reliability and uh what it means to prevent cascading failures.
- 12:43Now the failure story is never a GPU is preempted or GPU has died.
- 12:46The interesting stories is the feedback loop that follows.
- 12:49So a GPU can degrade, the latency can rise, the client retries, the Q depth increases, the healthy GPUs will saturate which will follow more retries, much more more full regional failures.
- 13:03This is the classic cascading failures.
- 13:05But for with a twist for agentic application, the KV cache, we cannot just casually restart or reroute to a different cluster.
- 13:13A cold pool has to warm up before it can absorb traffic during which the hot pool has to take on all that all those requests.
- 13:20This is why it's important to design the loop breakers very deliberately the circuit breakers at the routing layer the admission control which rejects rather than just queuing the load shedding tied to QEP not just CPU or memory utilization
- 13:34and we have to also think about retry budgets because if you don't think about all these things the cost can scale much much more quickly.
- 13:43Now we'll hand it over to my co-speaker Naman to talk about the remaining talk.
- 14:56Okay, this works I guess.
- 14:57Sorry for so once inference reach a production scale it starts looking much more like a distributed system.
- 15:04We are not longer just calling a model.
- 15:06It's more like a classic distributed uh system problem.
- 15:09So in distributed system we talk about cues, scheduuling, autoscaling, fault isolation.
- 15:15These are some of the dimensions.
- 15:16Inference has all these problems.
- 15:19But there are new constraints.
- 15:20Now instead of CPU, memory alone, we have CPU, HVM, KV cache and course per successful task.
- 15:27So the operating question becomes how the platform know what to do next.
- 15:31And that's where observability comes into play.
- 15:34It's not just about dashboards.
- 15:35It's about uh how to provide input signal to the control loop telemetry fields analysis analysis drive decisions is change of shoulduling and routing and finally we just rinse and repeat
- 15:48um I'll just give an overview what are some important metrics first one is time to first token which tells me about uh how much time does it really take to get the first response
- 15:58then we have utilization ratio which tell me whether memory or compute is the bottleneck we have success per dollar that tests us whether platform is actually delivering and working efficiently.
- 16:10And finally, we have end to end race latency that tells us what's the time being spent across the full request path.
- 16:19There's a core trader between latency, cost, and throughput.
- 16:22You cannot just get all of them.
- 16:24It's pretty analogous to cap theorem.
- 16:26If I increase the batch size, um I improve the throughput and cost efficiency, but I may hurt tail latency.
- 16:33If I use speculative decoding, I may improve latency, but there are some extra compute.
- 16:38Ultimately, you know, we increase the cost per token.
- 16:42And finally, I can use a simple model, smaller model.
- 16:44I can reduce the latency and cost, but the response will be of low quality.
- 16:48Ultimately, I'll do failure analysis, do retries, which brings the cost back up.
- 16:52So, every serving decision moves system somewhere in this triangle.
- 16:56And our job is to find the perfect setting.
- 16:58It's just an optimization problem.
- 17:00Now this is where the industry is heading right now.
- 17:05Inference needs its own control plane.
- 17:07Everything we discussed routing, batching, caching, scheduuling, reliability, they cannot be a separate knob.
- 17:14Now they're converging into a logical layer.
- 17:17Let's call it inference control plane.
- 17:19We used to manage VMs before in distributed system.
- 17:21We have autoscaling scheduulers and we had Kubernetes which turned these into control plane.
- 17:27Inference is going through the same transition now.
- 17:30uh models are becoming resources.
- 17:32GPU, KV cache, token, latency, cost are now scheduled around.
- 17:36The control plane decides which models serve which request and how it is batched.
- 17:42So whether we build this layer internally, use open source or from a vendor, the key design is to assume layer will exist.
- 17:50Now let's discuss about where are some of the operating lessons we have experienced in a infra and how they are applicable here.
- 17:57The first lesson is that infrastructure bottlenecks usually show up before model bottlenecks in production.
- 18:03Many failures can come but there can be just aboutuling and routing or capacity breakdown.
- 18:08So these are not related to inference.
- 18:10It's about infrastructure problems.
- 18:12Then we have elasticity.
- 18:14We need elasticity in a system.
- 18:15We can have more GPUs but this will not really solve the problem.
- 18:19We are just hiding the problem.
- 18:21Then our solution to schedule the decision overpowered the efficiency.
- 18:26The same fleet can deliver very optimally depending on how you're shoulduling it or how you're batching it.
- 18:32Then we have control loops which beats the manual process.
- 18:35The platform has to sense, detect and automatically adapt to the system.
- 18:40So main takeaway is do not optimize for tokens.
- 18:44Optimize for successful task.
- 18:49So this is a broader shift I want to leave you with.
- 18:51The first phase of a infrastructure was about better model.
- 18:54We invest a lot of time in improving our models, smarting, making the model smarter and coming with better benchmarks.
- 19:00The current phase right now is faster inference, lower latency, better batching and better GP utilization.
- 19:08But the next phase is about orchestration.
- 19:10That means GPU, memory, cache and everything.
- 19:13These are just resources and they need to be scheduled and controlled.
- 19:17The teams that understand this early on will build infrastructure for the future.
- 19:21So the closing idea is infrastructure is no longer a server problem.
- 19:26It's an orchestration problem.
- 19:29Thank you.
- 19:31[applause]