Lightning-AI/pytorch-lightning · error · ValueError

Trainer is already configured with a `LearningRateFinder` ca

Error message

Trainer is already configured with a `LearningRateFinder` callback.Please remove it if you want to use the Tuner.

What it means

_check_lr_find_configuration rejects running tuner.lr_find when the Trainer already has a LearningRateFinder callback attached, since the Tuner installs its own and duplication would conflict.

Source

Thrown at src/lightning/pytorch/tuner/tuning.py:235

            raise MisconfigurationException(
                f"In tuner with method={method!r}, `dataloaders` argument should be None,"
                " please consider setting `train_dataloaders` and `val_dataloaders` instead."
            )
    else:
        if train_dataloaders is not None or val_dataloaders is not None:
            raise MisconfigurationException(
                f"In tuner with `method`={method!r}, `train_dataloaders` and `val_dataloaders`"
                " arguments should be None, please consider setting `dataloaders` instead."
            )


def _check_lr_find_configuration(trainer: "pl.Trainer") -> None:
    # local import to avoid circular import
    from lightning.pytorch.callbacks.lr_finder import LearningRateFinder

    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

  1. Remove LearningRateFinder from the Trainer's callbacks list and rely on tuner.lr_find alone
  2. Or keep the callback and skip calling tuner.lr_find

Example fix

# before
trainer = Trainer(callbacks=[LearningRateFinder()])
trainer.tuner.lr_find(model)
# after
trainer = Trainer()
trainer.tuner.lr_find(model)
Defensive patterns

Strategy: validation

Validate before calling

from lightning.pytorch.callbacks.lr_finder import LearningRateFinder
assert not any(isinstance(cb, LearningRateFinder) for cb in trainer.callbacks)

Type guard

def has_lr_finder_callback(trainer) -> bool:
    from lightning.pytorch.callbacks.lr_finder import LearningRateFinder
    return any(isinstance(cb, LearningRateFinder) for cb in trainer.callbacks)

Prevention

When it happens

Trigger: trainer = Trainer(callbacks=[LearningRateFinder(...)]) followed by trainer.tuner.lr_find(model).

Common situations: Copy-pasting a callback-based LR-find snippet and also calling the Tuner API; migrating from the callback approach to the Tuner without removing the callback.

Related errors


AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28). Data as JSON: /api/errors/0d0d0c76ce7eadda. Report an issue: GitHub.