PySyft Notes

hook = sy.TorchHook(torch)

Hook shows the usage of template method, a design pattern.

It extend the function and interfaces of torch.

bob = sy.VirtualWorker(hook, id="bob")

Define a node participating in federated training.

x = torch.tensor([1,2,3,4,5])
y = torch.tensor([1,1,1,1,1])
# x y都是本地的数据
z = x + y # z 也是本地的
# 将x发送到alice、y发送到bob
x_ptr = x.send(alice)
y_ptr = y.send(bob)
# 这一句不能执行,因为x_ptr是alice的数据,y_ptr是bob的数据
z = x_ptr + y
# 可以执行,x_ptr和y_ptr此时都在bob上
x_ptr = x.send(bob)
z = x_ptr+y_ptr

Only the manipulation between tensors in the same agent can be executed.

Avatar
Pei Fang
Student, Coder

Enthusiasm is impetus.