Resets the gradient of a value object (and all its ancestors in the computational graph) to zero. This is useful when reusing parameters across multiple optimization steps.
Usage
zero_grad(e)
# S3 method for class 'value'
zero_grad(e)
# S3 method for class 'list'
zero_grad(e)
# Default S3 method
zero_grad(e)Details
After calling backward(), gradients accumulate in the computational graph.
Before computing new gradients, you should reset them with zero_grad().