【发布时间】:2019-04-03 07:47:20
【问题描述】:
这是一个在多GPU环境中运行的简单类。第一次迭代后成员变量self.firstIter应该是False。
Class TestNetwork(nn.Module):
def __init__(self):
super(TestNetwork, self).__init__()
self.firstIter = True #indicates whether it's the first iteration
def forward(self, input):
print 'is firstIter: ', self.firstIter #always True!!
if self.firstIter is True:
self.firstIter = False
# do otherthings
仅使用一个 gpu 时,代码可以正常工作。
但是,当使用多 GPU(即nn.DataParallel)时,self.firstIter 的值始终打印为True。
为什么会这样?代码有什么问题?
使用 PyTorch 0.3.1 版。
【问题讨论】:
标签: variables pytorch multi-gpu