code: def train_torch_lightning(
      model, batch_size, num_workers, data_dir, use_ipex=False
  ):
      orig_parameters = deepcopy(model.state_dict())
      # list to store the right key of dict
      orig_parameters_list = deepcopy(list(model.named_parameters()))
  
      train_loader = create_data_loader(
          data_dir, batch_size, num_workers, data_transform
      )
  
      from bigdl.nano.pytorch import Trainer
  
      trainer = Trainer(max_epochs=1, use_ipex=use_ipex)
  
      trainer.fit(model, train_loader)
  
      trained_parameters = model.state_dict()
  
      # Check if the training and the freeze operation is successful
      for i in range(len(orig_parameters_list)):
          name, para = orig_parameters_list[i]
          para1 = orig_parameters[name]
          para2 = trained_parameters[name]
  
          if (
              name == "model.1.bias"
              or name == "model.1.weight"
              or name == "new_classifier.1.bias"
              or name == "new_classifier.1.weight"
          ):
              # Top layer is trained
              if torch.all(torch.eq(para1, para2)):
                  raise Exception(
                      "Parameter "
                      + name
                      + " remains the same after training."
                  )
          else:
              # Frozen parameters should not change
              if not torch.all(torch.eq(para1, para2)):
                  raise Exception(name + " freeze failed.")
      print("pass")
  
file_path: BigDL/python/nano/test/pytorch/utils/_train_torch_lightning.py
imports: import torch
  from copy import deepcopy
  import pytorch_lightning
  import torchvision.transforms
  from torchvision.datasets import CIFAR10
  from torch.utils.data import DataLoader
  from torch.utils.data.sampler import SequentialSampler
  from bigdl.nano.pytorch.vision.models import ImageClassifier
label_desc: Use image node_id 4 for calling a global function with example usage: train_torch_lightning(model, batch_size, num_workers, data_dir, use_ipex) without return types