{"record":{"id":"74f95a8a2a33c619","repo":"Lightning-AI/pytorch-lightning","slug":"method-fit-is-the-only-valid-configuration-to-ru","errorCode":null,"errorMessage":"method='fit' is the only valid configuration to run lr finder.","messagePattern":"method='fit' is the only valid configuration to run lr finder\\.","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/tuner/tuning.py","lineNumber":176,"sourceCode":"                loss at any point is larger than early_stop_threshold*best_loss\n                then the search is stopped. To disable, set to None.\n            update_attr: Whether to update the learning rate attribute or not.\n            attr_name: Name of the attribute which stores the learning rate. The names 'learning_rate' or 'lr' get\n                automatically detected. Otherwise, set the name here.\n            weights_only: Defaults to ``None``. If ``True``, restricts loading to ``state_dicts`` of plain\n                ``torch.Tensor`` and other primitive types. If loading a checkpoint from a trusted source that contains\n                an ``nn.Module``, use ``weights_only=False``. If loading checkpoint from an untrusted source, we\n                recommend using ``weights_only=True``. For more information, please refer to the\n                `PyTorch Developer Notes on Serialization Semantics <https://docs.pytorch.org/docs/main/notes/serialization.html#id3>`_.\n\n        Raises:\n            MisconfigurationException:\n                If learning rate/lr in ``model`` or ``model.hparams`` isn't overridden,\n                or if you are using more than one optimizer.\n\n        \"\"\"\n        if method != \"fit\":\n            raise MisconfigurationException(\"method='fit' is the only valid configuration to run lr finder.\")\n\n        _check_tuner_configuration(train_dataloaders, val_dataloaders, dataloaders, method)\n        _check_lr_find_configuration(self._trainer)\n\n        # local import to avoid circular import\n        from lightning.pytorch.callbacks.lr_finder import LearningRateFinder\n\n        lr_finder_callback: Callback = LearningRateFinder(\n            min_lr=min_lr,\n            max_lr=max_lr,\n            num_training_steps=num_training,\n            mode=mode,\n            early_stop_threshold=early_stop_threshold,\n            update_attr=update_attr,\n            attr_name=attr_name,\n            weights_only=weights_only,\n        )\n","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/tuner/tuning.py#L158-L194","documentation":"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.","triggerScenarios":"Calling trainer.tuner.lr_find(model, method='validate'|'test'|'predict') or passing any method string other than 'fit'.","commonSituations":"Copying a scale_batch_size/validate call pattern and reusing it for lr_find; programmatically looping tuner methods over the same arguments.","solutions":["Call trainer.tuner.lr_find(model) without the method argument (defaults to 'fit')","If you passed dataloaders positionally, switch to train_dataloaders/val_dataloaders since method='fit' forbids `dataloaders`"],"exampleFix":"// before\ntrainer.tuner.lr_find(model, dataloaders=dl, method=\"validate\")\n// after\ntrainer.tuner.lr_find(model, train_dataloaders=dl)","handlingStrategy":"validation","validationCode":"if method != \"fit\":\n    raise ValueError(\"lr_find only supports method='fit'\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call tuner.lr_find without a method argument","Reserve method overrides for scale_batch_size which supports non-fit methods"],"tags":["lr-finder","tuner","misconfiguration","lightning"],"backgroundTag":"invalid-argument-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}