class_docstr: Trainer for BigDL-Nano pytorch.
  
  This Trainer extends PyTorch Lightning Trainer by adding
  various options to accelerate pytorch training.
class_docstr_tok: ["Trainer","for","BigDL-Nano","pytorch",".","This","Trainer","extends","PyTorch","Lightning","Trainer","by","adding","various","options","to","accelerate","pytorch","training","."]
docstr: Construct a pytorch-lightning model.
  
  If model is already a pytorch-lightning model,
  return model. If model is pytorch model, construct a new pytorch-lightning module
  with model, loss and optimizer.
  
  :param model:       A model instance.
  :param loss:        Loss to construct pytorch-lightning model.
                      Should be None if model is instance of pl.LightningModule.
  :param optimizer:   Optimizer to construct pytorch-lightning model Should be None.
                      if model is instance of pl.LightningModule.
  :param metrics:     A list of torchmetrics to validate/test performance.
  :return:            A LightningModule object.
docstr_tok: ["Construct","a","pytorch-lightning","model",".","If","model","is","already","a","pytorch-lightning","model",",","return","model",".","If","model","is","pytorch","model",",","construct","a","new","pytorch-lightning","module","with","model",",","loss","and","optimizer",".",":","param","model",":","A","model","instance",".",":","param","loss",":","Loss","to","construct","pytorch-lightning","model",".","Should","be","None","if","model","is","instance","of","pl.LightningModule",".",":","param","optimizer",":","Optimizer","to","construct","pytorch-lightning","model","Should","be","None",".","if","model","is","instance","of","pl.LightningModule",".",":","param","metrics",":","A","list","of","torchmetrics","to","validate\/test","performance",".",":","return",":","A","LightningModule","object","."]
code: def compile(
      model: nn.Module,
      loss: _Loss = None,
      optimizer: torch.optim.Optimizer = None,
      scheduler: _LRScheduler = None,
      metrics: List[Metric] = None,
  ):
      """
      Construct a pytorch-lightning model.
  
      If model is already a pytorch-lightning model,
      return model. If model is pytorch model, construct a new pytorch-lightning module
      with model, loss and optimizer.
  
      :param model:       A model instance.
      :param loss:        Loss to construct pytorch-lightning model.
                          Should be None if model is instance of pl.LightningModule.
      :param optimizer:   Optimizer to construct pytorch-lightning model Should be None.
                          if model is instance of pl.LightningModule.
      :param metrics:     A list of torchmetrics to validate/test performance.
      :return:            A LightningModule object.
      """
      invalidInputError(
          isinstance(model, nn.Module),
          "Model must be instance of nn.Module but got {}".format(
              model.__class__
          ),
      )
  
      pl_model = None
      if isinstance(model, pl.LightningModule):
          invalidInputError(
              not (loss or optimizer),
              "Loss and optimizer should be None if model"
              " is a pytorch-lightning model.",
          )
          pl_model = model
      else:
          pl_model = LightningModule(
              model, loss, optimizer, scheduler, metrics
          )
  
      return pl_model
  
imports: import copy
  from logging import warning
  from typing import Any, List, Optional, Union
  import pytorch_lightning
  import torch
  from torch import nn
  from torch.nn.modules.loss import _Loss
  from torch.utils.data import DataLoader
  from torchmetrics.metric import Metric
  from torch.optim.lr_scheduler import _LRScheduler
  from bigdl.nano.pytorch import InferenceOptimizer
  from bigdl.nano.utils.pytorch import TORCH_VERSION_LESS_1_11, check_ccl
  from bigdl.nano.utils.pytorch import ChannelsLastCallback
  from bigdl.nano.utils.pytorch import save_model, load_model
  from bigdl.nano.pytorch.algorithms import SelectiveBackprop
  from bigdl.nano.pytorch.lightning import LightningModule
  from bigdl.nano.pytorch.strategies import IPEXStrategy, DDPSpawnStrategy, DDPSubprocessStrategy, DDPK8sStrategy
  from bigdl.nano.deps.automl.hpo_api import create_hpo_searcher, check_hpo_status
  from bigdl.nano.deps.ray.ray_api import create_ray_strategy
  from bigdl.nano.utils.common import invalidInputError
  from bigdl.nano.utils.common import _avx512_checker
  from bigdl.nano.utils.common import deprecated
label_desc: Use image node_id 3 for calling the Trainer obj's underlying member method code with example usage: obj.compile(model, loss, optimizer, scheduler, metrics) and returns: pl_model