Lightning-AI/pytorch-lightning · error · MisconfigurationException
In tuner with `method`={method!r}, `train_dataloaders` and `
Error message
In tuner with `method`={method!r}, `train_dataloaders` and `val_dataloaders` arguments should be None, please consider setting `dataloaders` instead. What it means
For tuner calls with method != 'fit' (validate/test/predict), the train_dataloaders and val_dataloaders arguments must be None; only the unified `dataloaders` argument is accepted. Violating this raises MisconfigurationException.
Source
Thrown at src/lightning/pytorch/tuner/tuning.py:223
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(
"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:View on GitHub (pinned to 9fed5c27d2)
Solutions
- Remove train_dataloaders/val_dataloaders and pass dataloaders=... instead
- Check you actually meant a non-fit method; use 'fit' if you want train/val loaders
Example fix
# before trainer.tuner.lr_find(model, method="test", train_dataloaders=dl) # after trainer.tuner.lr_find(model, method="test", dataloaders=dl)
Defensive patterns
Strategy: validation
Validate before calling
if method != "fit":
assert train_dataloaders is None and val_dataloaders is None
assert dataloaders is not None Prevention
- Remember the argument symmetry: fit -> train/val loaders, non-fit -> dataloaders
When it happens
Trigger: trainer.tuner.lr_find(model, method='validate', train_dataloaders=dl) or scale_batch_size with train/val loaders and a non-fit method.
Common situations: Reusing a fit-style call signature while switching the method to validate/test/predict.
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}, `dataloaders` argument shou
- 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/bab6bf720482f3d1.
Report an issue: GitHub.