vllm-setup.md 6.19 KB
Newer Older
Ryan Olson's avatar
Ryan Olson committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!--
SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# Running KVBM in vLLM

20
This guide explains how to leverage KVBM (KV Block Manager) to manage KV cache and do KV offloading in vLLM.
Ryan Olson's avatar
Ryan Olson committed
21

22
To learn what KVBM is, please check [here](kvbm_architecture.md)
Ryan Olson's avatar
Ryan Olson committed
23
24
25
26
27

## Quick Start

To use KVBM in vLLM, you can follow the steps below:

28
### Docker Setup
Ryan Olson's avatar
Ryan Olson committed
29
```bash
30
# Start up etcd for KVBM leader/worker registration and discovery
ZichengMa's avatar
ZichengMa committed
31
docker compose -f deploy/docker-compose.yml up -d
Ryan Olson's avatar
Ryan Olson committed
32

33
34
# Build a dynamo vLLM container (KVBM is built in by default)
./container/build.sh --framework vllm
Ryan Olson's avatar
Ryan Olson committed
35

36
# Launch the container
jthomson04's avatar
jthomson04 committed
37
./container/run.sh --framework vllm -it --mount-workspace --use-nixl-gds
38
```
Ryan Olson's avatar
Ryan Olson committed
39

40
41
### Aggregated Serving with KVBM
```bash
42
cd $DYNAMO_HOME/examples/backends/vllm
43
44
./launch/agg_kvbm.sh
```
Ryan Olson's avatar
Ryan Olson committed
45

46
### Disaggregated Serving with KVBM
47
```bash
48
# 1P1D - one prefill worker and one decode worker
49
# NOTE: need at least 2 GPUs
50
cd $DYNAMO_HOME/examples/backends/vllm
51
./launch/disagg_kvbm.sh
52
53
54

# 2P2D - two prefill workers and two decode workers
# NOTE: need at least 4 GPUs
55
cd $DYNAMO_HOME/examples/backends/vllm
56
./launch/disagg_kvbm_2p2d.sh
57
```
58

59
> [!NOTE]
60
> Configure or tune KVBM cache tiers (choose one of the following options):
61
62
63
64
65
66
67
68
69
70
71
> ```bash
> # Option 1: CPU cache only (GPU -> CPU offloading)
> # 4 means 4GB of pinned CPU memory would be used
> export DYN_KVBM_CPU_CACHE_GB=4
>
> # Option 2: Both CPU and Disk cache (GPU -> CPU -> Disk tiered offloading)
> export DYN_KVBM_CPU_CACHE_GB=4
> # 8 means 8GB of disk would be used
> export DYN_KVBM_DISK_CACHE_GB=8
>
> # [Experimental] Option 3: Disk cache only (GPU -> Disk direct offloading, bypassing CPU)
72
> # NOTE: this option is only experimental and it might not give out the best performance.
73
74
75
76
77
78
> # NOTE: disk offload filtering is not support when using this option.
> export DYN_KVBM_DISK_CACHE_GB=8
> ```
>
> You can also use "DYN_KVBM_CPU_CACHE_OVERRIDE_NUM_BLOCKS" or
> "DYN_KVBM_DISK_CACHE_OVERRIDE_NUM_BLOCKS" to specify exact block counts instead of GB
Ryan Olson's avatar
Ryan Olson committed
79

80
81
82
83
84
> [!NOTE]
> When disk offloading is enabled, to extend SSD lifespan, disk offload filtering would be enabled by default. The current policy is only offloading KV blocks from CPU to disk if the blocks have frequency equal or more than `2`. Frequency is determined via doubling on cache hit (init with 1) and decrement by 1 on each time decay step.
>
> To disable disk offload filtering, set `DYN_KVBM_DISABLE_DISK_OFFLOAD_FILTER` to true or 1.

