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
9bc3773c
Commit
9bc3773c
authored
Feb 27, 2019
by
lukovnikov
Browse files
added warning
parent
60a37238
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
3 deletions
+12
-3
pytorch_pretrained_bert/optimization.py
pytorch_pretrained_bert/optimization.py
+12
-3
No files found.
pytorch_pretrained_bert/optimization.py
View file @
9bc3773c
...
@@ -35,19 +35,28 @@ def warmup_constant(x, warmup=0.002):
...
@@ -35,19 +35,28 @@ def warmup_constant(x, warmup=0.002):
return
x
/
warmup
return
x
/
warmup
return
1.0
return
1.0
class
Warmup_Linear_with_Warning
(
object
):
def
__init__
(
self
,
**
kw
):
super
(
Warmup_Linear_with_Warning
,
self
).
__init__
()
self
.
warned_at_x
=
-
1
def
__call__
(
self
,
x
,
warmup
=
0.002
):
if
x
>
1
and
x
>
self
.
warned_at_x
:
logger
.
warning
(
"Training beyond specified 't_total' steps. Learning rate set to zero. Please set 't_total' of BertAdam correctly."
)
self
.
warned_at_x
=
x
return
warmup_linear
(
x
,
warmup
=
warmup
)
def
warmup_linear
(
x
,
warmup
=
0.002
):
def
warmup_linear
(
x
,
warmup
=
0.002
):
""" Specifies a triangular learning rate schedule where peak is reached at `warmup`*`t_total`-th (as provided to BertAdam) training step.
""" Specifies a triangular learning rate schedule where peak is reached at `warmup`*`t_total`-th (as provided to BertAdam) training step.
After `t_total`-th training step, learning rate is zero. """
After `t_total`-th training step, learning rate is zero. """
if
x
<
warmup
:
if
x
<
warmup
:
return
x
/
warmup
return
x
/
warmup
if
x
>
1
:
logger
.
warning
(
"Training beyond specified 't_total' steps. Learning rate set to zero. Please set 't_total' of BertAdam correctly."
)
return
max
((
x
-
1.
)
/
(
warmup
-
1.
),
0
)
return
max
((
x
-
1.
)
/
(
warmup
-
1.
),
0
)
SCHEDULES
=
{
SCHEDULES
=
{
'warmup_cosine'
:
warmup_cosine
,
'warmup_cosine'
:
warmup_cosine
,
'warmup_constant'
:
warmup_constant
,
'warmup_constant'
:
warmup_constant
,
'warmup_linear'
:
warmup_linear
,
'warmup_linear'
:
Warmup_Linear_with_Warning
(),
#
warmup_linear,
}
}
...
...
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