【问题标题】:Asynchronous evaluation in ipython parallelipython并行中的异步评估
【发布时间】:2013-09-09 11:05:52
【问题描述】:

自从很棒的1.0.0 发布以来,我一直在玩iPython 并行接口。我想做的是建立一个异步随机梯度下降系统。在我看来,我想向所有节点发送一个函数,并在结果出来时得到结果。从我能够实现的内容和从文档中一目了然,实现的标准视图并不真正支持这一点。 get(timeout) 方法可以做到这一点,但您不能真正使用超时循环遍历 <ASync_result> 对象中的每个条目。我设法让它运行的方式如下

c = Client()
calls = []
for i,j in enumerate(args):
    calls.append( c[ i % len( c.ids ) ].apply( f, j ) )

while condition:
    dels = []
    for i,j in enumerate( calls ):
         try:
             print j.get(0.01) #or some other timeout
             dels.append( i ) #I keep track of the calls that have been called
             #do something with the last result, throw a new call
             calls.append( c[ i % len(c.ids) ].apply( f, argument )
         except:
             pass

    for i,d in enumerate( dels ):
         del calls[ d - i ] #delete gotten calls

    #evaluate stopping condition

现在,在你们大喊这是可怕的代码和愚蠢的做法之前,我知道这一点。我可以让这种特殊的方式做得更好,但我只是想知道在 IPython.parallel 中是否有一些内置的方式来做类似的事情。

提前感谢任何抽出时间的人。

最好, 阿尔。

【问题讨论】:

  • 当你有一个等待所有任务完成的while循环时,异步执行有什么意义?您刚刚在异步 API 之上实现了同步执行 :)
  • 没错,但最终我想实现一个循环,不断抛出新调用并在它们出现时获取它们。我将在示例中更新它。
  • 我的目标是为神经网络实现异步 sgd。所以调用可能与当前参数有些不同步。我会一直打电话给他们,直到误差变化小于一定数量,作为移动平均线或类似的东西。该死的,维克多,你在 ipython 标签上肯定很快!非常感谢!

标签: python parallel-processing ipython ipython-parallel


【解决方案1】:

您可以创建多个异步调用,然后遍历它们。

c = Client()
dview = c[:]
asyncs = [dview.map_async(f, [arg]) for arg in args]
while asyncs:
    for async in asyncs[:]:
        if async.ready():
            asyncs.remove(async)
            print async.result[0]

【讨论】:

    猜你喜欢
    • 2021-12-19
    • 2017-10-21
    • 1970-01-01
    • 2011-05-31
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 2020-03-14
    相关资源
    最近更新 更多