使用Torch.Multiprocessing并行训练集成神经网络

时间:2018-09-15 12:46:20

标签: python multiprocessing pytorch

我正在尝试使用pytorch实现集成模型,并且由于存在一些独立的模型,我想使用torch.multiprocessing并行训练模型,但是,我总是得到{{ 1}}错误。

这是重现该错误的最小示例:

Too many open files

这是错误消息:

import torch
import torch.nn as nn
from   torch.multiprocessing import Pool

class MyModel:
    def __init__(self):
        self.nn = nn.Sequential(
                nn.Linear(10, 10),
                nn.ReLU(),
                nn.Linear(10, 10), 
                nn.ReLU(), 
                nn.Linear(10, 10), 
                nn.ReLU(), 
                nn.Linear(10, 10), 
                nn.ReLU(), 
                nn.Linear(10, 10), 
                nn.ReLU(), 
                nn.Linear(10, 10), 
                nn.ReLU(), 
                nn.Linear(10, 10), 
                nn.ReLU(), 
                nn.Linear(10, 10), 
                nn.ReLU()
                )

    def train(self):
        pass

class EnsembleModel:
    def __init__(self, K):
        self.K      = K;
        self.models = [MyModel() for i in range(self.K)]

    def f(self, i):
        return i

    def train(self):

        pool = Pool(processes = 3)
        ret  = pool.map(self.f, range(self.K))
        print(ret)


md = EnsembleModel(15);
md.train()

0 个答案:

没有答案