Skip to content

Commit

Permalink
refactor: order
Browse files Browse the repository at this point in the history
  • Loading branch information
kozistr committed Nov 9, 2024
1 parent e65c0cd commit 26d77ed
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pytorch_optimizer/optimizer/adopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ def step(self, closure: CLOSURE = None) -> LOSS:
exp_avg_sq.addcmul_(grad, grad.conj())
continue

exp_avg_sq.mul_(beta2).addcmul_(grad, grad.conj(), value=1.0 - beta2)

de_nom = exp_avg_sq.sqrt().clamp_(min=group['eps'])
if group['step'] == 2:
exp_avg.addcdiv_(grad, de_nom)
else:
exp_avg.mul_(beta1).addcdiv_(grad, de_nom, value=1.0 - beta1)

p.add_(exp_avg, alpha=-group['lr'])
exp_avg_sq.mul_(beta2).addcmul_(grad, grad.conj(), value=1.0 - beta2)

return loss

0 comments on commit 26d77ed

Please sign in to comment.