问题
使用多GPU训练模型时会报出如下警告占满屏幕,导致无法查看模型训练状态:
UserWarning::RNN module weights are not part of single contiguous chunk of memory. This means they need to be compacted at every call, possibly greatly increasing memory usage. To compact weights again call flatten_parameters().
解决方案
在def forward():下添加下面三行代码即可:
if not hasattr(self, '_flattened'):
self.gru.flatten_parameters()
setattr(self, '_flattened', True)