code: def check_resume(
      args: argparse.Namespace, output_folder: str
  ) -> bool:
      """
      Check if we should resume a broken training run.
  
      :param args: Arguments as returned by argparse.
      :param output_folder: Main output folder for the model.
  
      :return: Flag signaling if we are resuming training and the directory with
          the training status.
      """
      resume_training = False
      training_state_dir = os.path.join(
          output_folder, C.TRAINING_STATE_DIRNAME
      )
      if os.path.exists(output_folder):
          if args.overwrite_output:
              if utils.is_primary_worker():
                  logger.info(
                      "Removing existing output folder %s.",
                      output_folder,
                  )
                  shutil.rmtree(output_folder)
                  os.makedirs(output_folder)
          elif os.path.exists(training_state_dir):
              old_args = vars(
                  arguments.load_args(
                      os.path.join(output_folder, C.ARGS_STATE_NAME)
                  )
              )
              arg_diffs = _dict_difference(
                  vars(args), old_args
              ) | _dict_difference(old_args, vars(args))
              # Remove args that may differ without affecting the training.
              arg_diffs -= set(C.ARGS_MAY_DIFFER)
              if not arg_diffs:
                  resume_training = True
              else:
                  # We do not have the logger yet
                  logger.error(
                      "Mismatch in arguments for training continuation."
                  )
                  logger.error(
                      "Differing arguments: %s.", ", ".join(arg_diffs)
                  )
                  sys.exit(1)
          elif os.path.exists(
              os.path.join(output_folder, C.PARAMS_BEST_NAME)
          ):
              logger.error(
                  "Refusing to overwrite model folder %s as it seems to contain a trained model.",
                  output_folder,
              )
              sys.exit(1)
          else:
              logger.info(
                  "The output folder %s already exists, but no training state or parameter file was found. "
                  "Will start training from scratch.",
                  output_folder,
              )
      else:
          if utils.is_primary_worker():
              os.makedirs(output_folder)
      if utils.is_distributed():
          if utils.is_primary_worker():
              os.makedirs(
                  os.path.join(
                      output_folder, C.DIST_SECONDARY_WORKERS_LOGDIR
                  ),
                  exist_ok=True,
              )
          # Distributed sync point: output folder exists and we're ready to start
          # training
          torch.distributed.barrier()
      return resume_training
  
imports: from .None import initial_setup
  import argparse
  import gc
  import logging
  import os
  import shutil
  import sys
  import tempfile
  from typing import Any, cast, Callable, Optional, Dict, List, Tuple, Type
  import torch
  import torch.distributed
  import torch.distributed.elastic.multiprocessing.errors
  from .None import arguments
  from .None import checkpoint_decoder
  from .None import constants
  from .None import convert_deepspeed
  from .None import data_io
  from .None import encoder
  from .None import layers
  from .None import loss
  from .None import lr_scheduler
  from .None import model
  from .None import optimizers
  from .None import training
  from .None import transformer
  from .None import utils
  from .None import vocab
  from .config import Config
  from .log import setup_main_logger
  from .utils import check_condition
label_desc: Use image node_id 5 for calling a global function with example usage: check_resume(args, output_folder) and returns: resume_training