Skip to content

[Wheel] Support DataProto matrix partial reads - #3567

Merged
stmatengss merged 8 commits into
kvcache-ai:mainfrom
zxpdemonio:cruz/dataproto-submatrix-read
Sep 23, 2026
Merged

stmatengss merged 8 commits into
kvcache-ai:mainfrom
zxpdemonio:cruz/dataproto-submatrix-read

Conversation

@zxpdemonio

@zxpdemonio zxpdemonio commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Add partial matrix reads for dense two-dimensional DataProto batch fields.

The public batch_slices mapping selects a column slice per field and composes
with the existing rows selection. A single M x N implementation covers row
batches, column batches, and general submatrices without separate code paths.

The implementation:

  • plans byte ranges from matrix shape, dtype, selected rows, and column slice;
  • coalesces consecutive full-width rows;
  • uses one BufferPool lease and one get_into_ranges call across selected
    fields, DataProto stages, and payload chunks;
  • keeps NumPy results writable and rewrites native tensor metadata for the
    sliced shape;
  • commits caller destinations only after every selected field and the final
    DataProto result have been constructed successfully;
  • falls back to regular materialization when ranged reads are unavailable or
    the request exceeds the range or physical-fragment limits.

The fast path guarantees one batched ranged call. The fallback is intentionally
whole-request and does not guarantee a single backend call; this keeps the
destination commit semantics and the hot path small. Logical ranges are capped
per field, while physical fragments are capped at 4096 across the entire
batched request before BufferPool allocation.

The append write path is unchanged. Dense matrix fields added through
append_dataproto_fields() are resolved from their existing stage refs and can
participate in the same batched partial read.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • 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:

cd mooncake-wheel
python3 -m pytest -q tests/test_partial_read.py
python3 -m pytest -q tests/test_structured_object_store.py \
  -k "dataproto_matrix or empty_matrix_read"
python3 -m pytest -q \
  tests/test_structured_object_store.py::test_dataproto_later_field_failure_does_not_commit_matrix_destination \
  tests/test_structured_object_store.py::test_dataproto_result_failure_does_not_commit_matrix_destination \
  tests/test_structured_object_store.py::test_dataproto_copied_result_keeps_matrix_destination
python3 -m pytest -q \
  tests/test_structured_object_store.py::test_dataproto_helper_appends_stage_fields_without_rewriting_existing

python3 -m py_compile \
  mooncake/_partial_read.py \
  mooncake/structured_object_store.py \
  tests/test_partial_read.py \
  tests/test_structured_object_store.py

Test results:

  • Unit tests pass: planner 15 passed; matrix path 7 passed; destination
    atomicity 3 passed; append regression 1 passed
  • Integration tests pass (not run in this environment)
  • Manual testing done

The broader structured-object suite completed with 90 passed and 28 skipped.
Three native fast-copy PUT tests fail because the installed
_concat_arrays_into extension returns zero bytes. The same three tests fail
identically on current main at 266a966b.

Ruff check and format validation pass for both new files. py_compile and
git diff --check pass for all changed Python files. Full-file ruff-format
was not applied to the existing legacy files because it rewrites hundreds of
unrelated lines.

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 (not applicable: 401
    production additions, 417 including documentation)

AI Assistance Disclosure

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

Codex was used to help implement, simplify, review, and validate the change.
The human submitter is responsible for reviewing and defending the final code.

@zxpdemonio

Copy link
Copy Markdown
Collaborator Author

@stmatengss @yokinoshitayoki Could you please help review this PR? In particular, feedback on the DataProto matrix partial-read semantics and compatibility would be appreciated. Thanks!

@yokinoshitayoki

Copy link
Copy Markdown
Collaborator

@zxpdemonio I tried to rerun these two checks but still failed. Could you take a look?
Build & Test (Linux) / Check Python with Ruff (pull_request)
Build & Test (Linux) / CI Gate (pull_request)

…rix-read

* origin/main: (202 commits)
  [Reshard] Add KV cache reshard planning (kvcache-ai#3564)
  [Store] Release GIL during client setup (kvcache-ai#3947)
  [TENT] Export EGM host memory over multi-node NVLink (opt-in) (kvcache-ai#3978)
  [EP] Support NCCL ElasticBuffer recovery after rank replacement (kvcache-ai#3963)
  [TransferEngine] Prefer THP for shared-segment mmap without a HugeTLB pool (kvcache-ai#3952)
  [TransferEngine] Add POSIX SHM transport for same-host DRAM copies (kvcache-ai#3918)
  [Store] Sweep stale handles in bounded write-lock batches (kvcache-ai#3593)
  [Store] Add recoverable client liveness and asynchronous offboarding (kvcache-ai#2991)
  [Store] Wire opt-in batch OpLog snapshots into standby runtime (kvcache-ai#3950)
  [Store] Structure CxlSegmentConfig environment settings (kvcache-ai#3967)
  [Store] Structure ClientNumaConfig environment settings (kvcache-ai#3966)
  [Store] Structure MmapArenaConfig environment settings (kvcache-ai#3956)
  [Store] Structure NoFRegisterConfig environment settings (kvcache-ai#3949)
  [Store] Structure NvmeKvConnectorConfig environment settings (kvcache-ai#3948)
  [Store] Introduce SegmentPool catalog and lifecycle (kvcache-ai#3705)
  TENT: deliver self-targeted notifications in-process (kvcache-ai#3464)
  [Integration] Fail Python init when allocator support is unavailable (kvcache-ai#2404)
  [Py] Fix batch_id leak on timeout and submit failure paths (kvcache-ai#2350)
  [Bugfix][TransferEngine] Export the requested range for dma-buf registration under CUDA VMM (fixes kvcache-ai#2511) (kvcache-ai#3538)
  [Store] Validate DummyClient registration of external pinned buffers (kvcache-ai#3712)
  ...
Signed-off-by: Teng Ma <stmatengss@gmail.com>
@stmatengss
stmatengss merged commit 419cf0f into kvcache-ai:main Sep 23, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/Build documentation Improvements or additions to documentation Installation run-ci Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants