Deploy PySyft Workers using Docker

We will begin by starting our three workers using that docker-compose file


In [1]:
!docker-compose up -d


Creating network "deploy_workers_default" with the default driver
Creating deploy_workers_alice_1 ... 
Creating deploy_workers_charlie_1 ... 
Creating deploy_workers_bob_1     ... 
ting deploy_workers_charlie_1 ... done

Then import syft and hook pytorch


In [2]:
import torch
import syft
from syft import WebsocketClientWorker

hook = syft.TorchHook(torch)


WARNING:tf_encrypted:Falling back to insecure randomness since the required custom op could not be found for the installed version of TensorFlow. Fix this by compiling custom ops. Missing file was '/usr/lib/python3.7/site-packages/tf_encrypted/operations/secure_random/secure_random_module_tf_1.14.0.so'
WARNING:tensorflow:From /usr/lib/python3.7/site-packages/tf_encrypted/session.py:26: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

WARNING:tensorflow:From /usr/lib/python3.7/site-packages/tf_encrypted/session.py:26: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

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())


tensor([73, 74, 75])
tensor([73, 74, 75])
tensor([73, 74, 75])

Here we deployed and interacted with 3 different workers in just some line of code.

Stopping the workers

You wouldn't love to have 3 workers running on the background without notice, so don't forget to run this cell to stop all the 3 workers.


In [7]:
!docker-compose down


Stopping deploy_workers_charlie_1 ... 
Stopping deploy_workers_alice_1   ... 
Stopping deploy_workers_bob_1     ... 
ping deploy_workers_alice_1   ... doneRemoving deploy_workers_charlie_1 ... 
Removing deploy_workers_alice_1   ... 
Removing deploy_workers_bob_1     ... 
Removing network deploy_workers_defaultdone