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

Multi-scheduler support for multi-optimizer case #923

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- `force` and `bert-level` keywords to `catalyst-data text2embedding` ([#917](https://github.com/catalyst-team/catalyst/pull/917))

- `OptunaCallback` to `catalyst.contrib` ([#915](https://github.com/catalyst-team/catalyst/pull/915))
- Multi-scheduler support for multi-optimizer case ([#923](https://github.com/catalyst-team/catalyst/pull/923))

### Changed

Expand Down
36 changes: 18 additions & 18 deletions catalyst/dl/experiment/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,31 +343,31 @@ def get_optimizer(
return optimizer

@staticmethod
def _get_scheduler(*, optimizer, **params):
def _get_scheduler(
*, optimizer: Union[Optimizer, Dict[str, Optimizer]], **params: Any
) -> Union[Scheduler, Dict[str, Scheduler]]:
optimizer_key = params.pop("_optimizer", None)
optimizer_ = optimizer[optimizer_key] if optimizer_key else optimizer
scheduler = SCHEDULERS.get_from_params(**params, optimizer=optimizer_)

return scheduler

def get_scheduler(
self, stage: str, optimizer: Union[Optimizer, Dict[str, Optimizer]]
) -> Union[Scheduler, Dict[str, Scheduler]]:
"""Returns the scheduler for a given stage."""
params = self.stages_config[stage].get("scheduler_params", {})
key_value_flag = params.pop("_key_value", False)

if key_value_flag:
scheduler = {}
for scheduler_key, scheduler_params in params.items():
scheduler[
scheduler_key
] = ConfigExperiment._get_scheduler( # noqa: WPS437
scheduler: Dict[str, Scheduler] = {}
for key, scheduler_params in params.items():
scheduler[key] = self._get_scheduler(
optimizer=optimizer, **scheduler_params
)
else:
scheduler = SCHEDULERS.get_from_params(
**params, optimizer=optimizer
)
return scheduler
scheduler = self._get_scheduler(optimizer=optimizer, **params)
Comment on lines +355 to +369
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please provide an examples config for this case?


def get_scheduler(self, stage: str, optimizer: Optimizer) -> Scheduler:
"""Returns the scheduler for a given stage."""
scheduler_params = self.stages_config[stage].get(
"scheduler_params", {}
)
scheduler = self._get_scheduler(
optimizer=optimizer, **scheduler_params
)
return scheduler

@staticmethod
Expand Down