class_docstr: Automatically monitor and logs learning rate for learning rate schedulers during training.
  
  Args:
      logging_interval: set to ``'epoch'`` or ``'step'`` to log ``lr`` of all optimizers
          at the same interval, set to ``None`` to log at individual interval
          according to the ``interval`` key of each scheduler. Defaults to ``None``.
      log_momentum: option to also log the momentum values of the optimizer, if the optimizer
          has the ``momentum`` or ``betas`` attribute. Defaults to ``False``.
  
  Raises:
      MisconfigurationException:
          If ``logging_interval`` is none of ``"step"``, ``"epoch"``, or ``None``.
  
  Example::
  
      >>> from lightning.pytorch import Trainer
      >>> from lightning.pytorch.callbacks import LearningRateMonitor
      >>> lr_monitor = LearningRateMonitor(logging_interval='step')
      >>> trainer = Trainer(callbacks=[lr_monitor])
  
  Logging names are automatically determined based on optimizer class name.
  In case of multiple optimizers of same type, they will be named ``Adam``,
  ``Adam-1`` etc. If a optimizer has multiple parameter groups they will
  be named ``Adam/pg1``, ``Adam/pg2`` etc. To control naming, pass in a
  ``name`` keyword in the construction of the learning rate schedulers.
  A ``name`` keyword can also be used for parameter groups in the
  construction of the optimizer.
  
  Example::
  
      def configure_optimizer(self):
          optimizer = torch.optim.Adam(...)
          lr_scheduler = {
              'scheduler': torch.optim.lr_scheduler.LambdaLR(optimizer, ...)
              'name': 'my_logging_name'
          }
          return [optimizer], [lr_scheduler]
  
  Example::
  
      def configure_optimizer(self):
          optimizer = torch.optim.SGD(
              [{
                  'params': [p for p in self.parameters()],
                  'name': 'my_parameter_group_name'
              }],
              lr=0.1
          )
          lr_scheduler = torch.optim.lr_scheduler.LambdaLR(optimizer, ...)
          return [optimizer], [lr_scheduler]
docstr: Called before training, determines unique names for all lr schedulers in the case of multiple of the same
  type or in the case of multiple parameter groups.
  
  Raises:
      MisconfigurationException:
          If ``Trainer`` has no ``logger``.
docstr_tok: ["Called","before","training",",","determines","unique","names","for","all","lr","schedulers","in","the","case","of","multiple","of","the","same","type","or","in","the","case","of","multiple","parameter","groups",".","Raises",":","MisconfigurationException",":","If","``","Trainer","``","has","no","``","logger","``","."]
code: def on_train_start(
      self, trainer: "pl.Trainer", *args: Any, **kwargs: Any
  ) -> None:
      """Called before training, determines unique names for all lr schedulers in the case of multiple of the same
      type or in the case of multiple parameter groups.
  
      Raises:
          MisconfigurationException:
              If ``Trainer`` has no ``logger``.
  
      """
      if not trainer.loggers:
          raise MisconfigurationException(
              "Cannot use `LearningRateMonitor` callback with `Trainer` that has no logger."
          )
  
      if self.log_momentum:
  
          def _check_no_key(key: str) -> bool:
              if trainer.lr_scheduler_configs:
                  return any(
                      key not in config.scheduler.optimizer.defaults
                      for config in trainer.lr_scheduler_configs
                  )
  
              return any(
                  key not in optimizer.defaults
                  for optimizer in trainer.optimizers
              )
  
          if _check_no_key("momentum") and _check_no_key("betas"):
              rank_zero_warn(
                  "You have set log_momentum=True, but some optimizers do not"
                  " have momentum. This will log a value 0 for the momentum.",
                  category=RuntimeWarning,
              )
  
      # Find names for schedulers
      names: List[List[str]] = []
      (
          sched_hparam_keys,
          optimizers_with_scheduler,
          optimizers_with_scheduler_types,
      ) = self._find_names_from_schedulers(trainer.lr_scheduler_configs)
      names.extend(sched_hparam_keys)
  
      # Find names for leftover optimizers
      optimizer_hparam_keys, _ = self._find_names_from_optimizers(
          trainer.optimizers,
          seen_optimizers=optimizers_with_scheduler,
          seen_optimizer_types=optimizers_with_scheduler_types,
      )
      names.extend(optimizer_hparam_keys)
  
      # Initialize for storing values
      names_flatten = list(itertools.chain.from_iterable(names))
      self.lrs = {name: [] for name in names_flatten}
      self.last_momentum_values = {
          name + "-momentum": None for name in names_flatten
      }
      self.last_weight_decay_values = {
          name + "-weight_decay": None for name in names_flatten
      }
  
imports: import itertools
  from collections import defaultdict
  from typing import Any, DefaultDict, Dict, List, Literal, Optional, Set, Tuple, Type
  import torch
  from torch.optim.optimizer import Optimizer
  from typing_extensions import override
  import lightning.pytorch
  from lightning.pytorch.callbacks.callback import Callback
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.rank_zero import rank_zero_warn
  from lightning.pytorch.utilities.types import LRSchedulerConfig
label_desc: Use image node_id 2 for calling the LearningRateMonitor obj's underlying member method code with example usage: obj.on_train_start(trainer) and returns: any, any