Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

fix bug in nag optimizer #13683

Merged
merged 6 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/mxnet/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,10 +974,10 @@ def update(self, index, weight, grad, state):
if state is not None:
mom = state
mom[:] *= self.momentum
grad += wd * weight
mom[:] += grad
mom[:] += wd * weight
grad[:] += self.momentum * mom
weight[:] += -lr * grad
weight[:] -= lr * grad
else:
assert self.momentum == 0.0
weight[:] += -lr * (grad + wd * weight)
Expand Down
8 changes: 4 additions & 4 deletions tests/python/unittest/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,10 @@ def update(self, index, weight, grad, state):
else:
mom = state
mom[:] *= self.momentum
grad += wd * weight
mom[:] += grad
mom[:] += wd * weight
grad[:] += self.momentum * mom
weight[:] += -lr * grad
weight[:] -= lr * grad
else:
grad32 = array(grad, ctx=grad.context, dtype=np.float32)
grad32 = grad32 * self.rescale_grad
Expand All @@ -400,10 +400,10 @@ def update(self, index, weight, grad, state):
weight32[:] += -lr * (grad32 + wd * weight32)
else:
mom[:] *= self.momentum
grad32 += wd * weight32
mom[:] += grad32
mom[:] += wd * weight32
grad32[:] += self.momentum * mom
weight32[:] += -lr * grad32
weight32[:] -= lr * grad32
tmp = weight32.astype(weight.dtype)
tmp.copyto(weight)

Expand Down