Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LEE-Transformers
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Ebert
LEE-Transformers
Commits
8e5dbcda
Commit
8e5dbcda
authored
Sep 11, 2023
by
Jan Ebert
Browse files
Options
Downloads
Patches
Plain Diff
Implement linear warmup flag for scheduler
Linear warmup is used often in the literature.
parent
b5803738
No related branches found
No related tags found
No related merge requests found
Pipeline
#154608
passed
Sep 11, 2023
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tn_transformers/schedules.py
+27
-11
27 additions, 11 deletions
tn_transformers/schedules.py
with
27 additions
and
11 deletions
tn_transformers/schedules.py
+
27
−
11
View file @
8e5dbcda
...
@@ -21,6 +21,8 @@ class CosineAnnealingWithWarmupLR:
...
@@ -21,6 +21,8 @@ class CosineAnnealingWithWarmupLR:
max_steps: Number of steps to reach `end_lr` (including warm-up phase).
max_steps: Number of steps to reach `end_lr` (including warm-up phase).
start_lr: Initial learning rate to warm up from.
start_lr: Initial learning rate to warm up from.
end_lr: Final learning rate to anneal to after warmup.
end_lr: Final learning rate to anneal to after warmup.
linear_warmup: Whether to use a linear schedule for the initial
warmup.
last_epoch: The index of the last step taken. Used to continue
last_epoch: The index of the last step taken. Used to continue
training. If -1, no step has been taken.
training. If -1, no step has been taken.
"""
"""
...
@@ -32,6 +34,7 @@ class CosineAnnealingWithWarmupLR:
...
@@ -32,6 +34,7 @@ class CosineAnnealingWithWarmupLR:
max_steps
:
int
,
max_steps
:
int
,
start_lr
:
float
=
0.0
,
start_lr
:
float
=
0.0
,
end_lr
:
float
=
0.0
,
end_lr
:
float
=
0.0
,
linear_warmup
:
bool
=
False
,
last_epoch
:
int
=
-
1
,
last_epoch
:
int
=
-
1
,
)
->
None
:
)
->
None
:
self
.
optimizer
=
optimizer
self
.
optimizer
=
optimizer
...
@@ -47,6 +50,7 @@ class CosineAnnealingWithWarmupLR:
...
@@ -47,6 +50,7 @@ class CosineAnnealingWithWarmupLR:
self
.
last_epoch
=
last_epoch
self
.
last_epoch
=
last_epoch
self
.
T_max_warmup
=
warmup_steps
self
.
T_max_warmup
=
warmup_steps
self
.
T_max_total
=
max_steps
self
.
T_max_total
=
max_steps
self
.
linear_warmup
=
linear_warmup
# Initial step.
# Initial step.
self
.
step
()
self
.
step
()
...
@@ -65,6 +69,18 @@ class CosineAnnealingWithWarmupLR:
...
@@ -65,6 +69,18 @@ class CosineAnnealingWithWarmupLR:
def
get_lr
(
self
)
->
List
[
float
]:
def
get_lr
(
self
)
->
List
[
float
]:
if
self
.
last_epoch
<=
self
.
T_max_warmup
:
if
self
.
last_epoch
<=
self
.
T_max_warmup
:
if
self
.
linear_warmup
:
values
=
[
(
base_lr
+
(
(
self
.
eta_max_warmup
-
base_lr
)
*
(
1
-
(
self
.
last_epoch
/
self
.
T_max_warmup
))
)
)
for
base_lr
in
self
.
base_lrs
]
else
:
values
=
[
values
=
[
(
(
base_lr
base_lr
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment