code: def test_checkpoint_resume(self):
      model = _SimpleModel()
      dataloader = self._data_loader("cpu")
      opt = torch.optim.SGD(model.parameters(), 0.1)
      scheduler = torch.optim.lr_scheduler.StepLR(opt, 3)
  
      with tempfile.TemporaryDirectory(prefix="detectron2_test") as d:
          trainer = SimpleTrainer(model, dataloader, opt)
          checkpointer = Checkpointer(
              model, d, opt=opt, trainer=trainer
          )
  
          trainer.register_hooks(
              [
                  hooks.LRScheduler(scheduler=scheduler),
                  # checkpoint after scheduler to properly save the state of scheduler
                  hooks.PeriodicCheckpointer(checkpointer, 10),
              ]
          )
  
          trainer.train(0, 12)
          self.assertAlmostEqual(opt.param_groups[0]["lr"], 1e-5)
          self.assertEqual(scheduler.last_epoch, 12)
          del trainer
  
          opt = torch.optim.SGD(
              model.parameters(), 999
          )  # lr will be loaded
          trainer = SimpleTrainer(model, dataloader, opt)
          scheduler = torch.optim.lr_scheduler.StepLR(opt, 3)
          trainer.register_hooks(
              [
                  hooks.LRScheduler(scheduler=scheduler),
              ]
          )
          checkpointer = Checkpointer(
              model, d, opt=opt, trainer=trainer
          )
          checkpointer.resume_or_load("non_exist.pth")
          self.assertEqual(
              trainer.iter, 11
          )  # last finished iter number (0-based in Trainer)
          # number of times `scheduler.step()` was called (1-based)
          self.assertEqual(scheduler.last_epoch, 12)
          self.assertAlmostEqual(opt.param_groups[0]["lr"], 1e-5)
  
imports: import json
  import math
  import os
  import tempfile
  import time
  import unittest
  from unittest import mock
  import torch
  from fvcore.common.checkpoint import Checkpointer
  from torch import nn
  from detectron2 import model_zoo
  from detectron2.config import configurable, get_cfg
  from detectron2.engine import DefaultTrainer, SimpleTrainer, default_setup, hooks
  from detectron2.modeling.meta_arch import META_ARCH_REGISTRY
  from detectron2.utils.events import CommonMetricPrinter, JSONWriter
label_desc: Use image node_id 9 for calling the TestTrainer obj's underlying member method code with example usage: obj.test_checkpoint_resume() without return types