Incubator-mxnet: How to manually modify the gradient using symbol?

Created on 30 Mar 2018  路  5Comments  路  Source: apache/incubator-mxnet

When using gluon,I can set grad_req = 'add' and use net.collect_params().zero_grad() to clear the gradient.I want to do the same thing by using mxnet.symbol. What should I do to set the grad_req and manually clear the gradient?Anyone help?

Doc

Most helpful comment

If you are using the executor interface, the gradient are in grad_dict(https://mxnet.incubator.apache.org/api/python/executor/executor.html#mxnet.executor.Executor.grad_dict). If you are using the Module interface, the gradients are in mod._exec_group.grad_arrays.

All 5 comments

@zjuzuhe You can do that when you construct your executor (or Module). There is a grad_req option in the bind function, e.g, here https://mxnet.incubator.apache.org/api/python/module/module.html?highlight=grad_req#mxnet.module.BaseModule.bind

@sxjscience Thx.And if I set it to 'add' in the bind function,how could I set the gradients manually to zero after one epoch?I didn't find it in the website.

If you are using the executor interface, the gradient are in grad_dict(https://mxnet.incubator.apache.org/api/python/executor/executor.html#mxnet.executor.Executor.grad_dict). If you are using the Module interface, the gradients are in mod._exec_group.grad_arrays.

@zjuzuhe if your question has been answered, please consider closing the issue, thanks!

@indhub could you kindly close out this issue as it has been addressed?

Was this page helpful?
0 / 5 - 0 ratings