Skip to content

Where to put optimizer.zero_grad() ? #1172

Answered by danli349
AloscariS asked this question in Q&A
Discussion options

You must be logged in to vote

I think the gradients will keep unchanged during the Forward pass and Calculate the Loss, the gradients are only changed during the Backward Pass, so you only need to place optimizer.zero_grad() before the Backward Pass.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@AloscariS
Comment options

Answer selected by AloscariS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants