Lightning-AI/pytorch-lightning · error · MisconfigurationException
In tuner with method={method!r}, `dataloaders` argument shou
Error message
In tuner with method={method!r}, `dataloaders` argument should be None, please consider setting `train_dataloaders` and `val_dataloaders` instead. What it means
When the tuner runs with method='fit', the combined `dataloaders` argument is disallowed because training needs distinct train and validation loaders. Passing `dataloaders` raises MisconfigurationException.
Source
Thrown at src/lightning/pytorch/tuner/tuning.py:217
self._trainer.callbacks = [cb for cb in self._trainer.callbacks if cb is not lr_finder_callback]
return lr_finder_callback.optimal_lr
def _check_tuner_configuration(
train_dataloaders: Optional[Union[TRAIN_DATALOADERS, "pl.LightningDataModule"]] = None,
val_dataloaders: Optional[EVAL_DATALOADERS] = None,
dataloaders: Optional[EVAL_DATALOADERS] = None,
method: Literal["fit", "validate", "test", "predict"] = "fit",
) -> None:
supported_methods = ("fit", "validate", "test", "predict")
if method not in supported_methods:
raise ValueError(f"method {method!r} is invalid. Should be one of {supported_methods}.")
if method == "fit":
if dataloaders is not None:
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(View on GitHub (pinned to 9fed5c27d2)
Solutions
- Pass train_dataloaders=... (and optionally val_dataloaders=...) instead of dataloaders
- Or let lr_find reuse the loaders already attached to the model/trainer by omitting the argument
Example fix
# before trainer.tuner.lr_find(model, dataloaders=train_dl) # after trainer.tuner.lr_find(model, train_dataloaders=train_dl, val_dataloaders=val_dl)
Defensive patterns
Strategy: validation
Validate before calling
assert dataloaders is None, "method='fit' requires train_dataloaders/val_dataloaders, not dataloaders"
Prevention
- Use keyword arguments (train_dataloaders=...) so mistakes surface early
When it happens
Trigger: trainer.tuner.lr_find(model, dataloaders=dl) or tuner.scale_batch_size(..., dataloaders=dl, method='fit') (method defaults to 'fit').
Common situations: Migrating from an older API that accepted a single dataloaders argument; reusing a validate/test-style call for fitting.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- In tuner with `method`={method!r}, `train_dataloaders` and `
- method='fit' is the only valid configuration to run lr finde
- Device should be CPU, got {device} instead.
- Trying to inject custom `Sampler` into the `{dataloader_cls_
- You are trying to `self.log()` but the loop's result collect
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/bad9b3bcdc478a8d.
Report an issue: GitHub.