Skip to content

[Store] Support sparse attention replay with aligned tensor I/O - #5581

Draft
zxpdemonio wants to merge 3 commits into
kvcache-ai:mainfrom
zxpdemonio:feat/registered-tensor-buffer-leases
Draft

zxpdemonio wants to merge 3 commits into
kvcache-ai:mainfrom
zxpdemonio:feat/registered-tensor-buffer-leases

Conversation

@zxpdemonio

@zxpdemonio zxpdemonio commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Sparse attention replay stores rollout token/block selections for training to reuse. This PR lets Mooncake deliver those tensors into aligned, reusable buffers. Router replay can use the same byte-storage interface.

  • FieldSchema.direct_alignment selects strict, payload-only reads into a registered CPU/CUDA TensorDestination. Layout, dtype, shape, alignment, bounds and aliases are checked. Other schemas retain ordinary behavior.
  • BufferPool.register_external_region() returns the existing BufferLease. Opaque borrows retain its allocation and prevent lease release. Confirmed unregister failures can be retried; ambiguous registration errors retain the owner without blind cleanup.

The framework owns replay semantics and CUDA consumer scheduling. Mooncake reuses its pool, registration and range-transfer paths. Drain consumers and release borrows/leases/pool before closing or reconfiguring the Store or sleeping its allocator; raw operations on managed regions are unsupported. External registration requires a private classic engine without NoF. Strict CUDA I/O rejects unsupported paths, including TCP and TENT.

Rebased onto d936855e3. Cumulative against that base: +2262/-144 — production +1142/-114, tests +1097/-30, docs +23. The revision removes the global RealClient ownership state machine and shares row planning and test setup. The tests keep one case per contract instead of one per parameter combination, and behaviour this PR does not touch is no longer re-tested here.

Related overlaps: #5384 (pool release/retry), #5379 (registered source members); reconcile before merge.

Contribution: Cruz Zhao — implementation, tests and documentation.

Suggested Merge Priority

  • P0 — Urgent
  • P1 — High
  • P2 — Normal
  • P3 — Low

Module

  • Mooncake Store (mooncake-store)
  • Integration (mooncake-integration)
  • Python Wheel (mooncake-wheel)
  • Docs

Type of Change

  • New feature
  • Documentation update

How Has This Been Tested?

Rebuilt from source on this commit (Release, current nanobind bindings) and run on one CPU-only host.

  • External registration and direct reads: destinations 24 passed; buffer pool and external leases 30 passed; RDMA destination cases 1 passed, 4 skipped (no RDMA device here).
  • Native: external-registration capability 2 passed; gather 21 passed, 13 RDMA-dependent skips; transfer-engine unit 65 passed.
  • Structured objects: 199 passed, 2 optional skips, 2 failures. test_dataproto_helper_reads_rows_with_real_store_ranges (ragged member) and test_dataproto_helper_same_stage_append_reads_rows_with_real_store (object evicted, -704) also fail when the whole base test file is run on this host, both against the base build and against this branch's build; each passes when run on its own, so neither is introduced here.
  • Repository CI gates reproduced locally: scripts/ci/tests 110 tests OK (1 skip), mooncake-wheel/tests/test_testpypi_wheel_gate.py 6 passed, clang-format 20 clean on all nine changed C++ files, ruff 0.6.9 clean on the changed Python files, and git diff --check passes.
python3 -m pytest -q python/tests/store/test_tensor_destination.py
python3 -m pytest -q python/tests/store/test_buffer_pool_native.py
python3 -m pytest -q python/tests/store/test_structured_object_store.py
./build/mooncake-store/tests/pybind_client_test --gtest_filter='RealClientTest.ExternalPoolCapability*'
MC_GATHER_TEST_DEVICE=<rdma-device> ./build/mooncake-store/src/store_gather_read_test

This Draft still needs GPU/RDMA validation on the rebased tree and independent final review. Earlier GPU builds do not validate this tree; no end-to-end performance claim is made.

Checklist

  • Every commit includes the author's DCO sign-off
  • Self-review, scoped formatting and pre-commit completed
  • Tests and API documentation updated
  • Native build and focused tests pass
  • Full related Python suite passes (two baseline-reproduced failures)
  • Human review of every changed line completed
  • Related-PR reconciliation complete
  • For changes >500 LOC: a dedicated RFC issue has been filed

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used

OpenAI Codex assisted with implementation, review, tests and drafting. Assistant review is not presented as human review.

@github-actions github-actions Bot added documentation Improvements or additions to documentation run-ci Store Transfer Engine Installation Integration Tests size/L 1001+ changed lines (additions + deletions) labels Nov 17, 2026
@zxpdemonio zxpdemonio changed the title [Store] Add aligned tensor I/O and owned external buffer leases [Store] Support sparse attention replay with aligned tensor I/O Nov 17, 2026
@zxpdemonio
zxpdemonio force-pushed the feat/registered-tensor-buffer-leases branch 4 times, most recently from 4f8bcd4 to 8d5db6b Compare November 17, 2026 10:03
@zxpdemonio
zxpdemonio force-pushed the feat/registered-tensor-buffer-leases branch 4 times, most recently from 4750931 to 733c86d Compare November 28, 2026 15:26
Reuse registered range transfers for caller-owned tensor destinations and strict device-source chunks. Keep direct alignment opt-in and preserve ordinary structured fields.

Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
Register caller-owned memory through the existing pool and retain its owner
until lease release. Opaque byte-range borrows reuse the lease export count
without exposing device memory through the Python buffer protocol. Retain
failed cleanup for retry and quarantine ambiguous registration outcomes.

Use the existing caller-owned Store lifetime: drain transfers and consumers,
release borrows and leases, then close the pool before closing or resetting
the Store. No global interception of raw registration or close is added.

Share tensor row range planning across payload-only and encoded readers and
validate the current destination layout against schema requirements and
native registration bounds.

Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
Keep one case per direct-read path, keep the direct-destination docs to
ownership and lifecycle, and remove the prefer_pool plumbing that only
changed an internal allocation path.

Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
@zxpdemonio
zxpdemonio force-pushed the feat/registered-tensor-buffer-leases branch from 733c86d to 85b66be Compare November 28, 2026 15:40

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Installation Integration run-ci size/L 1001+ changed lines (additions + deletions) Store Tests Transfer Engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant