Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Fine-tuning | Training an existing model a little more on your own data. |
| LoRA | Low-Rank Adaptation: storing a fine-tune as two thin matrices per layer instead of a full copy of the weights. |
| Adapter | One LoRA fine-tune: a few megabytes of extra matrices that sit on top of a base model. |
| Rank (r) | How thin the LoRA matrices are; typically 8 to 64. Higher rank, more capacity, more cost. |
| Merging | Adding the adapter into the base weights once, producing an ordinary model. |
| Slot | Space on the GPU for one active adapter. --max-loras sets how many. |
| LRU | Least recently used: the eviction rule for the CPU adapter cache. |
1. What is it?#
A fine-tuned model is usually the base model plus a small correction. LoRA stores that correction as two thin matrices per layer, a few megabytes instead of many gigabytes. vLLM holds many adapters next to one copy of the base weights and applies a different one to each request in the same batch. To the client each adapter looks like a separate model name; on the GPU it is one model whose linear layers add a per-row correction.
The scheduler, the prefix cache and the CUDA graph manager each needed one small change to make that safe. When to use many adapters versus many models is 20.i; this lesson is how vLLM v0.32.0 does it. Facts checked on 12 November 2026.
2. Why does it exist?#
- Cost. Ten fine-tunes of an 8B model as full models need ten GPUs’ worth of weights. As adapters they need one base model plus about a gigabyte.
- Long tail. Many teams have dozens or hundreds of fine-tunes, each with little traffic. One base model serving all of them keeps the GPU busy.
- Fast switching. Moving an adapter from CPU memory into a GPU slot takes milliseconds; loading a new full model takes minutes.
3. Simple analogy#
One piano, many players. Each player brings a thin booklet of personal markings (the adapter)
that sits on the shared score (the base weights). The piano is never rebuilt; only the booklets
change. The music stand holds max_loras booklets at once; others wait in the cupboard (CPU
cache) and can be swapped in quickly.
4. Tiny example#
For a layer with weight W of size d × d, LoRA trains A (r × d) and B (d × r):
y = W·x + (α / r) · B·A·x
d = 4096, r = 16
W 16,777,216 numbers
A and B 131,072 numbers (under 1% of W)W is untouched. vLLM keeps W shared and adds B·A·x at run time, row by row, choosing each
row’s adapter.
5. Technical explanation#
Using it#
vllm serve meta-llama/Llama-3.2-3B-Instruct \
--enable-lora \
--lora-modules sql-lora=jeeejeee/llama32-3b-text2sql-spider \
--max-loras 4 --max-lora-rank 32Each adapter appears in /v1/models. A client selects one by putting its name in the request’s
model field; the base model’s name selects none.
| Flag | Default (v0.32.0) | Meaning |
|---|---|---|
--enable-lora | off | Build the model with LoRA-capable layers |
--max-loras | 1 | Distinct adapters allowed in one batch; also the number of GPU slots |
--max-lora-rank | 16 | Largest rank any adapter may have (one of 1, 8, 16, 32, 64, 128, 256, 320, 512). Slots are sized for it. |
--max-cpu-loras | = max_loras | Adapters kept in CPU memory, LRU eviction |
--lora-modules | — | Adapters to register at startup, name=path |
--fully-sharded-loras | off | Shard the whole LoRA computation under tensor parallelism; faster at long sequences, high rank or high TP |
Setting --max-lora-rank above what you need wastes memory and compute: every slot is allocated
at the maximum rank.
Three tiers of storage#
| Tier | Holds | Limit | Cost to reach the next tier |
|---|---|---|---|
| Disk or hub | Every adapter you could load | Unlimited | Download and parse: slow |
| CPU cache | Parsed adapter tensors | max_cpu_loras | Copy into a GPU slot: fast |
| GPU slots | Adapters usable in this step | max_loras | — |
A server with --max-loras 4 --max-cpu-loras 64 can serve 64 adapters, four at a time per batch.
The scheduler’s part#
From vllm/v1/core/sched/scheduler.py (v0.32.0):
# Check that adding the request still respects the max_loras constraint.
if (
self.lora_config
and request.lora_request
and (
len(scheduled_loras) == self.lora_config.max_loras
and request.lora_request.lora_int_id not in scheduled_loras
)
):
# Scheduling would exceed max_loras, skip.
skip_request(request_queue)
continueA waiting request whose adapter would be the (max_loras + 1)-th distinct adapter is
skipped, not blocked on. Requests behind it that use an adapter already in the batch, or none,
can still be admitted (17.c). It returns to the queue for the next step.
This is the main operational risk. With max_loras = 1 and traffic spread over ten adapters, one
adapter’s requests run at a time and the other nine wait. Throughput collapses although the GPU is
not full. Size max_loras to the number of adapters active at the same time, not the number that
exist.
The prefix cache’s part#
The same prompt produces different KV under different adapters, so the adapter is part of every block hash (17.f):
def _gen_lora_extra_hash_keys(request: Request) -> list[tuple[str, str, str]]:
"""Generate extra keys related to LoRA for block hash computation.
The adapter path is included so that re-pointing a LoRA name at a different
adapter does not reuse KV computed with the previous one.
...It returns ("lora", lora_name, lora_path). Requests using adapter A never share cached blocks
with adapter B or the base model, even for an identical system prompt. Ten adapters with a common
4,000-token system prompt hold ten copies of its KV.
The model runner’s part#
Each LoRA-capable layer keeps stacked A and B tensors with one slot per active adapter, and
receives a per-token index saying which slot (or none) applies to each row of the flat batch
(18.b). The correction is computed for all rows at once by Triton kernels in
vllm/lora/ops/triton_ops/: lora_shrink (multiply by A) and lora_expand (multiply by B),
with FP8 variants and a fused MoE LoRA kernel for mixture-of-experts layers. The “Punica” wrapper
(vllm/lora/punica_wrapper/) organises the per-token metadata.
Two configuration details show where the cost goes:
max_num_batched_tokensis part of the compile cache key because, inSchedulerConfig’s hash comment, “LoRA creates static buffers based on max_num_batched_tokens. The tensor sizes and strides get captured in the torch.compile graph explicitly.”- A batch with adapters runs different operations, so CUDA graphs are keyed by LoRA state (18.d).
With
cudagraph_specialize_lora(on by default) graphs are captured with and without LoRA, roughly doubling the count.--specialize-active-loragoes further and captures per number of active adapters (powers of two up tomax_loras), trading startup time and memory for speed when the count varies.
6. Under the hood#
Loading adapters while running#
With VLLM_ALLOW_RUNTIME_LORA_UPDATING=True, two endpoints manage adapters without a restart:
curl -X POST http://localhost:8000/v1/load_lora_adapter \
-H "Content-Type: application/json" \
-d '{"lora_name": "support-lora", "lora_path": "/adapters/support-v3"}'
curl -X POST http://localhost:8000/v1/unload_lora_adapter \
-H "Content-Type: application/json" \
-d '{"lora_name": "support-lora"}'They are utility calls executed between engine steps (16.g), so no lock is needed around the adapter tables.
warning
The documentation warns that this feature “comes with security risks. It should not be used in production unless it is an isolated, fully trusted environment.” Anyone who can reach the endpoint can make the server read a path or download a repository. In a replicated deployment it also creates drift: an adapter loaded on one replica does not exist on the others.
A LoRA resolver plugin inverts the flow: when a request names an unknown model, vLLM asks the
registered resolvers for an adapter of that name and loads it on demand. Every replica resolves a
name the same way, so there is no drift (19.f). vLLM ships two, lora_filesystem_resolver (a
local directory) and lora_hf_hub_resolver (listed Hugging Face repositories; the documentation
calls remote downloads insecure and not for production). Resolvers also require
VLLM_ALLOW_RUNTIME_LORA_UPDATING, so restrict who can reach the server.
Other features#
- MoE adapters. Mixture-of-experts models can take LoRA on expert layers;
--enable-mixed-moe-lora-formatserves 2D (Megatron-style) and 3D (PEFT-style) expert adapters side by side. - Vision towers.
--enable-tower-connector-lora(experimental) adapts the vision encoder and connector of some multimodal models;default_mm_lorasattaches an adapter automatically when a given modality is present. - Both runners support LoRA; Model Runner V2 has its own
lora_utils.py.
Adapter memory and the max_loras effect#
package main
import "fmt"
func main() {
// --- memory ---
const (
d = 4096 // hidden size
layers = 32
modules = 4 // adapted projections per layer, e.g. q, k, v, o
)
base := float64(layers*modules) * float64(d*d) * 2 / (1 << 30) // GiB at 16 bits
fmt.Printf("base weights in the adapted projections: %.1f GiB\n\n", base)
fmt.Printf("%6s %10s %22s\n", "rank", "one adapter", "GPU slots for max_loras=8")
for _, r := range []int{8, 16, 64, 256} {
one := float64(layers*modules*2*d*r) * 2 / (1 << 20) // MiB
fmt.Printf("%6d %8.0f MiB %18.2f GiB\n", r, one, one*8/1024)
}
// --- scheduling ---
fmt.Println("\n64 requests, 8 per adapter, arriving interleaved; each needs 20 decode steps.")
fmt.Printf("%10s %8s %22s\n", "max_loras", "steps", "avg requests per step")
for _, maxLoras := range []int{1, 2, 4, 8} {
type req struct{ adapter, left int }
var waiting []*req
for i := 0; i < 64; i++ {
waiting = append(waiting, &req{adapter: i % 8, left: 20})
}
var running []*req
steps, served := 0, 0
for len(waiting)+len(running) > 0 {
// Adapters already in the batch.
active := map[int]bool{}
for _, r := range running {
active[r.adapter] = true
}
// Admit from the queue; skip requests whose adapter would exceed max_loras.
var still []*req
for _, r := range waiting {
if active[r.adapter] || len(active) < maxLoras {
active[r.adapter] = true
running = append(running, r)
} else {
still = append(still, r) // skipped, keeps its place
}
}
waiting = still
steps++
served += len(running)
keep := running[:0]
for _, r := range running {
if r.left--; r.left > 0 {
keep = append(keep, r)
}
}
running = keep
}
fmt.Printf("%10d %8d %22.1f\n", maxLoras, steps, float64(served)/float64(steps))
}
}Output:
base weights in the adapted projections: 4.0 GiB
rank one adapter GPU slots for max_loras=8
8 16 MiB 0.12 GiB
16 32 MiB 0.25 GiB
64 128 MiB 1.00 GiB
256 512 MiB 4.00 GiB
64 requests, 8 per adapter, arriving interleaved; each needs 20 decode steps.
max_loras steps avg requests per step
1 160 8.0
2 80 16.0
4 40 32.0
8 20 64.0With one slot the server takes eight times as many steps and runs batches of eight; with eight slots all 64 requests share every step. Same GPU, model and traffic; only the flag changed.
7. Performance implications#
- Per token: the extra shrink and expand multiplies in every adapted layer. A few percent to low tens of percent of decode time, depending on rank, the number of adapted modules and the batch mix.
- Memory:
max_loras × layers × modules × 2 × d × max_lora_ranknumbers. Small next to the base model, but rank 256 with eight slots equals the base projections in the example. - Cache efficiency: no prefix sharing across adapters.
- Scheduling: head-of-line effects when distinct active adapters exceed
max_loras. - Startup: extra CUDA graphs for the LoRA cases.
When one adapter carries nearly all the traffic, merging it into the base weights and serving the result as a plain model removes all five costs.
8. Production implications#
- Size
max_lorasfrom traffic. Count the adapters active in a typical second, not the catalogue. - Size
max_cpu_lorasfrom the catalogue’s hot set to avoid reloading from disk. - Route by adapter. A router that sends each adapter’s traffic to a subset of replicas (20.f) keeps prefix-cache hits and reduces slot churn.
- Prefer resolver plugins over the load endpoint in shared clusters, and keep both behind authentication.
- Watch
vllm:num_requests_waiting. A rising queue with an idle GPU usually meansmax_lorasis too low.
9. Common mistakes#
- Reading
--max-lorasas “adapters I can serve”. It is adapters per batch. - Setting
--max-lora-rank 256“just in case”. Every slot pays for it. - Expecting a shared system prompt to be cached across adapters. It is not.
- Exposing
/v1/load_lora_adapterto the internet. - Serving a single dominant adapter unmerged and paying LoRA overhead on all traffic.
10. Hands-on exercise#
- In the scheduling experiment, make traffic skewed: 50 requests for adapter 0 and 2 each for
the other seven. How much does
max_loras = 2cost now compared with 8? - Compute the slot memory for your own model at rank 64 with 16 slots.
- On a real server with two adapters and
--max-loras 1, send alternating requests and watchvllm:num_requests_waiting. Repeat with--max-loras 2. - Compare startup time and the
Graph capturing finishedline with and without--specialize-active-loraat--max-loras 8.
11. Interview questions#
- Why does vLLM not merge adapters into the base weights?
- What happens to a waiting request whose adapter is not in the batch when the batch already
holds
max_lorasdistinct adapters? - Two tenants use different adapters and the same system prompt. Do they share prefix-cache blocks? Why?
- Why does enabling LoRA change the number of CUDA graphs captured?
- Why is a resolver plugin safer than the runtime load endpoint in a replicated deployment?
12. Further reading#
Checked on 12 November 2026.
- LoRA adapters (vLLM v0.32.0 docs)
- LoRA resolver plugins
vllm/config/lora.pyvllm/v1/core/sched/scheduler.py: themax_lorascheckvllm/v1/core/kv_cache_utils.py:_gen_lora_extra_hash_keysvllm/lora/ops/triton_ops/: shrink and expand kernels- LoRA: Low-Rank Adaptation of Large Language Models