pytorch并行化交叉验证循环

问题描述 投票:0回答:1

我有一个安装了tensorflow和pytorch的cuda9-docker,我正在对图像数据集进行交叉验证。目前我正在使用for循环来进行交叉验证。就像是

for data_train, data_test in sklearn.kfold(5, all_data):
  train(data_train)
  test(data_test)

但for循环需要太长时间,以下代码是否可以并行化for循环?也许已经有了解决方案。但这不是数据并行化。

from multiprocessing import Pool

def f(trainset, testset):
    train_result = train(trainset)
    test_result = test(testset)
    save_train_result()
    save_test_result()

if __name__ == '__main__':
    with Pool(5) as p:
        print(p.map(f, sklearn.cvfold(5, all_data)))

我不确定多处理是否只会使cpu或cpu和gpu并行化?这可能比在一个模型中做并行而更容易,我猜想像https://discuss.pytorch.org/t/parallelize-simple-for-loop-for-single-gpu/33701,因为在我的情况下,没有必要在每个进程之间进行通信?

pytorch gpu-programming
1个回答
1
投票

你使用PyTorch尝试horovod。

ResNet50示例在这里:https://github.com/horovod/horovod/blob/master/examples/pytorch_imagenet_resnet50.py

与horovod相关的变化应该是小而孤立的。

© www.soinside.com 2019 - 2024. All rights reserved.