# How Do You Serve Many LoRA Adapters?

> How one shared base model serves many LoRA adapters: loading on demand, batching across adapters, memory limits and trade-offs, for your AI interview.

**In short:** Keep one copy of the base model loaded, keep the small LoRA adapters in memory, load on demand the ones a request needs, and batch requests for different adapters together. Serving systems such as vLLM and S-LoRA are built for this.

AI and LLM interview question Q303, Fine-tuning and adaptation. Advanced, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-serve-many-lora-adapters

## Say it in 30 seconds

I keep one copy of the base model on the GPU and treat each LoRA adapter as a small add-on. The adapters wait in memory, and the ones a request needs are loaded when it arrives. Requests for different adapters go into the same batch, so the GPU stays busy. The limits are GPU memory, the delay of a cache miss, and one busy customer crowding out the rest. Systems like vLLM and S-LoRA are built for this.

## Say it in 2 minutes

The cost starts with full copies. If every adapter had its own copy of the base model, GPU memory would run out after a handful of adapters. A LoRA adapter is small because the base weights stay frozen and only small added grids of numbers, called matrices, are trained, so one base can carry many adapters.

The better design loads the base model once and keeps the busiest adapters on the GPU. A request names its adapter. If that adapter is not on the GPU, it is copied in first, which is a cache miss and adds a delay to that one request. The server then batches requests for different adapters, so the GPU works on them in one pass. Punica and S-LoRA are research systems that show this works. vLLM serves adapters per request, and S-LoRA is built for many of them at once.

The limits are real. GPU memory is shared by the base weights, the adapters and each running request. Set the maximum rank to the largest one you use. Watch cache misses and wait times for each adapter, and set a per-customer limit so one busy customer does not slow everyone else.

In an interview I would say: one base, many adapters, a cache of the hot ones, batching across adapters, and clear limits. Then I would say what I'd measure before I trusted it.

## What is serving many LoRA adapters, in plain words?

A LoRA adapter (short for low-rank adaptation) is a small add-on of learned changes that sits on top of a base model. The base model is the big shared model, and its weights stay as they are. Each adapter teaches it one job, such as answering auto claim questions or home claim questions.

Serving means answering live requests from users. A made-up insurer with 120 adapters could run a full model for each one, but that uses a lot of GPU memory. The better design loads the base model once and brings in each adapter when a request needs it.

Think of a claims office with one senior adjuster who knows the whole job, and a short note for each claim type. The adjuster keeps the same knowledge for every claim and reads only the note that matches the file on the desk. In the AI version, the base model is the adjuster and each LoRA adapter is one of those notes.

The 2021 LoRA paper froze the base weights and trained only small added grids of numbers, called matrices. That is why one base model can carry many adapters.

- **Base model:** The big shared model. Every adapter sits on top of the same copy.
- **LoRA adapter:** A small add-on file of learned changes, loaded on top of the base model.
- **Batch:** A group of requests the GPU works on together in one pass.
- **Cache miss:** A request needs an adapter that is not on the GPU yet, so it must be loaded first.

## Why not one full model per adapter?

Full copies are the simple option, and that is the trap. Each copy holds all the base weights, so memory runs out quickly. Two research papers make the point.

> "deploying independent instances of fine-tuned models, each with 175B parameters, is prohibitively expensive" (LoRA paper, 2021)
>
> "This allows a GPU to hold only a single copy of the underlying pre-trained model when serving multiple, different LoRA models" (Punica paper, 2023)

Traffic is uneven, and the mix matters. In the made-up insurer, auto and home claims make up most calls, so a few adapters are busy while the rest get a call now and then. The chart compares the two designs side by side.

*Diagram, Two ways to serve 120 adapters: Two ways to serve the same made-up set of 120 adapters. Full copies fill GPU memory with models that sit idle. One shared base loads only the adapters in use.*
1. Each adapter gets a full copy, so GPU memory fills up.
2. One base serves them all, and only the adapters in use are loaded.

