class_docstr: Delegate the whole training to PyTorch Lightning.
  
  Since the arguments passed to the initialization needs to be serialized, ``LightningModule``, ``Trainer`` or
  ``DataLoader`` in this file should be used. Another option is to hide dataloader in the Lightning module, in
  which case, dataloaders are not required for this class to work.
  
  Following the programming style of Lightning, metrics sent to NNI should be obtained from ``callback_metrics``
  in trainer. Two hooks are added at the end of validation epoch and the end of ``fit``, respectively. The metric name
  and type depend on the specific task.
  
  .. warning::
  
     The Lightning evaluator are stateful. If you try to use a previous Lightning evaluator,
     please note that the inner ``lightning_module`` and ``trainer`` will be reused.
  
  Parameters
  ----------
  lightning_module
      Lightning module that defines the training logic.
  trainer
      Lightning trainer that handles the training.
  train_dataloders
      Used in ``trainer.fit()``. A PyTorch DataLoader with training samples.
      If the ``lightning_module`` has a predefined train_dataloader method this will be skipped.
      It can be any types of dataloader supported by Lightning.
  val_dataloaders
      Used in ``trainer.fit()``. Either a single PyTorch Dataloader or a list of them, specifying validation samples.
      If the ``lightning_module`` has a predefined val_dataloaders method this will be skipped.
      It can be any types of dataloader supported by Lightning.
  datamodule
      Used in ``trainer.fit()``. See `Lightning DataModule <https://pytorch-lightning.readthedocs.io/en/stable/data/datamodule.html>`__.
  fit_kwargs
      Keyword arguments passed to ``trainer.fit()``.
  detect_interrupt
      Lightning has a `graceful shutdown <https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html>`__
      mechanism. It does not terminate the whole program (but only the training) when a KeyboardInterrupt is received.
      Setting this to ``True`` will raise the KeyboardInterrupt to the main process, so that the whole program can be terminated.
  
  Examples
  --------
  Users should define a Lightning module that inherits :class:`LightningModule`,
  and use :class:`Trainer` and :class:`DataLoader` from ```nni.nas.evaluator.pytorch``,
  and make them parameters of this evaluator::
  
      import nni
      from nni.nas.evaluator.pytorch.lightning import Lightning, LightningModule, Trainer, DataLoader
class_docstr_tok: ["Delegate","the","whole","training","to","PyTorch","Lightning",".","Since","the","arguments","passed","to","the","initialization","needs","to","be","serialized",",","``","LightningModule","``",",","``","Trainer","``","or","``","DataLoader","``","in","this","file","should","be","used",".","Another","option","is","to","hide","dataloader","in","the","Lightning","module",",","in","which","case",",","dataloaders","are","not","required","for","this","class","to","work",".","Following","the","programming","style","of","Lightning",",","metrics","sent","to","NNI","should","be","obtained","from","``","callback_metrics","``","in","trainer",".","Two","hooks","are","added","at","the","end","of","validation","epoch","and","the","end","of","``","fit","``",",","respectively",".","The","metric","name","and","type","depend","on","the","specific","task",".","..","warning",":",":","The","Lightning","evaluator","are","stateful",".","If","you","try","to","use","a","previous","Lightning","evaluator",",","please","note","that","the","inner","``","lightning_module","``","and","``","trainer","``","will","be","reused",".","Parameters","--","--","--","--","--","lightning_module","Lightning","module","that","defines","the","training","logic",".","trainer","Lightning","trainer","that","handles","the","training",".","train_dataloders","Used","in","``","trainer.fit","(",")","``",".","A","PyTorch","DataLoader","with","training","samples",".","If","the","``","lightning_module","``","has","a","predefined","train_dataloader","method","this","will","be","skipped",".","It","can","be","any","types","of","dataloader","supported","by","Lightning",".","val_dataloaders","Used","in","``","trainer.fit","(",")","``",".","Either","a","single","PyTorch","Dataloader","or","a","list","of","them",",","specifying","validation","samples",".","If","the","``","lightning_module","``","has","a","predefined","val_dataloaders","method","this","will","be","skipped",".","It","can","be","any","types","of","dataloader","supported","by","Lightning",".","datamodule","Used","in","``","trainer.fit","(",")","``",".","See","`","Lightning","DataModule","<","https",":","\/\/pytorch-lightning.readthedocs.io\/en\/stable\/data\/datamodule.html",">","`","__",".","fit_kwargs","Keyword","arguments","passed","to","``","trainer.fit","(",")","``",".","detect_interrupt","Lightning","has","a","`","graceful","shutdown","<","https",":","\/\/pytorch-lightning.readthedocs.io\/en\/stable\/common\/trainer.html",">","`","__","mechanism",".","It","does","not","terminate","the","whole","program","(","but","only","the","training",")","when","a","KeyboardInterrupt","is","received",".","Setting","this","to","``","True","``","will","raise","the","KeyboardInterrupt","to","the","main","process",",","so","that","the","whole","program","can","be","terminated",".","Examples","--","--","--","--","Users","should","define","a","Lightning","module","that","inherits",":","class",":","`","LightningModule","`",",","and","use",":","class",":","`","Trainer","`","and",":","class",":","`","DataLoader","`","from","``","`","nni.nas.evaluator.pytorch","``",",","and","make","them","parameters","of","this","evaluator",":",":","import","nni","from","nni.nas.evaluator.pytorch.lightning","import","Lightning",",","LightningModule",",","Trainer",",","DataLoader"]
code: def __init__(
      self,
      lightning_module: LightningModule,
      trainer: Trainer,
      train_dataloaders: Optional[Any] = None,
      val_dataloaders: Optional[Any] = None,
      train_dataloader: Optional[Any] = None,
      datamodule: Optional[pl.LightningDataModule] = None,
      fit_kwargs: Optional[Dict[str, Any]] = None,
      detect_interrupt: bool = True,
  ):
      assert isinstance(
          lightning_module, LightningModule
      ), f"Lightning module must be an instance of {__name__}.LightningModule."
      if train_dataloader is not None:
          warnings.warn(
              "`train_dataloader` is deprecated and replaced with `train_dataloaders`.",
              DeprecationWarning,
          )
          train_dataloaders = train_dataloader
      if not (
          isinstance(trainer, pl.Trainer) and is_traceable(trainer)
      ):
          raise TypeError(
              f"Trainer must be imported from {__name__}, but found {trainer.__class__.__qualname__}"
          )
      if not _check_dataloader(train_dataloaders):
          warnings.warn(
              f"When using training service to spawn trials, please try to wrap PyTorch DataLoader with nni.trace or "
              f"import DataLoader from {__name__}: {train_dataloaders}",
              RuntimeWarning,
          )
      if not _check_dataloader(val_dataloaders):
          warnings.warn(
              f"When using training service to spawn trials, please try to wrap PyTorch DataLoader with nni.trace or "
              f"import DataLoader from {__name__}: {val_dataloaders}",
              RuntimeWarning,
          )
      self.module = lightning_module
      self.trainer = trainer
      self.train_dataloaders = train_dataloaders
      self.val_dataloaders = val_dataloaders
      self.datamodule = datamodule
      self.fit_kwargs = fit_kwargs or {}
      self.detect_interrupt = detect_interrupt
  
imports: import logging
  import os
  import warnings
  from pathlib import Path
  from typing import Any, Dict, Union, Optional, List, Type
  import pytorch_lightning
  import torch.nn
  import torch.nn.functional
  import torch.optim
  import torchmetrics
  import torchmetrics.classification
  import torch.utils.data
  import nni
  from nni.common.serializer import is_traceable
  from nni.nas.evaluator import MutableEvaluator
label_desc: Use image node_id 1 to create a new Lightning object from inherited base classes: MutableEvaluator with example: obj = Lightning(lightning_module, trainer, train_dataloaders, val_dataloaders, train_dataloader, datamodule, fit_kwargs, detect_interrupt)