4

我必须使用芹菜来并行化随机梯度下降算法,尽管这可能不是用芹菜做的更好选择,这仍然是我的问题=)

该算法看起来像这样,其中 datas 是样本矩阵:

#Random init of the minimum:
x_current = np.random.random(n_dim)    

for i in range(max_iter):
    #Randomizes the lines, i.e. the samples of the minibatches at each iteration
    np.random.shuffle(datas)

    #I update my gradient by minibatches of n samples
    for batch in range(datas.shape[0] / n)

        delta = gradient(x_current, datas[(batch*n):(batch*(n+1)),:])
        x_current += delta

梯度是作为任务分配的函数。假设我有 10 个工人,首先,我用 10 个前小批量创建 10 个任务梯度。

当有人完成时,我希望用下一个小批量创建一个新任务(它是否改变迭代并返回到第一个小批量并不重要)和当前版本的 x_current(如果不是没关系最后一个版本)。

此外,我必须得到结果并使用返回的 delta 更新 x_current。所有增量都必须在 x_current 上“按顺序”应用(但顺序无关紧要),并且与任务创建异步。

我的问题是,用芹菜做最优雅的方法是什么?谢谢 :)

4

0 回答 0