Lightning-AI/pytorch-lightning · error · MisconfigurationException

method='fit' is the only valid configuration to run lr finde

Error message

method='fit' is the only valid configuration to run lr finder.

What it means

The Tuner's lr_find API only supports running via trainer.fit. It raises MisconfigurationException when the method argument passed to tuner.lr_find is anything other than 'fit', because learning-rate finding requires a training loop.

Source

Thrown at src/lightning/pytorch/tuner/tuning.py:176

                loss at any point is larger than early_stop_threshold*best_loss
                then the search is stopped. To disable, set to None.
            update_attr: Whether to update the learning rate attribute or not.
            attr_name: Name of the attribute which stores the learning rate. The names 'learning_rate' or 'lr' get
                automatically detected. Otherwise, set the name here.
            weights_only: Defaults to ``None``. If ``True``, restricts loading to ``state_dicts`` of plain
                ``torch.Tensor`` and other primitive types. If loading a checkpoint from a trusted source that contains
                an ``nn.Module``, use ``weights_only=False``. If loading checkpoint from an untrusted source, we
                recommend using ``weights_only=True``. For more information, please refer to the
                `PyTorch Developer Notes on Serialization Semantics <https://docs.pytorch.org/docs/main/notes/serialization.html#id3>`_.

        Raises:
            MisconfigurationException:
                If learning rate/lr in ``model`` or ``model.hparams`` isn't overridden,
                or if you are using more than one optimizer.

        """
        if method != "fit":
            raise MisconfigurationException("method='fit' is the only valid configuration to run lr finder.")

        _check_tuner_configuration(train_dataloaders, val_dataloaders, dataloaders, method)
        _check_lr_find_configuration(self._trainer)

        # local import to avoid circular import
        from lightning.pytorch.callbacks.lr_finder import LearningRateFinder

        lr_finder_callback: Callback = LearningRateFinder(
            min_lr=min_lr,
            max_lr=max_lr,
            num_training_steps=num_training,
            mode=mode,
            early_stop_threshold=early_stop_threshold,
            update_attr=update_attr,
            attr_name=attr_name,
            weights_only=weights_only,
        )

View on GitHub (pinned to 9fed5c27d2)

Solutions

  1. Call trainer.tuner.lr_find(model) without the method argument (defaults to 'fit')
  2. If you passed dataloaders positionally, switch to train_dataloaders/val_dataloaders since method='fit' forbids `dataloaders`

Example fix

// before
trainer.tuner.lr_find(model, dataloaders=dl, method="validate")
// after
trainer.tuner.lr_find(model, train_dataloaders=dl)
Defensive patterns

Strategy: validation

Validate before calling

if method != "fit":
    raise ValueError("lr_find only supports method='fit'")

Prevention

When it happens

Trigger: Calling trainer.tuner.lr_find(model, method='validate'|'test'|'predict') or passing any method string other than 'fit'.

Common situations: Copying a scale_batch_size/validate call pattern and reusing it for lr_find; programmatically looping tuner methods over the same arguments.

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


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