Skip to main content

Asynchronous P2P communication backend for decentralized pipeline parallelism, built on top of Iroh

Project description

Prime Intellect

PRIME-IROH: P2P Pipeline Parallel Communication


This library exposes a Python interface for reliable, asynchronous peer-to-peer communication built upon Iroh. The core classes exposed are:

  • Node: A class combining a single-peer sender/ receiver in one class, allowing to send to exactly one and receive from exactly one (potentially different) peer. The class allows for concurrent communication by opening multiple, consistent streams.
  • Work: A class representing the future of an asynchronous operation, that can be awaited using a wait method.

Because we are building on top of Iroh, we get many nice networking features out of the box. Most importantly, the library guarantees reliable P2P connections between nodes, trying to establish directions connections whenever possible, and falling back to NAT-hole punching and relaying when necessary. The API is mirroring the way asynchronous communication is handled in torch.distributed, i.e. exposing isend and irecv that return work objects that can be awaited using a wait method. This allows for a clean integration with the rest of the PyTorch ecosystem.

Installation

Quick Install: Run the following command for a quick install:

curl -sSL https://raw.githubusercontent.com/PrimeIntellect-ai/prime-iroh/refs/heads/master/script/install.sh | bash

Manual Install: First, install uv and cargo to build the project.

curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env

Then, clone the repository

git clone git@github.com:PrimeIntellect-ai/prime-iroh.git && cd prime-iroh

To build the Rust backend run cargo build, to build the Python bindings run uv sync. This will let you install prime-iroh as a Python package within the virtual environment.

Usage

You can find the basic usage examples in the examples directory showing unidirectional and bidirectional communication patterns in Rust.

Run unidirectional communication example:

cargo run --example unidirectional

Run bidirectional communication example:

cargo run --example bidirectional

For Python usage, you would use the node class as follows:

# On the receiver side
from prime_iroh import Node

# Initialize the node
node = Node(num_streams=1)
print(f"Connect to: {node.node_id()}")

# Wait for sender to connect
while not node.can_recv():
    time.sleep(0.1)

# Receive message
msg = node.irecv(tag=0).wait()
# On the sender side
from prime_iroh import Node

# Initialize the node
node = Node(num_streams=1)

# Connect to the receiver
node.connect(peer_id=...)

# Wait for connection to be established
while not node.can_send():
    time.sleep(0.1)

# Send message
node.isend("Hello, world!".encode(), tag=0, latency=None).wait()

Tests

We include unit tests and integration tests for the Rust backend which can be run using cargo test. The integration tests for uni- and bidirectional communication are also ported to Python and can be run using uv run pytest.

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.

prime_iroh-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

prime_iroh-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

prime_iroh-0.1.2-cp311-cp311-manylinux_2_34_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

prime_iroh-0.1.2-cp310-cp310-manylinux_2_34_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

File details

Details for the file prime_iroh-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for prime_iroh-0.1.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4f694a0587c773355bedfb1150f5e72fb97cd8c97b50c9baaf03748c2e37763b
MD5 bd273d0faaa956516db8c266692dfbee
BLAKE2b-256 f4c60f423f10b87d6c3ad21a3d6858696bdd96e13f7a5c71587a502153de0caf

See more details on using hashes here.

File details

Details for the file prime_iroh-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for prime_iroh-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 226c1d05b4929dfbd3c08734e37f5d3ae4e6a21aadb863c295261aa0b546af2b
MD5 268e6bab2fb4627298ce9dfcc0291936
BLAKE2b-256 fcc0aadf5a43145537aea760bce000a83958f6fc2678f43c1b34777ebf9ba789

See more details on using hashes here.

File details

Details for the file prime_iroh-0.1.2-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for prime_iroh-0.1.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d96cf28a681ac3199aa5a10252b3d3f7ac769787eefcadb5564bb07fb4e8a332
MD5 a9a3377f1d9eb7d02dbe84171017398b
BLAKE2b-256 0871da6c5c5c8a96d637190c4e84c4218855cb449a352483712e2ba845fcfa5b

See more details on using hashes here.

File details

Details for the file prime_iroh-0.1.2-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for prime_iroh-0.1.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 611d10e7e328634610a854f42e0584b516b3c5d33164d6ad4b47c2587f51ce9f
MD5 b71556f6b49acbd64468507a88e90b59
BLAKE2b-256 5b3c071424a6be40f93cf88a703d9553f9e11040fd0af9b838867129796f06c4

See more details on using hashes here.

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