jmacglashan opened a new issue #7312: gluon Trainer does not accept Optimizer 
object, only str
URL: https://github.com/apache/incubator-mxnet/issues/7312
 
 
   The gluon Trainer is supposed to accept either a string name of an 
Optimizer, or an actual Optimizer object. However, if you try to pass it an 
Optimizer object it does not handle it correctly, expecting a string. Modifying 
the Trainer `_init_optimizer` method as follows fixes it, although I'm not sure 
if this is the way it wants to be handled:
   
   ```
   def _init_optimizer(self, optimizer, optimizer_params):
       if isinstance(optimizer, opt.Optimizer):
           self._optimizer = optimizer
       else:
           self._optimizer = opt.create(optimizer, **optimizer_params)
   
           lr_mult = {}
           wd_mult = {}
           for i, param in enumerate(self._params):
               lr_mult[i] = param.lr_mult
               wd_mult[i] = param.wd_mult
           self._optimizer.set_lr_mult(lr_mult)
           self._optimizer.set_wd_mult(wd_mult)
   
       self._updaters = [opt.get_updater(self._optimizer) \
                           for _ in self._context
   ```
   
   I would also recommend making the `optimizer_params` argument of the Trainer 
constructor optional since they are not needed if you provide a full Optimizer 
object.
 
----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to