Repository navigation
[Refactor][KV Connector][Mooncake] Move connector metadata and wire structs to their own modules - #62255
[Refactor][KV Connector][Mooncake] Move connector metadata and wire structs to their own modules#62255CAICAIIs wants to merge 2 commits into
Conversation
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment Once the PR is approved or has the If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. Agent GuidelinesIMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban. 🚀 |
9c53b31 to
88f0d51
Compare
|
This pull request has merge conflicts that must be resolved before it can be |
f8c5ac0 to
2b34fc7
Compare
bf28245 to
4477d83
Compare
|
This pull request has merge conflicts that must be resolved before it can be |
…tructs to their own modules Step S1 of vllm-project#62243. Moves ReqId/TransferId, PullReqMeta, SendBlockMeta and MooncakeConnectorMetadata into mooncake/metadata.py and MooncakeXferMetadata, MooncakeXferResponseStatus and MooncakeXferResponse into mooncake/protocol.py. Wire formats, behavior and the names re-exported by mooncake_connector.py are unchanged. The moved MooncakeConnectorMetadata.reqs_not_processed becomes transfers_not_processed, along with the scheduler field it is assigned from: the set holds KV transfer ids, and the identically named NIXL field holds request ids. Adds test_mooncake_wire_format.py, which pins the encoded bytes and the field order of both wire messages against byte strings captured from the definitions before they moved, so a reordered field or a changed default fails a test instead of passing a round trip. Signed-off-by: CAICAIIs <3360776475@qq.com>
4477d83 to
d37fe47
Compare
Overview
Step S1 of #62243: move the Mooncake P2P connector metadata and wire structs into
mooncake/metadata.pyandmooncake/protocol.py, plus a test that pins the encoded wire bytes.Claims
ReqId,TransferId,PullReqMeta,SendBlockMeta,MooncakeConnectorMetadatamove tomooncake/metadata.py;MooncakeXferMetadata,MooncakeXferResponseStatus,MooncakeXferResponsemove tomooncake/protocol.py.omit_defaultsflag and the status values (FINISH=0,CONTINUE=1,ERROR=2,LAYOUT_MISS=3) all matchmain, andtest_mooncake_wire_format.pynow states that contract as a table.mooncake_connector.pystill re-exports every moved name, so existingfrom ...mooncake_connector import MooncakeXferMetadataimports keep working.MooncakeConnectorMetadata.reqs_not_processedbecomestransfers_not_processed, with the scheduler field it is assigned from.Validation
Tests (before =
mainat34ac4f96a, after = this branch, same command, macOS,VLLM_TARGET_DEVICE=cpu):424 passedin 84.72s.429 passedin 90.79s. The extra five are the new wire-format cases.-p no_mps_cleanup_pluginis only a local workaround for a macOS-only teardown segfault intorch.accelerator.empty_host_cache(); it is applied to both runs and touches no repository file.Lint and types:
All hooks pass:
ruff check,ruff format,typos,mypy(oldest supported Python),check-spdx-header,check-forbidden-imports,check-root-lazy-imports,check-test-tethering, plus the remaining hooks that apply to Python files.Name-level checks:
main: themetadata.pybody matchesmooncake_connector.pylines 99-100 and 658-714 ofmainapart from the one rename below, and theprotocol.pybody matches lines 608-657 exactly (diffof the extracted regions is empty).class MooncakeConnectorthroughgroup_concurrent_contiguousagainstmainyields only the six renamed lines.mooncake_connectoris unchanged apart fromIntEnum, which was an incidental re-export offrom enum import IntEnumand is now unused there (ruff flagged it). Every name the module defined before is still importable from it:python -c "from vllm.distributed.kv_transfer.kv_connector.v1.mooncake.mooncake_connector import MooncakeXferMetadata, PullReqMeta, SendBlockMeta, MooncakeConnectorMetadata, MooncakeXferResponse; print('ok')"Details
Names moved, and their new homes:
ReqId,TransferIdmooncake/metadata.pyPullReqMeta,SendBlockMetamooncake/metadata.pyMooncakeConnectorMetadatamooncake/metadata.pyMooncakeXferMetadata,MooncakeXferResponseStatus,MooncakeXferResponsemooncake/protocol.pyDependency direction is one-way and acyclic:
protocol.pyimportsReqId/TransferIdfrommetadata.py;metadata.pyimportsKVConnectorMetadatafrom..baseandEngineIdfromkv_connector/utils.py, and does not importprotocol.py.mooncake_connector.pyimports both and keeps them in its namespace, so tests and any external imports of those names are unaffected.The rename:
MooncakeConnectorMetadata.reqs_not_processedholdsset[TransferId], not request ids, while the identically named field innixl/metadata.pydoes holdset[ReqId]. Since the definition moves here, it is renamed totransfers_not_processedtogether with the scheduler field assigned into it (_transfers_not_processed). Seven lines in the package and one attribute name in an existing assertion intest_mooncake_connector.py; no assertion semantics change, no wire impact.The wire test:
tests/v1/kv_connector/unit/test_mooncake_wire_format.pystates the push wire contract once, as data — nothing else. For each message it asserts the ordered(field, type, required-or-default)list read frommsgspec.structs.fields(), the struct configuration that shapes the encoding (omit_defaults,tag,tag_field,array_like,forbid_unknown_fields), and the status values. A reordered field, a renamed wire key, a changed type or default, a droppedomit_defaults, a switchedforbid_unknown_fieldsor a changed status value fails there, and the failing row is the diff. Golden byte strings would catch the same, but nobody can review them, and every deliberate format change turns into pasting new bytes, after which the guard is worth nothing. This table is the review-time half of the contract; the runtime half is the compatibility hash that #61974 adds and that #62243 folds intometadata.py, which refuses a P/D pair whose wire differs. The pull structs get the same tables in that PR's rebase and the bootstrap payload in S2, since neither exists onmainyet.Rebase note: the branch is on
mainat34ac4f96a. The conflict with #62282 was in the moved block itself, where that PR rewrote thePullReqMeta.failedcomment; the new wording is inmetadata.py, and its_complete_pull_taskaccounting is carried over unchanged.Names inside the moved code that were left alone, and why:
protocol.pyare wire keys; renaming any of them changes the encoded format.reqs_to_recv/reqs_to_send/need_send/sent/sending/PullReqMeta/SendBlockMeta/d_req_id/p_req_idkeep their names:reqs_to_recvandreqs_to_sendare shared withnixl/metadata.py, and [Feature][KV Connector][Mooncake] Add MooncakePullConnector for decode-side reads #61974 constructsSendBlockMeta(p_req_id=...)and insertsabortednext tosending, so renaming those here would only move conflict into that PR.mooncake_prefix inmooncake_connector.py/mooncake_utils.pyand theMooncakeXfer*class names belong to the later steps: [RFC]: Module layout for the Mooncake P2P KV connector #62243 keepsmooncake_connector.pyas the compatibility shim untilconnector.pyexists in S5.Follow-ups
bootstrap.pyandscheduler.py, the push-side geometry moving into the existingtransfer_plan.py, the worker becomingbase_worker.py+push_worker.py+pull_worker.py, and the facades moving toconnector.py. Each step waits for an in-flight PR to merge first: [KVConnector] Classify transfer groups from the framework's spec kinds #57309 for the spec classification, [Feature][KV Connector][Mooncake] Add MooncakePullConnector for decode-side reads #61974 for the pull connector, [KVConnector][Mooncake] Add a failure ledger for the failure spine #57529 for the failure ledger, [KV Connector][Mooncake] Expose transfer stats via Prometheus #56939 for metrics.metadata.py. The two wire protocols stay separate; unifying them would change the format.straliases are the only reasonprotocol.pydepends onmetadata.py, andmetadata.pypulls inv1.baseandkv_connector/utils.py. Whether those aliases belong in a leaf module is a layout decision for [RFC]: Module layout for the Mooncake P2P KV connector #62243 or [RFC]: Share KV transfer planning primitives across KV connectors #57373, not something to change inside a move.mooncake_connector.pykeeps itsmooncake_prefix and theMooncakeXfer*class names until S5, whenconnector.pyexists and the old path becomes an__all__shim.req_blocksentry gains a third element andremote_dcp_size/remote_block_sizeare appended, so the schema tables here and the compatibility hash are edited in whichever PR merges second. [Feature][KV Connector][Mooncake] Add layerwise and chunk-wise KV transfer #62504 adds a second execution shape of the WRITE path, so S3 and S4 keeptransfer_plan.py,push_worker.pyandscheduler.pysubclassable rather than closed.Why this is not a duplicate
mooncake_pull_connector.py,transfer_plan.pyandcompat.py; its pull wire structs, planning module and compatibility hash stay with that PR and are not absorbed here.Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.
BEFORE SUBMITTING, PLEASE READ https://docs.vllm.ai/en/latest/contributing (anything written below this line will be removed by GitHub Actions)