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.1-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.1-cp312-cp312-manylinux_2_34_x86_64.whl (8.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

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

File metadata

File hashes

Hashes for prime_iroh-0.1.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5c33013332121555927908eb8132943a93a7a40ac745be30541dfb6aea45edd3
MD5 e293e81b5cff59ff5ba515bd5d1b7074
BLAKE2b-256 a34eea6424209286ba42102a9745280037c975159393f8d97f68e0e2fc60170e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prime_iroh-0.1.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3defb179a3982fcc4e0d79146c5384fc6e827c38d12a59905f2471d44316166e
MD5 f128258b25d1997e132c7ff5577957dd
BLAKE2b-256 6c12d9bdef47ac16ab5e19123b2e6344d481d7d827a96a77ee1b36f14a709e97

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