code: def run_loop(args: RunConfiguration, checkpoint=None):
      is_resumed = checkpoint is not None
      quick_init_out = initialization.quick_init(
          args=args, verbose=True
      )
      print(quick_init_out.n_gpu)
      with quick_init_out.log_writer.log_context():
          jiant_task_container = container_setup.create_jiant_task_container_from_json(
              jiant_task_container_config_path=args.jiant_task_container_config_path,
              verbose=True,
          )
          runner = setup_runner(
              args=args,
              jiant_task_container=jiant_task_container,
              quick_init_out=quick_init_out,
              verbose=True,
          )
          if is_resumed:
              runner.load_state(checkpoint["runner_state"])
              del checkpoint["runner_state"]
          checkpoint_saver = jiant_runner.CheckpointSaver(
              metadata={"args": args.to_dict()},
              save_path=os.path.join(args.output_dir, "checkpoint.p"),
          )
          if args.do_train:
              metarunner = jiant_metarunner.JiantMetarunner(
                  runner=runner,
                  save_every_steps=args.save_every_steps,
                  eval_every_steps=args.eval_every_steps,
                  save_checkpoint_every_steps=args.save_checkpoint_every_steps,
                  no_improvements_for_n_evals=args.no_improvements_for_n_evals,
                  checkpoint_saver=checkpoint_saver,
                  output_dir=args.output_dir,
                  verbose=True,
                  save_best_model=args.do_save or args.do_save_best,
                  save_last_model=args.do_save or args.do_save_last,
                  load_best_model=True,
                  log_writer=quick_init_out.log_writer,
              )
              if is_resumed:
                  metarunner.load_state(checkpoint["metarunner_state"])
                  del checkpoint["metarunner_state"]
              metarunner.run_train_loop()
  
          if args.do_val:
              val_results_dict = runner.run_val(
                  task_name_list=runner.jiant_task_container.task_run_config.val_task_list,
                  return_preds=args.write_val_preds,
              )
              jiant_evaluate.write_val_results(
                  val_results_dict=val_results_dict,
                  metrics_aggregator=runner.jiant_task_container.metrics_aggregator,
                  output_dir=args.output_dir,
                  verbose=True,
              )
              if args.write_val_preds:
                  jiant_evaluate.write_preds(
                      eval_results_dict=val_results_dict,
                      path=os.path.join(args.output_dir, "val_preds.p"),
                  )
          else:
              assert not args.write_val_preds
  
          if args.write_test_preds:
              test_results_dict = runner.run_test(
                  task_name_list=runner.jiant_task_container.task_run_config.test_task_list,
              )
              jiant_evaluate.write_preds(
                  eval_results_dict=test_results_dict,
                  path=os.path.join(args.output_dir, "test_preds.p"),
              )
  
      if (
          not args.keep_checkpoint_when_done
          and args.save_checkpoint_every_steps
          and os.path.exists(
              os.path.join(args.output_dir, "checkpoint.p")
          )
      ):
          os.remove(os.path.join(args.output_dir, "checkpoint.p"))
  
      py_io.write_file(
          "DONE", os.path.join(args.output_dir, "done_file")
      )
  
imports: import os
  import torch
  import jiant.proj.main.modeling.model_setup
  import jiant.proj.main.runner
  import jiant.proj.main.components.container_setup
  import jiant.proj.main.metarunner
  import jiant.proj.main.components.evaluate
  import jiant.shared.initialization
  import jiant.shared.distributed
  import jiant.shared.model_setup
  import jiant.utils.python.io
  import jiant.utils.zconf
label_desc: Use image node_id 2 for calling a global function with example usage: run_loop(args, checkpoint) without return types