In [1]:
!docker-compose up -d
Then import syft and hook pytorch
In [2]:
import torch
import syft
from syft import WebsocketClientWorker
hook = syft.TorchHook(torch)
Here we connect to our three worker using their ids and ports.
Note: Wait few seconds before running this cell as the deployment may take some time.
In [4]:
alice = WebsocketClientWorker(hook=hook, id="alice", host='127.0.0.1', port=8777)
bob = WebsocketClientWorker(hook=hook, id="bob", host='127.0.0.1', port=8778)
charlie = WebsocketClientWorker(hook=hook, id="charlie", host='127.0.0.1', port=8779)
Now we can interact with those workers, here we send and get some tensors to make sure that it's working
In [5]:
t = torch.tensor([73, 74, 75])
ta = t.send(alice)
tb = t.send(bob)
tc = t.send(charlie)
print(ta.get())
print(tb.get())
print(tc.get())
Here we deployed and interacted with 3 different workers in just some line of code.
In [7]:
!docker-compose down