code: def main():
      args = parser.parse_args()
  
      if args.seed is not None:
          random.seed(args.seed)
          torch.manual_seed(args.seed)
          torch.cuda.manual_seed(args.seed)
          torch.cuda.manual_seed_all(args.seed)
          cudnn.deterministic = True
          cudnn.benchmark = False
          warnings.warn(
              "You have chosen to seed training. "
              "This will turn on the CUDNN deterministic setting, "
              "which can slow down your training considerably! "
              "You may see unexpected behavior when restarting "
              "from checkpoints."
          )
  
      if args.gpu is not None:
          warnings.warn(
              "You have chosen a specific GPU. This will completely "
              "disable data parallelism."
          )
  
      if args.world_size == -1:
          args.world_size = int(os.environ["WORLD_SIZE"])
  
      args.distributed = (
          args.world_size > 1 or args.multiprocessing_distributed
      )
  
      if torch.cuda.is_available():
          ngpus_per_node = torch.cuda.device_count()
      else:
          ngpus_per_node = 1
  
      args.world_size = ngpus_per_node * args.world_size
      t_losses, t_acc1s = main_worker(args.gpu, ngpus_per_node, args)
      # dist.barrier()
  
      # Write the losses to an excel file
      if dist.get_rank() == 0:
          all_losses = [
              torch.empty_like(t_losses) for _ in range(ngpus_per_node)
          ]
          dist.gather(tensor=t_losses, gather_list=all_losses, dst=0)
      else:
          dist.gather(tensor=t_losses, dst=0)
  
      if dist.get_rank() == 0:
          all_acc1s = [
              torch.empty_like(t_acc1s) for _ in range(ngpus_per_node)
          ]
          dist.gather(tensor=t_acc1s, gather_list=all_acc1s, dst=0)
      else:
          dist.gather(tensor=t_acc1s, dst=0)
  
      if dist.get_rank() == 0:
          outputfile = "Acc_loss_log.xlsx"
          workbook = Workbook()
          sheet1 = workbook.active
          sheet1.cell(row=1, column=1, value="Loss")
          sheet1.cell(row=1, column=ngpus_per_node + 4, value="Acc")
          for rank in range(ngpus_per_node):
              for row_idx, (gpu_losses, gpu_acc1s) in enumerate(
                  zip(all_losses[rank], all_acc1s[rank])
              ):
                  sheet1.cell(
                      row=row_idx + 2,
                      column=rank + 1,
                      value=float(gpu_losses),
                  )
                  sheet1.cell(
                      row=row_idx + 2,
                      column=rank + 1 + ngpus_per_node + 3,
                      value=float(gpu_acc1s),
                  )
          workbook.save(outputfile)
  
imports: import argparse
  import os
  import pdb
  import random
  import shutil
  import time
  import warnings
  from enum import Enum
  import torch
  import deepspeed
  from openpyxl import Workbook
  import torch.backends.cudnn
  import torch.distributed
  import torch.multiprocessing
  import torch.nn
  import torch.nn.parallel
  import torch.optim
  import torch.utils.data
  import torch.utils.data.distributed
  import torchvision.datasets
  import torchvision.models
  import torchvision.transforms
  from torch.optim.lr_scheduler import StepLR
  from torch.utils.data import Subset
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types