Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Base model | A full model with its own weights, such as Llama-3.1-8B or Qwen3-32B. |
| Fine-tune | A base model further trained for one task or customer. |
| LoRA adapter | A small add-on that turns a base model into a fine-tune: two thin matrices per adapted layer, tens of megabytes instead of gigabytes (18.g). |
| Multi-LoRA | One copy of a base model in GPU memory serving many adapters at once, in the same batch. |
| Resident | Loaded in GPU memory and ready, as opposed to on disk or in host memory. |
| LRU | Least recently used: when space runs out, evict whatever was used longest ago. |
| MPS / MIG | Two NVIDIA ways to share one GPU between processes: soft sharing (MPS) and hard partitions (MIG). Lesson 21.d compares them. |
1. What is it?#
Serving more than one model from shared infrastructure. There are three different problems under that name, and they have different answers:
1. MANY FINE-TUNES OF ONE BASE one base model, many LoRA adapters
2. MANY BASE MODELS different models on a shared fleet
3. VERSIONS OF ONE MODEL the same model, old and new, during a rollout (20.j)Mixing them up leads to bad architecture: treating 50 fine-tunes as 50 models costs 50 times too much; treating 50 different models as if they could share weights does not work at all.
Facts checked on 12 November 2026.
2. Why does it matter?#
PROBLEM You have 50 models. A dedicated GPU (or eight) for each means most of
them sit idle most of the time.
WHY Traffic per model is small and bursty; GPU memory is the constraint;
and loading a model takes seconds to minutes.
OPTIMIZE Depends on which of the three problems you have.In most organisations a handful of models carry nearly all the traffic and a long tail carries the rest. The hot few deserve dedicated replicas. The question is what to do with the tail.
3. Simple analogy#
A theatre company.
- Multi-LoRA is one actor with many costumes. Changing costume takes seconds, and on a busy night the same actor can play several parts in one scene.
- Many base models are different actors. Only so many fit backstage (GPU memory). An actor who is not in the building takes an hour to arrive (a cold load); one waiting in the green room takes a minute (a model asleep in host memory).
- Versions are understudies rehearsing the same part.
4. Tiny example: when does swapping models work?#
Twenty base models share a pool of GPUs, one model per GPU at a time. Popularity follows a typical long tail (the second model gets half the traffic of the first, the third a third, and so on). A request for a model that is not loaded evicts the least recently used one and waits for the load.
// swap.go — many models, few GPUs: how often does a request wait for a model load?
package main
import (
"fmt"
"math"
"math/rand"
)
// run serves `models` models, popularity falling as 1/rank (Zipf), on `gpus` GPUs that each
// hold one model. A request for a model that is not loaded evicts the least recently used one
// and waits for the load. It returns the share of requests that waited, and the GPU time that
// loads demand as a share of all GPU time (above 100%: loads cannot keep up, the pool thrashes).
func run(models, gpus int, rate, loadSec float64) (waited, loading float64) {
rng := rand.New(rand.NewSource(3))
weights := make([]float64, models)
var sum float64
for i := range weights {
weights[i] = 1 / float64(i+1)
sum += weights[i]
}
type slot struct {
model int
lastUse, from float64 // last request; when the model became usable
}
slots := make([]slot, gpus)
for i := range slots {
slots[i] = slot{model: i} // start with the most popular models loaded
}
const simTime = 24 * 3600.0
n, w := 0, 0
var loadTime float64
for t := 0.0; t < simTime; t += rng.ExpFloat64() / rate {
x, m := rng.Float64()*sum, 0
for x > weights[m] {
x -= weights[m]
m++
}
n++
k := -1
for i, s := range slots {
if s.model == m {
k = i
}
}
if k < 0 { // not loaded: evict the least recently used slot
k = 0
for i, s := range slots {
if s.lastUse < slots[k].lastUse {
k = i
}
}
// a slot still loading something else finishes that load first
slots[k] = slot{model: m, from: math.Max(t, slots[k].from) + loadSec}
loadTime += loadSec
}
if slots[k].from > t {
w++ // this request waits for a load in progress
}
slots[k].lastUse = math.Max(t, slots[k].from)
}
return float64(w) / float64(n), loadTime / (simTime * float64(gpus))
}
func main() {
fmt.Println("20 models, 1/rank popularity, 0.5 requests/s in total")
fmt.Printf("%-5s %-26s %14s %17s\n", "GPUs", "load time", "requests wait", "GPU time loading")
for _, g := range []int{4, 8, 12} {
for _, l := range []struct {
name string
sec float64
}{{"90 s (cold, from storage)", 90}, {"15 s (node cache, stream)", 15}, {"3 s (wake from sleep)", 3}} {
wt, ld := run(20, g, 0.5, l.sec)
verdict := ""
if ld >= 1 {
verdict = " ← thrashing"
}
fmt.Printf("%-5d %-26s %13.1f%% %15.0f%%%s\n", g, l.name, wt*100, ld*100, verdict)
}
}
}Output:
20 models, 1/rank popularity, 0.5 requests/s in total
GPUs load time requests wait GPU time loading
4 90 s (cold, from storage) 100.0% 705% ← thrashing
4 15 s (node cache, stream) 100.0% 118% ← thrashing
4 3 s (wake from sleep) 68.1% 23%
8 90 s (cold, from storage) 100.0% 229% ← thrashing
8 15 s (node cache, stream) 55.3% 36%
8 3 s (wake from sleep) 39.1% 7%
12 90 s (cold, from storage) 91.7% 92%
12 15 s (node cache, stream) 26.6% 13%
12 3 s (wake from sleep) 21.4% 3%How to read it:
- With 90-second loads, swapping does not work at any pool size here: loads would need more GPU time than exists, so the pool spends its life loading and almost every request waits.
- Load time decides viability. The same 8 GPUs go from thrashing to “7% of time loading” when a switch takes 3 seconds instead of 90.
- Even then, a fifth to two-thirds of requests wait for a switch. Swapping suits traffic that tolerates an occasional slow first token: internal tools, evaluations, rarely used models.
- The rule of thumb: swapping is viable when load time is short compared with the gap between requests for the same model.
5. Technical explanation#
The decision tree#
Are the models fine-tunes of ONE base?
├─ YES → MULTI-LORA. One base in memory, adapters chosen per request.
│ Hundreds of variants for the cost of one model. ← the big win
│
└─ NO, different base models
├─ A few hot, many cold?
│ → dedicated replicas for the hot ones; a shared swap pool for the tail
├─ All small (under ~3B) and low traffic?
│ → several per GPU: separate processes with MPS, or MIG slices (21.d)
├─ All large and all busy?
│ → dedicated replicas. There is no trick; you need the GPUs.
└─ Very bursty, latency-tolerant?
→ scale to zero with fast loading (20.g)Multi-LoRA: the highest-value case#
From the serving side, a LoRA adapter replaces each adapted weight W with W + B·A, where A
and B are thin matrices of rank r (typically 8–64). The base W is shared; only A and B
differ per adapter. How big is an adapter? For Llama-3.1-8B at rank 16:
one adapted matrix of shape (in × out) adds r × (in + out) numbers
per layer, all seven linear layers adapted:
q 4096→4096 16 × 8,192 = 131k
k 4096→1024 16 × 5,120 = 82k
v 4096→1024 16 × 5,120 = 82k
o 4096→4096 16 × 8,192 = 131k
gate, up, down 4096↔14336 3 × 16 × 18,432 = 885k
total ≈ 1.31M
× 32 layers ≈ 42M numbers ≈ 84 MB in BF16 (attention q and v only: ≈ 14 MB)
base model: 16 GBA hundred such adapters take 8.4 GB of host memory; the GPU only holds the few in use. The
engine runs one big matrix multiply for the shared base weights across the whole batch, plus a
grouped low-rank multiply where each request uses its own adapter’s A and B. Punica
(SGMV kernels) and S-LoRA (adapters paged like KV cache) made that efficient; vLLM, SGLang and
TensorRT-LLM all do it today. Lesson 18.g reads vLLM’s implementation.
What the serving system has to decide:
| Decision | vLLM setting | Rule |
|---|---|---|
| Distinct adapters per batch (GPU slots) | --max-loras | Small (4–8). More slots, more per-step overhead. |
| Adapters kept in host memory | --max-cpu-loras | As many as fit: activating from host RAM takes milliseconds. |
| Largest rank allowed | --max-lora-rank | The largest you actually serve; every slot is sized for it. |
| Adding adapters while running | a resolver plugin, or /v1/load_lora_adapter with VLLM_ALLOW_RUNTIME_LORA_UPDATING | Prefer a resolver: every replica resolves the same name the same way (18.g). |
SGLang’s equivalents are --max-loras-per-batch and --max-loaded-loras.
Route by adapter. Requests for the same adapter should go to the same few replicas, so the adapter stays resident and batches together, and the number of distinct adapters per batch stays under the slot limit. That is affinity (20.f) with the adapter name as the key; lesson 21.g shows a router for it. Note that the prefix cache is not shared across adapters: the same system prompt under two adapters is computed twice.
When one adapter carries nearly all of a replica’s traffic, merge it into the base weights and serve the result as a plain model: no overhead at all.
Different base models on shared GPUs#
Co-location. Several small models, each in its own server process, on one GPU. MPS lets their kernels run at the same time; MIG gives each a hard slice of compute and memory. Neither helps a large model, and a MIG slice of 1/7 of a GPU is too small for most LLMs. Lesson 21.d covers the mechanisms.
Swapping. A pool of GPUs, each hosting whichever model is needed now, with LRU eviction (section 4). Make it work by:
- shortening the switch: node-cached or streamed weights (20.g), or vLLM sleep mode,
which parks an idle model's weights in host memory and wakes it in seconds (20.h)
- pinning the hot set so a burst for a cold model cannot evict them
- hysteresis: do not evict a model used in the last few minutes
- queueing requests for a model that is loading, instead of starting a second load
- a separate swap pool, so cold-model churn never touches the hot replicasServerless model platforms#
Managed “serverless” GPU platforms sell exactly this swap pool as a product: you pay per request, and they absorb the cold starts with large node caches, snapshots of initialized processes and warm pools. Self-hosted, llm-d’s experimental fast model actuation and KServe with a scale-to-zero autoscaler aim at the same thing. Measure their real cold start for your model size before relying on it.
6. Under the hood: the control plane#
A multi-model platform needs bookkeeping that a single-model service does not:
Registry model or adapter id → weights location, revision, base model, config (21.b)
Router request.model → which pool, which replica (21.g)
Placement which models on which GPUs, and when to move them (21.e)
Autoscaler replica counts per model, from per-model traffic (20.g)For multi-LoRA the routing decision is simple: any replica with the base model, preferring the ones that already hold the adapter. For many base models it is a bin-packing problem, because models have different sizes and GPU types; that is where most of the complexity lives (21.e).
7. Performance implications#
Approach Models per GPU Overhead Isolation Switch cost
Dedicated 1 none full —
Multi-LoRA (same base) hundreds of LoRAs a few % to ~25%* none ms (host RAM → GPU)
Co-location (MPS) 2–6 small models contention weak —
MIG slices up to 7 little hard repartition (drain the GPU)
Swapping 1 at a time none once loaded full seconds to minutes* The multi-LoRA overhead grows with rank, the number of adapted layers and the number of distinct adapters in each batch. Measure it at your rank and slot count.
- Multi-LoRA is in a different league for the case it covers. If your 50 models are fine-tunes of one base, it is the answer.
- Swapping costs latency, not throughput, as long as loads are rare. Once loads are frequent (section 4), they cost both.
8. Production implications#
- Measure per-model traffic first. Usually a handful of models carry nearly all of it.
- Use multi-LoRA for fine-tunes of a shared base, and train new variants as adapters where quality allows.
- Keep
--max-lorassmall and route by adapter, so batches stay within it. - Give hot base models dedicated replicas; pool only the long tail.
- Make switching fast before you swap: node caches, streaming, sleep mode.
- Pin and register adapters like models: revision, base model, owner (21.b).
- Watch deferred requests. In vLLM,
vllm:num_requests_waiting_by_reason{reason="deferred"}rising means requests are waiting for a free LoRA slot (19.c).
9. Common mistakes#
- A dedicated GPU per fine-tune when they share a base.
- Too many adapter slots. Each slot costs memory and per-step work whether used or not.
- No adapter affinity. Every replica loads every adapter, and batches mix many of them.
- Swapping with slow loading. The pool thrashes.
- MIG for large models. The slices are too small.
- Runtime adapter loading on one replica only. The others do not know the adapter exists.
- Designing for the long tail first. Five models are probably 95% of your traffic.
10. Hands-on exercise#
A. Swap economics. Run swap.go. Raise total traffic to 5 requests per second. Does
swapping get better or worse, and why? Then pin the top 4 models so they are never evicted.
B. Multi-LoRA overhead. Serve one base model with 8 adapters in vLLM. Measure throughput and
p95 inter-token latency with requests spread over 1, 2, 4 and 8 adapters, at --max-loras 4 and
--max-loras 8.
C. Adapter affinity. Simulate 4 replicas and 40 adapters with long-tail popularity. Compare random routing with adapter affinity: distinct adapters per batch and adapter loads per minute.
D. Sleep as a swap. On one GPU, run two small vLLM servers with --enable-sleep-mode (dev
mode, on your own machine). Switch between them with /sleep and /wake_up, and compare the
switch time with a full restart.
E. Traffic analysis. For a real or synthetic multi-model workload, plot traffic per model. What share of models carries 95% of requests? Design the placement accordingly.
11. Interview questions#
- What are the three different multi-model problems, and how do their solutions differ?
- Estimate the size of a rank-16 LoRA adapter for an 8B model. Why can one server hold hundreds?
- What does
--max-loraslimit, and why keep it small? - When is model swapping viable? Give the rule and the arithmetic.
- Why does adapter-aware routing matter?
- Compare MPS and MIG for packing small models onto one GPU.
- You have 50 fine-tuned variants of one 8B model. Design the serving architecture.
12. Further reading#
Checked on 12 November 2026.
- [ESTABLISHED] Hu et al., “LoRA: Low-Rank Adaptation of Large Language Models” (2021)
- [ESTABLISHED] Chen et al., “Punica: Multi-Tenant LoRA Serving” (MLSys 2024)
- [ESTABLISHED] Sheng et al., “S-LoRA: Serving Thousands of Concurrent LoRA Adapters” (MLSys 2024)
- [REFERENCE] vLLM LoRA adapters
- [REFERENCE] SGLang server arguments (LoRA)
- [REFERENCE] vLLM sleep mode
- [REFERENCE] NVIDIA MPS and MIG user guide