Path: blob/master/Federated-Learning-Intro/Pysyft_API_Tutorial.ipynb
3118 views
Basic API details
Install pysyft using pip
Now we import PyTorch and PySyft, however we hook torch with syft with TorchHook
function. The TorchHook
does the wrapping by adding all the additional functionality to PyTorch for doing Federated Learning and other Private AI techniques.
First, let's create a virtual machine owned by some health clinic, say harmony_clinic
. We will be using this to simulate a machine present at a remote location. A thing to note is that syft calls these machines as VirtualWorker
.
harmony_clinic
is at a remote location but it doesn't have any data we can use. Let's create some data so that we can send it to harmony_clinic
We see that the PointerTensor
points from me
(which is us, PySyft creates this me
worker automatically) to harmony_clinic
. We also see some random numbers, these are actually object IDs that PySyft assigns to every object.
dna_ptr
.
Now harmony_clinic
has the tensor that we sent. We can use harmony_clinic._objects
to see objects that
currently has.harmony_clinic
And in the same way, we can get a tensor back from a remote location by using the .get()
function.
Deep Learning with Pointers
Something very interesting happened behind the scenes, i.e. when did c = a + b
on our machine, a command was sent to the remote machine that did that exact calculation, created a new tensor on its machine and then sent back a pointer to us which we now call c
.
The amazing thing is this API has been extended to all the PyTorch operations including Back propogation. Hurray !!
This means that we can use the same PyTorch code that we usually do when doing Machine Learning.