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

Breaking change for IncreaseBSOnPlateau #19

Merged
merged 2 commits into from
Dec 5, 2024
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
7 changes: 3 additions & 4 deletions bs_scheduler/batch_size_schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,7 @@ class IncreaseBSOnPlateau(BSScheduler):
Increases the batch size when a metric has stopped improving. Models often benefit from increasing the batch size
by a factor once the learning stagnates. This scheduler receives a metric value and if no improvement is seen for a
given number of epochs, the batch size is increased.
Unfortunately, this class is not compatible with the other batch size schedulers as its step() function needs to
receive the metric value.
The step() function needs to receive the metric value using the `metrics` keyword argument.

Args:
dataloader (DataLoader): Wrapped dataloader.
Expand Down Expand Up @@ -1068,9 +1067,9 @@ def get_new_bs(self, **kwargs) -> int:
if self.last_epoch == 0: # Don't do anything at initialization.
return self.batch_size

metric = kwargs.pop('metric', None)
metric = kwargs.pop('metrics', None)
if metric is None:
raise TypeError("IncreaseBSOnPlateau requires passing a 'metric' keyword argument in the step() function.")
raise TypeError("IncreaseBSOnPlateau requires passing a 'metrics' keyword argument in the step() function.")

current = float(metric)
if self.is_better(current, self.best, self.threshold):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_IncreaseBSOnPlateau.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_constant_metric(self):
max_batch_size = 100

n_epochs = 100
metrics = [{"metric": 0.1}] * n_epochs
metrics = [{"metrics": 0.1}] * n_epochs

dataloader = create_dataloader(self.dataset, batch_size=base_batch_size)
scheduler1 = IncreaseBSOnPlateau(dataloader, mode='min', threshold_mode='rel', max_batch_size=max_batch_size)
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_loading_and_unloading(self):

self.reloading_scheduler(scheduler)
self.torch_save_and_load(scheduler)
scheduler.step(metric=10)
scheduler.step(metrics=10)
self.assertEqual(scheduler.mode, mode)
self.assertEqual(scheduler.threshold_mode, threshold_mode)

Expand All @@ -69,7 +69,7 @@ def test_graphic(self):
max_batch_size = 100

n_epochs = 100
metrics = [{"metric": 0.1}] * n_epochs
metrics = [{"metrics": 0.1}] * n_epochs

dataloader = create_dataloader(self.dataset, batch_size=base_batch_size)
scheduler = IncreaseBSOnPlateau(dataloader, mode='min', threshold_mode='rel', max_batch_size=max_batch_size)
Expand Down
Loading