我正在尝试使用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()