vLLM serves adapters per request with minimal overhead. S-LoRA describes itself as "a system designed for the scalable serving of many LoRA adapters".

## How does one server answer requests for different adapters?

Three things happen, in order. First, each request names its adapter in the model field, the same way it would name any other model. Second, the server groups waiting requests into a batch, even when they use different adapters. Third, the GPU runs that batch in one pass with custom code, called a kernel. Punica built one for this.

*Diagram, One base model, adapters loaded on demand: A request names its adapter, and the batch builder groups requests for one base model. A cache miss copies the adapter in from CPU memory first. Each answer comes from its own adapter.*
1. The auto claim question asks for the auto adapter by name.
2. The home claim question asks for the home adapter by name.
3. On a cache miss, the adapter is copied from CPU memory to the GPU.
4. One mixed batch runs on the shared base model, each row with its own adapter.
5. Each user gets an answer from their own adapter.

1. **Adapter already on the GPU:** The request joins the shared batch at once, with no extra wait.
2. **Adapter in CPU memory:** This is a cache miss. The adapter is copied to the GPU first, which adds delay to that request. S-LoRA keeps all adapters in main memory and fetches the ones in use to the GPU.
3. **GPU memory is full:** Drop the least recently used adapter to make room. It is a common rule, not the only one.

vLLM's docs say requests for an adapter run in parallel with base model requests, and potentially with other adapter requests when max_loras is set high enough. That setting is one of several LoRA limits the server accepts.

Here is the cache idea in plain Python, with a made-up morning of claim traffic. The GPU has room for three adapters, and the rest wait in CPU memory.

```python
# Simplified adapter cache. The GPU has room for 3 adapters; the rest wait in CPU memory.
from collections import OrderedDict

GPU_SLOTS = 3
gpu = OrderedDict()  # adapter name -> loaded, least recently used first
loads = 0

def serve(adapter):
    global loads
    if adapter in gpu:
        gpu.move_to_end(adapter)  # mark as recently used
        return f"{adapter}: on GPU"
    loads += 1  # a cache miss: copy the adapter from CPU memory to the GPU
    evicted = ""
    if len(gpu) == GPU_SLOTS:
        old, _ = gpu.popitem(last=False)  # drop the least recently used one
        evicted = f", evicted {old}"
    gpu[adapter] = True
    return f"{adapter}: loaded from CPU{evicted}"

traffic = ["claims-auto", "claims-home", "claims-auto", "claims-travel",
           "claims-pet", "claims-auto", "claims-home"]
for name in traffic:
    print(serve(name))
print("cache misses:", loads)
```

Output:

```text
claims-auto: loaded from CPU
claims-home: loaded from CPU
claims-auto: on GPU
claims-travel: loaded from CPU
claims-pet: loaded from CPU, evicted claims-home
claims-auto: on GPU
claims-home: loaded from CPU, evicted claims-travel
cache misses: 5
```

The printout shows five cache misses in seven requests. Real traffic is different, so the hit rate depends on how skewed the adapter mix is. Measure it.

## What limits do you have to plan for?

1. **GPU memory is shared:** The base weights, the loaded adapters and the working memory of each running request all compete for the same GPU.
2. **Set the maximum rank:** Rank sets how big each adapter's small added matrices are. In vLLM, set --max-lora-rank to the largest rank you actually use. Going much higher wastes memory.
3. **Cache misses cost time:** Each miss adds load time to the one request that triggers it. Watch the miss rate, and keep the busiest adapters hot.
4. **One busy customer:** Set a limit per customer, and watch the wait time for each adapter, not only the average.
5. **Adapters can change while it runs:** vLLM can load an adapter through an API, with a POST request to /v1/load_lora_adapter, while the server runs. First set the environment variable VLLM_ALLOW_RUNTIME_LORA_UPDATING to True. The docs warn that this feature has security risks and should not be used in production unless the environment is isolated and fully trusted.

