piiswrong commented on a change in pull request #7654: Making mixed precision
work with all optimizers
URL: https://github.com/apache/incubator-mxnet/pull/7654#discussion_r140909630
##########
File path: python/mxnet/optimizer.py
##########
@@ -191,6 +230,33 @@ def update(self, index, weight, grad, state):
"""
raise NotImplementedError()
+ def update_mp(self, index, weight, grad, state):
+ """Updates the given parameter using the corresponding gradient and
state.
+ Mixed precision version.
+
+ Parameters
+ ----------
+ index : int
+ The unique index of the parameter into the individual learning
+ rates and weight decays. Learning rates and weight decay
+ may be set via `set_lr_mult()` and `set_wd_mult()`, respectively.
+ weight : NDArray
+ The parameter to be updated.
+ grad : NDArray
+ The gradient of the objective with respect to this parameter.
+ state : any obj
+ The state returned by `create_state()`.
+ """
+ if self.multi_precision and weight.dtype == numpy.float16:
+ # Wrapper for mixed precision
+ weight_master_copy = state[0]
+ original_state = state[1]
+ grad32 = array(grad, ctx=grad.context, dtype=numpy.float32)
Review comment:
grad.astype
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services