Developer Documentation
Adding a KV offload backend
On this page
A KV offload backend decides what keeps an instance's KV cache beyond the GPU: the engine's own memory and disk tiers, or a component outside the engine (LMCache or Mooncake Store, for example). This page is for contributors adding a backend. It describes the backend model, where each part lives and what adding a backend changes. The design trade-offs are in ADR 0069.
Backend model
A backend is one descriptor row in internal/server/kvbackend, unique per (engine, id) and compiled into the binary:
| Field | Meaning |
|---|---|
ID, Engine | The backend id and its engine; the id is the value of the deployment parameter kv_offload_backend |
Label | The product name, shown as is on the deploy form's card and the instance panel |
Default | The engine's own offload; an empty kv_offload_backend resolves to it, at most one per engine |
External | A component outside the engine keeps the KV cache; the requested-feature snapshot records external_kv_cache |
Vendors | Accelerator vendor allow-list; empty means every vendor |
Replaces | Native parameter keys that cannot be set while the backend is selected; every selectable row must list every key of the engine's own offload, including kv_offload_block_size, which has no dictionary row |
PDRoles | PD roles that keep the backend, always including prefill; other roles launch without offload |
Topology | The node-count cap and whether PP and DP are allowed |
A row holds only the data decisions are made on. There is no init() registration and no mutable package state. Today the built-in table carries vllm/native (the default) and vllm/lmcache (the first external backend).
Where each part lives
-
Selection:
kv_offload_backendin the parameter table is a selector key (Selector) with no flag, and it is not a platform parameter. It is published only when the engine has at least one non-default row, with options generated from the registry; otherwise the key is dropped from requests. -
Rendering:
internal/server/deploy/kv_render_vllm.gogives each backend's vLLM half (vllmOffloadBackend) by id. Its renderer receives the wholeParams(PD role, vendor, compute network, parallelism) and returns the connector object. It may also return keys for theMultiConnectorthat wraps it (wrapper; the composer's own keys win) and environment for the engine process (env, merged once invLLMEngine.Build).composeVLLMKVTransferinkv_compose.gocomposes the PD part and the offload part into the one--kv-transfer-config. The config the platform composes for a non-PD launch is never classified as PD, whatever its connector is called. Only vLLM has an offload adapter today. -
Validation:
kv_offload.goreturns these codes (text inui/src/i18n/locales/{en,zh}/common.json):Code When KV_OFFLOAD_BACKEND_UNKNOWNThe engine has no selectable backend with that id; checked on evaluate, edit and launch KV_OFFLOAD_BACKEND_CONFLICTS_NATIVE_TIERA native key in Replaceshas an effective value; values the platform writes by default do not countKV_OFFLOAD_BACKEND_CONFLICTS_ARGAn argument layer of an external backend states a flag that would replace its configuration ( KVConflictFlags, matched across spellings); checked under PD tooKV_OFFLOAD_BACKEND_UNSUPPORTED_ON_TARGETThe target vendor is not in Vendors; an unknown vendor (not placed yet) is allowed and checked after placementKV_OFFLOAD_BACKEND_TOPOLOGY_UNSUPPORTEDThe node count, PP or DP is outside TopologyThe last two are checked in
ValidateTargetFeatures, which both validating modes reach; collecting capabilities alone does not check them. -
PD:
PDRoleLaunchConfigclears the selection and the native fields when the role is not inPDRoles.KVOffloadPDRolesgives the roles that keep offload; when decode is not among them, evaluate returns the warningPD_KV_OFFLOAD_PREFILL_ONLY. -
Reverse parsing: the engine hook
RecognizeKVBackendreads a backend's non-PD rendering back into the selection.ReverseArgsandCanUnsetTemplateFlagshare it, so saving as a template round-trips. A backend whose object carries its own values provides a reader (vllmOffloadBackend.recognize); the values it returns read back as dictionary values beside the selection. A backend without a reader is recognized only by its rendering with nothing else stated. -
Frontend: the engine profile's
kv_backendslists the selectable backends (ProfileForTargetfilters them by vendor). The deploy form shows one card per entry, and when one is selectedprojectDraftunsets the keys in itsreplaces; a selected backend the profile no longer lists (the target changed) is not sent and is unset. In a deployment's read, each instance carrieskv_offload_backend({id, label}, scoped by the server to the instance's PD role), which the instance panel shows.ui/srcnames no backend id.
Adding a backend
- Add a row in
kvbackend.Builtin(), filling only the fields it really uses. A new field arrives together with the first row that uses it. - Add a renderer for the id in
vllmOffloadBackends()(kv_render_vllm.go), with a reader when its object carries its own values.internal/engines/features.goneeds no change: the non-PD config the platform composes is not classified by connector name. - Add the id to the
kv_backend_id_literalspattern inscripts/check_architecture.sh. - Tests: the table invariants in
kvbackend;TestKVBackendSetRendersEverySelectableRowindeploy(kvBackendSetProblems) checks that every selectable row has a renderer, thatReplacescovers every key of the engine's own offload, and that a non-PD launch requests no PD. The generic rules are already covered by the test rowvllm/testext(kv_backends_helpers_test.go), so a new backend adds tests for its own rendering and a real-hardware L4 case. - Update the cards' execution status in the browser E2E ledger
test/e2e/coverage/deployment-wizard-create.json.
Known limits
- In a mixed-vendor cluster the scheduler does not filter nodes by backend vendor; an unsupported vendor is refused at target validation after placement.
- An older server drops
kv_offload_backend: a deployment that selected an external backend runs without offload there. - Only vLLM has an offload adapter. A SGLang row (HiCache, say) first needs SGLang-side rendering, conflict flags and a reader; the tests refuse a row with no adapter.
- A backend's own dictionary keys (keys that depend on
kv_offload_backend) have no mechanism yet.PDRoleLaunchConfigclears only the native keys, andTestPDRoleLaunchConfigDropsEveryOffloadKeyfails once such a key appears, as a reminder to clear it on roles that do not keep the backend. - A rendering cannot carry mounts or
/dev/shmneeds yet; the first backend that needs them adds the fields.
Was this page helpful?