Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
distiller
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
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
distiller
Commits
fb44c8d0
Commit
fb44c8d0
authored
6 years ago
by
Guy Jacob
Browse files
Options
Downloads
Patches
Plain Diff
Add missing documentation and missing input check in MultiStepMultiGammaLR
parent
02f7871b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
distiller/learning_rate.py
+10
-0
10 additions, 0 deletions
distiller/learning_rate.py
tests/test_learning_rate.py
+11
-0
11 additions, 0 deletions
tests/test_learning_rate.py
with
21 additions
and
0 deletions
distiller/learning_rate.py
+
10
−
0
View file @
fb44c8d0
...
...
@@ -41,10 +41,20 @@ class PolynomialLR(_LRScheduler):
class
MultiStepMultiGammaLR
(
_LRScheduler
):
"""
Similar to torch.otpim.MultiStepLR, but instead of a single gamma value, specify a gamma value per-milestone.
Args:
optimizer (Optimizer): Wrapped optimizer.
milestones (list): List of epoch indices. Must be increasing.
gammas (list): List of gamma values. Must have same length as milestones.
last_epoch (int): The index of last epoch. Default: -1.
"""
def
__init__
(
self
,
optimizer
,
milestones
,
gammas
,
last_epoch
=-
1
):
if
not
list
(
milestones
)
==
sorted
(
milestones
):
raise
ValueError
(
'
Milestones should be a list of
'
'
increasing integers. Got {}
'
,
milestones
)
if
len
(
milestones
)
!=
len
(
gammas
):
raise
ValueError
(
'
Milestones and Gammas lists should be of same length.
'
)
self
.
milestones
=
milestones
self
.
multiplicative_gammas
=
[
1
]
...
...
This diff is collapsed.
Click to expand it.
tests/test_learning_rate.py
+
11
−
0
View file @
fb44c8d0
...
...
@@ -16,6 +16,7 @@
import
os
import
sys
import
pytest
module_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
'
..
'
))
if
module_path
not
in
sys
.
path
:
sys
.
path
.
append
(
module_path
)
...
...
@@ -28,6 +29,16 @@ from distiller.learning_rate import MultiStepMultiGammaLR
def
test_multi_step_multi_gamma_lr
():
dummy_tensor
=
torch
.
zeros
(
3
,
3
,
3
,
requires_grad
=
True
)
dummy_optimizer
=
Optimizer
([
dummy_tensor
],
{
'
lr
'
:
0.1
})
# Test input checks
with
pytest
.
raises
(
ValueError
):
lr_sched
=
MultiStepMultiGammaLR
(
dummy_optimizer
,
milestones
=
[
60
,
30
,
80
],
gammas
=
[
0.1
,
0.1
,
0.2
])
with
pytest
.
raises
(
ValueError
):
lr_sched
=
MultiStepMultiGammaLR
(
dummy_optimizer
,
milestones
=
[
30
,
60
],
gammas
=
[
0.1
,
0.1
,
0.2
])
with
pytest
.
raises
(
ValueError
):
lr_sched
=
MultiStepMultiGammaLR
(
dummy_optimizer
,
milestones
=
[
30
,
60
,
80
],
gammas
=
[
0.1
,
0.1
])
# Test functionality
lr_sched
=
MultiStepMultiGammaLR
(
dummy_optimizer
,
milestones
=
[
30
,
60
,
80
],
gammas
=
[
0.1
,
0.1
,
0.2
])
expected_gammas
=
[
1
,
1
*
0.1
,
1
*
0.1
*
0.1
,
1
*
0.1
*
0.1
*
0.2
]
expected_lrs
=
[
0.1
*
gamma
for
gamma
in
expected_gammas
]
...
...
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