Lightning-AI/pytorch-lightning · error · ValueError
Trainer is already configured with a `BatchSizeFinder` callb
Error message
Trainer is already configured with a `BatchSizeFinder` callback.Please remove it if you want to use the Tuner.
What it means
_check_scale_batch_size_configuration rejects tuner.scale_batch_size when a BatchSizeFinder callback is already attached to the Trainer, to avoid conflicting duplicate batch-size tuning logic.
Source
Thrown at src/lightning/pytorch/tuner/tuning.py:250
configured_callbacks = [cb for cb in trainer.callbacks if isinstance(cb, LearningRateFinder)]
if configured_callbacks:
raise ValueError(
"Trainer is already configured with a `LearningRateFinder` callback."
"Please remove it if you want to use the Tuner."
)
def _check_scale_batch_size_configuration(trainer: "pl.Trainer") -> None:
if trainer._accelerator_connector.is_distributed:
raise ValueError("Tuning the batch size is currently not supported with distributed strategies.")
# local import to avoid circular import
from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder
configured_callbacks = [cb for cb in trainer.callbacks if isinstance(cb, BatchSizeFinder)]
if configured_callbacks:
raise ValueError(
"Trainer is already configured with a `BatchSizeFinder` callback."
"Please remove it if you want to use the Tuner."
)
View on GitHub (pinned to 9fed5c27d2)
Solutions
- Remove the BatchSizeFinder callback and use only tuner.scale_batch_size
- Or keep the callback and drop the tuner call
Example fix
# before trainer = Trainer(callbacks=[BatchSizeFinder()]) trainer.tuner.scale_batch_size(model) # after trainer = Trainer() bs = trainer.tuner.scale_batch_size(model)
Defensive patterns
Strategy: validation
Validate before calling
from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder assert not any(isinstance(cb, BatchSizeFinder) for cb in trainer.callbacks)
Type guard
def has_batch_size_finder(trainer) -> bool:
from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder
return any(isinstance(cb, BatchSizeFinder) for cb in trainer.callbacks) Prevention
- Pick one batch-size tuning mechanism per Trainer
When it happens
Trigger: trainer = Trainer(callbacks=[BatchSizeFinder(...)]) followed by trainer.tuner.scale_batch_size(model).
Common situations: Mixing the callback-based auto batch-size tuning with the Tuner API in the same script.
Related errors
- Trainer is already configured with a `LearningRateFinder` ca
- Tuning the batch size is currently not supported with distri
- Received multiple values for {', '.join(duplicated_plugin_ke
- Trainer was configured with `enable_checkpointing=False` but
- You added multiple progress bar callbacks to the Trainer, bu
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/7b7d62b2a2c1ed18.
Report an issue: GitHub.