{"record":{"id":"e502db2aa04b2910","repo":"Lightning-AI/pytorch-lightning","slug":"the-attribute-name-for-the-learning-rate-was-set-t","errorCode":null,"errorMessage":"The attribute name for the learning rate was set to {attr_name}, but could not find this as a field in `model` or `model.hparams`.","messagePattern":"The attribute name for the learning rate was set to (.+?), but could not find this as a field in `model` or `model\\.hparams`\\.","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/tuner/lr_finder.py","lineNumber":51,"sourceCode":"# check if ipywidgets is installed before importing tqdm.auto\n# to ensure it won't fail and a progress bar is displayed\nif importlib.util.find_spec(\"ipywidgets\") is not None:\n    from tqdm.auto import tqdm\nelse:\n    from tqdm import tqdm\n\nif TYPE_CHECKING:\n    import matplotlib.pyplot as plt\n    from matplotlib.axes import Axes\n\n_MATPLOTLIB_AVAILABLE = RequirementCache(\"matplotlib\")\nlog = logging.getLogger(__name__)\n\n\ndef _determine_lr_attr_name(model: \"pl.LightningModule\", attr_name: str = \"\") -> str:\n    if attr_name:\n        if not lightning_hasattr(model, attr_name):\n            raise AttributeError(\n                f\"The attribute name for the learning rate was set to {attr_name}, but\"\n                \" could not find this as a field in `model` or `model.hparams`.\"\n            )\n        return attr_name\n\n    attr_options = (\"lr\", \"learning_rate\")\n    for attr in attr_options:\n        if lightning_hasattr(model, attr):\n            return attr\n\n    raise AttributeError(\n        \"When using the learning rate finder, either `model` or `model.hparams` should\"\n        f\" have one of these fields: {attr_options}. If your model has a different name for the learning rate, set\"\n        f\" it with `.lr_find(attr_name=...)`.\"\n    )\n\n\nclass _LRFinder:","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/tuner/lr_finder.py#L33-L69","documentation":"The LR finder was given attr_name=<name> via tuner.lr_find(model, attr_name=...), but that attribute exists neither on the LightningModule itself nor in model.hparams. The finder needs to know which field holds the learning rate so it can update it during the search.","triggerScenarios":"tuner.lr_find(model, attr_name=\"lr_rate\") where the model defines no such attribute or hparams key (typo or renamed field).","commonSituations":"Renaming the learning-rate field in the model (e.g. lr -> base_lr) without updating attr_name, or misspelling it.","solutions":["Fix the attr_name to match the actual attribute or hparams key (e.g. \"lr\" or \"learning_rate\")","Expose the LR as model.hparams.lr or as a plain self.lr attribute","Omit attr_name so the finder auto-detects lr/learning_rate"],"exampleFix":"# before\ntuner.lr_find(model, attr_name=\"lr_rate\")  # model uses `lr`\n# after\ntuner.lr_find(model)  # auto-detects `lr`","handlingStrategy":"type-guard","validationCode":"from lightning.pytorch.utilities.model_helpers import lightning_hasattr\nif not lightning_hasattr(model, attr_name):\n    raise ValueError(f\"{attr_name!r} not a model field or hparams key\")\ntuner.lr_find(model, attr_name=attr_name)","typeGuard":"def attr_exists(model, name: str) -> bool:\n    from lightning.pytorch.utilities.model_helpers import lightning_hasattr\n    return lightning_hasattr(model, name)","tryCatchPattern":null,"preventionTips":["Keep the LR field name stable (lr or learning_rate) across model refactors","Store LR in hparams via save_hyperparameters so it is discoverable"],"tags":["lr-finder","tuner","attr-name","hyperparameters","pytorch-lightning"],"backgroundTag":"attribute-not-found","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}