optimizer and loss.backward() related functions

Insert image description here

optimizer.zero_grad() # Gradient clearing (the gradient must be cleared first, so that the grad in the tensor will not accumulate)
loss.backward() is used for derivation of
optimizer.step(). Generally speaking, it is based on The derivative of the gradient descent algorithm is used to update the parameters.

The above sequence of steps cannot be changed

Guess you like

Origin blog.csdn.net/qq_45560230/article/details/132822819