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
torchani
Commits
71b9c75f
"megatron/git@developer.sourcefind.cn:OpenDAS/megatron-lm.git" did not exist on "6c0a5bd880780ea630d038b9cf75ee02a8aee408"
Unverified
Commit
71b9c75f
authored
May 14, 2019
by
Gao, Xiang
Committed by
GitHub
May 14, 2019
Browse files
Add support for weight decay (#223)
parent
4cec6442
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
41 deletions
+40
-41
tests/test_data/inputtrain.ipt
tests/test_data/inputtrain.ipt
+24
-24
torchani/neurochem/__init__.py
torchani/neurochem/__init__.py
+16
-17
No files found.
tests/test_data/inputtrain.ipt
View file @
71b9c75f
...
...
@@ -26,22 +26,22 @@ network_setup {
nodes=160;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.0001;
l2norm=1;
l2valu=0.0001;
]
layer [
nodes=128;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.00001;
l2norm=1;
l2valu=0.00001;
]
layer [
nodes=96;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.000001;
l2norm=1;
l2valu=0.000001;
]
layer [
nodes=1;
...
...
@@ -54,22 +54,22 @@ network_setup {
nodes=144;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.0001;
l2norm=1;
l2valu=0.0001;
]
layer [
nodes=112;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.00001;
l2norm=1;
l2valu=0.00001;
]
layer [
nodes=96;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.000001;
l2norm=1;
l2valu=0.000001;
]
layer [
nodes=1;
...
...
@@ -82,22 +82,22 @@ network_setup {
nodes=128;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.0001;
l2norm=1;
l2valu=0.0001;
]
layer [
nodes=112;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.00001;
l2norm=1;
l2valu=0.00001;
]
layer [
nodes=96;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.000001;
l2norm=1;
l2valu=0.000001;
]
layer [
nodes=1;
...
...
@@ -110,22 +110,22 @@ network_setup {
nodes=128;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.0001;
l2norm=1;
l2valu=0.0001;
]
layer [
nodes=112;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.00001;
l2norm=1;
l2valu=0.00001;
]
layer [
nodes=96;
activation=9;
type=0;
!
l2norm=1;
!
l2valu=0.000001;
l2norm=1;
l2valu=0.000001;
]
layer [
nodes=1;
...
...
torchani/neurochem/__init__.py
View file @
71b9c75f
...
...
@@ -404,6 +404,7 @@ if sys.version_info[0] > 2:
self
.
device
=
device
self
.
aev_caching
=
aev_caching
self
.
checkpoint_name
=
checkpoint_name
self
.
parameters
=
[]
if
tqdm
:
import
tqdm
self
.
tqdm
=
tqdm
.
tqdm
...
...
@@ -591,7 +592,6 @@ if sys.version_info[0] > 2:
input_size
,
network_setup
=
network_setup
if
input_size
!=
self
.
aev_computer
.
aev_length
:
raise
ValueError
(
'AEV size and input size does not match'
)
l2reg
=
[]
atomic_nets
=
{}
for
atom_type
in
network_setup
:
layers
=
network_setup
[
atom_type
]
...
...
@@ -611,18 +611,20 @@ if sys.version_info[0] > 2:
del
layer
[
'activation'
]
if
'l2norm'
in
layer
:
if
layer
[
'l2norm'
]
==
1
:
# NB: The "L2" implemented in NeuroChem is actually
# not L2 but weight decay. The difference of these
# two is:
# https://arxiv.org/pdf/1711.05101.pdf
# There is a pull request on github/pytorch
# implementing AdamW, etc.:
# https://github.com/pytorch/pytorch/pull/4429
# There is no plan to support the "L2" settings in
# input file before AdamW get merged into pytorch.
raise
NotImplementedError
(
'L2 not supported yet'
)
self
.
parameters
.
append
({
'params'
:
module
.
parameters
(),
'weight_decay'
:
layer
[
'l2valu'
],
})
else
:
self
.
parameters
.
append
({
'params'
:
module
.
parameters
(),
})
del
layer
[
'l2norm'
]
del
layer
[
'l2valu'
]
else
:
self
.
parameters
.
append
({
'params'
:
module
.
parameters
(),
})
if
layer
:
raise
ValueError
(
'unrecognized parameter in layer setup'
)
...
...
@@ -637,13 +639,10 @@ if sys.version_info[0] > 2:
self
.
container
=
Container
({
'energies'
:
self
.
nnp
}).
to
(
self
.
device
)
# losses
def
l2
():
return
sum
([
c
*
(
m
.
weight
**
2
).
sum
()
for
c
,
m
in
l2reg
])
self
.
mse_loss
=
TransformedLoss
(
MSELoss
(
'energies'
),
lambda
x
:
x
+
l2
())
self
.
mse_loss
=
MSELoss
(
'energies'
)
self
.
exp_loss
=
TransformedLoss
(
MSELoss
(
'energies'
),
lambda
x
:
0.5
*
(
torch
.
exp
(
2
*
x
)
-
1
)
+
l2
()
)
lambda
x
:
0.5
*
(
torch
.
exp
(
2
*
x
)
-
1
))
if
params
:
raise
ValueError
(
'unrecognized parameter'
)
...
...
@@ -776,7 +775,7 @@ if sys.version_info[0] > 2:
# training using mse loss first until the validation MAE decrease
# to < 1 Hartree
optimizer
=
torch
.
optim
.
Adam
(
self
.
model
.
parameters
()
,
lr
=
lr
)
optimizer
=
torch
.
optim
.
Adam
(
self
.
parameters
,
lr
=
lr
)
trainer
=
ignite
.
engine
.
create_supervised_trainer
(
self
.
container
,
optimizer
,
self
.
mse_loss
)
decorate
(
trainer
)
...
...
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