Skip to content

[Reshard] Plan Store KV reuse across TP, PP and host layouts - #4762

Merged
Bo-Vincent merged 4 commits into
kvcache-ai:mainfrom
LLLL114:kv-reshard-pr1-planning
Oct 21, 2026
Merged

Bo-Vincent merged 4 commits into
kvcache-ai:mainfrom
LLLL114:kv-reshard-pr1-planning

Conversation

@LLLL114

@LLLL114 LLLL114 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

First PR for #4719
Instances with different TP/PP configurations need to map stored KV data to their current placement. This PR adds a standalone Python planner that converts a source manifest and target placement into byte ranges covering every token of each page, ready for subsequent Store execution.

  • Define topology-independent logical page keys, model semantic domains, and immutable source manifests.
  • Plan reads through layer/head intersections across TP/PP configurations and PLHD, LPHD, and HPLD layouts.
  • Validate target memory bindings and lower logical plans into source Part offsets, destination offsets, and lengths, with range coalescing and batching.

Store execution, manifest publication/discovery, and framework integration follow in separate PRs.
The semantics for 'multipart' have not yet been fully implemented in Mooncake, so the review could be paused.

Suggested Merge Priority

  • P0 — Urgent: Critical security vulnerability, data loss/corruption, or widespread production outage requiring immediate action
  • P1 — High: Significant correctness or stability issue in existing functionality, or a regression blocking users without a practical workaround
  • P2 — Normal: Routine bug fix, validated performance/compatibility improvement, or new feature for a confirmed use case
  • P3 — Low: Experimental feature, optional enhancement, refactoring, or cleanup with no urgent user impact

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Test commands:

