main
md 80 lines 2.76 KB
Rendered Raw
1 # LMCache Examples
2
3 This folder demonstrates how to use LMCache with vLLM v1 for KV cache
4 offloading, disaggregated prefilling, and KV cache sharing.
5
6 ## Integration modes
7
8 LMCache integrates with vLLM v1 in two ways:
9
10 - **In-process mode** (`LMCacheConnectorV1`): LMCache runs inside the vLLM
11 process and is configured through environment variables or a YAML config
12 file (`LMCACHE_CONFIG_FILE`). This is the simplest way to add single-node
13 CPU/disk offloading.
14 - **Multi-process (MP) mode** (`LMCacheMPConnector`): LMCache runs as a
15 standalone server (`lmcache server`) that owns the KV cache storage; one or
16 more vLLM instances connect to it. This is the recommended mode for
17 distributed KV storage and for sharing KV cache across instances. See the
18 [LMCache docs](https://docs.lmcache.ai) for the full MP setup.
19
20 ## 1. CPU offload (in-process)
21
22 - `python cpu_offload_lmcache.py` - CPU offloading with `LMCacheConnectorV1`
23 for vLLM v1.
24
25 ## 2. CPU offload (multi-process)
26
27 - `bash cpu_offload_lmcache_mp.sh` - CPU offloading with `LMCacheMPConnector`,
28 using a standalone `lmcache server`. vLLM provides a built-in shortcut for
29 this setup via `--kv-offloading-backend lmcache` and
30 `--kv-offloading-size <GiB>`.
31
32 ## 3. Disaggregated Prefill in vLLM v1
33
34 This example demonstrates how to run LMCache with disaggregated prefill using
35 NIXL on a single node.
36
37 ### Prerequisites
38
39 - Install [LMCache](https://github.com/LMCache/LMCache). You can simply run `pip install lmcache`.
40 - Install [NIXL](https://github.com/ai-dynamo/nixl).
41 - At least 2 GPUs
42 - Valid Hugging Face token (HF_TOKEN) for Llama 3.1 8B Instruct.
43
44 ### Usage
45
46 Run
47 `cd disagg_prefill_lmcache_v1`
48 to get into `disagg_prefill_lmcache_v1` folder, and then run
49
50 ```bash
51 bash disagg_example_nixl.sh
52 ```
53
54 to run disaggregated prefill and benchmark the performance.
55
56 ### Components
57
58 #### Server Scripts
59
60 - `disagg_prefill_lmcache_v1/disagg_vllm_launcher.sh` - Launches individual vLLM servers for prefill/decode, and also launches the proxy server.
61 - `disagg_prefill_lmcache_v1/disagg_proxy_server.py` - FastAPI proxy server that coordinates between prefiller and decoder
62 - `disagg_prefill_lmcache_v1/disagg_example_nixl.sh` - Main script to run the example
63
64 #### Configuration
65
66 - `disagg_prefill_lmcache_v1/configs/lmcache-prefiller-config.yaml` - Configuration for prefiller server
67 - `disagg_prefill_lmcache_v1/configs/lmcache-decoder-config.yaml` - Configuration for decoder server
68
69 #### Log Files
70
71 The main script generates several log files:
72
73 - `prefiller.log` - Logs from the prefill server
74 - `decoder.log` - Logs from the decode server
75 - `proxy.log` - Logs from the proxy server
76
77 ## 4. KV Cache Sharing
78
79 The `kv_cache_sharing_lmcache_v1.py` example demonstrates how to share KV
80 caches between vLLM v1 instances through a centralized LMCache server.