Skip to content

[PG] Migrate Python loader to unified package - #3623

Open
Aionw wants to merge 6 commits into
kvcache-ai:mainfrom
Aionw:codex/migrate-pg-python
Open

Aionw wants to merge 6 commits into
kvcache-ai:mainfrom
Aionw:codex/migrate-pg-python

Conversation

@Aionw

@Aionw Aionw commented Aug 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Implement the Mooncake PG Python loader increment of Phase 2 in #3534.

  • move mooncake.pg from mooncake-wheel/mooncake/pg.py to the canonical python/mooncake/pg.py source tree;
  • preserve the public import behavior and version-suffixed Torch ABI selection without renaming native extensions;
  • update scikit-build/CMake installation and the temporary legacy wheel staging input to consume the canonical loader;
  • add source-tree loader tests and installed-wheel coverage proving the loader is packaged exactly once and stays lazy until mooncake.pg is imported;
  • update PG ownership and labeling for the canonical source and tests.

Overlap review:

Closes no issue; contributes to #3534.

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?

Original submission (before merging main on 2026-09-28; superseded by "After merging main" below):

Test commands:

MOONCAKE_TEST_WHEEL="$PWD/dist/mooncake_transfer_engine-0.3.12.post1-cp310-cp310-linux_x86_64.whl" python -m pytest -q python/tests/pg python/tests/packaging
CMAKE_BUILD_PARALLEL_LEVEL=128 python -m build --wheel
python -m twine check dist/mooncake_transfer_engine-0.3.12.post1-cp310-cp310-linux_x86_64.whl
bash -n scripts/build_wheel.sh
git fetch origin main
pre-commit run --files $(git diff --name-only --diff-filter=ACMR origin/main...HEAD)

Test results:

  • Unit tests pass (8 focused PG and packaging tests passed)
  • Integration tests pass (root PEP 517 wheel build, isolated wheel installation under python -I, and installed mooncake.pg ABI-loader smoke test)
  • Manual testing done (twine check passed and the wheel manifest contains exactly one mooncake/pg.py)

After merging main (d9152a4, 2026-09-28):

PYTHONPATH=python:mooncake-wheel python -m pytest -q python/tests/pg python/tests/packaging
pre-commit run --files $(git diff --name-only --diff-filter=ACMR origin/main...HEAD)
  • 18 passed, 2 skipped; the skips are the installed-wheel smoke tests, which need MOONCAKE_TEST_WHEEL / MOONCAKE_TEST_LEGACY_WHEEL.
  • The merge's conflicts in .github/CODEOWNERS were resolved by keeping both sides.
  • CI's changed-lines Python check (ruff check plus scripts/ci/check_changed_python_format.py, ruff 0.6.9) passes.
  • PR-scoped pre-commit passes every hook except cmake-format, which only rewrites the tent_metrics block in mooncake-integration/CMakeLists.txt inherited from main; main at d9152a4 fails the same way, and this PR's own CMake lines pass.
  • The root PEP 517 wheel build, twine check, and installed-wheel smoke runs from the original submission were not repeated after the merge. CI does not run them either (it builds only the legacy scripts/build_wheel.sh wheel and runs scripts/test_installation.sh), so they still need a rerun.

Checklist

  • I have performed a self-review of my own code
  • C/C++ formatting is not applicable; no C/C++ sources changed and the pre-commit hook skipped them
  • I have run pre-commit on the files changed in this PR and all hooks pass (after merging main, except the pre-existing cmake-format issue noted under "After merging main")
  • Documentation updates are not applicable because public imports and behavior are unchanged
  • I have added tests to prove my changes are effective
  • RFC [RFC]: Unify Mooncake's Python package, build, and release architecture #3534 covers this migration (the effective diff is 95 lines after merging main)

AI Assistance Disclosure

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

OpenAI Codex assisted with the module migration, build-path audit, test coverage,
validation, and PR preparation. The human submitter remains responsible for
understanding and defending every changed line.

Claude Code (Anthropic) merged main into this branch on 2026-09-28, resolved the conflicts, re-ran the focused tests listed under "After merging main", and updated this description.

Conflict resolutions, all of the same shape: main landed the sibling
Phase-2 migrations (async_store, CLI, EP, SSD) after this branch forked,
so the PG change had to fold into the generalized machinery main grew
instead of standing alone.

- .github/CODEOWNERS: keep main's full /python/... block, re-add the two
  PG entries next to the EP ones.
- .github/labeler.yml: main widened Tests to 'python/tests/**/*', which
  subsumes the PR's 'python/tests/pg/**/*'.
- mooncake-integration/CMakeLists.txt: union of the two migrations; all
  four EP/PG modules now install from ../python/mooncake/.
- scripts/build_wheel.sh: main replaced the one-off PG staging with a
  MIGRATED_PYTHON_MODULES array; pg.py joins that array.
- python/tests/packaging/test_project.py: keep both new "one
  authoritative source" tests. Also drop "pg.py" from the legacy-tree
  module list in test_scikit_build_consumes_unified_python_sources --
  that assertion was written against a tree where the file had not moved
  yet, and would fail as of this merge.
- python/tests/packaging/test_installed_wheel.py: union of the smoke
  script assertions. The PG block runs last so its "torch was never
  imported" check also covers main's imports and its stub torch module
  cannot leak into them; it now reuses main's import_module.
The rule this exclusion guarded globs the legacy mooncake-wheel/mooncake
source tree, and pg.py no longer lives there after the move to
python/mooncake, so the pattern never matches anything.

main already settled the convention for this on the sibling EP
migration: ep.py, mooncake_ep_buffer.py and mooncake_elastic_buffer.py
moved the same way and added no exclusion. Follow it, which drops
python/CMakeLists.txt from this change entirely.
@github-actions github-actions Bot added the Tests label Sep 21, 2026
Conflict resolution:
- .github/CODEOWNERS: kept both sides. The /python/mooncake/pg.py and
  /python/tests/pg/ entries stay grouped after /python/tests/ep/ (same
  owners), followed by main's
  /python/tests/services/test_http_metadata_server.py entry from kvcache-ai#3632.

All other files merged cleanly. .github/workflows/ci_rocm.yml now matches
main (including kvcache-ai#4266's setup-python change).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant