Lightning-AI/pytorch-lightning · error · ValueError

`mode` should be either of {self.SUPPORTED_MODES}

Error message

`mode` should be either of {self.SUPPORTED_MODES}

What it means

_LRFinder (used by `lr_finder(runner)(model, ...)` / Tuner's lr_find) accepts only `mode='exponential'` or `mode='linear'` (case-insensitive) for the learning-rate sweep. Any other value raises ValueError after lowercasing the input.

Source

Thrown at src/lightning/pytorch/callbacks/lr_finder.py:104

    """

    SUPPORTED_MODES = ("linear", "exponential")

    def __init__(
        self,
        min_lr: float = 1e-8,
        max_lr: float = 1,
        num_training_steps: int = 100,
        mode: str = "exponential",
        early_stop_threshold: Optional[float] = 4.0,
        update_attr: bool = True,
        attr_name: str = "",
        weights_only: Optional[bool] = None,
    ) -> None:
        mode = mode.lower()
        if mode not in self.SUPPORTED_MODES:
            raise ValueError(f"`mode` should be either of {self.SUPPORTED_MODES}")

        self._min_lr = min_lr
        self._max_lr = max_lr
        self._num_training_steps = num_training_steps
        self._mode = mode
        self._early_stop_threshold = early_stop_threshold
        self._update_attr = update_attr
        self._attr_name = attr_name
        self._weights_only = weights_only

        self._early_exit = False
        self.optimal_lr: Optional[_LRFinder] = None

    def lr_find(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule") -> None:
        with isolate_rng():
            self.optimal_lr = _lr_find(
                trainer,
                pl_module,

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Use exactly 'exponential' (default) or 'linear'
  2. Trim/normalize config strings: `mode.strip().lower()`
  3. For log-scale sweeps, use 'exponential', which multiplies the lr by a factor each step

Example fix

# before
lr_find(model, mode='log')
# after
lr_find(model, mode='exponential')
Defensive patterns

Strategy: type-guard

Validate before calling

mode = mode.strip().lower()
assert mode in ('exponential', 'linear')

Type guard

def is_valid_lr_find_mode(mode: str) -> bool:
    return isinstance(mode, str) and mode.strip().lower() in ('exponential', 'linear')

Prevention

When it happens

Trigger: Calling the lr_find runner with `mode='log'`, `mode='Exponential '` (whitespace), or a typo like `mode='expo'`. The value is lowercased first, so 'EXPONENTIAL' works but 'logarithmic' does not.

Common situations: Assuming a log-scale option under a different name; passing mode from a config with whitespace or a typo; older code using names from other libraries.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of Lightning-AI/pytorch-lightning@9fed5c27d2 (2026-08-28). Data as JSON: /api/errors/973d1b19366d9b3b. Report an issue: GitHub.