You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@mxnet.apache.org by Xia Xuehai via MXNet Forum <mx...@discoursemail.com.INVALID> on 2020/08/10 10:22:34 UTC
[MXNet Forum] [Gluon] How to use EMA training with multi-gpus
I want to use exponential moving average model to train the date.The code is like this:
class EMA():
def __init__(self, model, decay):
self.model = model
self.decay = decay
self.shadow = {}
self.backup = {}
def register(self):
params = self.model.collect_params()
for name in params:
self.shadow[name] = paramsp[name].data().copy()
# after trainer.step()
def update(self):
params = self.model.collect_params()
for name in params:
assert name in self.shadow
new_average = (1.0 - self.decay) * params[name].data() + self.decay * self.shadow[name]
self.shadow[name] = new_average.copy()
# when eval
def apply_shadow(self):
params = self.model.collect_params()
for name in params:
assert name in self.shadow
self.backup[name] = params[name].data()
params[name].data() = self.shadow[name]
def restore(self):
params = self.model.collect_params()
for name in params:
assert name in self.backup
params[name].data() = self.backup[name]
self.backup = {}
How to modify the code for running in multi-gpus?
---
[Visit Topic](https://discuss.mxnet.io/t/how-to-use-ema-training-with-multi-gpus/6479/1) or reply to this email to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, [click here](https://discuss.mxnet.io/email/unsubscribe/ac34f6d4e28f694500ee983c41bf5d23c4d50943d0c6c65cd0acc61b60ce6e4c).