hypercache-lmcache-native 0.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hypercache_lmcache_native-0.10.0/Cargo.lock +265 -0
- hypercache_lmcache_native-0.10.0/Cargo.toml +24 -0
- hypercache_lmcache_native-0.10.0/PKG-INFO +195 -0
- hypercache_lmcache_native-0.10.0/README.md +173 -0
- hypercache_lmcache_native-0.10.0/pyproject.toml +34 -0
- hypercache_lmcache_native-0.10.0/rustfmt.toml +1 -0
- hypercache_lmcache_native-0.10.0/src/connector.rs +1448 -0
- hypercache_lmcache_native-0.10.0/src/daemon.rs +488 -0
- hypercache_lmcache_native-0.10.0/src/io.rs +634 -0
- hypercache_lmcache_native-0.10.0/src/key.rs +118 -0
- hypercache_lmcache_native-0.10.0/src/lib.rs +13 -0
- hypercache_lmcache_native-0.10.0/src/python.rs +242 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "autocfg"
|
|
7
|
+
version = "1.5.1"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "cfg-if"
|
|
13
|
+
version = "1.0.5"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "crc32fast"
|
|
19
|
+
version = "1.5.4"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "5f97d3416d5337d15c4b0d78c8c91df922ca143f57ec20e2d1c188333047ef04"
|
|
22
|
+
dependencies = [
|
|
23
|
+
"cfg-if",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[[package]]
|
|
27
|
+
name = "heck"
|
|
28
|
+
version = "0.5.0"
|
|
29
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
30
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
31
|
+
|
|
32
|
+
[[package]]
|
|
33
|
+
name = "hypercache-lmcache-connector"
|
|
34
|
+
version = "0.10.0"
|
|
35
|
+
dependencies = [
|
|
36
|
+
"crc32fast",
|
|
37
|
+
"libc",
|
|
38
|
+
"pyo3",
|
|
39
|
+
"serde",
|
|
40
|
+
"serde_json",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[[package]]
|
|
44
|
+
name = "indoc"
|
|
45
|
+
version = "2.0.8"
|
|
46
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
47
|
+
checksum = "a37b2691796cffeb8a8cd305ac66e65841559f147f4e63231d0eafa4db5384d1"
|
|
48
|
+
dependencies = [
|
|
49
|
+
"rustversion",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[[package]]
|
|
53
|
+
name = "itoa"
|
|
54
|
+
version = "1.0.18"
|
|
55
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
+
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
|
57
|
+
|
|
58
|
+
[[package]]
|
|
59
|
+
name = "libc"
|
|
60
|
+
version = "0.2.191"
|
|
61
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
62
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
63
|
+
|
|
64
|
+
[[package]]
|
|
65
|
+
name = "memchr"
|
|
66
|
+
version = "2.8.3"
|
|
67
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
68
|
+
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
69
|
+
|
|
70
|
+
[[package]]
|
|
71
|
+
name = "memoffset"
|
|
72
|
+
version = "0.9.1"
|
|
73
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
74
|
+
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
|
|
75
|
+
dependencies = [
|
|
76
|
+
"autocfg",
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[[package]]
|
|
80
|
+
name = "once_cell"
|
|
81
|
+
version = "1.21.4"
|
|
82
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
83
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
84
|
+
|
|
85
|
+
[[package]]
|
|
86
|
+
name = "portable-atomic"
|
|
87
|
+
version = "1.15.0"
|
|
88
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
89
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
90
|
+
|
|
91
|
+
[[package]]
|
|
92
|
+
name = "proc-macro2"
|
|
93
|
+
version = "1.0.107"
|
|
94
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
95
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
96
|
+
dependencies = [
|
|
97
|
+
"unicode-ident",
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
[[package]]
|
|
101
|
+
name = "pyo3"
|
|
102
|
+
version = "0.24.2"
|
|
103
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
104
|
+
checksum = "e5203598f366b11a02b13aa20cab591229ff0a89fd121a308a5df751d5fc9219"
|
|
105
|
+
dependencies = [
|
|
106
|
+
"cfg-if",
|
|
107
|
+
"indoc",
|
|
108
|
+
"libc",
|
|
109
|
+
"memoffset",
|
|
110
|
+
"once_cell",
|
|
111
|
+
"portable-atomic",
|
|
112
|
+
"pyo3-build-config",
|
|
113
|
+
"pyo3-ffi",
|
|
114
|
+
"pyo3-macros",
|
|
115
|
+
"unindent",
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
[[package]]
|
|
119
|
+
name = "pyo3-build-config"
|
|
120
|
+
version = "0.24.2"
|
|
121
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
122
|
+
checksum = "99636d423fa2ca130fa5acde3059308006d46f98caac629418e53f7ebb1e9999"
|
|
123
|
+
dependencies = [
|
|
124
|
+
"once_cell",
|
|
125
|
+
"target-lexicon",
|
|
126
|
+
]
|
|
127
|
+
|
|
128
|
+
[[package]]
|
|
129
|
+
name = "pyo3-ffi"
|
|
130
|
+
version = "0.24.2"
|
|
131
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
132
|
+
checksum = "78f9cf92ba9c409279bc3305b5409d90db2d2c22392d443a87df3a1adad59e33"
|
|
133
|
+
dependencies = [
|
|
134
|
+
"libc",
|
|
135
|
+
"pyo3-build-config",
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
[[package]]
|
|
139
|
+
name = "pyo3-macros"
|
|
140
|
+
version = "0.24.2"
|
|
141
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
142
|
+
checksum = "0b999cb1a6ce21f9a6b147dcf1be9ffedf02e0043aec74dc390f3007047cecd9"
|
|
143
|
+
dependencies = [
|
|
144
|
+
"proc-macro2",
|
|
145
|
+
"pyo3-macros-backend",
|
|
146
|
+
"quote",
|
|
147
|
+
"syn 2.0.119",
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
[[package]]
|
|
151
|
+
name = "pyo3-macros-backend"
|
|
152
|
+
version = "0.24.2"
|
|
153
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
154
|
+
checksum = "822ece1c7e1012745607d5cf0bcb2874769f0f7cb34c4cde03b9358eb9ef911a"
|
|
155
|
+
dependencies = [
|
|
156
|
+
"heck",
|
|
157
|
+
"proc-macro2",
|
|
158
|
+
"pyo3-build-config",
|
|
159
|
+
"quote",
|
|
160
|
+
"syn 2.0.119",
|
|
161
|
+
]
|
|
162
|
+
|
|
163
|
+
[[package]]
|
|
164
|
+
name = "quote"
|
|
165
|
+
version = "1.0.47"
|
|
166
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
167
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
168
|
+
dependencies = [
|
|
169
|
+
"proc-macro2",
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
[[package]]
|
|
173
|
+
name = "rustversion"
|
|
174
|
+
version = "1.0.23"
|
|
175
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
176
|
+
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
|
177
|
+
|
|
178
|
+
[[package]]
|
|
179
|
+
name = "serde"
|
|
180
|
+
version = "1.0.229"
|
|
181
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
182
|
+
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
|
183
|
+
dependencies = [
|
|
184
|
+
"serde_core",
|
|
185
|
+
"serde_derive",
|
|
186
|
+
]
|
|
187
|
+
|
|
188
|
+
[[package]]
|
|
189
|
+
name = "serde_core"
|
|
190
|
+
version = "1.0.229"
|
|
191
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
192
|
+
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
|
193
|
+
dependencies = [
|
|
194
|
+
"serde_derive",
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
[[package]]
|
|
198
|
+
name = "serde_derive"
|
|
199
|
+
version = "1.0.229"
|
|
200
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
201
|
+
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
|
202
|
+
dependencies = [
|
|
203
|
+
"proc-macro2",
|
|
204
|
+
"quote",
|
|
205
|
+
"syn 3.0.9",
|
|
206
|
+
]
|
|
207
|
+
|
|
208
|
+
[[package]]
|
|
209
|
+
name = "serde_json"
|
|
210
|
+
version = "1.0.154"
|
|
211
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
212
|
+
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
|
213
|
+
dependencies = [
|
|
214
|
+
"itoa",
|
|
215
|
+
"memchr",
|
|
216
|
+
"serde",
|
|
217
|
+
"serde_core",
|
|
218
|
+
"zmij",
|
|
219
|
+
]
|
|
220
|
+
|
|
221
|
+
[[package]]
|
|
222
|
+
name = "syn"
|
|
223
|
+
version = "2.0.119"
|
|
224
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
225
|
+
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
|
226
|
+
dependencies = [
|
|
227
|
+
"proc-macro2",
|
|
228
|
+
"quote",
|
|
229
|
+
"unicode-ident",
|
|
230
|
+
]
|
|
231
|
+
|
|
232
|
+
[[package]]
|
|
233
|
+
name = "syn"
|
|
234
|
+
version = "3.0.9"
|
|
235
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
236
|
+
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
|
|
237
|
+
dependencies = [
|
|
238
|
+
"proc-macro2",
|
|
239
|
+
"quote",
|
|
240
|
+
"unicode-ident",
|
|
241
|
+
]
|
|
242
|
+
|
|
243
|
+
[[package]]
|
|
244
|
+
name = "target-lexicon"
|
|
245
|
+
version = "0.13.5"
|
|
246
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
247
|
+
checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
|
|
248
|
+
|
|
249
|
+
[[package]]
|
|
250
|
+
name = "unicode-ident"
|
|
251
|
+
version = "1.0.27"
|
|
252
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
253
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
254
|
+
|
|
255
|
+
[[package]]
|
|
256
|
+
name = "unindent"
|
|
257
|
+
version = "0.2.4"
|
|
258
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
259
|
+
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
|
260
|
+
|
|
261
|
+
[[package]]
|
|
262
|
+
name = "zmij"
|
|
263
|
+
version = "1.0.23"
|
|
264
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
265
|
+
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "hypercache-lmcache-connector"
|
|
3
|
+
version = "0.10.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
license = "Apache-2.0"
|
|
6
|
+
description = "LMCache native L2 connector backed by the HyperCache daemon"
|
|
7
|
+
publish = false
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
|
|
10
|
+
[lib]
|
|
11
|
+
name = "hypercache_lmcache_native"
|
|
12
|
+
crate-type = ["cdylib", "rlib"]
|
|
13
|
+
|
|
14
|
+
[features]
|
|
15
|
+
# Plain `cargo test` builds without Python, so the tests need no interpreter or LMCache.
|
|
16
|
+
python = ["dep:pyo3"]
|
|
17
|
+
extension-module = ["python", "pyo3/extension-module"]
|
|
18
|
+
|
|
19
|
+
[dependencies]
|
|
20
|
+
crc32fast = "1"
|
|
21
|
+
libc = "0.2"
|
|
22
|
+
pyo3 = { version = "0.24", optional = true }
|
|
23
|
+
serde = { version = "1", features = ["derive"] }
|
|
24
|
+
serde_json = "1"
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hypercache-lmcache-native
|
|
3
|
+
Version: 0.10.0
|
|
4
|
+
Classifier: Development Status :: 4 - Beta
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
7
|
+
Classifier: Programming Language :: Rust
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Summary: LMCache native L2 connector backed by the HyperCache daemon
|
|
13
|
+
Keywords: lmcache,vllm,kv-cache,nvme,hypercache
|
|
14
|
+
Author: Looe Labs
|
|
15
|
+
License: Apache-2.0
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
18
|
+
Project-URL: Documentation, https://github.com/looelabs/hypercache/blob/main/lmcache-connector/README.md
|
|
19
|
+
Project-URL: Homepage, https://github.com/looelabs/hypercache
|
|
20
|
+
Project-URL: Issues, https://github.com/looelabs/hypercache/issues
|
|
21
|
+
|
|
22
|
+
# HyperCache connector for LMCache (Rust)
|
|
23
|
+
|
|
24
|
+
Lets an LMCache MP-mode server keep KV-cache chunks on HyperCache's NVMe and RAM tiers. LMCache loads it through its `native_plugin` adapter type. Below LMCache's own wrapper, all the work runs in Rust worker threads without the Python interpreter lock.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
From PyPI, in the environment that runs the LMCache server (Linux x86_64, CPython 3.10 to 3.13), from the first HyperCache release that publishes it:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pip install hypercache-lmcache-native
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Use the same version as the HyperCache daemon; the two are released together.
|
|
35
|
+
|
|
36
|
+
## Build
|
|
37
|
+
|
|
38
|
+
To build it yourself, you need a Rust toolchain and maturin. Build against the Python that runs LMCache:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
cd lmcache-connector
|
|
42
|
+
maturin build --release -i python3.12
|
|
43
|
+
pip install target/wheels/hypercache_lmcache_native-*.whl
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick start with vLLM
|
|
47
|
+
|
|
48
|
+
This is the setup the vLLM results (`benchmarks/results/lmcache_rust_connector_vllm.md`) ran with: vLLM 0.33.0, LMCache 0.5.7.post1 in multiprocess (MP) mode, and HyperCache on one NVMe drive. In MP mode, vLLM sends KV cache to a separate LMCache server process. That server keeps it in memory (L1) and hands it to this connector (L2), which stores it on the drive through the HyperCache daemon.
|
|
49
|
+
|
|
50
|
+
**1. Start the daemon on a dedicated drive.** The daemon writes to the raw device, so use a drive with nothing on it: no filesystem, not mounted. Save as `kv.toml`:
|
|
51
|
+
|
|
52
|
+
```toml
|
|
53
|
+
device_discovery_mode = "manual"
|
|
54
|
+
block_devices = ["/dev/nvme1n1"]
|
|
55
|
+
include_partitions = false
|
|
56
|
+
exclude_root_device = true
|
|
57
|
+
storage_backing_mode = "raw_block"
|
|
58
|
+
chunk_size_bytes = 4194304
|
|
59
|
+
device_start_offset_bytes = 4096
|
|
60
|
+
metadata_persistence_enabled = true # keep the KV cache across daemon restarts
|
|
61
|
+
agent_enabled = false
|
|
62
|
+
metrics_enabled = false
|
|
63
|
+
ram_cache_enabled = false
|
|
64
|
+
# KV blocks are local-only and never flushed. The backend defaults to S3, so point it at an
|
|
65
|
+
# address that answers nothing: nothing can then be uploaded by mistake.
|
|
66
|
+
authoritative_backend = "s3"
|
|
67
|
+
s3_endpoint = "http://127.0.0.1:9"
|
|
68
|
+
s3_region = "us-east-1"
|
|
69
|
+
s3_bucket = "unused"
|
|
70
|
+
allow_synthetic_s3_fallback = false
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
sudo hypercache -c kv.toml start # socket: /run/hypercache/hypercache.sock
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**2. Install LMCache and the connector where the LMCache server runs.** Use LMCache 0.5.7.post1. The `vllm/vllm-openai:v0.33.0` image ships 0.5.6, whose GPU kernels don't load there (see below), so install 0.5.7.post1 over it. Install the connector as in [Install](#install), then check the kernels:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
pip install "lmcache==0.5.7.post1"
|
|
81
|
+
pip install hypercache-lmcache-native
|
|
82
|
+
python3 -c "import hypercache_lmcache_native as h; print(h.check_lmcache_gpu_ops())" # must print None
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**3. Start the LMCache server with the connector as its L2.** Pick a `namespace` that names the model and its revision (see [Use](#use)):
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
lmcache server --host 127.0.0.1 --port 18555 --l1-size-gb 6 --eviction-policy LRU --chunk-size 256 \
|
|
89
|
+
--l2-adapter '{"type": "native_plugin", "module_path": "hypercache_lmcache_native",
|
|
90
|
+
"class_name": "HyperCacheNativeConnector", "max_capacity_gb": 0,
|
|
91
|
+
"adapter_params": {"namespace": "qwen2.5-7b-awq-b250375", "tier": "nvme"}}'
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**4. Start vLLM pointed at that server:**
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
vllm serve Qwen/Qwen2.5-7B-Instruct-AWQ --kv-transfer-config \
|
|
98
|
+
'{"kv_connector": "LMCacheMPConnector", "kv_role": "kv_both",
|
|
99
|
+
"kv_connector_extra_config": {"lmcache.mp.host": "127.0.0.1", "lmcache.mp.port": 18555}}'
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**5. Check it works.** Send the same long prompt twice: the second first-token time should drop sharply. Then restart the LMCache server and vLLM, leave the daemon running, and send it again. LMCache's `Prefetch request completed` log line should count the keys as L2, which means they came from the drive. `scripts/e2e/lmcache_vllm_e2e.py` automates this and compares the answers. The connector prints any store or checksum failure to the LMCache server's stderr.
|
|
103
|
+
|
|
104
|
+
**In containers:** the LMCache server's container needs the daemon's socket directory mounted (`-v /run/hypercache:/run/hypercache`) and the drive itself (`--device /dev/nvme1n1`), because the connector reads and writes the drive directly. Without `--device`, every store fails and LMCache quietly runs on L1 alone, so check its log for failed L2 stores. With `tier: "ram"`, it needs the host's `/dev/shm` instead.
|
|
105
|
+
|
|
106
|
+
**Troubleshooting:**
|
|
107
|
+
|
|
108
|
+
| Symptom | Cause |
|
|
109
|
+
|---|---|
|
|
110
|
+
| Every store fails with "no local-only commit support" | The daemon is older than the connector. Upgrade the daemon. |
|
|
111
|
+
| Every store fails with a permission or "No such file" error on the drive | The process can't open the drive: add `--device`, or add its user to the daemon's `client_gid`. |
|
|
112
|
+
| Warning "cuda_ops compiled extension not found" | LMCache doesn't match the installed torch. Its fallback can store wrong KV data: fix the install, then change `namespace`. |
|
|
113
|
+
| Hits but no speedup after a restart | L1 is too small for the load to fit (LMCache only evicts L1 down to 80%), or the prompt is shorter than one 256-token chunk. |
|
|
114
|
+
|
|
115
|
+
## Use
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"type": "native_plugin",
|
|
120
|
+
"module_path": "hypercache_lmcache_native",
|
|
121
|
+
"class_name": "HyperCacheNativeConnector",
|
|
122
|
+
"adapter_params": {
|
|
123
|
+
"namespace": "qwen2.5-7b-awq-rev1234",
|
|
124
|
+
"socket_path": "/run/hypercache/hypercache.sock",
|
|
125
|
+
"tier": "nvme",
|
|
126
|
+
"num_workers": 32
|
|
127
|
+
},
|
|
128
|
+
"max_capacity_gb": 0
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
| Setting | Meaning |
|
|
133
|
+
|---|---|
|
|
134
|
+
| `namespace` | Required. Must change when the model weights, dtype or engine settings change. LMCache's key has a model name but no revision, so without this a weight change could return wrong KV data. |
|
|
135
|
+
| `socket_path` | Daemon socket. Defaults to the same search order as the Python client. |
|
|
136
|
+
| `tier` | `nvme` (default) or `ram`. For `ram`, LMCache must share `/dev/shm` with the daemon. |
|
|
137
|
+
| `num_workers` | Objects read or written at once, per direction (default 32). Each object is read one chunk at a time, so this sets the queue depth. On one drive, 8 loaded fastest. On 4 drives, 32 did. |
|
|
138
|
+
| `timeout_s` | Daemon request timeout in seconds (default 30). Commits get at least 300. |
|
|
139
|
+
| `max_capacity_gb` | Keep at 0. The daemon owns capacity and evicts under pressure. |
|
|
140
|
+
|
|
141
|
+
## Check LMCache's GPU kernels first
|
|
142
|
+
|
|
143
|
+
LMCache copies KV data between the GPU and its memory tier with compiled kernels in `lmcache.cuda_ops`. If they don't load, LMCache falls back to plain torch ops and logs a single warning:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
lmcache.cuda_ops compiled extension not found; CudaDeviceOps stays on the torch baseline for all ops.
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
With that fallback, answers at temperature 0 changed after a cache hit on 24 or 25 of 25 test prompts, with or without HyperCache. LMCache [#6673](https://github.com/LMCache/LMCache/issues/6673) traces it to the fallback's copy not waiting for the GPU kernel that fills it, so a store can save stale KV data. HyperCache then keeps exactly those bytes, so **anything stored while the fallback was active may be wrong, and stays wrong after the fix**: change `namespace` once the kernels load. It happens in the `vllm/vllm-openai:v0.33.0` image, whose LMCache 0.5.6 was built for torch 2.13 while the image has 2.14. See `benchmarks/results/lmcache_rust_connector_xeon.md`.
|
|
150
|
+
|
|
151
|
+
Check before going live, in the environment that runs the LMCache server, with a GPU visible:
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
python3 -c "import hypercache_lmcache_native as h; print(h.check_lmcache_gpu_ops())"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
It prints `None` when the kernels load, and the reason when they don't. The connector runs the same check at startup and prints a warning to stderr on a problem. It does not stop LMCache from starting. Fix it with an LMCache build that matches the installed torch. vLLM 0.31.0 with LMCache 0.5.5 is a tested pair whose answers matched. In the vLLM 0.33.0 image, LMCache 0.5.7.post1 from PyPI loads its kernels, and with batch invariance cached answers matched cold answers on 25 of 25. The connector's safety and failure tests pass on 0.5.7.post1, and answers from KV loaded off the drive matched no-cache answers on 9 of 9 prompts (`benchmarks/results/lmcache_rust_connector_vllm.md`).
|
|
158
|
+
|
|
159
|
+
## What isn't supported
|
|
160
|
+
|
|
161
|
+
- `list_l2_keys` and LMCache's IsolatedLRU quotas.
|
|
162
|
+
- Versions other than LMCache 0.5.5, 0.5.6 and 0.5.7.post1, which are the ones tested. Nothing in the connector enforces that yet.
|
|
163
|
+
- A daemon without `local_only` commits. Stores fail before writing any data, and lookups miss.
|
|
164
|
+
|
|
165
|
+
## Behaviour
|
|
166
|
+
|
|
167
|
+
- Any doubt about a block is a miss. Lookup only accepts committed local-only blocks with a checksum for every chunk, and load verifies every chunk before reporting success.
|
|
168
|
+
- If the daemon restarts, the connector reconnects by itself. A request that couldn't be sent is resent once, and one the daemon may have received is never resent, so it reports a failure.
|
|
169
|
+
- Blocks are never flushed to a backend. Against an older daemon, stores fail before any data is written and lookups miss. Support is checked again on every new connection, because a restarted daemon may be a different version, and a commit only counts when the daemon confirms `LOCAL_ONLY`.
|
|
170
|
+
- A commit names the layout this connector staged, so if another writer replaced the block in between, the daemon refuses it and the store fails.
|
|
171
|
+
- Two stores of the same block in one process run one after the other, and each reports its real outcome. A block already stored counts only if its size and layout match.
|
|
172
|
+
- In a process forked from the one that opened the connector, closing it does nothing: the workers belong to the parent.
|
|
173
|
+
- A block that fails its checksum is evicted, unless it was replaced during the read.
|
|
174
|
+
- On raw block devices, writes use O_DIRECT. Page-aligned L1 buffers (`--l1-align-bytes 4096`) go to and from the drive with no copy. A partial last block goes through the page cache on writes and an aligned copy on reads.
|
|
175
|
+
|
|
176
|
+
## LMCache's wrapper
|
|
177
|
+
|
|
178
|
+
LMCache's `NativeConnectorL2Adapter` wrapper sits between LMCache and this connector, which leads to some behaviour worth knowing.
|
|
179
|
+
|
|
180
|
+
- **Locks.** The wrapper tracks lookup locks itself and doesn't check them before a delete, so a locked block can be deleted. The later load is a miss, never wrong data. LMCache only calls delete from global eviction, which `max_capacity_gb: 0` turns off.
|
|
181
|
+
- **Status.** `report_status` doesn't include this connector's counters. Checksum failures are logged to stderr, and `adapter._client.stats()` returns the counters.
|
|
182
|
+
- **Store accounting.** The wrapper counts bytes per key it hasn't seen in this process, so after a restart a store of an existing block reports its bytes even though nothing was written.
|
|
183
|
+
- **Partial store failures.** A store task with any failed key reports zero bytes, even if other keys in it were stored.
|
|
184
|
+
|
|
185
|
+
## Test
|
|
186
|
+
|
|
187
|
+
```sh
|
|
188
|
+
cargo test # no Python, LMCache or GPU needed
|
|
189
|
+
scripts/e2e/lmcache_l2_ci.sh --python python3 # 30 checks against real LMCache on a loop device
|
|
190
|
+
python3 scripts/e2e/lmcache_l2_e2e.py --socket /run/hypercache/hypercache.sock
|
|
191
|
+
python3 scripts/e2e/lmcache_vllm_e2e.py --fillers 40 # against a running vLLM + LMCache
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`lmcache_l2_ci.sh` needs LMCache, torch (CPU is fine) and the connector wheel installed for that Python, and sudo for `losetup`; CI runs it on every pull request. `lmcache_l2_e2e.py` runs the same checks against a daemon you already started, on a real device, and damages one stored chunk on purpose. `lmcache_vllm_e2e.py` checks that answers loaded from L2 match cold ones. Results are in `benchmarks/results/lmcache_rust_connector.md`, `lmcache_rust_connector_xeon.md` and `lmcache_rust_connector_nvme.md`.
|
|
195
|
+
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# HyperCache connector for LMCache (Rust)
|
|
2
|
+
|
|
3
|
+
Lets an LMCache MP-mode server keep KV-cache chunks on HyperCache's NVMe and RAM tiers. LMCache loads it through its `native_plugin` adapter type. Below LMCache's own wrapper, all the work runs in Rust worker threads without the Python interpreter lock.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
From PyPI, in the environment that runs the LMCache server (Linux x86_64, CPython 3.10 to 3.13), from the first HyperCache release that publishes it:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pip install hypercache-lmcache-native
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Use the same version as the HyperCache daemon; the two are released together.
|
|
14
|
+
|
|
15
|
+
## Build
|
|
16
|
+
|
|
17
|
+
To build it yourself, you need a Rust toolchain and maturin. Build against the Python that runs LMCache:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
cd lmcache-connector
|
|
21
|
+
maturin build --release -i python3.12
|
|
22
|
+
pip install target/wheels/hypercache_lmcache_native-*.whl
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick start with vLLM
|
|
26
|
+
|
|
27
|
+
This is the setup the vLLM results (`benchmarks/results/lmcache_rust_connector_vllm.md`) ran with: vLLM 0.33.0, LMCache 0.5.7.post1 in multiprocess (MP) mode, and HyperCache on one NVMe drive. In MP mode, vLLM sends KV cache to a separate LMCache server process. That server keeps it in memory (L1) and hands it to this connector (L2), which stores it on the drive through the HyperCache daemon.
|
|
28
|
+
|
|
29
|
+
**1. Start the daemon on a dedicated drive.** The daemon writes to the raw device, so use a drive with nothing on it: no filesystem, not mounted. Save as `kv.toml`:
|
|
30
|
+
|
|
31
|
+
```toml
|
|
32
|
+
device_discovery_mode = "manual"
|
|
33
|
+
block_devices = ["/dev/nvme1n1"]
|
|
34
|
+
include_partitions = false
|
|
35
|
+
exclude_root_device = true
|
|
36
|
+
storage_backing_mode = "raw_block"
|
|
37
|
+
chunk_size_bytes = 4194304
|
|
38
|
+
device_start_offset_bytes = 4096
|
|
39
|
+
metadata_persistence_enabled = true # keep the KV cache across daemon restarts
|
|
40
|
+
agent_enabled = false
|
|
41
|
+
metrics_enabled = false
|
|
42
|
+
ram_cache_enabled = false
|
|
43
|
+
# KV blocks are local-only and never flushed. The backend defaults to S3, so point it at an
|
|
44
|
+
# address that answers nothing: nothing can then be uploaded by mistake.
|
|
45
|
+
authoritative_backend = "s3"
|
|
46
|
+
s3_endpoint = "http://127.0.0.1:9"
|
|
47
|
+
s3_region = "us-east-1"
|
|
48
|
+
s3_bucket = "unused"
|
|
49
|
+
allow_synthetic_s3_fallback = false
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
sudo hypercache -c kv.toml start # socket: /run/hypercache/hypercache.sock
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**2. Install LMCache and the connector where the LMCache server runs.** Use LMCache 0.5.7.post1. The `vllm/vllm-openai:v0.33.0` image ships 0.5.6, whose GPU kernels don't load there (see below), so install 0.5.7.post1 over it. Install the connector as in [Install](#install), then check the kernels:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
pip install "lmcache==0.5.7.post1"
|
|
60
|
+
pip install hypercache-lmcache-native
|
|
61
|
+
python3 -c "import hypercache_lmcache_native as h; print(h.check_lmcache_gpu_ops())" # must print None
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**3. Start the LMCache server with the connector as its L2.** Pick a `namespace` that names the model and its revision (see [Use](#use)):
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
lmcache server --host 127.0.0.1 --port 18555 --l1-size-gb 6 --eviction-policy LRU --chunk-size 256 \
|
|
68
|
+
--l2-adapter '{"type": "native_plugin", "module_path": "hypercache_lmcache_native",
|
|
69
|
+
"class_name": "HyperCacheNativeConnector", "max_capacity_gb": 0,
|
|
70
|
+
"adapter_params": {"namespace": "qwen2.5-7b-awq-b250375", "tier": "nvme"}}'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**4. Start vLLM pointed at that server:**
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
vllm serve Qwen/Qwen2.5-7B-Instruct-AWQ --kv-transfer-config \
|
|
77
|
+
'{"kv_connector": "LMCacheMPConnector", "kv_role": "kv_both",
|
|
78
|
+
"kv_connector_extra_config": {"lmcache.mp.host": "127.0.0.1", "lmcache.mp.port": 18555}}'
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**5. Check it works.** Send the same long prompt twice: the second first-token time should drop sharply. Then restart the LMCache server and vLLM, leave the daemon running, and send it again. LMCache's `Prefetch request completed` log line should count the keys as L2, which means they came from the drive. `scripts/e2e/lmcache_vllm_e2e.py` automates this and compares the answers. The connector prints any store or checksum failure to the LMCache server's stderr.
|
|
82
|
+
|
|
83
|
+
**In containers:** the LMCache server's container needs the daemon's socket directory mounted (`-v /run/hypercache:/run/hypercache`) and the drive itself (`--device /dev/nvme1n1`), because the connector reads and writes the drive directly. Without `--device`, every store fails and LMCache quietly runs on L1 alone, so check its log for failed L2 stores. With `tier: "ram"`, it needs the host's `/dev/shm` instead.
|
|
84
|
+
|
|
85
|
+
**Troubleshooting:**
|
|
86
|
+
|
|
87
|
+
| Symptom | Cause |
|
|
88
|
+
|---|---|
|
|
89
|
+
| Every store fails with "no local-only commit support" | The daemon is older than the connector. Upgrade the daemon. |
|
|
90
|
+
| Every store fails with a permission or "No such file" error on the drive | The process can't open the drive: add `--device`, or add its user to the daemon's `client_gid`. |
|
|
91
|
+
| Warning "cuda_ops compiled extension not found" | LMCache doesn't match the installed torch. Its fallback can store wrong KV data: fix the install, then change `namespace`. |
|
|
92
|
+
| Hits but no speedup after a restart | L1 is too small for the load to fit (LMCache only evicts L1 down to 80%), or the prompt is shorter than one 256-token chunk. |
|
|
93
|
+
|
|
94
|
+
## Use
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"type": "native_plugin",
|
|
99
|
+
"module_path": "hypercache_lmcache_native",
|
|
100
|
+
"class_name": "HyperCacheNativeConnector",
|
|
101
|
+
"adapter_params": {
|
|
102
|
+
"namespace": "qwen2.5-7b-awq-rev1234",
|
|
103
|
+
"socket_path": "/run/hypercache/hypercache.sock",
|
|
104
|
+
"tier": "nvme",
|
|
105
|
+
"num_workers": 32
|
|
106
|
+
},
|
|
107
|
+
"max_capacity_gb": 0
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
| Setting | Meaning |
|
|
112
|
+
|---|---|
|
|
113
|
+
| `namespace` | Required. Must change when the model weights, dtype or engine settings change. LMCache's key has a model name but no revision, so without this a weight change could return wrong KV data. |
|
|
114
|
+
| `socket_path` | Daemon socket. Defaults to the same search order as the Python client. |
|
|
115
|
+
| `tier` | `nvme` (default) or `ram`. For `ram`, LMCache must share `/dev/shm` with the daemon. |
|
|
116
|
+
| `num_workers` | Objects read or written at once, per direction (default 32). Each object is read one chunk at a time, so this sets the queue depth. On one drive, 8 loaded fastest. On 4 drives, 32 did. |
|
|
117
|
+
| `timeout_s` | Daemon request timeout in seconds (default 30). Commits get at least 300. |
|
|
118
|
+
| `max_capacity_gb` | Keep at 0. The daemon owns capacity and evicts under pressure. |
|
|
119
|
+
|
|
120
|
+
## Check LMCache's GPU kernels first
|
|
121
|
+
|
|
122
|
+
LMCache copies KV data between the GPU and its memory tier with compiled kernels in `lmcache.cuda_ops`. If they don't load, LMCache falls back to plain torch ops and logs a single warning:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
lmcache.cuda_ops compiled extension not found; CudaDeviceOps stays on the torch baseline for all ops.
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
With that fallback, answers at temperature 0 changed after a cache hit on 24 or 25 of 25 test prompts, with or without HyperCache. LMCache [#6673](https://github.com/LMCache/LMCache/issues/6673) traces it to the fallback's copy not waiting for the GPU kernel that fills it, so a store can save stale KV data. HyperCache then keeps exactly those bytes, so **anything stored while the fallback was active may be wrong, and stays wrong after the fix**: change `namespace` once the kernels load. It happens in the `vllm/vllm-openai:v0.33.0` image, whose LMCache 0.5.6 was built for torch 2.13 while the image has 2.14. See `benchmarks/results/lmcache_rust_connector_xeon.md`.
|
|
129
|
+
|
|
130
|
+
Check before going live, in the environment that runs the LMCache server, with a GPU visible:
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
python3 -c "import hypercache_lmcache_native as h; print(h.check_lmcache_gpu_ops())"
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
It prints `None` when the kernels load, and the reason when they don't. The connector runs the same check at startup and prints a warning to stderr on a problem. It does not stop LMCache from starting. Fix it with an LMCache build that matches the installed torch. vLLM 0.31.0 with LMCache 0.5.5 is a tested pair whose answers matched. In the vLLM 0.33.0 image, LMCache 0.5.7.post1 from PyPI loads its kernels, and with batch invariance cached answers matched cold answers on 25 of 25. The connector's safety and failure tests pass on 0.5.7.post1, and answers from KV loaded off the drive matched no-cache answers on 9 of 9 prompts (`benchmarks/results/lmcache_rust_connector_vllm.md`).
|
|
137
|
+
|
|
138
|
+
## What isn't supported
|
|
139
|
+
|
|
140
|
+
- `list_l2_keys` and LMCache's IsolatedLRU quotas.
|
|
141
|
+
- Versions other than LMCache 0.5.5, 0.5.6 and 0.5.7.post1, which are the ones tested. Nothing in the connector enforces that yet.
|
|
142
|
+
- A daemon without `local_only` commits. Stores fail before writing any data, and lookups miss.
|
|
143
|
+
|
|
144
|
+
## Behaviour
|
|
145
|
+
|
|
146
|
+
- Any doubt about a block is a miss. Lookup only accepts committed local-only blocks with a checksum for every chunk, and load verifies every chunk before reporting success.
|
|
147
|
+
- If the daemon restarts, the connector reconnects by itself. A request that couldn't be sent is resent once, and one the daemon may have received is never resent, so it reports a failure.
|
|
148
|
+
- Blocks are never flushed to a backend. Against an older daemon, stores fail before any data is written and lookups miss. Support is checked again on every new connection, because a restarted daemon may be a different version, and a commit only counts when the daemon confirms `LOCAL_ONLY`.
|
|
149
|
+
- A commit names the layout this connector staged, so if another writer replaced the block in between, the daemon refuses it and the store fails.
|
|
150
|
+
- Two stores of the same block in one process run one after the other, and each reports its real outcome. A block already stored counts only if its size and layout match.
|
|
151
|
+
- In a process forked from the one that opened the connector, closing it does nothing: the workers belong to the parent.
|
|
152
|
+
- A block that fails its checksum is evicted, unless it was replaced during the read.
|
|
153
|
+
- On raw block devices, writes use O_DIRECT. Page-aligned L1 buffers (`--l1-align-bytes 4096`) go to and from the drive with no copy. A partial last block goes through the page cache on writes and an aligned copy on reads.
|
|
154
|
+
|
|
155
|
+
## LMCache's wrapper
|
|
156
|
+
|
|
157
|
+
LMCache's `NativeConnectorL2Adapter` wrapper sits between LMCache and this connector, which leads to some behaviour worth knowing.
|
|
158
|
+
|
|
159
|
+
- **Locks.** The wrapper tracks lookup locks itself and doesn't check them before a delete, so a locked block can be deleted. The later load is a miss, never wrong data. LMCache only calls delete from global eviction, which `max_capacity_gb: 0` turns off.
|
|
160
|
+
- **Status.** `report_status` doesn't include this connector's counters. Checksum failures are logged to stderr, and `adapter._client.stats()` returns the counters.
|
|
161
|
+
- **Store accounting.** The wrapper counts bytes per key it hasn't seen in this process, so after a restart a store of an existing block reports its bytes even though nothing was written.
|
|
162
|
+
- **Partial store failures.** A store task with any failed key reports zero bytes, even if other keys in it were stored.
|
|
163
|
+
|
|
164
|
+
## Test
|
|
165
|
+
|
|
166
|
+
```sh
|
|
167
|
+
cargo test # no Python, LMCache or GPU needed
|
|
168
|
+
scripts/e2e/lmcache_l2_ci.sh --python python3 # 30 checks against real LMCache on a loop device
|
|
169
|
+
python3 scripts/e2e/lmcache_l2_e2e.py --socket /run/hypercache/hypercache.sock
|
|
170
|
+
python3 scripts/e2e/lmcache_vllm_e2e.py --fillers 40 # against a running vLLM + LMCache
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`lmcache_l2_ci.sh` needs LMCache, torch (CPU is fine) and the connector wheel installed for that Python, and sudo for `losetup`; CI runs it on every pull request. `lmcache_l2_e2e.py` runs the same checks against a daemon you already started, on a real device, and damages one stored chunk on purpose. `lmcache_vllm_e2e.py` checks that answers loaded from L2 match cold ones. Results are in `benchmarks/results/lmcache_rust_connector.md`, `lmcache_rust_connector_xeon.md` and `lmcache_rust_connector_nvme.md`.
|