bug in 'lr_mult' attribute and optimizer
When user explicitly specify weight and bias variables in FullyConnected and Convolution, the `lr_mult`` attribute can not be set correctly, and the optimizer can not get correct learning rate in this case.
example:
W=mx.sym.Variable(name='custom-weight')
b=mx.sym.Variable(name='custom-bias')
fc=mx.sym.FullyConnected(data=data, weight=W, bias=b, num_hidden=10, name='fc')
@pluskid @piiswrong
W and b is not variables. they are ndarray type.
@starimpact Thanks for your reply. But W & b are indeed mx.Variables.
Current implementation only works when the weight and bias variables are generated by default, whose names would be fc_weight and fc_bias for the example case. But if we explicitly specify them and the name changes, it would be incorrect. You can simply verify that by printing lr in any optimizer.
what I mean is that you should create W and b as ndarray type. if you create them as variable type, you will fix the sizes in the bind function.It is complicated. And ,I think your name should be "_weight" and "_bias". I do not use optimizer, I update the parameters by myself code.
If you create variables explicitly, you should follow the same naming convention, i.e. xxx_weight for weights and xxx_bias for bias.
@piiswrong I explicitly create variables for sharing weight in RNN, just like the RNN example in MxNet repo.
@piiswrong I don't know if I made it clear. For implementing RNN and many other cases, users need to explicitly create shared weight and bias symbols between different operators, we cannot follow the naming convention you mentioned.
what you need to do is only to let your postfix be fixed.It is not contradictory with your implementation.
@sodabeta7 I met the same problem. It seems that the problem is due to the _get_lr(self, index) function in optimizer.py. In lr *= self.lr_mult.get(self.idx2name[index], 1.0) (https://github.com/dmlc/mxnet/blob/master/python/mxnet/optimizer.py#L205) the names in idx2name does not exist in the keys of self.lr_mult. Thus it will return 1.0.
if you create variables by hand, set attributes in the variable, e.g.:
W=mx.sym.Variable(name='custom-weight', attr={'lr_mult':'0.01'})
b=mx.sym.Variable(name='custom-bias')
fc=mx.sym.FullyConnected(data=data, weight=W, bias=b, num_hidden=10, name='fc')
@piiswrong Thanks. That seems a good solution.