# LoRAX

> Serve thousands of LoRA adapters over one base model on a single GPU

- Category: Models & Inference / Serving & Deployment
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/predibase/lorax
- Website: https://loraexchange.ai/
- Canonical page: https://ai-tldr.dev/tools/lorax/

## In short

LoRAX — LoRA eXchange — is an inference server built around a simple observation: a fleet of fine-tuned models usually shares one base model and differs only in its LoRA adapters. It sits in the Serving & Deployment category of the Models & Inference tools and is open-source, written in Python and licensed Apache-2.0.

## Overview

LoRAX — LoRA eXchange — is an inference server built around a simple observation: a fleet of fine-tuned models usually shares one base model and differs only in its LoRA adapters. Instead of standing up a GPU per fine-tune, LoRAX keeps the base model resident and swaps adapters per request, which the project frames as serving thousands of fine-tuned models on a single GPU without giving up throughput or latency.

Three mechanisms make that work. Dynamic adapter loading pulls any LoRA adapter from the Hugging Face Hub, Predibase or a local filesystem at request time, just-in-time and without blocking concurrent requests, and adapters can be merged per request to build ensembles on the fly. Heterogeneous continuous batching packs requests for different adapters into the same batch, so latency and throughput stay close to flat as the number of concurrent adapters grows. Adapter exchange scheduling prefetches and offloads adapters between GPU and CPU memory asynchronously, and schedules batching to maximise aggregate throughput.

Underneath it is a conventional optimised serving stack: tensor parallelism, pre-compiled CUDA kernels for flash attention, paged attention and SGMV, quantization and token streaming. Base models can be loaded in fp16 or quantized with bitsandbytes, GPT-Q or AWQ, and supported architectures include Llama (with CodeLlama), Mistral (with Zephyr) and Qwen. Adapters trained with PEFT or Ludwig are supported, and any linear layer in the model can be adapted.

It is packaged for production rather than notebooks: prebuilt Docker images, Helm charts for Kubernetes, Prometheus metrics, distributed tracing through OpenTelemetry, an OpenAI-compatible API with multi-turn chat, per-request tenant isolation for private adapters, and structured JSON output. The licence is Apache 2.0, which the README notes explicitly makes it free for commercial use.

## What it does

- Dynamic adapter loading from the Hugging Face Hub, Predibase or any filesystem, just-in-time and non-blocking
- Heterogeneous continuous batching — requests for different adapters packed into one batch
- Adapter exchange scheduling that prefetches and offloads adapters between GPU and CPU memory
- Per-request adapter merging to build ensembles without a separate deployment
- Optimised inference: tensor parallelism, flash attention, paged attention, SGMV kernels, quantization, token streaming
- fp16 or bitsandbytes / GPT-Q / AWQ quantized base models; PEFT and Ludwig adapters on any linear layer
- Production packaging: Docker images, Helm charts, Prometheus metrics, OpenTelemetry tracing, tenant isolation, JSON mode
- OpenAI-compatible API alongside its own REST and Python clients

## Getting started

The recommended path is the prebuilt Docker image, which avoids compiling the custom CUDA kernels. Minimum requirements are an Ampere-or-newer NVIDIA GPU, CUDA 11.8+ drivers, Linux and Docker with the NVIDIA container toolkit installed.

1. Launch the server

   Point the image at a base model and mount a volume for the weights cache.

```bash
model=mistralai/Mistral-7B-Instruct-v0.1
volume=$PWD/data

docker run --gpus all --shm-size 1g -p 8080:80 -v $volume:/data \
    ghcr.io/predibase/lorax:main --model-id $model
```

2. Prompt the base model over REST

   The /generate endpoint takes the prompt and generation parameters.

```bash
curl 127.0.0.1:8080/generate \
    -X POST \
    -d '{"inputs": "[INST] Your prompt here [/INST]", "parameters": {"max_new_tokens": 64}}' \
    -H 'Content-Type: application/json'
```

3. Prompt a LoRA adapter

   The same request with an adapter_id loads that adapter just-in-time and serves the request against it.

```bash
curl 127.0.0.1:8080/generate \
    -X POST \
    -d '{"inputs": "[INST] Your prompt here [/INST]", "parameters": {"max_new_tokens": 64, "adapter_id": "vineetsharma/qlora-adapter-Mistral-7B-Instruct-v0.1-gsm8k"}}' \
    -H 'Content-Type: application/json'
```

4. Use the Python client

   The client mirrors the REST API, with adapter_id as a per-call argument.

```bash
pip install lorax-client
```

5. Call it from Python

   Point the client at the server and pass adapter_id to route a call to a specific fine-tune.

```python
from lorax import Client

client = Client("http://127.0.0.1:8080")
prompt = "[INST] Your prompt here [/INST]"

print(client.generate(prompt, max_new_tokens=64).generated_text)

adapter_id = "vineetsharma/qlora-adapter-Mistral-7B-Instruct-v0.1-gsm8k"
print(client.generate(prompt, max_new_tokens=64, adapter_id=adapter_id).generated_text)
```

## When to use it

- Reach for it when you have many per-customer or per-task fine-tunes of one base model and a GPU each is unaffordable
- Reach for it to A/B several adapters in production without redeploying a server for each
- Reach for it when adapters need to be private per tenant but share the same serving fleet
- Reach for it to merge adapters per request and test ensembles before committing to a merged checkpoint
