{"record":{"id":"2448f6577ae59cfd","repo":"Lightning-AI/pytorch-lightning","slug":"cannot-use-learningratemonitor-callback-with-tr","errorCode":null,"errorMessage":"Cannot use `LearningRateMonitor` callback with `Trainer` that has no logger.","messagePattern":"Cannot use `LearningRateMonitor` callback with `Trainer` that has no logger\\.","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/callbacks/lr_monitor.py","lineNumber":128,"sourceCode":"        self.log_weight_decay = log_weight_decay\n        self.log_key_prefix = log_key_prefix or \"\"\n\n        self.lrs: dict[str, list[float]] = {}\n        self.last_momentum_values: dict[str, Optional[list[float]]] = {}\n        self.last_weight_decay_values: dict[str, Optional[list[float]]] = {}\n\n    @override\n    def on_train_start(self, trainer: \"pl.Trainer\", *args: Any, **kwargs: Any) -> None:\n        \"\"\"Called before training, determines unique names for all lr schedulers in the case of multiple of the same\n        type or in the case of multiple parameter groups.\n\n        Raises:\n            MisconfigurationException:\n                If ``Trainer`` has no ``logger``.\n\n        \"\"\"\n        if not trainer.loggers:\n            raise MisconfigurationException(\n                \"Cannot use `LearningRateMonitor` callback with `Trainer` that has no logger.\"\n            )\n\n        if self.log_momentum:\n\n            def _check_no_key(key: str) -> bool:\n                if trainer.lr_scheduler_configs:\n                    return any(\n                        key not in config.scheduler.optimizer.defaults for config in trainer.lr_scheduler_configs\n                    )\n\n                return any(key not in optimizer.defaults for optimizer in trainer.optimizers)\n\n            if _check_no_key(\"momentum\") and _check_no_key(\"betas\"):\n                rank_zero_warn(\n                    \"You have set log_momentum=True, but some optimizers do not\"\n                    \" have momentum. This will log a value 0 for the momentum.\",\n                    category=RuntimeWarning,","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/callbacks/lr_monitor.py#L110-L146","documentation":"LearningRateMonitor writes learning rates (and optionally momentum/weight decay) to the Trainer's logger(s). If `trainer.loggers` is empty, `on_train_start` raises MisconfigurationException — there is nowhere to log to.","triggerScenarios":"`Trainer(logger=False, callbacks=[LearningRateMonitor()])` or a logger list that resolves empty. Fails at the start of training.","commonSituations":"Disabling logging for a debug run but leaving the monitor callback in the list; CSV/TensorBoard logger path misconfigured so loggers ends up empty; conditional logger setup in a script.","solutions":["Attach a logger: `Trainer(logger=CSVLogger('logs'))` (or TensorBoardLogger/WandbLogger)","Or remove LearningRateMonitor from callbacks when running with logger=False","If you conditionally disable loggers, filter the callback list the same way"],"exampleFix":"# before\nTrainer(logger=False, callbacks=[LearningRateMonitor()])\n# after\nTrainer(logger=CSVLogger('logs'), callbacks=[LearningRateMonitor()])","handlingStrategy":"validation","validationCode":"if not trainer.loggers:\n    callbacks = [c for c in callbacks if not isinstance(c, LearningRateMonitor)]\n# or ensure a logger:\n# trainer = Trainer(logger=CSVLogger('logs'), ...)","typeGuard":"def lr_monitor_ok(trainer) -> bool:\n    return bool(trainer.loggers)","tryCatchPattern":null,"preventionTips":["Always pair LearningRateMonitor with at least one logger","Filter monitor callbacks whenever running with logger=False (debug runs)"],"tags":["lightning","lr-monitor","missing-logger","trainer-config"],"backgroundTag":"missing-logger-dependency","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}