{"componentChunkName":"component---src-templates-blog-post-js","path":"/blog/2026-11-23-serve-multiple-lora-adapters-one-gpu/","result":{"data":{"site":{"siteMetadata":{"title":"M. Hassan Ahmed","author":"Hassan11196"}},"markdownRemark":{"id":"c8ad4a87-e868-5ee2-97ea-175f2a4f329e","excerpt":"You fine-tuned the same open model five different ways: one adapter for SQL, one for support tickets, one for each of three customers who wanted their own tone…","html":"<p>You fine-tuned the same open model five different ways: one adapter for SQL, one for support tickets, one for each of three customers who wanted their own tone. Each one is a <a href=\"https://arxiv.org/abs/2106.09685\">LoRA</a>, so each is a small file sitting next to a base model you never changed. Now you have to serve all five. The obvious plan is five deployments, five copies of the base weights, five GPUs mostly sitting idle. For a 7B model in fp16 that is about 70 GB of weights to hold the same numbers five times over.</p>\n<p>There is a better plan. Because every adapter shares one frozen base, you can keep a single copy of that base on one GPU and swap the small adapter part in and out per request. This is multi-LoRA serving, and it is the difference between renting one GPU and renting a rack of them.</p>\n<p>This post is for engineers who already serve open models and now have more than one fine-tune to host. It covers why LoRA makes this possible, the batching problem that makes it harder than it sounds, the kernels that solve that problem, how to turn it on in <a href=\"https://github.com/vllm-project/vllm\">vLLM</a>, and the ways it bites in production. It is a companion to my guide on <a href=\"/blog/2026-11-05-inference-engineering/\">what an inference engineer does</a>; serving many fine-tunes from one deployment is one of the jobs that guide describes.</p>\n<p>\n  <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/884af7404e4bc82a6982ff8a8b68f8b9/25a1a/hero.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n  \n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block; margin: 7vw 0; max-width: 1360px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 52.64705882352941%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsSAAALEgHS3X78AAABt0lEQVQoz3WRyZLcIAyG/f5vltwmlUtPb24btxswBsy+KuqZ5BiV+Eugj0VigC/rvZdS5nk5n+/ThHqbJnK/T5fL/XS6riu73cZxnFpDsMM/G3DUWsOXKaX3XWl9SKkwRhVCoiuFK+9pCLHUmnP+PmJotYtNcSYx+HoClAq1wf8shkxfW/D5vXlf2zZX9sgbqcFB9NoI4jXrSRe/Za+tbnSxO48xtmC7eDax1P3Z/AHDfMirYCe2jkocKfUowU+Wfcj5R7f3YulOYTyp9RGQNjk+9I48qop+EDyviyWT5jQZU0sQ3S87+fW6/SxmqobP3P8m9EKxCcXZvLGEPKqzdeAM1hWepLMXOActyu5JOpagluZJMUwoIDwxWa1t3nVG4bUCqrUwTMpchf7k8i4PHUuLqjnSPda0gF+y4VaD1dnqigXrmMc3rx7SyBAHifmgXk6IpGNNvWDbjDcqWB3s4a11JhkdzZFK7qmnPR08SFTf4mA82AAuAAbo2nWu6kzTwvPCEqGR0ED3pGzF1DfjPBz4LxkGrmHT8K3odG8zjeeHvRL/Odrz5M4PNz7DS5Tt+Mu8efW+8g88dnApn3btJwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n    >\n      <picture>\n        <source\n          srcset=\"/static/884af7404e4bc82a6982ff8a8b68f8b9/51a8e/hero.webp 340w,\n/static/884af7404e4bc82a6982ff8a8b68f8b9/713b7/hero.webp 680w,\n/static/884af7404e4bc82a6982ff8a8b68f8b9/54376/hero.webp 1360w,\n/static/884af7404e4bc82a6982ff8a8b68f8b9/521a5/hero.webp 2000w\"\n          sizes=\"(max-width: 1360px) 100vw, 1360px\"\n          type=\"image/webp\"\n        />\n        <source\n          srcset=\"/static/884af7404e4bc82a6982ff8a8b68f8b9/ad208/hero.png 340w,\n/static/884af7404e4bc82a6982ff8a8b68f8b9/a5a26/hero.png 680w,\n/static/884af7404e4bc82a6982ff8a8b68f8b9/60356/hero.png 1360w,\n/static/884af7404e4bc82a6982ff8a8b68f8b9/25a1a/hero.png 2000w\"\n          sizes=\"(max-width: 1360px) 100vw, 1360px\"\n          type=\"image/png\"\n        />\n        <img\n          class=\"gatsby-resp-image-image\"\n          style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n          src=\"/static/884af7404e4bc82a6982ff8a8b68f8b9/60356/hero.png\"\n          alt=\"One frozen base model on a single GPU, with a pool of small LoRA adapters that are applied per request to a mixed batch\"\n          title=\"\"\n          src=\"/static/884af7404e4bc82a6982ff8a8b68f8b9/60356/hero.png\"\n        />\n      </picture>\n      </span>\n  </span>\n  \n  </a>\n    </p>\n<h2>Why one base model is enough</h2>\n<p>A standard fine-tune rewrites the model’s weights. Serve ten of those and you hold ten full models. LoRA does something different. It leaves the pretrained weight matrix <code class=\"language-text\">W0</code> alone and learns a small correction next to it.</p>\n<p>For a weight matrix of shape <code class=\"language-text\">(d_out, d_in)</code>, LoRA adds two thin matrices: <code class=\"language-text\">B</code> of shape <code class=\"language-text\">(d_out, r)</code> and <code class=\"language-text\">A</code> of shape <code class=\"language-text\">(r, d_in)</code>, where the rank <code class=\"language-text\">r</code> is small, often 8 or 16. The layer’s output becomes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">y = W0 x  +  (B A) x * (alpha / r)</code></pre></div>\n<p><code class=\"language-text\">W0</code> is the same for every adapter. Only <code class=\"language-text\">B</code> and <code class=\"language-text\">A</code> change, and because <code class=\"language-text\">r</code> is tiny they are tiny too. The <a href=\"https://arxiv.org/abs/2106.09685\">original LoRA paper (Hu et al., 2021)</a> reports cutting trainable parameters by several orders of magnitude against full fine-tuning while matching its quality. For serving, the number that matters is the one on disk.</p>\n<p>Work it out for an 8B model. The base weights in fp16 are about 16 GB. A rank-16 adapter that targets the four attention projections across all layers adds <code class=\"language-text\">r * (d_in + d_out)</code> parameters per matrix, which for a 4096-wide model lands around 30 MB. So a hundred adapters is roughly 3 GB on top of one 16 GB base. A hundred <em>merged</em> copies would be 1.6 TB, more than twenty 80 GB cards. That gap is the entire reason multi-LoRA serving exists.</p>\n<p><img src=\"/ceb1f86b14f19f15c4b71e6f75e150a4/memory-footprint.svg\" alt=\"Memory footprint for 100 fine-tunes of an 8B model: 100 merged copies need about 1.6 TB across more than twenty GPUs, while one shared base plus 100 adapters fits in about 19 GB on a single card\"></p>\n<p>The same math says when <em>not</em> to bother: if you only ever serve one adapter, merge it into <code class=\"language-text\">W0</code> and ship a normal model. The LoRA paper points out the merge adds zero inference latency. Multi-LoRA is for when you need several adapters live at once.</p>\n<h2>The part that is harder than it looks</h2>\n<p>Keeping one base and a pile of small adapters sounds easy until you remember how LLMs are served efficiently. Fast serving means <a href=\"/blog/2026-08-31-continuous-batching-llm-serving/\">continuous batching</a>: the engine packs tokens from many in-flight requests into one forward pass so the expensive GPU work is shared. The trouble is that a single batch now mixes requests belonging to <em>different</em> adapters.</p>\n<p>The base term is fine. <code class=\"language-text\">W0 x</code> is one large matrix multiply over the whole batch, shared by everyone, exactly the GEMM the GPU is built for. The adapter term is the problem. Row 1 of the batch needs adapter A’s <code class=\"language-text\">B A</code>, row 2 needs adapter B’s, row 3 is back on adapter A. The naive fix is to split the batch by adapter and run a separate small matmul for each group.</p>\n<p>That wrecks performance. GPUs are efficient on large, regular matrix multiplies and terrible at a scatter of tiny ones: each kernel launch has overhead, and small GEMMs leave the Tensor Cores underfed. You traded one big efficient operation for a ragged pile of little inefficient ones. This is the problem any multi-LoRA system has to solve, and it is why “just loop over the adapters” is a demo, not a serving system.</p>\n<p><img src=\"/8ca9f575c21ab6e853add543a7e6c745/ragged-batch.svg\" alt=\"A mixed batch flows through one shared base GEMM, then a batched adapter kernel applies the correct LoRA to each row in a single pass instead of a loop of small matmuls\"></p>\n<h2>The kernels that fix it</h2>\n<p>Two research systems worked out how to apply many different adapters in one pass, and production engines picked up the ideas.</p>\n<p><a href=\"https://arxiv.org/abs/2310.18547\"><strong>Punica</strong></a> (Chen et al., MLSys 2024) introduced a kernel called SGMV, Segmented Gather Matrix-Vector multiplication. It applies the right adapter to each segment of the batch inside a single kernel, grouping requests that share an adapter so the work has enough arithmetic intensity to use the Tensor Cores. One copy of the base model in memory serves every adapter. The paper reports up to 12x higher throughput than baseline systems when serving many LoRA models on a fixed cluster, and the code is at <a href=\"https://github.com/punica-ai/punica\">punica-ai/punica</a>.</p>\n<p><a href=\"https://arxiv.org/abs/2311.03285\"><strong>S-LoRA</strong></a> (Sheng et al., 2023) went after memory. It keeps all adapters in host RAM and pages only the ones that running requests need onto the GPU. Its Unified Paging puts adapter weights of different ranks and the <a href=\"/blog/2026-07-12-llm-kv-cache-gpu-memory/\">KV cache</a> of different sequence lengths into one memory pool, so neither fragments the other, the same idea that <a href=\"/blog/2026-08-16-pagedattention-vllm-kv-cache/\">PagedAttention</a> applies to the KV cache alone. Custom kernels batch the heterogeneous adapter work. The <a href=\"https://lmsys.org/blog/2023-11-15-slora\">LMSYS writeup</a> reports up to 4x throughput over Hugging Face PEFT and naive vLLM while scaling to thousands of adapters.</p>\n<p>You rarely write these kernels yourself. The point of knowing they exist is to understand what the engine is doing when you flip the flag, and what its knobs actually control.</p>\n<h2>Turning it on in vLLM</h2>\n<p>vLLM has multi-LoRA built in. You register adapters at startup and pick one per request by name. These flags match the <a href=\"https://docs.vllm.ai/en/latest/features/lora.html\">vLLM LoRA docs</a>; confirm them against your installed version, since the names have shifted across releases.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">vllm serve meta-llama/Meta-Llama-3-8B-Instruct <span class=\"token punctuation\">\\</span>\n  --enable-lora <span class=\"token punctuation\">\\</span>\n  --lora-modules sql-bot<span class=\"token operator\">=</span>/adapters/sql <span class=\"token assign-left variable\">support</span><span class=\"token operator\">=</span>/adapters/support <span class=\"token punctuation\">\\</span>\n  --max-loras <span class=\"token number\">4</span> <span class=\"token punctuation\">\\</span>\n  --max-lora-rank <span class=\"token number\">16</span> <span class=\"token punctuation\">\\</span>\n  --max-cpu-loras <span class=\"token number\">32</span></code></pre></div>\n<p>A request chooses its adapter through the <code class=\"language-text\">model</code> field, as if each adapter were its own model:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">curl</span> http://localhost:8000/v1/completions <span class=\"token punctuation\">\\</span>\n  -H <span class=\"token string\">'content-type: application/json'</span> <span class=\"token punctuation\">\\</span>\n  -d <span class=\"token string\">'{\"model\": \"sql-bot\", \"prompt\": \"Count orders per customer last month.\"}'</span></code></pre></div>\n<p>The four flags are the whole tuning surface, and each one is a tradeoff:</p>\n<ul>\n<li><code class=\"language-text\">--enable-lora</code> turns the feature on. Off by default.</li>\n<li><code class=\"language-text\">--max-loras</code> is how many <em>distinct</em> adapters can be active in one batch. The default is 1, which quietly serializes requests that use different adapters. Set it to the real concurrency you expect across adapters; higher costs GPU memory.</li>\n<li><code class=\"language-text\">--max-lora-rank</code> has to cover your highest-rank adapter. vLLM sizes its buffers to this, so a single rank-64 adapter inflates the budget for every request, even the rank-8 ones.</li>\n<li><code class=\"language-text\">--max-cpu-loras</code> is the size of the host-side adapter cache that feeds the GPU, the S-LoRA style pool.</li>\n</ul>\n<p>For adapters that come and go, vLLM can load and unload at runtime through <code class=\"language-text\">/v1/load_lora_adapter</code> and <code class=\"language-text\">/v1/unload_lora_adapter</code> once you set <code class=\"language-text\">VLLM_ALLOW_RUNTIME_LORA_UPDATING=True</code>, so you do not restart the server to add a tenant.</p>\n<h2>Where it breaks</h2>\n<p>The demo works on the first try. These are the failures that show up later.</p>\n<p><strong>Cold adapters stall.</strong> The first request for an adapter that is not resident pays a copy from host RAM, or worse from disk, onto the GPU before it can run. Under a long tail of rarely-used adapters, that cost lands on real users as a latency spike. Size <code class=\"language-text\">--max-cpu-loras</code> for your working set and keep hot adapters pinned.</p>\n<p><strong>The batch serializes without warning.</strong> If more distinct adapters show up in a window than <code class=\"language-text\">--max-loras</code> allows, the extra ones wait for the next batch. Throughput looks fine in a single-adapter load test and falls over in production, where traffic is spread across adapters. Load test with the adapter mix you actually expect.</p>\n<p><strong>Rank padding wastes memory.</strong> Because the engine pads to <code class=\"language-text\">--max-lora-rank</code>, mixing a few high-rank adapters with many low-rank ones taxes all of them. If you control training, keep ranks uniform, or run the outliers in a separate deployment.</p>\n<p><strong>Base and template drift is silent.</strong> An adapter is trained against one specific base checkpoint and chat template. Serve it on a different base version, or format the prompt differently than training did, and quality degrades with no error at all. Pin the base checkpoint and reuse the exact template. The same warning applies to quantization: a <a href=\"/blog/2026-07-26-llm-quantization-int8-gptq-awq/\">QLoRA</a> adapter trained against a 4-bit base will not behave the same on an fp16 one.</p>\n<p><strong>Throughput tracks adapter diversity.</strong> The base GEMM is shared no matter what, but the adapter step grows with how many distinct adapters are in flight. A batch dominated by one or two adapters is close to free; a batch spread thin across dozens is not. Where you can, route traffic so requests for the same adapter tend to land together.</p>\n<h2>What I would do differently</h2>\n<p>Reach for multi-LoRA when you have many adapters with uneven, spiky traffic, the per-customer or per-task long tail where dedicated replicas would sit idle most of the day. That is exactly where one base and a pool of small adapters pays off.</p>\n<p>If you have two or three adapters and GPUs are not scarce, I would skip it. Merge each adapter into its own base copy, serve them as ordinary models behind a router, and keep the simpler operational story: no <code class=\"language-text\">--max-loras</code> to tune, no cold-adapter spikes, no shared failure domain. The cost is more GPU memory. Whether that trade is worth it is a capacity question, and sizing it is the kind of <a href=\"/blog/2026-09-25-gpu-memory-serve-llm/\">GPU memory math</a> you do before any deployment.</p>\n<p>Serving open models well is less about any single trick and more about knowing which one fits the traffic in front of you. Multi-LoRA is the one that turns “a different fine-tune for everyone” from a budget problem into a config flag, which is why it keeps coming up in <a href=\"/blog/2026-11-05-inference-engineering/\">inference platform work</a> for teams running open weights.</p>\n<h2>FAQ</h2>\n<h3>Can I serve LoRA adapters with different ranks together?</h3>\n<p>Yes, systems like S-LoRA and vLLM handle mixed ranks. The catch in vLLM is that <code class=\"language-text\">--max-lora-rank</code> pads buffers to the largest rank you declare, so a few high-rank adapters raise the memory cost for all of them.</p>\n<h3>How much memory does an adapter add?</h3>\n<p>For a rank-16 adapter on the attention projections of an 8B model, on the order of tens of megabytes in fp16, against roughly 16 GB for the base. The adapter size scales with the rank and the number of layers you target, not with the size of the base.</p>\n<h3>Is multi-LoRA slower than serving one merged model?</h3>\n<p>Per adapter, slightly, because of the extra adapter kernel on top of the shared base matmul. Across many adapters it is far cheaper than running a full model copy for each, which is the comparison that matters once you have more than a couple of fine-tunes.</p>\n<h3>When should I merge the adapter instead?</h3>\n<p>When you only ever serve that one adapter. Merging folds <code class=\"language-text\">B A</code> back into <code class=\"language-text\">W0</code>, giving a normal model with no adapter kernel and no per-request overhead. Keep adapters separate only when you need several of them live at once.</p>\n<hr>\n<p><em>Diagrams by M. Hassan Ahmed, released under CC0. No external image was used for this post; the figures are original work by the author.</em></p>","frontmatter":{"title":"Serving Many LoRA Adapters on One GPU","date":"2026-11-23T00:00:00.000Z","description":"One base model, many fine-tuned LoRA adapters, one GPU. How multi-LoRA serving works, the batched kernels that make it fast, and how to run it in vLLM.","thumbnail":{"childImageSharp":{"fluid":{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsSAAALEgHS3X78AAABt0lEQVQoz3WRyZLcIAyG/f5vltwmlUtPb24btxswBsy+KuqZ5BiV+Eugj0VigC/rvZdS5nk5n+/ThHqbJnK/T5fL/XS6riu73cZxnFpDsMM/G3DUWsOXKaX3XWl9SKkwRhVCoiuFK+9pCLHUmnP+PmJotYtNcSYx+HoClAq1wf8shkxfW/D5vXlf2zZX9sgbqcFB9NoI4jXrSRe/Za+tbnSxO48xtmC7eDax1P3Z/AHDfMirYCe2jkocKfUowU+Wfcj5R7f3YulOYTyp9RGQNjk+9I48qop+EDyviyWT5jQZU0sQ3S87+fW6/SxmqobP3P8m9EKxCcXZvLGEPKqzdeAM1hWepLMXOActyu5JOpagluZJMUwoIDwxWa1t3nVG4bUCqrUwTMpchf7k8i4PHUuLqjnSPda0gF+y4VaD1dnqigXrmMc3rx7SyBAHifmgXk6IpGNNvWDbjDcqWB3s4a11JhkdzZFK7qmnPR08SFTf4mA82AAuAAbo2nWu6kzTwvPCEqGR0ED3pGzF1DfjPBz4LxkGrmHT8K3odG8zjeeHvRL/Odrz5M4PNz7DS5Tt+Mu8efW+8g88dnApn3btJwAAAABJRU5ErkJggg==","aspectRatio":1.899441340782123,"src":"/static/884af7404e4bc82a6982ff8a8b68f8b9/40a76/hero.png","srcSet":"/static/884af7404e4bc82a6982ff8a8b68f8b9/c972b/hero.png 340w,\n/static/884af7404e4bc82a6982ff8a8b68f8b9/27625/hero.png 680w,\n/static/884af7404e4bc82a6982ff8a8b68f8b9/40a76/hero.png 1360w,\n/static/884af7404e4bc82a6982ff8a8b68f8b9/ed396/hero.png 2000w","sizes":"(max-width: 1360px) 100vw, 1360px"}}}}}},"pageContext":{"slug":"/2026-11-23-serve-multiple-lora-adapters-one-gpu/","previous":"blog/2026-09-29-consistent-hashing-sharding-without-reshuffle/","next":null}},"staticQueryHashes":["32046230"]}