Skip to main content

Decentralized function memoization over iroh P2P

Project description

irohds

A drop-in Python decorator that caches function results and shares them automatically across every machine running the same code. No servers to manage, no configuration, no accounts.

If someone at another institution already computed train_model("cifar10", epochs=50), your machine downloads the result instead of spending hours recomputing it. If nobody has computed it yet, your machine does the work and makes the result available to everyone else.

import irohds

@irohds.memo
def train_model(dataset, epochs=10):
    ...  # hours of GPU time
    return model

result = train_model("cifar10", epochs=50)
# First run: computes (hours). Every subsequent run, on any peer: instant.

Who is this for

Research groups and institutions that repeatedly run expensive computations across many machines. If your lab has 20 people who all run the same preprocessing pipeline on the same datasets, irohds means only the first person waits. Everyone else gets the result in seconds.

Works across institutions, across continents, across networks. Peers find each other through the BitTorrent mainline DHT (16M+ nodes). No central server, no coordinator, no shared filesystem required.

What it is not for

Functions that complete in under 15 seconds. The network overhead of sharing results only pays off for genuinely expensive computations. For fast functions, use functools.cache, joblib.Memory, or diskcache. irohds will warn you if a decorated function is too cheap to benefit from network sharing.

Install

uv add irohds

This installs the Python package, the Rust daemon binary, and the coren machine capability library. The daemon starts automatically on first use and installs itself as a system service (starts at boot, runs in a sandbox).

Usage

import irohds

# Basic: share results with all peers globally
@irohds.memo
def expensive_etl(dataset_path):
    ...
    return processed_data

# Namespaced: only share with peers using the same namespace
@irohds.memo(ns="my-lab")
def train(config):
    ...

# Large file outputs
@irohds.memo
def generate_embeddings(corpus):
    ...
    torch.save(embeddings, irohds.resolve("embeddings.pt"))
    return irohds.FileRef("embeddings.pt")

ref = generate_embeddings("pubmed-2024")
embeddings = torch.load(ref.path)  # file is on disk, ready to use

# Selective eviction
irohds.evict("mymodule.train")  # clear cached results for one function

# Pre-warm peer discovery (optional, reduces first-call latency)
irohds.join("my-lab")

How it works

On the first call: irohds hashes the function's AST and arguments into a cache key, executes the function, stores the result in a local content-addressed blob store, and announces it to peers via gossip.

On subsequent calls (same machine): the result is returned from an in-process dict (~0.1us) or from the local blob store via IPC (~0.2ms). No network involved.

On a different machine: irohds checks whether any peer has the result. If yes, it uses coren to decide whether downloading is faster than recomputing locally (based on the function's compute cost and this machine's capabilities). Then it either fetches the result or recomputes, whichever is faster.

Peer discovery is automatic via three mechanisms:

  • Mainline DHT (global, zero config, 16M+ nodes)
  • mDNS (automatic on LAN)
  • Bootstrap peers (fallback for networks that block DHT)

The daemon (irohds-daemon) is a sandboxed Rust process that owns the blob store and handles gossip/P2P networking. It installs as a system service on first use. Python communicates with it over a Unix socket. The sandbox ensures iroh network traffic cannot access the host filesystem beyond the irohds data directory.

Restricted networks

If mainline DHT is blocked (some universities, corporate networks), add known peers to ~/.local/share/irohds/config.toml:

bootstrap_peers = ["<hex-encoded-node-id>"]

Get a peer's node ID with irohds-daemon info.

Performance

Scenario Latency
Repeated call, same process ~0.1us (in-process dict)
First call after process start, data local ~0.2ms (one IPC round-trip)
First call after daemon restart, data local ~1ms (load index + IPC)
Result available from remote peer seconds (network transfer)
Full miss, compute locally depends on function

Developing

cargo build --manifest-path daemon/Cargo.toml  # build the daemon
make test                                       # Rust + Python tests
make test-vm                                    # NixOS QEMU P2P integration test

License

MIT

Project details


Download files

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

Source Distribution

irohds-0.3.11.tar.gz (68.5 kB view details)

Uploaded Source

Built Distributions

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

irohds-0.3.11-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

irohds-0.3.11-py3-none-macosx_11_0_arm64.whl (10.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

irohds-0.3.11-py3-none-macosx_10_12_x86_64.whl (10.4 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file irohds-0.3.11.tar.gz.

File metadata

  • Download URL: irohds-0.3.11.tar.gz
  • Upload date:
  • Size: 68.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for irohds-0.3.11.tar.gz
Algorithm Hash digest
SHA256 f20ceb3f741e72d6dd3b4a04df08c75424db14279b86a69fcc4477cdd643c09a
MD5 1629b546a28638235df4cfd11ec29ba0
BLAKE2b-256 c0a2c19f6b1fc73d0f6e9e0397119f1a543544b124a14adbd76223b3e06ef9f9

See more details on using hashes here.

File details

Details for the file irohds-0.3.11-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for irohds-0.3.11-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a69f871dd71eaf136b2ed95c5e1d15b9433633abe9ba11218e51d491b34a34f8
MD5 9ec7ff85a739cbf8d5ae3d15c320e609
BLAKE2b-256 1c141aeaa225d275745065d3030a79a48d55ea344be5b0036906b1ea5c788462

See more details on using hashes here.

File details

Details for the file irohds-0.3.11-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for irohds-0.3.11-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6aa493b2c12c684f40d09a0eb72ff5852fb12c32213afb013168978e1e575cf3
MD5 43e758f735ee1b0cb915f8eebb4690cb
BLAKE2b-256 651f10dca032a9dde5a028a5fbdecc34db874a8cfc6d4ad5de1b265c7db2ea1e

See more details on using hashes here.

File details

Details for the file irohds-0.3.11-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for irohds-0.3.11-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0368f0f51a1c807e9f97deb1d5c876bb55762b2f9cc845f7507944f868bdb5e8
MD5 bc46e62a6422711da98e430a8877fdc3
BLAKE2b-256 2c54acbc2ad49421cc8a1ec1b017c9e61c0d5f484b85578af5aec72d0eaf1480

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