Sub topic 17
Serving LoRA Adapters
This chapter assumes that you know how to run a base model with vLLM, call an OpenAI-compatible API, and use basic Python. LoRA, or Low-Rank Adaptation, is a method for fine-tuning a model by storing a small set of additional weight matrices instead of copying the full model weights.
Why serve an adapter?
A LoRA adapter changes a base model's behavior for a task, style, or domain. For example, one base model can serve separate adapters for legal text, customer support, and code review.
The base model remains in GPU memory. vLLM loads an adapter and applies its low-rank updates during inference. Multiple adapters can share the same base model, which usually uses less memory than loading a separate full model for each task.
An adapter must match the base model that produced it. An adapter trained for one model family or architecture cannot normally be attached to an unrelated base model.
| Choice | Memory use | Typical use |
|---|---|---|
| Separate full model | Highest | Different model behaviors or architectures |
| One base model with LoRA adapters | Lower | Several task-specific variants |
| One base model without adapters | Lowest | A single general behavior |
Start a server with adapters
Start the server with LoRA support enabled. Each adapter receives a name that clients use as the model name.
vllm serve Qwen/Qwen2.5-1.5B-Instruct \
--enable-lora \
--lora-modules support=/models/support-lora legal=/models/legal-lora \
--max-loras 2 \
--max-lora-rank 64The adapter directories must contain the files produced by the fine-tuning tool, including the adapter configuration and weights. max-loras limits how many adapters can be active in one batch. max-lora-rank should be at least as large as the rank used by every adapter.
A client selects an adapter by sending its registered name in the model field:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
response = client.chat.completions.create(
model="support",
messages=[{"role": "user", "content": "Summarize this ticket."}],
max_tokens=100,
)
print(response.choices[0].message.content)The server still uses the base model's tokenizer and runtime. The adapter changes the model computation, not the API protocol.
Operational limits
Adapters increase scheduling and memory costs. Start with a small max-loras value and increase it only after measuring GPU usage and latency. Keep adapter files in trusted, controlled locations. Loading an adapter is a deployment change, so do not let untrusted users select arbitrary filesystem paths.
If requests use many adapters, group traffic by adapter when possible. This can reduce adapter switching and make latency more predictable.
Exercise
A server uses --max-loras 1, but clients request two different adapters in the same batch. What should you expect?
Show answer
vLLM cannot keep both adapters active for that batch. Increase --max-loras if the GPU has room, or separate and schedule the requests so fewer adapters are active together.