Skip to content

Commit 383d340

Browse files
jma127facebook-github-bot
authored andcommitted
Small optimization for adam (pytorch#12107)
Summary: Apply weight decay for Adam in-place instead of via copy. Synced offline with soumith , who mentioned that it should be OK. This is also consistent with other optimizers, e.g. https://github.com/pytorch/pytorch/blob/eee01731a5d33d5be58d875711bd2577e38dbddf/torch/optim/sgd.py#L93 Pull Request resolved: pytorch#12107 Reviewed By: soumith Differential Revision: D10071787 Pulled By: jma127 fbshipit-source-id: 5fd7939c79039693b225c44c4c80450923b8d673
1 parent 5da8a8c commit 383d340

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

torch/optim/adam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def step(self, closure=None):
8787
state['step'] += 1
8888

8989
if group['weight_decay'] != 0:
90-
grad = grad.add(group['weight_decay'], p.data)
90+
grad.add_(group['weight_decay'], p.data)
9191

9292
# Decay the first and second moment running average coefficient
9393
exp_avg.mul_(beta1).add_(1 - beta1, grad)

0 commit comments

Comments
 (0)