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

Custom Optimizer and LR schedulers #290

Merged
merged 16 commits into from
Jun 14, 2023
Merged

Custom Optimizer and LR schedulers #290

merged 16 commits into from
Jun 14, 2023

Conversation

wistuba
Copy link
Contributor

@wistuba wistuba commented Jun 9, 2023

Optimizer and LR scheduler can be defined via Renate config file.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@wistuba wistuba changed the title custom optimizer and lr schedulers can be added to the config file Custom Optimizer and LR schedulers Jun 9, 2023
@github-actions
Copy link

github-actions bot commented Jun 9, 2023

Coverage report

The coverage rate went from 85.68% to 85.16% ⬇️

100% of new lines are covered.

Diff Coverage details (click to unfold)

src/renate/updaters/experimental/repeated_distill.py

100% of new lines are covered (100% of the complete file).

src/renate/utils/module.py

100% of new lines are covered (93.75% of the complete file).

src/renate/shift/detector.py

100% of new lines are covered (89.74% of the complete file).

src/renate/updaters/experimental/fine_tuning.py

100% of new lines are covered (100% of the complete file).

src/renate/updaters/experimental/gdumb.py

100% of new lines are covered (94.44% of the complete file).

src/renate/utils/optimizer.py

100% of new lines are covered (100% of the complete file).

src/renate/cli/parsing_functions.py

100% of new lines are covered (79.18% of the complete file).

src/renate/cli/run_training.py

100% of new lines are covered (96.92% of the complete file).

src/renate/updaters/experimental/offline_er.py

100% of new lines are covered (81.08% of the complete file).

src/renate/updaters/model_updater.py

100% of new lines are covered (95.2% of the complete file).

src/renate/updaters/experimental/joint.py

100% of new lines are covered (95.83% of the complete file).

src/renate/updaters/learner.py

100% of new lines are covered (100% of the complete file).

src/renate/defaults.py

100% of new lines are covered (99% of the complete file).

src/renate/updaters/avalanche/model_updater.py

100% of new lines are covered (94.57% of the complete file).

src/renate/memory/storage.py

100% of new lines are covered (46.42% of the complete file).

src/renate/updaters/experimental/er.py

100% of new lines are covered (91.61% of the complete file).

src/renate/utils/distributed_strategies.py

100% of new lines are covered (90.9% of the complete file).

src/renate/shift/ks_detector.py

100% of new lines are covered (100% of the complete file).

@wistuba wistuba marked this pull request as ready for review June 10, 2023 16:35
lr_scheduler_plugin = None
optimizers_scheduler = self._dummy_learner.configure_optimizers()
if isinstance(optimizers_scheduler, tuple):
optimizer, scheduler_config = optimizers_scheduler
Copy link
Contributor

Choose a reason for hiding this comment

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

What do these two lines do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Return value can either be Tuple[Optimizer, Scheduler] or Optimizer. We are checking for this case and conditionally add a LRCallback.

Copy link
Contributor

@prabhuteja12 prabhuteja12 left a comment

Choose a reason for hiding this comment

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

The self.save_hyperparameters must now include the optimizer object.

@@ -421,6 +290,8 @@ def get_simple_updater(
metric=None,
deterministic_trainer=False,
):
if learner_kwargs is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this form?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand. Are you asking why we compare with is None?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Is there a test that populates different learner_kwargs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, e.g., test_joint.py L27. This change is not changing the behavior but rather avoiding the unwanted behavior when using dicts and the likes as defaults in functions.

learning_rate_scheduler_step_size: int = defaults.LEARNING_RATE_SCHEDULER_STEP_SIZE,
momentum: float = defaults.MOMENTUM,
weight_decay: float = defaults.WEIGHT_DECAY,
learning_rate_scheduler: Optional[partial] = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Type Callable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed it

@wistuba
Copy link
Contributor Author

wistuba commented Jun 12, 2023

The self.save_hyperparameters must now include the optimizer object.

I've also ignored the lr_scheduler

@@ -47,6 +47,11 @@ instantiating the method you selected. See :doc:`supported_algorithms` for more



.. note::
If you have defined the ``optimizer_fn`` function in your Renate config, do not pass values for the keys
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a check for this in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. run_training_job.py will not add these params in the argparse code and therefore the script will fail if these arguments are passed but not expected.

@wistuba wistuba merged commit 15541cf into dev Jun 14, 2023
18 checks passed
@wistuba wistuba deleted the mw-custom-opt-scheduler branch June 14, 2023 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants