code: def train_eval_lightning(
      train_dataset,
      eval_dataset,
      test_dataset,
      trainer_module,
      data_module,
      num_epochs,
      logger_name: str,
      batch_preprocessor=None,
      reader_options: Optional[ReaderOptions] = None,
      checkpoint_path: Optional[str] = None,
      resource_options: Optional[ResourceOptions] = None,
  ) -> pl.Trainer:
      resource_options = resource_options or ResourceOptions()
      use_gpu = resource_options.use_gpu
      reader_options = reader_options or ReaderOptions()
      datamodule = data_module or PetastormLightningDataModule(
          train_dataset,
          eval_dataset,
          batch_preprocessor,
          reader_options,
      )
      trainer = pl.Trainer(
          logger=OssTensorboardLogger(
              save_dir="pl_log_tensorboard", name=logger_name
          ),
          max_epochs=num_epochs * 1000,
          gpus=int(use_gpu),
          reload_dataloaders_every_n_epochs=1,
          resume_from_checkpoint=checkpoint_path,
          callbacks=[StoppingEpochCallback(num_epochs)],
      )
      trainer.fit(trainer_module, datamodule=datamodule)
      if has_test_step_override(trainer_module):
          trainer.test(ckpt_path=None, datamodule=datamodule)
      else:
          logger.warning(
              f"Module {type(trainer_module).__name__} doesn't implement test_step(). Skipping testing"
          )
      if checkpoint_path is not None:
          # Overwrite the warmstart path with the new model
          trainer_module.set_clean_stop(True)
          trainer.save_checkpoint(checkpoint_path)
      return trainer
  
imports: import logging
  from typing import Dict, List, Optional
  import pytorch_lightning
  import torch
  from petastorm import make_batch_reader
  from petastorm.pytorch import DataLoader, decimal_friendly_collate
  from reagent.core.oss_tensorboard_logger import OssTensorboardLogger
  from reagent.data.spark_utils import get_spark_session
  from reagent.preprocessing.batch_preprocessor import BatchPreprocessor
  from reagent.training import StoppingEpochCallback
  from reagent.training.reagent_lightning_module import has_test_step_override
  from .types import Dataset, ReaderOptions, ResourceOptions
label_desc: Use image node_id 5 for calling a global function with example usage: train_eval_lightning(train_dataset, eval_dataset, test_dataset, trainer_module, data_module, num_epochs, logger_name, batch_preprocessor, reader_options, checkpoint_path, resource_options) and returns: trainer