A multiple parties involved execution engine on the top of Ray.
Project description
RayFed
A multiple parties joint, distributed execution engine on the top of Ray.
Installation
Install it from pypi.
pip install -U secretflow-rayfed
Quick Start
This example shows how to do aggregation across two participators.
Step 1: save the code.
Save the code as a python file, e.g., test.py.
import sys
import fed
@fed.remote
class MyActor:
def __init__(self, value):
self.value = value
def inc(self, num):
self.value = self.value + num
return self.value
@fed.remote
def aggregate(val1, val2):
return val1 + val2
def main(party):
cluster = {
'alice': {'address': '127.0.0.1:11010'},
'bob': {'address': '127.0.0.1:11011'},
}
fed.init(address='local', cluster=cluster, party=party)
actor_alice = MyActor.party("alice").remote(1)
actor_bob = MyActor.party("bob").remote(1)
val_alice = actor_alice.inc.remote(1)
val_bob = actor_bob.inc.remote(2)
sum_val_obj = aggregate.party("bob").remote(val_alice, val_bob)
result = fed.get(sum_val_obj)
print(f"The result in party {party} is {result}")
fed.shutdown()
if __name__ == "__main__":
assert len(sys.argv) == 2, 'Please run this script with party.'
main(sys.argv[1])
Step 2: run the code.
Open a terminal and run the code as alice
. It's recommended to run the code with Ray TLS enabled (please refer to Ray TLS)
RAY_USE_TLS=1 \
RAY_TLS_SERVER_CERT='/path/to/the/server/cert/file' \
RAY_TLS_SERVER_KEY='/path/to/the/server/key/file' \
RAY_TLS_CA_CERT='/path/to/the/ca/cert/file' \
python test.py alice
In the mean time, open another terminal and run the code as bob
.
RAY_USE_TLS=1 \
RAY_TLS_SERVER_CERT='/path/to/the/server/cert/file' \
RAY_TLS_SERVER_KEY='/path/to/the/server/key/file' \
RAY_TLS_CA_CERT='/path/to/the/ca/cert/file' \
python test.py bob
Then you will get The result in party alice is 5
on the first terminal screen and The result in party bob is 5
on the second terminal screen.
Running untrusted codes
As a general rule: Always execute untrusted codes inside a sandbox (e.g., nsjail).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for secretflow_rayfed-0.1.0b0-py3-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c04c8c97fdb986018dcf2f2a8fc719015b6a02fee0f3c9c07297d576e80c6002 |
|
MD5 | 963546bd88d09e6b2852ec7e6b65b364 |
|
BLAKE2b-256 | c4003a47b3f194f6c42222c6207a8b7cbb95b0c6c9ba443364a85d98042174cf |