Pysyft实验20220222 @程序员也会giao
通过指针移动数据
import syft as sy
import torch
from torch import nn
from torch import optim
hook = sy.TorchHook(torch)
bob = sy.VirtualWorker(hook, id = "bob")
alice = sy.VirtualWorker(hook, id = "alice")
x = torch.tensor([1,2,3,4,5]).send(bob)
现在指针指向bob,数据发送给了bob
print(' bob:', bob._objects)
print('alice:',alice._objects)
x
输出看到bob有数据,alice没有,x为me指向bob的指针
bob: {1108984722: tensor([1, 2, 3, 4, 5])}
alice: {}
(Wrapper)>[PointerTensor | me:32268898849 -> bob:1108984722]
通过指针.move()操作将数据移动给alice
x = x.move(alice)
print(' bob:', bob._objects)
print('alice:',alice._objects)
可以看到数据已经给了alice
bob: {}
alice: {1108984722: tensor([1, 2, 3, 4, 5])}
接着查看这个指针,可以看到指向alice
x
(Wrapper)>[PointerTensor | me:32268898849 -> alice:1108984722]
|