PYTHONPATH=mooncake-reshard/python python -m pytest -q mooncake-reshard/tests
python -m pyright --project mooncake-reshard/pyrightconfig.json

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (describe below)

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue([RFC]: Mooncake Store KV Cache Reshard #4719)

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

Codex assisted with implementation, testing, and commit organization. The human submitter is responsible for final review.

Define semantic cache identities and immutable source layouts, compute target-driven logical intersections, and lower every token of each page into validated byte ranges. Plans identify source Part indices and relative offsets; Store RPCs, discovery, leases and data transfer are outside this commit. Include independent byte-exact layout and topology tests.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 05:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

regions = {r.region_id: r for r in binding.regions}
groups: dict[tuple[int, KVCacheComponent], list[KVCacheResolvedRange]] = {}
spans: list[tuple[int, int]] = []
for item in binding.ranges:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Share the range geometry validation
    validate_store_binding() duplicates much of the range validation in resolved.py. Could we extract a shared geometry validator while keeping Store and R2R identity checks separate? This would avoid maintaining the same bounds, stride, and coverage rules twice

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. I extracted a shared geometry validator for bounds, strides, alignment, overlap, coverage, and validation limits. Store and R2R retain separate binding types and identity checks, including R2R snapshot validation.

layout: KVCacheStoreLayout,
target_placement: KVCachePlacementManifest,
*,
runtime_format: KVCacheStoreFormat,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Remove the unused runtime_format parameter
    runtime_format is only type-checked and does not affect the plan; destination layout comes from the runtime binding strides. Could we remove this parameter before the API is finalized?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I removed runtime_format from the load-planning API and updated the callers and tests, including the page reader in the follow-up implementation.

… API

Keep Store and R2R binding identity checks separate while sharing bounds, stride, coverage and validation-limit checks. Remove the unused runtime_format argument from Store load planning and update its tests.

Signed-off-by: huanglong <huanglong@linux.alibaba.com>

@Bo-Vincent Bo-Vincent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Bo-Vincent
Bo-Vincent merged commit e2d6e8e into kvcache-ai:main Oct 21, 2026
29 checks passed
zxpdemonio added a commit to zxpdemonio/Mooncake that referenced this pull request Oct 21, 2026
…20261021

* upstream/main: (507 commits)
  [Reshard] Plan Store KV reuse across TP, PP and host layouts (kvcache-ai#4762)
  [Store] Walk tenants through shard-backed cursors and build the removes on them (kvcache-ai#4796)
  [Store-RS][Bugfix] Match TENT Request Layout to the C ABI (kvcache-ai#4732)
  [TransferEngine] Recover auto GID after data-path retry exhaustion (kvcache-ai#4290)
  [Store] Add the namespace layer over the object route (kvcache-ai#4721)
  [Store] Fix silent loss of offload keys deferred to the ungrouped pool (kvcache-ai#3006) (kvcache-ai#3009)
  [Store] Remove redundant alignment headroom from DFS shard allocation (kvcache-ai#4753)
  [CI/Build] Gate ROCm hardware tests and bound nightly Docker builds (kvcache-ai#4750)
  [Bugfix][Store] Fix double-counting of segment OpLog metrics in OpLogApplier (kvcache-ai#4771)
  [Store] Skip hot-cache writeback for device-resident read destinations (kvcache-ai#4764)
  [Reshard] Add bounded in-flight execution for weight transfers (kvcache-ai#4628)
  [Store] Avoid racing with detached hot-cache fills during key scans (kvcache-ai#4334)
  [Store] HA: drain the master on SIGTERM/SIGINT before exit (part 1 of kvcache-ai#4710) (kvcache-ai#4745)
  TENT: report a notification the receiver could not take (kvcache-ai#4754)
  [Store] Reach object metadata through a per-key accessor contract (kvcache-ai#4717)
  [Store][Bugfix] Fix DFS sync client test retry failure (kvcache-ai#4781)
  [Wheel] Keep integer dtype for typed_ragged rows when a row is an empty list (kvcache-ai#4611)
  [Doc] Sync README news onto the docs homepage (kvcache-ai#4767)
  [CI] remove stale Torch version binding after PG JIT (kvcache-ai#4760)
  [TransferEngine] Add buffer-protocol and page-gathered batch transfer APIs (kvcache-ai#4763)
  ...
zxpdemonio added a commit to zxpdemonio/Mooncake that referenced this pull request Oct 21, 2026
…-ranges-20261021

* upstream/main: (394 commits)
  [Reshard] Plan Store KV reuse across TP, PP and host layouts (kvcache-ai#4762)
  [Store] Walk tenants through shard-backed cursors and build the removes on them (kvcache-ai#4796)
  [Store-RS][Bugfix] Match TENT Request Layout to the C ABI (kvcache-ai#4732)
  [TransferEngine] Recover auto GID after data-path retry exhaustion (kvcache-ai#4290)
  [Store] Add the namespace layer over the object route (kvcache-ai#4721)
  [Store] Fix silent loss of offload keys deferred to the ungrouped pool (kvcache-ai#3006) (kvcache-ai#3009)
  [Store] Remove redundant alignment headroom from DFS shard allocation (kvcache-ai#4753)
  [CI/Build] Gate ROCm hardware tests and bound nightly Docker builds (kvcache-ai#4750)
  [Bugfix][Store] Fix double-counting of segment OpLog metrics in OpLogApplier (kvcache-ai#4771)
  [Store] Skip hot-cache writeback for device-resident read destinations (kvcache-ai#4764)
  [Reshard] Add bounded in-flight execution for weight transfers (kvcache-ai#4628)
  [Store] Avoid racing with detached hot-cache fills during key scans (kvcache-ai#4334)
  [Store] HA: drain the master on SIGTERM/SIGINT before exit (part 1 of kvcache-ai#4710) (kvcache-ai#4745)
  TENT: report a notification the receiver could not take (kvcache-ai#4754)
  [Store] Reach object metadata through a per-key accessor contract (kvcache-ai#4717)
  [Store][Bugfix] Fix DFS sync client test retry failure (kvcache-ai#4781)
  [Wheel] Keep integer dtype for typed_ragged rows when a row is an empty list (kvcache-ai#4611)
  [Doc] Sync README news onto the docs homepage (kvcache-ai#4767)
  [CI] remove stale Torch version binding after PG JIT (kvcache-ai#4760)
  [TransferEngine] Add buffer-protocol and page-gathered batch transfer APIs (kvcache-ai#4763)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants