Skip to main content

Monarch: Single controller library

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Monarch 🦋

Monarch is a distributed programming framework for PyTorch based on scalable actor messaging. It provides:

  1. Remote actors with scalable messaging: Actors are grouped into collections called meshes and messages can be broadcast to all members.
  2. Fault tolerance through supervision trees: Actors and processes form a tree and failures propagate up the tree, providing good default error behavior and enabling fine-grained fault recovery.
  3. Point-to-point RDMA transfers: cheap registration of any GPU or CPU memory in a process, with the one-sided transfers based on libibverbs
  4. Distributed tensors: actors can work with tensor objects sharded across processes

Monarch code imperatively describes how to create processes and actors using a simple python API:

from monarch.actor import Actor, endpoint, this_host

# spawn 8 trainer processes one for each gpu
training_procs = this_host().spawn_procs({"gpus": 8})


# define the actor to run on each process
class Trainer(Actor):
    @endpoint
    def train(self, step: int): ...


# create the trainers
trainers = training_procs.spawn("trainers", Trainer)

# tell all the trainers to take a step
fut = trainers.train.call(step=0)

# wait for all trainers to complete
fut.get()

The introduction to monarch concepts provides an introduction to using these features.

⚠️ Early Development Warning Monarch is currently in an experimental stage. You should expect bugs, incomplete features, and APIs that may change in future versions. The project welcomes bugfixes, but to make sure things are well coordinated you should discuss any significant change before starting the work. It's recommended that you signal your intention to contribute in the issue tracker, either by filing a new issue or by claiming an existing one.

📖 Documentation

View Monarch's hosted documentation at this link.

Installation

Note for running distributed tensors, the local torch version must match the version that monarch was built with.

On Fedora distributions

Stable

pip install torchmonarch

torchmonarch stable is built with the latest stable torch.

Nightly

pip install torchmonarch-nightly

torchmonarch-nightly is built with torch nightly.

or manually

# Create and activate the conda environment
conda create -n monarchenv python=3.10 -y
conda activate monarchenv

# Install nightly rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup toolchain install nightly
rustup default nightly

# Install non-python dependencies
conda install libunwind -y

# Install the correct cuda and cuda-toolkit versions for your machine
sudo dnf install cuda-toolkit-12-0 cuda-12-0

# Install clang-dev and nccl-dev
sudo dnf install clang-devel libnccl-devel
# Or, in some environments, the following may be necessary instead
conda install -c conda-forge clangdev nccl
conda update -n monarchenv --all -c conda-forge -y

# If you are building with RDMA support, build monarch with `USE_TENSOR_ENGINE=1 pip install --no-build-isolation .` and dnf install the following packages
sudo dnf install -y libibverbs rdma-core libmlx5 libibverbs-devel rdma-core-devel

# Install build dependencies
pip install -r build-requirements.txt
# Install test dependencies
pip install -r python/tests/requirements.txt

# Build and install Monarch
pip install --no-build-isolation .
# or setup for development
pip install --no-build-isolation -e .

# Run unit tests. consider -s for more verbose output
pytest python/tests/ -v -m "not oss_skip"

On Ubuntu distributions

# Clone the repository and navigate to it
git clone https://github.com/meta-pytorch/monarch.git
cd monarch

# Install nightly rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustup toolchain install nightly
rustup default nightly

# Install Ubuntu-specific system dependencies
sudo apt install -y ninja-build
sudo apt install -y libunwind-dev
sudo apt install -y clang

# Set clang as the default C/C++ compiler
export CC=clang
export CXX=clang++

# Install build dependencies
pip install -r build-requirements.txt
# Install test dependencies
pip install -r python/tests/requirements.txt

# Build and install Monarch (with tensor engine support)
pip install --no-build-isolation .

# or
# Build and install Monarch (without tensor engine support)
USE_TENSOR_ENGINE=0 pip install --no-build-isolation .

# or setup for development
pip install --no-build-isolation -e .

# Verify installation
pip list | grep monarch

On MacOS

You can also build Monarch to run locally on a MacOS system.

Note that this does not support tensor engine, which is tied to CUDA and RDMA (via ibverbs).

# Create and activate the conda environment
conda create -n monarchenv python=3.10 -y
conda activate monarchenv

# Install nightly rust toolchain
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup toolchain install nightly
rustup default nightly

# Install build dependencies
pip install -r build-requirements.txt
# Install test dependencies
pip install -r python/tests/requirements.txt

# Build and install Monarch
USE_TENSOR_ENGINE=0 pip install --no-build-isolation .
# or setup for development
USE_TENSOR_ENGINE=0 pip install --no-build-isolation -e .

Running examples

Check out the examples/ directory for demonstrations of how to use Monarch's APIs.

We'll be adding more examples as we stabilize and polish functionality!

License

Monarch is BSD-3 licensed, as found in the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file torchmonarch_nightly-2025.10.2-cp313-cp313-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for torchmonarch_nightly-2025.10.2-cp313-cp313-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c45fe6f204bf435cecabf2035c35df76d09a0dda7da3d98f2f0c0a585a27cc98
MD5 175e07af08825deed1a3c795460703de
BLAKE2b-256 88e3337c685b1181c592cd3a41a13d82186de8e5a3e3afbd632e123f0a364a90

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchmonarch_nightly-2025.10.2-cp313-cp313-manylinux2014_x86_64.whl:

Publisher: wheels.yml on meta-pytorch/monarch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchmonarch_nightly-2025.10.2-cp312-cp312-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for torchmonarch_nightly-2025.10.2-cp312-cp312-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a084af424588688bcdcc06451fbecaf85d269a6dec90b66c29e72db59b0c6c0a
MD5 467eb16cc13aaac471786f8367c0ed04
BLAKE2b-256 e0defa5f9280a8cdd802d9d6dee2a66110e04a61d8d7241fa919d931b3f0b5fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchmonarch_nightly-2025.10.2-cp312-cp312-manylinux2014_x86_64.whl:

Publisher: wheels.yml on meta-pytorch/monarch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchmonarch_nightly-2025.10.2-cp311-cp311-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for torchmonarch_nightly-2025.10.2-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 544b3f41e81060a9c5106f3539834dcb0f567bf3c0ef9921cc2f3a1e4ec37ccb
MD5 b00f2225299359e5212271a9b113e9d1
BLAKE2b-256 444c179af13de94043bcbe4dd7cd661742b39552b3d2f6dafb96acdab17e04f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchmonarch_nightly-2025.10.2-cp311-cp311-manylinux2014_x86_64.whl:

Publisher: wheels.yml on meta-pytorch/monarch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchmonarch_nightly-2025.10.2-cp310-cp310-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for torchmonarch_nightly-2025.10.2-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1986456fde50668eceb71624d361cc7b971d802bec96fa0c5b54b0f0bd64982
MD5 d703d043efd8ef86c5b6d4b90fc05062
BLAKE2b-256 cde0229054ae1173f94bf6d7d1a44ddd2662e2a579932273dd71b72f9b8a0ec3

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchmonarch_nightly-2025.10.2-cp310-cp310-manylinux2014_x86_64.whl:

Publisher: wheels.yml on meta-pytorch/monarch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page