问题1
allennlp框架多gpu训练时warning:UserWarning: RNN module weights are not part of single contiguous chunk of memory. This means they need to be compacted at every call, possibly greately increasing memory usage. To compact weights again call flatten_parameters()
解决方案1
1.普通pytorch模型处理方式,在forward函数中加上flatten_parameters()
def forward...
if not hasattr(self, '_flattened'):
self.rnn.flatten_parameters() #rnn为自定义的rnn模型
setattr(self, '_flattened', True)
2. allennlp多gpu模型时处理方式,由于self.ner_encoder在allennlp框架中进行了封装,因此需要进行以下操作:
def forward...
if not hasattr(self.ner_encoder._module, '_flattened'):
self.ner_encoder._module.flatten_parameters()
if not hasattr(self.ner_decoder._module, '_flattened'):
self.ner_decoder._module.flatten_parameters()
版权声明:本文为nihao1621原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。