Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
20686b78
Commit
20686b78
authored
Apr 03, 2019
by
lukovnikov
Browse files
schedule fix
parent
1b4ce76c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
4 deletions
+4
-4
pytorch_pretrained_bert/optimization.py
pytorch_pretrained_bert/optimization.py
+3
-3
tests/optimization_test.py
tests/optimization_test.py
+1
-1
No files found.
pytorch_pretrained_bert/optimization.py
View file @
20686b78
...
@@ -42,8 +42,8 @@ class LRSchedule(object):
...
@@ -42,8 +42,8 @@ class LRSchedule(object):
logger
.
warning
(
"t_total value of {} results in schedule not being applied"
.
format
(
t_total
))
logger
.
warning
(
"t_total value of {} results in schedule not being applied"
.
format
(
t_total
))
if
not
0.0
<=
warmup
<
1.0
and
not
warmup
==
-
1
:
if
not
0.0
<=
warmup
<
1.0
and
not
warmup
==
-
1
:
raise
ValueError
(
"Invalid warmup: {} - should be in [0.0, 1.0[ or -1"
.
format
(
warmup
))
raise
ValueError
(
"Invalid warmup: {} - should be in [0.0, 1.0[ or -1"
.
format
(
warmup
))
warmup
=
max
(
warmup
,
0
)
warmup
=
max
(
warmup
,
0
.
)
self
.
warmup
,
self
.
t_total
=
warmup
,
t_total
self
.
warmup
,
self
.
t_total
=
float
(
warmup
)
,
float
(
t_total
)
self
.
warned_for_t_total_at_progress
=
-
1
self
.
warned_for_t_total_at_progress
=
-
1
def
get_lr
(
self
,
step
,
nowarn
=
False
):
def
get_lr
(
self
,
step
,
nowarn
=
False
):
...
@@ -153,7 +153,7 @@ class WarmupLinearSchedule(LRSchedule):
...
@@ -153,7 +153,7 @@ class WarmupLinearSchedule(LRSchedule):
def
get_lr_
(
self
,
progress
):
def
get_lr_
(
self
,
progress
):
if
progress
<
self
.
warmup
:
if
progress
<
self
.
warmup
:
return
progress
/
self
.
warmup
return
progress
/
self
.
warmup
return
max
((
progress
-
1.
)
/
(
self
.
warmup
-
1.
),
0
)
return
max
((
progress
-
1.
)
/
(
self
.
warmup
-
1.
),
0
.
)
SCHEDULES
=
{
SCHEDULES
=
{
...
...
tests/optimization_test.py
View file @
20686b78
...
@@ -51,7 +51,7 @@ class OptimizationTest(unittest.TestCase):
...
@@ -51,7 +51,7 @@ class OptimizationTest(unittest.TestCase):
class
WarmupCosineWithRestartsTest
(
unittest
.
TestCase
):
class
WarmupCosineWithRestartsTest
(
unittest
.
TestCase
):
def
test_it
(
self
):
def
test_it
(
self
):
m
=
WarmupCosineWithWarmupRestartsSchedule
(
warmup
=
0.05
,
t_total
=
1000
,
cycles
=
5
)
m
=
WarmupCosineWithWarmupRestartsSchedule
(
warmup
=
0.05
,
t_total
=
1000
.
,
cycles
=
5
)
x
=
np
.
arange
(
0
,
1000
)
x
=
np
.
arange
(
0
,
1000
)
y
=
[
m
.
get_lr
(
xe
)
for
xe
in
x
]
y
=
[
m
.
get_lr
(
xe
)
for
xe
in
x
]
# plt.plot(y)
# plt.plot(y)
...
...
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