{"id":18613,"date":"2026-09-11T08:02:11","date_gmt":"2026-09-11T08:02:11","guid":{"rendered":"https:\/\/techtrendfeed.com\/?p=18613"},"modified":"2026-09-11T08:02:11","modified_gmt":"2026-09-11T08:02:11","slug":"scale-back-llm-latency-with-prefix-aware-routing-on-amazon-sagemaker-inference","status":"publish","type":"post","link":"https:\/\/techtrendfeed.com\/?p=18613","title":{"rendered":"Scale back LLM latency with prefix-aware routing on Amazon SageMaker Inference"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div id=\"\">\n<p>Whenever you construct an software on high of a big language mannequin (LLM), the immediate you ship to the mannequin sometimes has two elements. There\u2019s a hard and fast half that units up context (directions, reference paperwork, dialog historical past) and a variable half that comprises the precise consumer enter. Take a customer support bot for instance. Every request begins with the identical block of textual content: \u201cYou&#8217;re a assist agent for AnyCompany. Listed here are our insurance policies\u2026\u201d adopted by regardless of the buyer typed. The directions on the high may be 3,000 tokens. The shopper\u2019s query on the backside may be 50 tokens.<\/p>\n<p>Which means throughout lots of or hundreds of requests, your mannequin is processing that very same 3,000-token starting over and over.<\/p>\n<p>LLM serving frameworks like vLLM and TensorRT-LLM have an answer for this. They cache the computed key-value (KV) pairs for immediate prefixes which were seen earlier than. When the identical starting exhibits up in a brand new request, the mannequin reuses the cached computation and solely processes the brand new tokens on the finish. That is referred to as prefix caching, and it could scale back time-to-first-token (TTFT) considerably.<\/p>\n<p>However there\u2019s an issue while you scale past a single occasion. When you have a fleet of machines behind an endpoint, requests get distributed throughout all of them. That very same 3,000-token prefix lands on occasion A for one request, occasion B for the subsequent, occasion C after that. Every occasion computes it from scratch as a result of none of them see it often sufficient to construct a dependable cache. The prefix caching characteristic is there, however the routing layer spreads requests too thinly for it to assist.<\/p>\n<p>Right now, Amazon SageMaker Inference introduces prefix-aware routing. It&#8217;s a new routing technique that appears at first of every request and constantly sends requests with the identical starting to the identical occasion. The KV cache on that occasion really builds up and will get reused. In our benchmarks on Llama 3.1 70B, this lowered P50 TTFT by as much as 77 p.c and elevated throughput by as much as 16 p.c. It additionally pushed KV cache hit charges from roughly 25 p.c to over 80 p.c.<\/p>\n<h2 id=\"what-prefix-aware-routing-does\">What prefix-aware routing does<\/h2>\n<p>When a request arrives at your endpoint, Amazon SageMaker seems to be at first of the payload and makes use of it to determine which occasion ought to deal with it. The identical starting goes to the identical occasion. Completely different beginnings unfold throughout totally different cases. If 10 requests share a prefix or starting, all 10 go to the identical machine, and that machine\u2019s cache stays heat for that prefix.<\/p>\n<p>You don\u2019t must tag requests or handle affinity your self. The endpoint handles it primarily based on the content material of the request.<\/p>\n<p>There are two built-in safeguards:<\/p>\n<p>Overload safety. If one prefix is extraordinarily common and the goal occasion is already at capability, the endpoint routes the request to a much less busy occasion as an alternative. You configure the concurrency restrict, and the endpoint respects it. You would possibly miss a cache hit on that one request, however you keep away from overwhelming a single machine.<\/p>\n<p>Secure habits throughout scaling. Whenever you add or take away cases, most requests proceed going to the identical occasion they have been going to earlier than. Solely a small fraction of visitors shifts to account for the modified fleet. Your caches don\u2019t get invalidated each time you scale.<\/p>\n<h2 id=\"performance-benchmarks\">Efficiency benchmarks<\/h2>\n<p>We benchmarked prefix-aware routing in opposition to the default random routing baseline utilizing Llama 3.1 70B Instruct on 7 ml.p5.48xlarge cases with vLLM (prefix caching enabled). We ran 16 check configurations masking single mannequin endpoints, inference element endpoints, the native Invoke API, and the OpenAI-compatible API. All checks accomplished with one hundred pc success price.<\/p>\n<h3 id=\"long-context-workloads\">Lengthy context workloads<\/h3>\n<p>8,000-token shared prefixes, sustained over 1 hour:<\/p>\n<ul>\n<li>P90 TTFT: lowered by 33\u201337 p.c.<\/li>\n<li>P50 TTFT: lowered by 71\u201377 p.c.<\/li>\n<li>KV cache hit price: from roughly 25\u201382 p.c.<\/li>\n<li>Throughput: elevated 15\u201316 p.c.<\/li>\n<\/ul>\n<h3 id=\"short-context-workloads\">Brief context workloads<\/h3>\n<p>Variable-length ShareGPT-style conversations, half-hour:<\/p>\n<ul>\n<li>P90 TTFT: lowered by 24\u201337 p.c.<\/li>\n<li>P50 TTFT: lowered by 13\u201316 p.c.<\/li>\n<li>KV cache hit price: from roughly 30\u201380 p.c.<\/li>\n<li>Throughput: elevated 1.7\u20132.0 p.c.<\/li>\n<\/ul>\n<p>The longer your shared prefix, the larger the win. Lengthy context workloads profit probably the most as a result of there&#8217;s extra computation to skip on every cache hit. Brief context workloads nonetheless profit, however the shared prefixes are smaller so the financial savings per request are proportionally smaller.<\/p>\n<h3 id=\"routing-overhead\">Routing overhead<\/h3>\n<p>The prefix-aware routing logic provides 1.3\u20131.9 milliseconds per request. Mannequin TTFT in these checks ranged 63\u2013280 milliseconds. The routing value is negligible.<\/p>\n<p>Site visitors distribution remained balanced throughout all eventualities. Every of the 7 cases obtained 13.3\u201315.4 p.c of requests, inside 1 p.c of a really perfect even cut up. No scorching spots.<\/p>\n<h2 id=\"routing-strategies-on-sagemaker-inference\">Routing methods on SageMaker Inference<\/h2>\n<p>With this launch, Amazon SageMaker Inference gives three routing methods for real-time endpoints:<\/p>\n<p>RANDOM (default): Distributes requests uniformly throughout cases. Really useful for general-purpose workloads, non-LLM fashions, or a state of affairs the place requests are interchangeable and there\u2019s no profit to sending particular requests to particular cases.<\/p>\n<p>LEAST_OUTSTANDING_REQUESTS: Sends every request to the occasion with the fewest in-flight requests. Really useful when request processing occasions differ and also you wish to preserve all cases equally busy. Helps forestall sluggish requests from piling up on one machine whereas others sit idle.<\/p>\n<p>PREFIX_AWARE (new): Sends requests sharing the identical immediate prefix to the identical occasion. Really useful for LLM workloads the place many requests share frequent textual content at first and your serving framework has prefix caching enabled.<\/p>\n<p>You set the technique per manufacturing variant in your endpoint configuration. You&#8217;ll be able to change between them by updating the endpoint configuration with out redeploying your mannequin.<\/p>\n<h2 id=\"when-to-use-prefix-aware-routing\">When to make use of prefix-aware routing<\/h2>\n<p>The characteristic delivers worth when your requests share textual content at first. Listed here are the patterns the place it has probably the most affect:<\/p>\n<p>Retrieval Augmented Technology (RAG) purposes. You retrieve a doc and prepend it earlier than the consumer\u2019s query. When a number of customers ask questions on the identical doc, all of them share that doc as a prefix. Prefix-aware routing sends them to the identical occasion, the place the KV cache for that doc is already heat.<\/p>\n<p>Multi-turn conversations. Every flip in a dialog consists of the complete historical past of earlier turns. Because the dialog grows, that shared historical past turns into an extended and dearer prefix. Routing on that prefix retains the dialog\u2019s cache on one occasion throughout turns.<\/p>\n<p>Templated bots and assistants. Bots with lengthy, structured directions (insurance policies, formatting guidelines, persona definitions) ship those self same directions with each request. Solely the consumer message on the finish modifications. Prefix-aware routing implies that costly instruction block will get processed as soon as, not hundreds of occasions.<\/p>\n<p>Code completion. Coding assistants embody file contents as context. Whereas a developer works in the identical file, each completion request shares that file content material as a prefix.<\/p>\n<h2 id=\"how-to-enable-it\">The way to allow it<\/h2>\n<p>You configure prefix-aware routing while you create your endpoint configuration. Two parameters management the habits:<\/p>\n<p>PrefixLength (1024\u201365536): How a lot of the request to make use of for routing. For the native Amazon SageMaker Invoke API, that is bytes from the start of the request physique. For the OpenAI-compatible API, that is characters from the extracted message textual content. Set this to cowl your shared prefix plus sufficient distinctive content material to unfold totally different workloads throughout cases.<\/p>\n<p>ConcurrencyThreshold (1\u20131024): The utmost in-flight requests on the goal occasion earlier than overflow kicks in. If the goal occasion is at this restrict, the request goes to a much less loaded occasion as an alternative.<\/p>\n<p>Right here is an instance:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"language-bash\">aws sagemaker create-endpoint-config \n    --endpoint-config-name example-llm-config \n    --production-variants '[{\n        \"VariantName\": \"AllTraffic\",\n        \"ModelName\": \"example-llm-model\",\n        \"InitialInstanceCount\": 3,\n        \"InstanceType\": \"ml.p5.48xlarge\",\n        \"RoutingConfig\": {\n            \"RoutingStrategy\": \"PREFIX_AWARE\",\n            \"PrefixAwareRoutingConfig\": {\n                \"PrefixLength\": 4096,\n                \"ConcurrencyThreshold\": 10\n            }\n        }\n    }]'<\/code><\/pre>\n<\/p><\/div>\n<p>Then create your endpoint as common:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"language-bash\">aws sagemaker create-endpoint \n    --endpoint-name example-llm-endpoint \n    --endpoint-config-name example-llm-config<\/code><\/pre>\n<\/p><\/div>\n<p>No modifications to your mannequin container or serving framework are wanted. Prefix-aware routing operates solely on the endpoint routing layer.<\/p>\n<h2 id=\"invoking-the-endpoint\">Invoking the endpoint<\/h2>\n<p>Nothing modifications about the way you name the endpoint. The identical InvokeEndpoint and InvokeEndpointWithResponseStream APIs work precisely as earlier than:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"language-bash\">aws sagemaker-runtime invoke-endpoint \n    --endpoint-name example-llm-endpoint \n    --content-type software\/json \n    --body fileb:\/\/request.json \n    output.json<\/code><\/pre>\n<\/p><\/div>\n<p>Identical for the OpenAI-compatible Chat Completion API:<\/p>\n<div class=\"hide-language\">\n<pre><code class=\"language-python\">from openai import OpenAI\nfrom sagemaker.core.token_generator import generate_token\n\nconsumer = OpenAI(\n    base_url=f\"https:\/\/runtime.sagemaker.us-west-2.amazonaws.com\"\n             f\"\/endpoints\/example-llm-endpoint\/openai\/v1\",\n    api_key=generate_token(area=\"us-west-2\")\n)\nresponse = consumer.chat.completions.create(\n    mannequin=\"example-model\",\n    messages=[\n        {\"role\": \"user\", \"content\": \"What is your return policy?\"},\n    ],\n)<\/code><\/pre>\n<\/p><\/div>\n<h2 id=\"multi-tenant-prefix-isolation\">Multi-tenant prefix isolation<\/h2>\n<p>If totally different tenants share the identical immediate directions however you need them routed individually (to maintain cache contexts impartial), cross an non-obligatory ID:<\/p>\n<p>Native Invoke API: set the <code>X-Amzn-SageMaker-Prefix-Conscious-Id<\/code> header (as much as 64 ASCII characters).<\/p>\n<p>OpenAI API: embody the <code>prompt_cache_key<\/code> subject within the request physique.<\/p>\n<p>This ID combines with the prefix in order that requests with equivalent prefixes however totally different IDs land on totally different cases.<\/p>\n<h2 id=\"inference-components-and-lora-adapters\">Inference parts and LoRA adapters<\/h2>\n<p>Prefix-aware routing works with inference element endpoints and dynamic Low-Rank Adaptation (LoRA) adapters. For inference parts, it behaves the identical as single mannequin endpoints. For LoRA adapters, it operates inside the adapter\u2019s sticky occasion set, utilizing prefix-based choice among the many cases that have already got the adapter loaded.<\/p>\n<h2 id=\"practical-guidance\">Sensible steering<\/h2>\n<p>Allow prefix caching in your serving framework. Prefix-aware routing will get repeated prefixes to the identical occasion, however your container wants prefix caching turned on to really retailer and reuse these KV pairs. In vLLM, that is enabled by default in latest variations. Different frameworks would possibly require express configuration.<\/p>\n<p>Preserve request serialization constant. For the native Invoke API, PrefixLength operates on uncooked bytes. JSON whitespace, key ordering, and formatting all have an effect on routing. When you serialize the identical immediate otherwise throughout requests, they may find yourself on totally different cases. Use constant serialization.<\/p>\n<p>Measurement PrefixLength fastidiously. Too brief and all requests with the identical brief prefix get funneled to at least one occasion, triggering overflow. Too lengthy and small payload variations (like temperature values) scatter requests that ought to keep collectively. Begin with the size of your shared prefix plus a modest buffer.<\/p>\n<p>You want no less than two cases. With one occasion, all requests go to the identical place no matter technique.<\/p>\n<p>Monitor cache hit charges. Allow SageMaker detailed observability to trace KV cache hit charges on the mannequin degree. This confirms whether or not prefix-aware routing is working in your particular workload.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>Prefix-aware routing is obtainable at present on SageMaker real-time inference endpoints. Replace your AWS SDK or CLI to the newest model to entry the brand new RoutingStrategy and PrefixAwareRoutingConfig parameters. Check with this pocket book for examples of find out how to allow it throughout endpoint creation.<\/p>\n<hr style=\"width: 100%\"\/>\n<h2>In regards to the authors<\/h2>\n<footer>\n<div class=\"blog-author-box\" style=\"padding-top: 2.0em\">\n<div class=\"blog-author-image\" style=\"margin-right: 1.0em\">\n          <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2026\/09\/10\/ML-21885-1.jpg\" alt=\"Kareem Syed-Mohammed\" width=\"100\" height=\"133\"\/>\n         <\/div>\n<h3 class=\"lb-h4\">Kareem Syed-Mohammed<\/h3>\n<p style=\"overflow: hidden\">Kareem is a Principal Product Supervisor at AWS. He focuses on enabling generative AI mannequin improvement and governance on Amazon SageMaker HyperPod. Previous to this, at Amazon Fast Sight, he led embedded analytics and developer expertise. Along with Fast Sight, he has been with AWS Market and Amazon retail as a Product Supervisor. Kareem began his profession as a developer for name middle applied sciences, Native Professional and Adverts for Expedia, and administration marketing consultant at McKinsey.<\/p>\n<\/p><\/div>\n<div class=\"blog-author-box\" style=\"padding-top: 2.0em\">\n<div class=\"blog-author-image\" style=\"margin-right: 1.0em\">\n          <img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2026\/09\/10\/ML-21885-2.jpg\" alt=\"Vivek Gangasani\" width=\"100\" height=\"133\"\/>\n         <\/div>\n<h3 class=\"lb-h4\">Vivek Gangasani<\/h3>\n<p style=\"overflow: hidden\">Vivek is a Worldwide Chief for Options Structure, SageMaker Inference. He leads Answer Structure, Technical Go-to-Market (GTM) and Outbound Product technique for SageMaker Inference. He additionally helps enterprises and startups deploy and optimize generative AI fashions and construct AI workflows with SageMaker and GPUs. At the moment, he&#8217;s targeted on creating methods and content material for optimizing inference efficiency and use instances akin to agentic workflows and RAG. In his free time, Vivek enjoys mountaineering, watching motion pictures, and attempting totally different cuisines.<\/p>\n<\/p><\/div>\n<div class=\"blog-author-box\" style=\"padding-top: 2.0em\">\n<div class=\"blog-author-image\" style=\"margin-right: 1.0em\">\n          <img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2026\/09\/10\/ML-21885-3.jpg\" alt=\"Dmitry Soldatkin\" width=\"100\" height=\"133\"\/>\n         <\/div>\n<h3 class=\"lb-h4\">Dmitry Soldatkin<\/h3>\n<p style=\"overflow: hidden\">Dmitry is a Worldwide Chief for Specialist Options Structure, SageMaker Inference at AWS. He leads efforts to assist clients design, construct, and optimize generative AI and AI\/ML options throughout the enterprise. His work spans a variety of ML use instances, with a major concentrate on generative AI, deep studying, and deploying ML at scale. He has partnered with corporations throughout industries together with monetary providers, insurance coverage, and telecommunications. You&#8217;ll be able to join with Dmitry on <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.linkedin.com\/in\/dmitry-soldatkin\" target=\"_blank\" rel=\"noopener\">LinkedIn<\/a>.<\/p>\n<\/p><\/div>\n<div class=\"blog-author-box\" style=\"padding-top: 2.0em\">\n<div class=\"blog-author-image\" style=\"margin-right: 1.0em\">\n          <img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2026\/09\/10\/ML-21885-4.jpg\" alt=\"Vamsi Goparaju\" width=\"100\" height=\"133\"\/>\n         <\/div>\n<h3 class=\"lb-h4\">Vamsi Goparaju<\/h3>\n<p style=\"overflow: hidden\">Vamsi leads Go-to-Market (GTM) and Income Acceleration initiatives at AWS, enabling Inference and ModelOps workloads for our clients, and driving OSS Use Instances and Product options for Amazon SageMaker AI and Generative AI. With over 16 years of expertise spanning AWS, Dell, and Infosys, he brings a singular mix of technical depth and enterprise data throughout Cloud, Excessive-performance computing (HPC), Synthetic Intelligence (AI), Machine Studying (ML), and Analytics. He holds an MBA from Texas A&amp;M College\u2019s Mays Enterprise College.<\/p>\n<\/p><\/div>\n<div class=\"blog-author-box\" style=\"padding-top: 2.0em\">\n<div class=\"blog-author-image\" style=\"margin-right: 1.0em\">\n          <img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-139112\" src=\"https:\/\/d2908q01vomqb2.cloudfront.net\/f1f836cb4ea6efb2a0b1b99f41ad8b103eff4b59\/2026\/09\/10\/xu.jpg\" alt=\"\" width=\"100\" height=\"100\"\/>\n         <\/div>\n<h3 class=\"lb-h4\">Xu Deng<\/h3>\n<p style=\"overflow: hidden\">Xu Deng is a Software program Engineer Supervisor with the SageMaker workforce. He focuses on serving to clients construct and optimize their AI\/ML inference expertise on Amazon SageMaker. In his spare time, he loves touring and snowboarding.<\/p>\n<\/p><\/div>\n<\/footer>\n<p><!-- '\"` -->\n      <\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Whenever you construct an software on high of a big language mannequin (LLM), the immediate you ship to the mannequin sometimes has two elements. There\u2019s a hard and fast half that units up context (directions, reference paperwork, dialog historical past) and a variable half that comprises the precise consumer enter. Take a customer support bot [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":18615,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[387,1028,1809,74,10506,349,6804,388],"class_list":["post-18613","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-amazon","tag-inference","tag-latency","tag-llm","tag-prefixaware","tag-reduce","tag-routing","tag-sagemaker"],"_links":{"self":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/18613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18613"}],"version-history":[{"count":1,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/18613\/revisions"}],"predecessor-version":[{"id":18614,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/18613\/revisions\/18614"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/media\/18615"}],"wp:attachment":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}