[Integration] TensorRT-LLM Store-backed KV cache connector #6
Loading…
Reference in New Issue
No description provided.
Delete Branch "feiyangyoufeng/Mooncake:feature/tensorrt-llm-kv-connector"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
This PR adds a Store-backed KV cache connector for TensorRT-LLM that gives it
cross-request / cross-instance / cross-CTX–GEN global KVCache reuse through the
Mooncake Distributed Store.
TensorRT-LLM already ships the Mooncake Transfer Engine as a C++
cache_transmissionbackend for point-to-point KV movement between a prefill(CTX) worker and a decode (GEN) worker. That KV is ephemeral — when a request
finishes, its KV is freed, so the next request with the same system prompt or
conversation prefix re-runs prefill from scratch. This PR adds the missing layer:
a distributed KV pool with cache-hit scheduling, implemented through TensorRT-LLM's
official
KvCacheConnectorScheduler/KvCacheConnectorWorkerAPI.It is config-only on the TensorRT-LLM side (no fork) and ships in the
mooncakewheel asmooncake.tensorrt_llm:What's included
mooncake-wheel/mooncake/tensorrt_llm/— the connector package (scheduler,worker, Store client, key schema, paged-KV layout codec, heat-aware replication,
metrics, a config layer, and a TensorRT-LLM-free simulator).
mooncake-wheel/tests/tensorrt_llm/—unittesttest cases (hermetic bydefault; real-Store tests gated on
MC_BACKEND=mooncake).benchmarks/tensorrt_llm_kv_connector/— self-check, demo, benchmark scripts,CTX/GEN/Store config templates, and a one-click deploy script.
docs/source/getting_started/examples/tensorrt-llm-integration.md+ README andtoctree entries.
Design
dtype/layout and TP/PP/EP prefixes every object key, so incompatible
configurations occupy disjoint keyspaces and can never be reused across.
cache_salt, so a keymatch implies the entire prefix matches and tenants with different salts never
share cache.
mismatch is rejected rather than served. KV bytes move verbatim, so
float16/
bfloat16/fp8round-trip bit-exactly.marker for the blocks it durably saved; the aggregate manifest the scheduler
probes is published only once every rank's marker is present, so a partially
written or single-rank block can never be advertised as a hit.
(the runtime then skips prefill), a promised block that is missing or
layout-rejected at load time raises rather than leaving a stale device slot.
MC_LAYER_GRANULARITY=1theconnector stores KV per layer and uses the real
wait_for_layer_load/save_kv_layerhooks to overlap Store I/O with attention compute, instead ofloading the whole block before the forward pass.
ReplicateConfig.replica_numfrom a decayedpopularity estimate, giving hot shared prefixes more copies for read fan-out
and fault tolerance.
The package depends only on
numpyat import time; the Mooncake store client andthe TensorRT-LLM base classes are optional, with a process-shared file backend and
a faithful compat shim so the connector stays importable and testable without a
GPU, a TensorRT-LLM install, or a running Store.
Validation
ruff check,ruff format, andcodespellpass on all new files.tcp): theself-check passes (cold→warm full hit, bit-exact reuse, salt isolation), the
layer-granularity path round-trips bit-exactly with its manifest published in
the real store, and an agentic trace of 144 requests warms from 0% to ~88%
block hit ratio with every request verified bit-exact.
TTFT at a conservative 3000 tok/s prefill, 0 errors, numerical
consistency OK across backends. A freshly restarted instance reuses the warmed
Store immediately (1.0 hit ratio, 0 errors), demonstrating cross-instance
resilience.
Notes
identical across the memory / file / mooncake backends; only the measured Store
bandwidth differs.
--prefill-tok-per-sknob; hit ratio, bytes moved, bandwidth and numericalconsistency are measured against the real Store.
Step 1:
From your project repository, check out a new branch and test the changes.Step 2:
Merge the changes and update on Gitea.