Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Fairseq
Commits
173c577b
"vscode:/vscode.git/clone" did not exist on "32e16805a17401f5ef5ec825c808d645f5c26509"
Commit
173c577b
authored
Jan 16, 2018
by
Michael Auli
Committed by
Myle Ott
Jan 22, 2018
Browse files
Momentum correction
parent
dd31fa92
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
fairseq/nag.py
fairseq/nag.py
+7
-3
No files found.
fairseq/nag.py
View file @
173c577b
...
...
@@ -11,7 +11,7 @@ from torch.optim.optimizer import Optimizer, required
class
NAG
(
Optimizer
):
def
__init__
(
self
,
params
,
lr
=
required
,
momentum
=
0
,
weight_decay
=
0
):
defaults
=
dict
(
lr
=
lr
,
momentum
=
momentum
,
weight_decay
=
weight_decay
)
defaults
=
dict
(
lr
=
lr
,
lr_old
=
lr
,
momentum
=
momentum
,
weight_decay
=
weight_decay
)
super
(
NAG
,
self
).
__init__
(
params
,
defaults
)
def
step
(
self
,
closure
=
None
):
...
...
@@ -29,6 +29,8 @@ class NAG(Optimizer):
weight_decay
=
group
[
'weight_decay'
]
momentum
=
group
[
'momentum'
]
lr
=
group
[
'lr'
]
lr_old
=
group
.
get
(
'lr_old'
,
lr
)
lr_correct
=
lr
/
lr_old
for
p
in
group
[
'params'
]:
if
p
.
grad
is
None
:
...
...
@@ -43,9 +45,11 @@ class NAG(Optimizer):
if
weight_decay
!=
0
:
p
.
data
.
mul_
(
1
-
weight_decay
)
p
.
data
.
add_
(
momentum
*
momentum
,
buf
)
p
.
data
.
add_
(
momentum
*
momentum
*
lr_correct
,
buf
)
p
.
data
.
add_
(
-
(
1
+
momentum
)
*
lr
,
d_p
)
buf
.
mul_
(
momentum
).
add_
(
-
lr
,
d_p
)
buf
.
mul_
(
momentum
*
lr_correct
).
add_
(
-
lr
,
d_p
)
group
[
'lr_old'
]
=
lr
return
loss
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment