import torch as th
import syft as sy
'''
Part 8 bis - Introduction to Protocols
http://localhost:8888/notebooks/git-home/github/PySyft/examples/tutorials/Part%2008%20bis%20-%20Introduction%20to%20Protocols.ipynb
'''
'''
本例演示protocol
一个protocol是若干个plan的集合,这些plan可以分布在不同的远程节点上。protocol提供更多的运算符号
'''
hook = sy.TorchHook(th)
hook.local_worker.is_client_worker = False
#定义三个plan
@sy.func2plan(args_shape=[(1,)])
def inc1(x):
return x + 1
@sy.func2plan(args_shape=[(1,)])
def inc2(x):
return x + 1
@sy.func2plan(args_shape=[(1,)])
def inc3(x):
return x + 1
#把三个plan组装成一个protocol
protocol = sy.Protocol([("worker1", inc1), ("worker2", inc2), ("worker3", inc3)])
#创建虚拟节点
bob = sy.VirtualWorker(hook, id="bob")
alice = sy.VirtualWorker(hook, id="alice")
charlie = sy.Virtu
[pysyft-006]联邦学习pysyft从入门到精通--使用protocol
最新推荐文章于 2024-04-08 17:55:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)