简易高效的并行接口

在PARL中,一个 修饰符 ( parl.remote_class )就可以帮助用户实现自己的并行算法。请访问我们的 教程 以获取更多的并行训练信息。
以下我们通过 Hello World 的例子来说明如何简单地通过PARL来调度外部的计算资源实现并行计算:
#============Agent.py=================
@parl.remote_class
class Agent(object):

    def say_hello(self):
        print("Hello World!")

    def sum(self, a, b):
        return a+b
parl.connect('localhost:8037')
agent = Agent()
agent.say_hello()
ans = agent.sum(1,5) # it runs remotely, without consuming any local computation resources
两步调度外部的计算资源:
  1. 使用 parl.remote_class 修饰一个类,之后这个类就被转化为可以运行在其他CPU或者机器上的类。

  2. 调用 parl.connect 函数来初始化并行通讯,通过这种方式获取到的实例和原来的类是有同样的函数的。由于这些类是在别的计算资源上运行的,执行这些函数 不再消耗当前线程计算资源

../_images/decorator.png
如上图所示,真实的actor(橙色圆圈)运行在CPU集群,learner(蓝色圆圈)和remote actor(黄色圆圈)运行在本地的GPU上。
对于用户而言,完全可以像写多线程代码一样来实现并行算法,相当简单,但是这些多线程的运算利用了外部的计算资源。我们也提供了并行算法示例,更多细节请参考 IMPALA , A2C 和 GA3C。