{"record":{"id":"7b7d62b2a2c1ed18","repo":"Lightning-AI/pytorch-lightning","slug":"trainer-is-already-configured-with-a-batchsizefin","errorCode":null,"errorMessage":"Trainer is already configured with a `BatchSizeFinder` callback.Please remove it if you want to use the Tuner.","messagePattern":"Trainer is already configured with a `BatchSizeFinder` callback\\.Please remove it if you want to use the Tuner\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/tuner/tuning.py","lineNumber":250,"sourceCode":"\n    configured_callbacks = [cb for cb in trainer.callbacks if isinstance(cb, LearningRateFinder)]\n    if configured_callbacks:\n        raise ValueError(\n            \"Trainer is already configured with a `LearningRateFinder` callback.\"\n            \"Please remove it if you want to use the Tuner.\"\n        )\n\n\ndef _check_scale_batch_size_configuration(trainer: \"pl.Trainer\") -> None:\n    if trainer._accelerator_connector.is_distributed:\n        raise ValueError(\"Tuning the batch size is currently not supported with distributed strategies.\")\n\n    # local import to avoid circular import\n    from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder\n\n    configured_callbacks = [cb for cb in trainer.callbacks if isinstance(cb, BatchSizeFinder)]\n    if configured_callbacks:\n        raise ValueError(\n            \"Trainer is already configured with a `BatchSizeFinder` callback.\"\n            \"Please remove it if you want to use the Tuner.\"\n        )\n","sourceCodeStart":232,"sourceCodeEnd":254,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/tuner/tuning.py#L232-L254","documentation":"_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.","triggerScenarios":"trainer = Trainer(callbacks=[BatchSizeFinder(...)]) followed by trainer.tuner.scale_batch_size(model).","commonSituations":"Mixing the callback-based auto batch-size tuning with the Tuner API in the same script.","solutions":["Remove the BatchSizeFinder callback and use only tuner.scale_batch_size","Or keep the callback and drop the tuner call"],"exampleFix":"# before\ntrainer = Trainer(callbacks=[BatchSizeFinder()])\ntrainer.tuner.scale_batch_size(model)\n# after\ntrainer = Trainer()\nbs = trainer.tuner.scale_batch_size(model)","handlingStrategy":"validation","validationCode":"from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder\nassert not any(isinstance(cb, BatchSizeFinder) for cb in trainer.callbacks)","typeGuard":"def has_batch_size_finder(trainer) -> bool:\n    from lightning.pytorch.callbacks.batch_size_finder import BatchSizeFinder\n    return any(isinstance(cb, BatchSizeFinder) for cb in trainer.callbacks)","tryCatchPattern":null,"preventionTips":["Pick one batch-size tuning mechanism per Trainer"],"tags":["batch-size-finder","callbacks","tuner","duplicate-config"],"backgroundTag":"duplicate-callback-registration","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}