README.md 6.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Multimodal LoRA Serving Guide

Serve vision-language models (VLMs) with dynamically loadable LoRA adapters using Dynamo's aggregated architecture.

## Prerequisites

- **GPU**: NVIDIA GPU with sufficient VRAM (8 GB+ for 2B models, 24 GB+ for 7B models)
- **Dynamo**: Installed with vLLM support (`pip install dynamo[vllm]`)
- **jq** (optional, for pretty JSON output): `sudo apt install jq`
- **hf CLI** (optional, for downloading adapters): `pip install huggingface-hub`

## Quick Start

### 1. Launch the server

```bash
17
cd examples/backends/vllm/launch/lora/multimodal
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
./lora_agg.sh
```

This starts the frontend (port 8000) and vLLM worker (port 8081) with `Qwen/Qwen3-VL-2B-Instruct` as the base model.

Wait for both services to report ready in the logs (look for `Application startup complete`).

### 2. Verify the server is running

```bash
curl http://localhost:8000/v1/models | jq .
```

You should see the base model listed.

### 3. Download a LoRA adapter

Download a compatible vision LoRA to your local filesystem:

```bash
export HF_TOKEN=<your-huggingface-token>

hf download Chhagan005/Chhagan-DocVL-Qwen3 --local-dir /tmp/my-vlm-lora
```

### 4. Load the LoRA adapter

```bash
curl -s -X POST http://localhost:8081/v1/loras \
  -H "Content-Type: application/json" \
  -d '{
    "lora_name": "my-vlm-lora",
    "source": {"uri": "file:///tmp/my-vlm-lora"}
  }' | jq .
```

Expected response:
```json
{
  "status": "success",
  "message": "LoRA adapter 'my-vlm-lora' loaded successfully",
  "lora_name": "my-vlm-lora",
  "lora_id": 1207343256
}
```

### 5. Run inference with the LoRA adapter

```bash
curl -X POST http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "my-vlm-lora",
    "messages": [{"role": "user", "content": [
      {"type": "text", "text": "Describe this image in detail"},
      {"type": "image_url", "image_url": {"url": "https://vllm-public-assets.s3.us-west-2.amazonaws.com/vision_model_images/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"}}
    ]}],
    "max_tokens": 300,
    "temperature": 0.0
  }' | jq .
```

### 6. Compare with the base model

```bash
curl -X POST http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "Qwen/Qwen3-VL-2B-Instruct",
    "messages": [{"role": "user", "content": [
      {"type": "text", "text": "Describe this image in detail"},
      {"type": "image_url", "image_url": {"url": "https://vllm-public-assets.s3.us-west-2.amazonaws.com/vision_model_images/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"}}
    ]}],
    "max_tokens": 300,
    "temperature": 0.0
  }' | jq .
```

### 7. Unload the LoRA adapter

```bash
curl -X DELETE http://localhost:8081/v1/loras/my-vlm-lora | jq .
```

### 8. Stop the server

Press `Ctrl+C` in the terminal running `lora_agg.sh`. The trap handler will clean up child processes.

## Configuration

### Command-line options

```bash
./lora_agg.sh --model llava-hf/llava-1.5-7b-hf            # Use a different base model
./lora_agg.sh -- --enforce-eager                            # Pass extra vLLM args
./lora_agg.sh -- --mm-processor-kwargs '{"max_pixels": 1003520}'  # Cap image resolution
```

### Environment variables

| Variable | Default | Description |
|---|---|---|
| `DYN_MODEL_NAME` | `Qwen/Qwen3-VL-2B-Instruct` | Base VLM model |
| `DYN_HTTP_PORT` | `8000` | Frontend HTTP port |
| `DYN_SYSTEM_PORT` | `8081` | Worker system/admin port |
| `DYN_LORA_PATH` | `/tmp/dynamo_loras_multimodal` | Local LoRA adapter cache |
| `DYN_MAX_LORA_RANK` | `64` | Maximum LoRA rank supported |
| `CUDA_VISIBLE_DEVICES` | `0` | GPU device index |

### base models supported by this script

| Model | Notes |
|---|---|
| `Qwen/Qwen3-VL-2B-Instruct` | Default. Good for single-GPU testing. |
| `Qwen/Qwen2.5-VL-7B-Instruct` | Higher quality, needs 24 GB+ VRAM. |
| `llava-hf/llava-1.5-7b-hf` | LLaVA architecture, 4096 max context. |

## LoRA Management API

All management endpoints are served on the system port (default 8081).

### Load a LoRA

```
POST /v1/loras
```

```json
{
  "lora_name": "my-adapter",
  "source": {
    "uri": "file:///path/to/adapter"
  }
}
```

Supported URI schemes:
- `file://` — local filesystem path
- `s3://` — S3-compatible storage (requires `AWS_ENDPOINT`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`)

### List loaded LoRAs

```
GET /v1/loras
```

### Unload a LoRA

```
DELETE /v1/loras/{lora_name}
```

### List all models (base + LoRAs)

```
GET /v1/models        (on the frontend port, default 8000)
```

## Running the validation script

A validation script is provided to test the LoRA endpoints against a running server:

```bash
# Start the server in one terminal
./lora_agg.sh

# In another terminal, download a LoRA adapter
hf download Chhagan005/Chhagan-DocVL-Qwen3 --local-dir /tmp/my-vlm-lora

# Run the full test suite (with end-to-end LoRA load/infer/unload)
./validate_lora_agg.sh --lora-path /tmp/my-vlm-lora

# Or run only the error-handling and base-model tests (no adapter needed)
./validate_lora_agg.sh
```

The validation script covers:
- Frontend health and base model discovery
- LoRA load/unload error handling (missing fields, non-existent adapter)
- End-to-end LoRA lifecycle: load, verify in `/v1/models`, infer, unload (when `--lora-path` provided)
- Base model multimodal inference

## Troubleshooting

### Frontend fails to start
- Check if port 8000 is already in use: `lsof -i :8000`
- Set a different port: `DYN_HTTP_PORT=8001 ./lora_agg.sh`

### OOM during inference
- Reduce `--max-model-len` via extra args: `./lora_agg.sh -- --max-model-len 4096`
- Cap image resolution: `./lora_agg.sh -- --mm-processor-kwargs '{"max_pixels": 1003520}'`
- Lower GPU memory utilization: `./lora_agg.sh -- --gpu-memory-utilization 0.80`

### LoRA fails to load
- Verify the adapter path exists and contains `adapter_config.json` and `adapter_model.safetensors`
- Ensure the adapter is compatible with the base model architecture
- Check that `max-lora-rank` (default 64) is >= the adapter's rank
- Review worker logs for detailed error messages

### Inference returns errors after loading LoRA
- Verify the LoRA is loaded: `curl http://localhost:8081/v1/loras | jq .`
- Confirm the model name in the request matches the `lora_name` exactly (case-sensitive)
- Check that the adapter was trained for the same base model

### Cache issues
- Inspect the cache: `ls -la /tmp/dynamo_loras_multimodal/`
- Clear the cache: `rm -rf /tmp/dynamo_loras_multimodal/*`

## Cleanup

```bash
# Remove LoRA cache
rm -rf /tmp/dynamo_loras_multimodal

# Remove downloaded adapter
rm -rf /tmp/my-vlm-lora
```