85
86
### Sample Request
```bash
87
# Make a request to verify vLLM with KVBM is started up correctly
88
# NOTE: change the model name if served with a different one
Ryan Olson's avatar
Ryan Olson committed
89
curl localhost:8000/v1/chat/completions   -H "Content-Type: application/json"   -d '{
90
    "model": "Qwen/Qwen3-0.6B",
Ryan Olson's avatar
Ryan Olson committed
91
92
93
94
95
96
97
    "messages": [
    {
        "role": "user",
        "content": "In the heart of Eldoria, an ancient land of boundless magic and mysterious creatures, lies the long-forgotten city of Aeloria. Once a beacon of knowledge and power, Aeloria was buried beneath the shifting sands of time, lost to the world for centuries. You are an intrepid explorer, known for your unparalleled curiosity and courage, who has stumbled upon an ancient map hinting at ests that Aeloria holds a secret so profound that it has the potential to reshape the very fabric of reality. Your journey will take you through treacherous deserts, enchanted forests, and across perilous mountain ranges. Your Task: Character Background: Develop a detailed background for your character. Describe their motivations for seeking out Aeloria, their skills and weaknesses, and any personal connections to the ancient city or its legends. Are they driven by a quest for knowledge, a search for lost familt clue is hidden."
    }
    ],
    "stream":false,
98
    "max_tokens": 10
Ryan Olson's avatar
Ryan Olson committed
99
100
  }'
```
101

102
Alternatively, can use `vllm serve` directly to use KVBM for aggregated serving:
103
```bash
Richard Huo's avatar
Richard Huo committed
104
vllm serve --kv-transfer-config '{"kv_connector":"DynamoConnector","kv_role":"kv_both", "kv_connector_module_path": "kvbm.vllm_integration.connector"}' Qwen/Qwen3-0.6B
105
106
```

107
108
109
110
111
112
113
## Enable and View KVBM Metrics

Follow below steps to enable metrics collection and view via Grafana dashboard:
```bash
# Start the basic services (etcd & natsd), along with Prometheus and Grafana
docker compose -f deploy/docker-compose.yml --profile metrics up -d

114
# Set env var DYN_KVBM_METRICS to true, when launch via dynamo
115
# Optionally set DYN_KVBM_METRICS_PORT to choose the /metrics port (default: 6880).
116
# NOTE: update launch/disagg_kvbm.sh or launch/disagg_kvbm_2p2d.sh as needed
117
DYN_KVBM_METRICS=true \
118
python -m dynamo.vllm \
119
120
    --model Qwen/Qwen3-0.6B \
    --enforce-eager \
121
    --connector kvbm
122

123
# Optional, if firewall blocks KVBM metrics ports to send prometheus metrics
124
sudo ufw allow 6880/tcp
125
126
127
```

View grafana metrics via http://localhost:3001 (default login: dynamo/dynamo) and look for KVBM Dashboard
128
129
130

## Benchmark KVBM

131
Once the model is loaded ready, follow below steps to use LMBenchmark to benchmark KVBM performance:
132
133
134
```bash
git clone https://github.com/LMCache/LMBenchmark.git

135
136
# Show case of running the synthetic multi-turn chat dataset.
# We are passing model, endpoint, output file prefix and qps to the sh script.
137
138
cd LMBenchmark/synthetic-multi-round-qa
./long_input_short_output_run.sh \
139
    "Qwen/Qwen3-0.6B" \
140
141
142
143
144
145
146
147
148
149
    "http://localhost:8000" \
    "benchmark_kvbm" \
    1

# Average TTFT and other perf numbers would be in the output from above cmd
```
More details about how to use LMBenchmark could be found [here](https://github.com/LMCache/LMBenchmark).

`NOTE`: if metrics are enabled as mentioned in the above section, you can observe KV offloading, and KV onboarding in the grafana dashboard.

150
To compare, you can run `vllm serve Qwen/Qwen3-0.6B` to turn KVBM off as the baseline.