code: def resume_checkpoint(
      model,
      checkpoint_path,
      optimizer=None,
      loss_scaler=None,
      log_info=True,
  ):
      resume_epoch = None
      if os.path.isfile(checkpoint_path):
          checkpoint = torch.load(checkpoint_path, map_location="cpu")
          if (
              isinstance(checkpoint, dict)
              and "state_dict" in checkpoint
          ):
              if log_info:
                  _logger.info(
                      "Restoring model state from checkpoint..."
                  )
              new_state_dict = OrderedDict()
              for k, v in checkpoint["state_dict"].items():
                  name = k[7:] if k.startswith("module") else k
                  new_state_dict[name] = v
              model.load_state_dict(new_state_dict)
  
              if optimizer is not None and "optimizer" in checkpoint:
                  if log_info:
                      _logger.info(
                          "Restoring optimizer state from checkpoint..."
                      )
                  optimizer.load_state_dict(checkpoint["optimizer"])
  
              if (
                  loss_scaler is not None
                  and loss_scaler.state_dict_key in checkpoint
              ):
                  if log_info:
                      _logger.info(
                          "Restoring AMP loss scaler state from checkpoint..."
                      )
                  loss_scaler.load_state_dict(
                      checkpoint[loss_scaler.state_dict_key]
                  )
  
              if "epoch" in checkpoint:
                  resume_epoch = checkpoint["epoch"]
                  if (
                      "version" in checkpoint
                      and checkpoint["version"] > 1
                  ):
                      resume_epoch += 1  # start at the next epoch, old checkpoints incremented before save
  
              if log_info:
                  _logger.info(
                      "Loaded checkpoint '{}' (epoch {})".format(
                          checkpoint_path, checkpoint["epoch"]
                      )
                  )
          else:
              model.load_state_dict(checkpoint)
              if log_info:
                  _logger.info(
                      "Loaded checkpoint '{}'".format(checkpoint_path)
                  )
          return resume_epoch
      else:
          _logger.error(
              "No checkpoint found at '{}'".format(checkpoint_path)
          )
          raise FileNotFoundError()
  
imports: import logging
  import os
  import math
  from collections import OrderedDict
  from copy import deepcopy
  from typing import Any, Callable, Optional, Tuple
  import torch
  import torch.nn
  from torch.hub import load_state_dict_from_url
  from timm.models.features import FeatureListNet, FeatureDictNet, FeatureHookNet
  from timm.models.fx_features import FeatureGraphNet
  from timm.models.hub import has_hf_hub, download_cached_file, load_state_dict_from_hf
  from timm.models.layers import Conv2dSame, Linear
  from timm.models.vision_transformer import VisionTransformer, resize_pos_embed
  import tutel.impls.moe_layer
label_desc: Use image node_id 3 for calling a global function with example usage: resume_checkpoint(model, checkpoint_path, optimizer, loss_scaler, log_info) and returns: resume_epoch