Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] fix CosineRestart eta_min #639

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions mmengine/optim/scheduler/param_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,10 +1224,9 @@ def _get_value(self):
self.optimizer.param_groups):
eta_max = base_value * current_weight
if self.eta_min_ratio is None:
eta_min = self.eta_min * (1 - current_weight)
eta_min = self.eta_min
else:
eta_min = base_value * self.eta_min_ratio * (1 -
current_weight)
eta_min = base_value * self.eta_min_ratio
if step == 0:
values.append(eta_max)

Expand Down
18 changes: 18 additions & 0 deletions tests/test_optim/test_scheduler/test_param_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,24 @@ def test_cosine_restart_scheduler(self):
eta_min=0)
self._test_scheduler_value(scheduler, targets, epochs=10)

epochs = 10
t = 10
eta_min = 1e-7
HAOCHENYE marked this conversation as resolved.
Show resolved Hide resolved
single_targets = [
eta_min + (0.05 - eta_min) * (1 + math.cos(math.pi * x / t)) / 2
for x in range(epochs)
]
targets = [
single_targets, [x * self.layer2_mult for x in single_targets]
]
scheduler = CosineRestartParamScheduler(
self.optimizer,
param_name='lr',
periods=[t],
HAOCHENYE marked this conversation as resolved.
Show resolved Hide resolved
restart_weights=[1],
eta_min=eta_min)
self._test_scheduler_value(scheduler, targets, epochs=10)

def _check_scheduler_state_dict(self, construct, construct2, epochs=10):
scheduler = construct()
for _ in range(epochs):
Expand Down