{"record":{"id":"32572e2da08c2049","repo":"Lightning-AI/pytorch-lightning","slug":"tuning-the-batch-size-is-currently-not-supported-w","errorCode":null,"errorMessage":"Tuning the batch size is currently not supported with distributed strategies.","messagePattern":"Tuning the batch size is currently not supported with distributed strategies\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/tuner/tuning.py","lineNumber":243,"sourceCode":"                \" arguments should be None, please consider setting `dataloaders` instead.\"\n            )\n\n\ndef _check_lr_find_configuration(trainer: \"pl.Trainer\") -> None:\n    # local import to avoid circular import\n    from lightning.pytorch.callbacks.lr_finder import LearningRateFinder\n\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":225,"sourceCodeEnd":254,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/tuner/tuning.py#L225-L254","documentation":"Batch-size scaling (tuner.scale_batch_size) is not supported under distributed strategies (DDP, etc.) because it works by repeatedly re-fitting with growing batch sizes. _check_scale_batch_size_configuration raises ValueError when trainer._accelerator_connector.is_distributed is true.","triggerScenarios":"trainer = Trainer(strategy='ddp', devices=2, accelerator='gpu') then trainer.tuner.scale_batch_size(model); also multi-process launches (torchrun) or strategies that imply distribution.","commonSituations":"Tuning batch size in a multi-GPU or multi-node setup; forgetting devices>1 implies distributed.","solutions":["Run scale_batch_size on a single device (strategy='auto'/None, devices=1) to find a per-device batch size, then scale manually for distributed runs","Use the BatchSizeFinder callback alternative only if it fits your non-distributed setup","Tune on a smaller reproducible config before launching distributed training"],"exampleFix":"# before\ntrainer = Trainer(accelerator=\"gpu\", devices=4, strategy=\"ddp\")\ntrainer.tuner.scale_batch_size(model)\n# after\ntuner_trainer = Trainer(accelerator=\"gpu\", devices=1)\nmodel.hparams.batch_size = tuner_trainer.tuner.scale_batch_size(model)\ntrainer = Trainer(accelerator=\"gpu\", devices=4, strategy=\"ddp\")","handlingStrategy":"validation","validationCode":"assert not trainer._accelerator_connector.is_distributed, \"scale_batch_size requires a non-distributed setup\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Tune batch size on a single-device Trainer config","Keep a small tuning script separate from the distributed launch script"],"tags":["batch-size-finder","distributed","ddp","tuner"],"backgroundTag":"unsupported-distributed-operation","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}