code: def run_model_test(
      trainer_options,
      model: LightningModule,
      data: LightningDataModule = None,
      version=None,
      with_hpc: bool = True,
      min_acc: float = 0.25,
      min_change_ratio: float = 0.03,
  ):
      save_dir = trainer_options["default_root_dir"]
  
      # logger file to get meta
      logger = get_default_logger(save_dir, version=version)
      trainer_options.update(logger=logger)
      trainer = Trainer(**trainer_options)
      with torch.no_grad():
          initial_values = torch.cat(
              [x.view(-1) for x in model.parameters()]
          )
      trainer.fit(model, datamodule=data)
      with torch.no_grad():
          post_train_values = torch.cat(
              [x.view(-1) for x in model.parameters()]
          )
  
      # Check that the model has changed post-training
      change_ratio = torch.norm(
          initial_values - post_train_values
      ) / torch.norm(initial_values)
      assert change_ratio >= min_change_ratio, (
          f"The change in the model's parameter norm is {change_ratio:.1f}"
          f" relative to the initial norm, but expected a change by >={min_change_ratio}"
      )
  
      if trainer.world_size != trainer.num_devices:
          # we're in multinode. unless the filesystem is shared, only the main node will have access to the checkpoint
          # since we cannot know this, the code below needs to be skipped
          return
  
      # test model loading
      _ = load_model_from_checkpoint(
          trainer.checkpoint_callback.best_model_path, type(model)
      )
  
      # test new model accuracy
      test_loaders = (
          model.test_dataloader()
          if not data
          else data.test_dataloader()
      )
      if not isinstance(test_loaders, list):
          test_loaders = [test_loaders]
  
      if not isinstance(model, BoringModel):
          for dataloader in test_loaders:
              run_model_prediction(model, dataloader, min_acc=min_acc)
  
      if with_hpc:
          # test HPC saving
          # save logger to make sure we get all the metrics
          if logger:
              logger.finalize("finished")
          hpc_save_path = trainer._checkpoint_connector.hpc_save_path(
              save_dir
          )
          trainer.save_checkpoint(hpc_save_path)
          # test HPC loading
          checkpoint_path = trainer._checkpoint_connector._CheckpointConnector__get_max_ckpt_path_from_folder(
              save_dir
          )
          trainer._checkpoint_connector.restore(checkpoint_path)
  
file_path: pytorch-lightning/tests/tests_pytorch/helpers/pipelines.py
imports: from functools import partial
  import torch
  from lightning.pytorch import LightningDataModule, LightningModule, Trainer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.utilities.imports import _TORCHMETRICS_GREATER_EQUAL_0_11
  from torchmetrics.functional import accuracy
  from tests_pytorch.helpers.utils import get_default_logger, load_model_from_checkpoint
label_desc: Use image node_id 2 for calling a global function with example usage: run_model_test(trainer_options, model, data, version, with_hpc, min_acc, min_change_ratio) without return types