Skip to content

Commit 074e238

Browse files
committed
add assertion
1 parent 9d9ba18 commit 074e238

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/lightning/pytorch/callbacks/batch_size_finder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def __init__(
131131
if mode not in self.SUPPORTED_MODES:
132132
raise ValueError(f"`mode` should be either of {self.SUPPORTED_MODES}")
133133

134+
assert 0.0 <= margin < 1.0, f"`margin` should be between 0 and 1. Found {margin=}"
135+
134136
self.optimal_batch_size: Optional[int] = init_val
135137
self._mode = mode
136138
self._steps_per_trial = steps_per_trial

src/lightning/pytorch/tuner/batch_size_scaling.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def _scale_batch_size(
6767
when running on CPU or when automatic OOM detection is not available.
6868
6969
"""
70+
assert 0.0 <= margin < 1.0, f"`margin` should be between 0 and 1. Found {margin=}"
71+
7072
if trainer.fast_dev_run:
7173
rank_zero_warn("Skipping batch size scaler since `fast_dev_run` is enabled.")
7274
return None
@@ -244,6 +246,8 @@ def _run_binsearch_scaling(
244246
Hereafter, the batch size is further refined using a binary search
245247
246248
"""
249+
assert 0.0 <= margin < 1.0, f"`margin` should be between 0 and 1. Found {margin=}"
250+
247251
low = 1
248252
high = None
249253
count = 0

src/lightning/pytorch/tuner/tuning.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def scale_batch_size(
8686
"""
8787
_check_tuner_configuration(train_dataloaders, val_dataloaders, dataloaders, method)
8888
_check_scale_batch_size_configuration(self._trainer)
89+
assert 0.0 <= margin < 1.0, f"`margin` should be between 0 and 1. Found {margin=}"
8990

9091
# local import to avoid circular import
9192
from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder

0 commit comments

Comments
 (0)