问题:torch.nn.DataParallel设置之后,仍然在一块GPU上加载直到内存爆掉。
解决: 如果你的model包含encoder1,encoder2,decoder,discriminator等多个结构,应当对每个结构都用torch.nn.DataParallel包裹,而不是只对model进行包裹。
原来(出错):
model = MyModel.MyModel(opt).cuda()
model.train()
model = torch.nn.DataParallel(model)
model = model.module
应当改为:
self.encoder1= torch.nn.DataParallel(self.encoder1)
self.encoder2= torch.nn.DataParallel(self.encoder2)
self.decoder = torch.nn.DataParallel(self.decoder)
self.discriminator= torch.nn.DataParallel(self.discriminator)