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.0b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12e8a0690aaf68c9f4b1f70cb23f5238674bd88618c1621d296f220ade9e6b36 |
|
MD5 | fe770d8d8aa72da65e5cc2db408923d0 |
|
BLAKE2b-256 | 9869baf56534d93e59ba757b2f50d863c3e0c8bd174b8ff0cc5019771dc79513 |