[Fix] Isolate Mooncake KV-store keys by cache identity - #4932
Open
wildoranges wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
It changes production-critical external KV namespace semantics and online weight-update behavior without an end-to-end Mooncake Store integration run to validate real backend interoperability.
Pull request overview
This PR hardens the Mooncake external KV-store keyspace by binding store keys to an explicit tenant namespace plus a resolved KV-cache format and weights lineage, and by rotating the namespace across online weight updates to avoid stale/external-cache reuse.
Changes:
- Require explicit
cache_prefixandweights_version(or engine-provided model revision) for Mooncake connector configuration. - Introduce a versioned, hashed Mooncake store namespace derived from tenant/model/kv-format/weights identity plus a monotonic
weights_generation. - Rotate and propagate
weights_generationafter online weight updates, and add focused unit tests covering partitioning, validation, and propagation.
File summaries
| File | Description |
|---|---|
| tests/pytorch/kv_connector/test_mooncake_store_worker.py | Updates test configs for new identity requirements; adds tests for partitioning and generation rotation propagation to worker threads. |
| tests/pytorch/kv_connector/test_mooncake_store_connector.py | Extends connector delegation tests to cover set_weights_generation; updates required extra config fields. |
| tests/pytorch/engine/test_model_agent_kv_connector.py | Adds tests ensuring weight updates trigger Mooncake namespace rotation and metadata propagation. |
| tests/pytorch/engine/test_kv_connector_wiring.py | Validates config preparation enforces identity requirements and binds kv-format/generation to connector config. |
| lmdeploy/pytorch/kv_connector/mooncake/store/worker.py | Threads kv_cache_format, weights_version, and weights_generation into key metadata; adds runtime generation rotation API. |
| lmdeploy/pytorch/kv_connector/mooncake/store/data.py | Implements namespace_hash and a v2 namespace schema; enforces non-empty identity fields; updates key builder format. |
| lmdeploy/pytorch/kv_connector/mooncake/store/connector.py | Exposes set_weights_generation on the connector API and forwards to the worker. |
| lmdeploy/pytorch/kv_connector/factory.py | Enforces explicit tenant+weights identity; adds model-identity binding (kv_cache_format, weights_generation). |
| lmdeploy/pytorch/kv_connector/base.py | Adds a no-op default set_weights_generation hook to the base connector API. |
| lmdeploy/pytorch/kv_connector/init.py | Exports prepare_kv_connector_model_identity. |
| lmdeploy/pytorch/engine/model_agent/agent.py | Binds kv-format/generation before building the worker connector; rotates generation after weight updates and propagates to the connector. |
| lmdeploy/pytorch/engine/engine.py | Passes engine_config.revision through to connector config preparation for weights identity. |
| lmdeploy/cli/utils.py | Updates CLI help text/example to document required Mooncake identity configuration. |
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Local PR draft - F2 Mooncake KV-store key identity
Related issue: #4930
Motivation
Mooncake external KV-cache keys currently identify entries by model name, an
optional cache prefix, shard rank, and token-prefix hash. The key does not bind
the stored bytes to the resolved KV-cache format or the model weights lineage.
The default empty cache prefix also leaves deployments sharing a Mooncake store
without a required tenant partition.
This can advertise stale same-dtype KV after a weight revision or online weight
update. Mixed KV formats can produce false external-cache hits and unnecessary
transfer work, and deployments with colliding default configuration can share a
keyspace unintentionally. See #4930 for the production-code probe and impact
analysis.
Modification
cache_prefixfor Mooncake deployments.weights_version, using the engine model revision when available, andreject configurations without a usable weights identity.
quant_policy, and MLA KV-cache dtype.versioned weights generation into the Mooncake namespace.
serialized and distributed update paths, and propagate the new metadata to
active Mooncake transfer workers.
generation rotation, and sender/receiver metadata propagation.
The change is intentionally limited to F2 external-store key identity. KV-head
shard schema negotiation (F8), local prefix-cache invalidation (F1), and
adapter-weight fingerprinting are not part of this PR.
The documented update-weights workflow drains/sleeps the engine before loading
new weights. This PR rotates the active connector identity after the completed
update; ordering for transfer tasks that are intentionally left queued across an
update remains part of the separate cache-lifecycle work.
BC-breaking (Optional)
Yes, for the unreleased Mooncake connector configuration. Enabling
MooncakeStoreConnectornow requires an explicit non-emptycache_prefixand anon-empty
weights_version, unless the engine provides a model revision. Oldunscoped remote entries are no longer read by the new namespace, which is
intentional because their format and weights lineage cannot be verified.
Non-Mooncake connectors, local KV caching, and the public inference request API
are unchanged.
Use cases (Optional)
tenant prefixes.
older weights generation.
the same external store.
Checklist
git diff --checkpasses.pre-commit run --files <changed-files>passes.tests/pytorch/kv_connector/andtests/pytorch/engine/.125 passed).version, this PR should be tested with all supported versions of downstream
projects.
tutorials.
new identity requirements.
Verification command
Current result:
125 passed in 6.31sin the local CPU environment and125 passed in 11.32sonrtx4080withCUDA_VISIBLE_DEVICES=0,torch 2.12.1+cu130, and 8x RTX 4080 available. Related engine regression tests alsopass on the GPU host:
14 passed in 8.68s.compileall,ruff check,git diff --check, and all configured pre-commit hooks pass. A live MooncakeStore integration was not run because no Mooncake Store service/configuration
was provided.