on-internet
← Community

How can I do Gradient Clipping In Pytorch?

Stack Overflow ·

I am training a CNN in a custom training loop. I am updating the weights manually, and calculating the gradients with torch.autograd.grad and manually. grads = torch.autograd.grad(outputs=model.fx, inputs=model.layers_weight, allow_unused=True, grad_outputs=[torch.ones_like(out) for out in model.fx]) model.fx are the outputs of all the linear functions except for the last element which is the loss. The inputs are the weights. Using these gradients I calculate back in the network dl/dw for each layer. The resulting gradients are stored in a list for manual weight update in torch.no_grad later o

Comments

Sign in or sign up to comment and upvote.

No comments yet.