Precise KV-index routing: vLLM KV cache events through the agent, routed by leading blocks held
Plan §7.5 tier 2, opt-in per profile with kv_events. The agent starts vLLM publishing KV cache events to a loopback port it listens on (pure-Go zmq4, msgpack in both of vLLM's encodings), with sha256_cbor hashing and a fixed PYTHONHASHSEED; it mirrors each engine's blocks and sends net changes up the existing stream, with a full copy on every new one and a reset on gaps, restarts and clears. The control plane hands them to the router, for the sending node's own replicas only. The router tokenizes through a replica's /tokenize, hashes the tokens as vLLM does (checked against cbor2/hashlib golden values), and scores replicas by the share of leading blocks held, falling back to the approximate tree. New metrics beside llmgw_prefix_decisions_total. Untested against a running vLLM. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d41104a452
commit
117f417ef5
43 files changed
+3496
-263
No files matched your search
@@ -1028,6 +1028,65 @@ The adapter file must be a GGUF LoRA made for this model — llama.cpp's
|
||||
`convert_lora_to_gguf.py` makes one from a PEFT adapter — and not a model with
|
||||
the adapter already merged in, which is what most "LoRA GGUF" repositories hold.
|
||||
|
||||
### Routing by what each replica's cache actually holds
|
||||
|
||||
With several replicas of a vLLM model, a request is fastest on the replica
|
||||
that already holds its prompt's prefix in KV cache. The router guesses which
|
||||
that is from what it has sent where (`router.prefix`). It can also be told:
|
||||
vLLM publishes an event every time it stores or evicts a cache block, and with
|
||||
`kv_events` on a profile llmgw routes that model by those events.
|
||||
|
||||
```yaml
|
||||
- name: llama-3.1-8b-instruct
|
||||
source: meta-llama/Llama-3.1-8B-Instruct
|
||||
routing_profile: chat # chat or long-context; batch ignores prefixes
|
||||
profiles:
|
||||
- name: h100
|
||||
gpu_class: h100-80g
|
||||
kv_events: true
|
||||
```
|
||||
|
||||
How it works, so you know what you are paying for:
|
||||
|
||||
- The node agent starts vLLM with `--kv-events-config` publishing to a port
|
||||
on 127.0.0.1 that the agent listens on, `--prefix-caching-hash-algo
|
||||
sha256_cbor`, and `PYTHONHASHSEED=1729`. The events never leave the node:
|
||||
the agent keeps the set of blocks each engine holds and sends the changes,
|
||||
four times a second, up the stream it already has to the control plane,
|
||||
which hands them to the router. A new stream — a control plane restart, a
|
||||
failover — starts with a full copy. Nothing new is opened in the firewall.
|
||||
- For each request to such a model, the router asks one of its replicas to
|
||||
tokenize the prompt (vLLM's `/tokenize`, with the request's messages and
|
||||
tools), hashes the token ids into blocks the way vLLM does, and prefers the
|
||||
replica holding the most leading blocks. Tokenizing at the engine is what
|
||||
makes the hashes agree: the chat template is part of the tokens, and only
|
||||
the engine runs it exactly. It costs a round trip before the request is
|
||||
placed and the template run twice; `router.kv_index.tokenize_timeout`
|
||||
(250ms) bounds it.
|
||||
- When the index has nothing to say — no events have arrived yet, the
|
||||
request has an image or a `cache_salt` or names a LoRA adapter, the
|
||||
tokenize call failed — the router routes as it would without it: by the
|
||||
approximate tree if `router.prefix.enabled`, else by load. The imbalance
|
||||
guard of `router.prefix` applies to both.
|
||||
|
||||
Turning `kv_events` on changes how the engine is started, so replicas already
|
||||
running keep running without it (and show as stale) until they are replaced.
|
||||
Leave `--prefix-caching-hash-algo` out of the profile's `args`: an engine
|
||||
hashing another way publishes blocks the router can never match. The agent
|
||||
checks the first block of prompts against its own hashing, and if they never
|
||||
agree it says so in its log and on `llmgw_kv_index_problem`, and the replica
|
||||
is routed as though it published nothing.
|
||||
|
||||
Watch `llmgw_kv_index_decisions_total` beside `llmgw_prefix_decisions_total`:
|
||||
`kv_hit` is the index deciding, `kv_miss_min_load` is it knowing no replica
|
||||
holds enough (`router.kv_index.min_blocks`, 4 blocks), and the `fallback_*`
|
||||
values say why it could not answer. `llmgw_kv_index_tokenize_seconds` is what
|
||||
the tokenize call costs, and `llmgw_kv_index_blocks` what each replica holds.
|
||||
|
||||
This has been built and tested against vLLM's event format and its hashing as
|
||||
its source defines them, with libzmq and msgspec publishing — not yet against
|
||||
a running vLLM. Treat it as experimental until it has been.
|
||||
|
||||
### Models served outside the cluster
|
||||
|
||||
A model can be an OpenAI-compatible API elsewhere — a hosted provider, or
|
||||
|
||||
Reference in new issue
Block a user