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
ColossalAI
Commits
0cf8e8e9
Unverified
Commit
0cf8e8e9
authored
Jul 12, 2022
by
oahzxl
Committed by
GitHub
Jul 12, 2022
Browse files
[NFC] polish <colossalai/nn/lr_scheduler/poly.py> code style (#1267)
parent
c92f84fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
10 deletions
+18
-10
colossalai/nn/lr_scheduler/poly.py
colossalai/nn/lr_scheduler/poly.py
+18
-10
No files found.
colossalai/nn/lr_scheduler/poly.py
View file @
0cf8e8e9
...
@@ -17,7 +17,12 @@ class PolynomialLR(_LRScheduler):
...
@@ -17,7 +17,12 @@ class PolynomialLR(_LRScheduler):
the schedule is started from the beginning or When last_epoch=-1, sets initial lr as lr.
the schedule is started from the beginning or When last_epoch=-1, sets initial lr as lr.
"""
"""
def
__init__
(
self
,
optimizer
,
total_steps
:
int
,
end_lr
:
float
=
0.0001
,
power
:
float
=
1.0
,
last_epoch
:
int
=
-
1
,
def
__init__
(
self
,
optimizer
,
total_steps
:
int
,
end_lr
:
float
=
0.0001
,
power
:
float
=
1.0
,
last_epoch
:
int
=
-
1
,
**
kwargs
):
**
kwargs
):
if
end_lr
<
0
:
if
end_lr
<
0
:
raise
ValueError
(
f
'end_lr must >= 0, got
{
end_lr
}
'
)
raise
ValueError
(
f
'end_lr must >= 0, got
{
end_lr
}
'
)
...
@@ -30,11 +35,9 @@ class PolynomialLR(_LRScheduler):
...
@@ -30,11 +35,9 @@ class PolynomialLR(_LRScheduler):
return
self
.
_get_closed_form_lr
()
return
self
.
_get_closed_form_lr
()
def
_get_closed_form_lr
(
self
):
def
_get_closed_form_lr
(
self
):
return
[
return
[(
base_lr
-
self
.
end_lr
)
*
(
base_lr
-
self
.
end_lr
)
*
((
1
-
min
(
self
.
last_epoch
,
self
.
total_steps
)
/
((
1
-
min
(
self
.
last_epoch
,
self
.
total_steps
)
/
self
.
total_steps
)
**
self
.
power
)
+
self
.
end_lr
self
.
total_steps
)
**
self
.
power
)
+
self
.
end_lr
for
base_lr
in
self
.
base_lrs
]
for
base_lr
in
self
.
base_lrs
]
@
LR_SCHEDULERS
.
register_module
@
LR_SCHEDULERS
.
register_module
...
@@ -51,8 +54,13 @@ class PolynomialWarmupLR(WarmupScheduler):
...
@@ -51,8 +54,13 @@ class PolynomialWarmupLR(WarmupScheduler):
the schedule is started from the beginning or When last_epoch=-1, sets initial lr as lr.
the schedule is started from the beginning or When last_epoch=-1, sets initial lr as lr.
"""
"""
def
__init__
(
self
,
optimizer
,
total_steps
:
int
,
warmup_steps
:
int
=
0
,
end_lr
:
float
=
0.0001
,
power
:
float
=
1.0
,
def
__init__
(
self
,
last_epoch
:
int
=
-
1
,
**
kwargs
):
optimizer
,
base_scheduler
=
PolynomialLR
(
total_steps
:
int
,
optimizer
,
total_steps
-
warmup_steps
,
end_lr
=
end_lr
,
power
=
power
)
warmup_steps
:
int
=
0
,
end_lr
:
float
=
0.0001
,
power
:
float
=
1.0
,
last_epoch
:
int
=
-
1
,
**
kwargs
):
base_scheduler
=
PolynomialLR
(
optimizer
,
total_steps
-
warmup_steps
,
end_lr
=
end_lr
,
power
=
power
)
super
().
__init__
(
optimizer
,
warmup_steps
,
base_scheduler
,
last_epoch
=
last_epoch
)
super
().
__init__
(
optimizer
,
warmup_steps
,
base_scheduler
,
last_epoch
=
last_epoch
)
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