Migrate Python packaging to maturin - #4730
Draft
dulinriley wants to merge 2 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR replaces the setuptools/setuptools-rust packaging path with a project-owned PEP 517 backend layered on maturin. It preserves the
torchmonarchdistribution name, existing Python import paths, the nativemonarch-tuicommand, build feature environment variables, andMONARCH_VERSIONoverrides.The two Torch C++ modules are now compiled into the main PyO3 library and registered as
monarch.common._Candmonarch.gradient._gradient_generatorduring initialization. Cargo builds and stages the TUI executable as part of the same dependency graph as the extension. The wrapper builds frontend assets and rewrites wheel/sdist metadata andRECORDentries where necessary.Benefits
_rust_bindings,_C, and_gradient_generatorbecome one_rust_bindingslibrary.monarch-tuiremains a separate native executable.setup.pyand all setuptools/setuptools-rust build integration.setuptools,setuptools-rust,wheel,numpy, andtorchbecomematurin,packaging,numpy, andtorch.uv build,python -m build, and editable installs continue using standard PEP 517 hooks.monarch-tuias a Cargo artifact dependency of the PyO3 extension, so the extension and executable share one Cargo invocation, dependency graph, and target cache.MONARCH_REQUIRE_FRONTEND=1, while local builds retain the previous warning-and-continue behavior when npm is unavailable.RECORD, and sdist rewriting.Costs and tradeoffs
build_backend.py: 533,build_support.py: 437), versus the removed 551-linesetup.py: a net increase of 419 production lines. Including tests and related changes, the branch is approximately +1,501/-672 lines (+829 net).RECORDentry.PKG-INFO,monarch_extension/Cargo.toml, and themonarch_extensionentry inCargo.lock.bindepssupport; this is not yet a stable-Cargo-only packaging path..so/.dylibfiles or meaningful module__file__paths. Their public import paths and APIs remain unchanged, but low-level debugging and tooling will see symbols inside_rust_bindings.build-backendis not literallymaturin; this is expected because the project intentionally uses a wrapper backend.Validation completed locally
cargo checkpasses for the CPU tensor-engine configuration withembedded-cppenabled.0.0.0to1.2.3rc1.PKG-INFO, Cargo manifest, and lockfile versions. A wheel rebuilt successfully from that sdist with--locked.9.8.7.dev3; it contained 431 entries and was approximately 74 MB compressed on macOS..pyifiles, had a valid regeneratedRECORD, and installedmonarch-tuiwith executable permissions.import monarch,monarch.common._C, gradient generation, Torch build-version checking, andmonarch-tui --helpall succeeded.monarch-tuiexecutable with executable permissions.Local build timings
These are indicative measurements from one macOS arm64 workspace, not controlled CI benchmarks:
The large improvement comes from sharing one Cargo graph and cache, not from wheel assembly itself. CI should repeat cold and warm measurements before treating these figures as portable across Linux, CUDA, and ROCm builders.
CI coverage requested
The existing build matrices exercise slim Linux, macOS CPU tensor-engine, Linux CUDA, and opt-in ROCm builds across the supported Python versions (3.10-3.13). The build jobs now run the packaging unit tests, and release-oriented wheel jobs require frontend assets.