> **Tip:** Asked about limits, don't stop at GPU memory. Name the cache miss and the busy customer, then say what you would measure first.

### How would you add a new adapter for one customer without slowing the others?

Load the new adapter next to the others and send it a small share of traffic. Watch its cache misses, its wait time and its errors before you widen the share.

Check its rank against the server's maximum. If it keeps pushing busy adapters out of the cache, either the cache is too small or the mix is too wide for one GPU. That is a capacity decision for the team.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: small adapters on one shared base model.
- [ ] Why not a full model per adapter: memory runs out.
- [ ] How requests name an adapter and share a batch.
- [ ] Cache misses, and how the busy adapters stay on the GPU.
- [ ] The limits: GPU memory, adapter rank, and one busy customer.
- [ ] What you would measure before you trust the setup.

**Common traps**

- Trap: "Give every adapter its own model copy. It's the simplest." Better: It's simple at ten adapters and costly at a hundred. Keep one base and load the adapters into it.
- Trap: "Merge all the adapters into the base weights, then serve one model." Better: Merging removes the extra adapter step at inference, but gives one fixed model, so you lose the choice of adapter per request.
- Trap: "Adapters are tiny, so they cost nothing to keep." Better: They are small, but each loaded one takes GPU memory that the batches and the cache also need.

## Can you spot the problem?

**Spot the problem:** Your gateway knows three registered adapters: claims-auto, claims-home and claims-pet. It gets four requests. Which one should it reject before the GPU sees it?

A. model: claims-auto. Estimate the excess on policy 4471.
B. model: claims-home. Summarise the water damage photos for claim 9020.
C. model: claims-fraud-2019-final. Score this claim for fraud risk.
D. model: claims-pet. Which documents does a pet claim need?

**Answer:** C. That name matches no registered adapter. The gateway should refuse it before any load, so no wrong file is pulled into the cache.

**Quick check:** An insurer has 120 adapters, uneven traffic and one GPU budget. Which setup fits best?

A. One full model copy per adapter
B. One base model, with adapters cached and loaded on demand
C. Merge all adapters into one set of weights and serve only that
D. A dedicated GPU for each adapter, mostly idle

**Answer:** B. Full copies fill the memory, merging loses the choice of adapter per request, and a GPU per adapter sits idle most of the time. One base with a cache of the busy adapters fits uneven traffic.

## Can you answer these from memory?

**Flash cards**

- **What is a LoRA adapter?** A small add-on of learned changes, loaded on top of a shared base model.
- **Why not one full model per adapter?** Each copy holds all the base weights, so GPU memory runs out fast.
- **What is a cache miss here?** The adapter is not on the GPU yet, so it must be loaded first, adding delay.
- **What lets different adapters share a batch?** Custom GPU code, a kernel, that runs several adapters in one pass, as Punica does.
- **What is the main limit?** GPU memory, shared by the base weights, the adapters and each running request.
- **How do you stop one customer crowding out others?** Set a limit per customer and watch the wait time for each adapter.

## Likely follow-up questions

- Q284 What is LoRA? https://designervenkat.online/interview/ai/what-is-lora
- Q286 What does LoRA rank mean? https://designervenkat.online/interview/ai/what-does-lora-rank-mean
- Q305 Prompt/prefix tuning vs LoRA? https://designervenkat.online/interview/ai/prompt-prefix-tuning-vs-lora
- Q314 Static vs continuous batching? https://designervenkat.online/interview/ai/static-vs-continuous-batching
- Q320 Serving engines (vLLM, SGLang, TensorRT-LLM, llama.cpp)? https://designervenkat.online/interview/ai/serving-engines-vllm-sglang-tensorrt-llm-llama-cpp
- Q055 What is the KV cache, and why does it speed up generation? https://designervenkat.online/interview/ai/what-is-the-kv-cache
