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.5.tar.gz (160.4 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.5-py3-none-macosx_11_0_arm64.whl (10.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

irohds-0.3.5-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for irohds-0.3.5.tar.gz
Algorithm Hash digest
SHA256 9e3345cf5d4dc0f633c7661d36e8a402ee0fe014128df1f13c9662d925b3906a
MD5 8d269a1a7c57dbaecddafb54f216ef2d
BLAKE2b-256 7ac37a99de285e660b97171d29194bdb7bbbb8e4d943ae86f6e81a5f83f668b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for irohds-0.3.5-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 db83f8b04356880d46093ad1a51163dd9c6580b508a5898c36d8553512615300
MD5 506db9e02e1441a09b97199ad7409acc
BLAKE2b-256 189c680e8e027dfb8857ac384cef406ec114d84890831bad46b4e8f94b96bad5

See more details on using hashes here.

File details

Details for the file irohds-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: irohds-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for irohds-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6012fbd50d5475c43a533d66c5948b6066524db15ae404a9a1ee6f32dac0712a
MD5 4f675b27100d26a96859a3e93e3dda84
BLAKE2b-256 2e8706d4d5f4a16602cfdd5b23deee7f42165d43a4a4e32d29e5eb0930d8ee9d

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