Lightning-AI/pytorch-lightning · error · ValueError
method {method!r} is invalid. Should be one of {supported_me
Error message
method {method!r} is invalid. Should be one of {supported_methods}. What it means
The internal _check_tuner_configuration helper validates the method string used by tuner methods. It raises ValueError when method is not one of ('fit', 'validate', 'test', 'predict') — e.g. a typo like 'training' or 'Validate'.
Source
Thrown at src/lightning/pytorch/tuner/tuning.py:213
lr_finder_callback._early_exit = True
self._trainer.callbacks = [lr_finder_callback] + self._trainer.callbacks
self._trainer.fit(model, train_dataloaders, val_dataloaders, datamodule)
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 LearningRateFinderView on GitHub (pinned to 9fed5c27d2)
Solutions
- Use one of the exact strings: 'fit', 'validate', 'test', 'predict'
- Omit method entirely if 'fit' is what you want
Example fix
// before trainer.tuner.scale_batch_size(model, method="training") // after trainer.tuner.scale_batch_size(model, method="fit")
Defensive patterns
Strategy: validation
Validate before calling
assert method in ("fit", "validate", "test", "predict"), method Type guard
def is_valid_tuner_method(m: str) -> bool:
return m in ("fit", "validate", "test", "predict") Prevention
- Type method as Literal['fit','validate','test','predict'] in your own wrappers
When it happens
Trigger: Passing method="training", "fit_train", or any unrecognized string to tuner.lr_find or tuner.scale_batch_size.
Common situations: Typos or assuming method accepts strategy names or custom stage names.
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
- Device should be CUDA, got {device} instead.
- You requested to find {num_devices} devices but there are no
- `setup_optimizers` requires at least one optimizer as input.
- `setup_dataloaders` requires at least one dataloader as inpu
- Passed `{type(self).__name__}(precision={precision!r})`. Pre
AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28).
Data as JSON: /api/errors/3fda1e5c9ab024ee.
Report an issue: GitHub.