code: def test_load_model_from_checkpoint(tmpdir, model_template):
      """Verify test() on pretrained model."""
      model = model_template()
  
      trainer_options = {
          "enable_progress_bar": False,
          "max_epochs": 2,
          "limit_train_batches": 2,
          "limit_val_batches": 2,
          "limit_test_batches": 2,
          "callbacks": [
              ModelCheckpoint(
                  dirpath=tmpdir, monitor="val_loss", save_top_k=-1
              )
          ],
          "default_root_dir": tmpdir,
      }
  
      # fit model
      trainer = Trainer(**trainer_options)
      trainer.fit(model)
      trainer.test(model)
  
      # correct result and ok accuracy
      assert (
          trainer.state.finished
      ), f"Training failed with {trainer.state}"
  
      # load last checkpoint
      last_checkpoint = sorted(
          glob.glob(
              os.path.join(
                  trainer.checkpoint_callback.dirpath, "*.ckpt"
              )
          )
      )[-1]
  
      # Since `BoringModel` has `_save_hparams = True` by default, check that ckpt has hparams
      ckpt = torch.load(last_checkpoint)
      assert (
          model_template.CHECKPOINT_HYPER_PARAMS_KEY in ckpt
      ), "hyper_parameters missing from checkpoints"
  
      # Ensure that model can be correctly restored from checkpoint
      pretrained_model = model_template.load_from_checkpoint(
          last_checkpoint
      )
  
      # test that hparams loaded correctly
      for k, v in model.hparams.items():
          assert getattr(pretrained_model.hparams, k) == v
  
      # assert weights are the same
      for (old_name, old_p), (new_name, new_p) in zip(
          model.named_parameters(), pretrained_model.named_parameters()
      ):
          assert torch.all(
              torch.eq(old_p, new_p)
          ), "loaded weights are not the same as the saved weights"
  
      # Check `test` on pretrained model:
      new_trainer = Trainer(**trainer_options)
      new_trainer.test(pretrained_model)
  
imports: import glob
  import logging
  import os
  import pickle
  from copy import deepcopy
  from typing import Generic, Mapping, TypeVar
  import cloudpickle
  import pytest
  import torch
  from lightning.fabric import seed_everything
  from lightning.pytorch import Callback, Trainer
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.trainer.states import TrainerFn
  from lightning_utilities.test.warning import no_warning_call
  from torch import Tensor
  import tests_pytorch.helpers.pipelines
  import tests_pytorch.helpers.utils
  from tests_pytorch.helpers.datamodules import ClassifDataModule
  from tests_pytorch.helpers.runif import RunIf
  from tests_pytorch.helpers.simple_models import ClassificationModel
  from tests_pytorch.loops.test_loops import CustomException
label_desc: Use image node_id 10 for calling a global function with example usage: test_load_model_from_checkpoint(tmpdir, model_template) without return types