class_docstr: Learning rate finder handler for supervised trainers.
  
  While attached, the handler increases the learning rate in between two
  boundaries in a linear or exponential manner. It provides valuable
  information on how well the network can be trained over a range of learning
  rates and what can be an optimal learning rate.
  
  Examples:
      .. code-block:: python
  
          from ignite.handlers import FastaiLRFinder
  
          trainer = ...
          model = ...
          optimizer = ...
  
          lr_finder = FastaiLRFinder()
          to_save = {"model": model, "optimizer": optimizer}
  
          with lr_finder.attach(trainer, to_save=to_save) as trainer_with_lr_finder:
              trainer_with_lr_finder.run(dataloader)
  
          # Get lr_finder results
          lr_finder.get_results()
  
          # Plot lr_finder results (requires matplotlib)
          lr_finder.plot()
  
          # get lr_finder suggestion for lr
          lr_finder.lr_suggestion()
  
  
  Note:
      When context manager is exited all LR finder's handlers are removed.
  
  Note:
      Please, also keep in mind that all other handlers attached the trainer will be executed during LR finder's run.
  
  Note:
      This class may require `matplotlib` package to be installed to plot learning rate range test:
  
      .. code-block:: bash
  
          pip install matplotlib
  
  
  References:
  
      Cyclical Learning Rates for Training Neural Networks:
      https://arxiv.org/abs/1506.01186
  
      fastai/lr_find: https://github.com/fastai/fastai
  
  .. versionadded:: 0.4.6
docstr: Plots the learning rate range test.
  
  This method requires ``matplotlib`` package to be installed:
  
  .. code-block:: bash
  
      pip install matplotlib
  
  Args:
      skip_start: number of batches to trim from the start.
          Default: 10.
      skip_end: number of batches to trim from the start.
          Default: 5.
      log_lr: True to plot the learning rate in a logarithmic
          scale; otherwise, plotted in a linear scale. Default: True.
      display_suggestion: if True, red dot shows the suggested learning rate.
      ax: Pre-existing axes for the plot. Default: None.
      kwargs: optional kwargs passed to ``plt.subplots`` if ``ax`` is not provided.
  
  .. code-block:: python
  
      ax = lr_finder.plot(skip_end=0)
      ax.figure.savefig("output.jpg")
docstr_tok: ["Plots","the","learning","rate","range","test",".","This","method","requires","``","matplotlib","``","package","to","be","installed",":","..","code-block",":",":","bash","pip","install","matplotlib","Args",":","skip_start",":","number","of","batches","to","trim","from","the","start",".","Default",":","10.","skip_end",":","number","of","batches","to","trim","from","the","start",".","Default",":","5.","log_lr",":","True","to","plot","the","learning","rate","in","a","logarithmic","scale",";","otherwise",",","plotted","in","a","linear","scale",".","Default",":","True",".","display_suggestion",":","if","True",",","red","dot","shows","the","suggested","learning","rate",".","ax",":","Pre-existing","axes","for","the","plot",".","Default",":","None",".","kwargs",":","optional","kwargs","passed","to","``","plt.subplots","``","if","``","ax","``","is","not","provided",".","..","code-block",":",":","python","ax","=","lr_finder.plot","(","skip_end=0",")","ax.figure.savefig","(","``","output.jpg","''",")"]
code: def plot(
      self,
      skip_start: int = 10,
      skip_end: int = 5,
      log_lr: bool = True,
      display_suggestion: bool = True,
      ax: Optional[Any] = None,
      **kwargs: Any,
  ) -> None:
      """Plots the learning rate range test.
  
      This method requires ``matplotlib`` package to be installed:
  
      .. code-block:: bash
  
          pip install matplotlib
  
      Args:
          skip_start: number of batches to trim from the start.
              Default: 10.
          skip_end: number of batches to trim from the start.
              Default: 5.
          log_lr: True to plot the learning rate in a logarithmic
              scale; otherwise, plotted in a linear scale. Default: True.
          display_suggestion: if True, red dot shows the suggested learning rate.
          ax: Pre-existing axes for the plot. Default: None.
          kwargs: optional kwargs passed to ``plt.subplots`` if ``ax`` is not provided.
  
      .. code-block:: python
  
          ax = lr_finder.plot(skip_end=0)
          ax.figure.savefig("output.jpg")
  
      """
      try:
          from matplotlib import pyplot as plt
      except ImportError:
          raise ModuleNotFoundError(
              "This method requires matplotlib to be installed. "
              "Please install it with command: \n pip install matplotlib"
          )
      if not self._history:
          raise RuntimeError(
              "learning rate finder didn't run yet so results can't be plotted"
          )
      if skip_start < 0:
          raise ValueError("skip_start cannot be negative")
      if skip_end < 0:
          raise ValueError("skip_end cannot be negative")
  
      # Get the data to plot from the history dictionary.
      lrs = self._history["lr"]
      losses = self._history["loss"]
  
      num_groups = len(lrs[0]) if isinstance(lrs[0], list) else 1
      legends = [
          f"suggested lr for param_groups {i}"
          for i in range(num_groups)
      ]
  
      if ax is None:
          fig, ax = plt.subplots(**kwargs)
  
      # Check to show the suggested learning rate
      if display_suggestion:
          sug_lr = self.lr_suggestion()
          idx = self._history["lr"].index(sug_lr)
  
          if skip_start >= idx:
              warnings.warn(
                  "skip_start is larger than the suggested LR found"
                  " and it will not be visible on the plot. Please, make the value smaller.",
                  UserWarning,
              )
  
          corresponding_loss = self._history["loss"][int(idx)]
  
          # Check if optimizer has multiple param_groups
          if not isinstance(sug_lr, list):
              sug_lr = [
                  sug_lr,
              ]
          for lr in sug_lr:
              ax.scatter(
                  lr,
                  corresponding_loss,
                  color="red" if len(sug_lr) == 1 else None,
                  s=75,
                  marker="o",
                  zorder=3,
              )
  
      # handle skip_end=0 properly
      if skip_end == 0:
          lrs = lrs[skip_start:]
          losses = losses[skip_start:]
      else:
          lrs = lrs[skip_start:-skip_end]
          losses = losses[skip_start:-skip_end]
  
      plt.legend(legends)
      # Plot loss as a function of the learning rate
      ax.plot(lrs, losses)
      if log_lr:
          ax.set_xscale("log")
      lr_min = min(lrs[0]) if isinstance(lrs[0], list) else lrs[0]
      lr_max = max(lrs[-1]) if isinstance(lrs[-1], list) else lrs[-1]
      ax.set_xlim([lr_min, lr_max])
      ax.set_xlabel("Learning rate")
      ax.set_ylabel("Loss")
      plt.show()
      return ax
  
imports: import contextlib
  import logging
  import tempfile
  import warnings
  from math import ceil
  from pathlib import Path
  from typing import Any, Callable, Dict, List, Mapping, Optional, Union
  import torch
  from torch.optim import Optimizer
  from torch.optim.lr_scheduler import _LRScheduler
  import ignite.distributed
  from ignite.engine import Engine, Events
  from ignite.handlers import Checkpoint
  from ignite.handlers.param_scheduler import LRScheduler, ParamGroupScheduler, PiecewiseLinear
label_desc: Use image node_id 9 for calling the FastaiLRFinder obj's underlying member method code with example usage: obj.plot(skip_start, skip_end, log_lr, display_suggestion, ax) and returns: ax