wkcn commented on a change in pull request #18325:
URL: https://github.com/apache/incubator-mxnet/pull/18325#discussion_r425780192



##########
File path: python/mxnet/optimizer/lars.py
##########
@@ -252,6 +253,13 @@ def fused_step(self, indices, weights, grads, states):
                 wd = wds[i]
                 lr = lrs[i]
                 lr *= self._get_lars(index, weight, grad, wd)
+                # normal SGD picks up momentum correction by default,
+                # so need to modify the momentum to undo that.
+                # The correction term is previous_lr / current_lr.
+                kwargs['momentum'] = (self.momentum * (self.last_lr / lr)) \

Review comment:
       Thank you for the fix!
   
   It will reduce the times of getting an item of `self.last_lr`.
   ```python
   kwargs['momentum'] = (self.momentum * (self.last_lr.get(index, lr) / lr)) \
                                        if lr != 0 else \
                                        self.momentum
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to