code: def main():
      # Check if GPU is available
      # (ImageNet example does not support CPU execution)
      if not chainer.cuda.available:
          raise RuntimeError("ImageNet requires GPU support.")
  
      archs = {
          "alex": alex.Alex,
          "googlenet": googlenet.GoogLeNet,
          "googlenetbn": googlenetbn.GoogLeNetBN,
          "nin": nin.NIN,
          "resnet50": resnet50.ResNet50,
      }
  
      parser = argparse.ArgumentParser(
          description="Learning convnet from ILSVRC2012 dataset"
      )
      parser.add_argument(
          "train", help="Path to training image-label list file"
      )
      parser.add_argument(
          "val", help="Path to validation image-label list file"
      )
      parser.add_argument(
          "--arch",
          "-a",
          choices=archs.keys(),
          default="nin",
          help="Convnet architecture",
      )
      parser.add_argument(
          "--batchsize",
          "-B",
          type=int,
          default=32,
          help="Learning minibatch size",
      )
      parser.add_argument(
          "--epoch",
          "-E",
          type=int,
          default=10,
          help="Number of epochs to train",
      )
      parser.add_argument(
          "--initmodel", help="Initialize the model from given file"
      )
      parser.add_argument(
          "--loaderjob",
          "-j",
          type=int,
          help="Number of parallel data loading processes",
      )
      parser.add_argument(
          "--mean",
          "-m",
          default="mean.npy",
          help="Mean file (computed by compute_mean.py)",
      )
      parser.add_argument(
          "--resume",
          "-r",
          default="",
          help="Initialize the trainer from given file",
      )
      parser.add_argument(
          "--out", "-o", default="result", help="Output directory"
      )
      parser.add_argument(
          "--root",
          "-R",
          default=".",
          help="Root directory path of image files",
      )
      parser.add_argument(
          "--val_batchsize",
          "-b",
          type=int,
          default=250,
          help="Validation minibatch size",
      )
      parser.add_argument("--test", action="store_true")
      parser.add_argument("--communicator", default="pure_nccl")
      parser.set_defaults(test=False)
      args = parser.parse_args()
  
      # Start method of multiprocessing module need to be changed if we
      # are using InfiniBand and MultiprocessIterator. This is because
      # processes often crash when calling fork if they are using
      # Infiniband.  (c.f.,
      # https://www.open-mpi.org/faq/?category=tuning#fork-warning )
      # Also, just setting the start method does not seem to be
      # sufficient to actually launch the forkserver processes, so also
      # start a dummy process.
      # See also our document:
      # https://chainermn.readthedocs.io/en/stable/tutorial/tips_faqs.html#using-multiprocessiterator
      # This must be done *before* ``chainermn.create_communicator``!!!
      multiprocessing.set_start_method("forkserver")
      p = multiprocessing.Process()
      p.start()
      p.join()
  
      # Prepare ChainerMN communicator.
      comm = chainermn.create_communicator(args.communicator)
      device = comm.intra_rank
  
      if comm.rank == 0:
          print("==========================================")
          print("Num process (COMM_WORLD): {}".format(comm.size))
          print("Using {} communicator".format(args.communicator))
          print("Using {} arch".format(args.arch))
          print("Num Minibatch-size: {}".format(args.batchsize))
          print("Num epoch: {}".format(args.epoch))
          print("==========================================")
  
      model = archs[args.arch]()
      if args.initmodel:
          print("Load model from", args.initmodel)
          chainer.serializers.load_npz(args.initmodel, model)
  
      chainer.cuda.get_device_from_id(
          device
      ).use()  # Make the GPU current
      model.to_gpu()
  
      # Split and distribute the dataset. Only worker 0 loads the whole dataset.
      # Datasets of worker 0 are evenly split and distributed to all workers.
      mean = np.load(args.mean)
      if comm.rank == 0:
          train = PreprocessedDataset(
              args.train, args.root, mean, model.insize
          )
          val = PreprocessedDataset(
              args.val, args.root, mean, model.insize, False
          )
      else:
          train = None
          val = None
      train = chainermn.scatter_dataset(train, comm, shuffle=True)
      val = chainermn.scatter_dataset(val, comm)
  
      # A workaround for processes crash should be done before making
      # communicator above, when using fork (e.g. MultiProcessIterator)
      # along with Infiniband.
      train_iter = chainer.iterators.MultiprocessIterator(
          train, args.batchsize, n_processes=args.loaderjob
      )
      val_iter = chainer.iterators.MultiprocessIterator(
          val,
          args.val_batchsize,
          repeat=False,
          n_processes=args.loaderjob,
      )
  
      # Create a multi node optimizer from a standard Chainer optimizer.
      optimizer = chainermn.create_multi_node_optimizer(
          chainer.optimizers.MomentumSGD(lr=0.01, momentum=0.9), comm
      )
      optimizer.setup(model)
  
      # Set up a trainer
      updater = training.StandardUpdater(
          train_iter, optimizer, device=device
      )
      trainer = training.Trainer(
          updater, (args.epoch, "epoch"), args.out
      )
  
      val_interval = (10, "iteration") if args.test else (1, "epoch")
      log_interval = (10, "iteration") if args.test else (1, "epoch")
  
      # Create a multi node evaluator from an evaluator.
      evaluator = TestModeEvaluator(val_iter, model, device=device)
      evaluator = chainermn.create_multi_node_evaluator(evaluator, comm)
      trainer.extend(evaluator, trigger=val_interval)
  
      # Some display and output extensions are necessary only for one worker.
      # (Otherwise, there would just be repeated outputs.)
      if comm.rank == 0:
          trainer.extend(extensions.DumpGraph("main/loss"))
          trainer.extend(extensions.LogReport(trigger=log_interval))
          trainer.extend(extensions.observe_lr(), trigger=log_interval)
          trainer.extend(
              extensions.PrintReport(
                  [
                      "epoch",
                      "iteration",
                      "main/loss",
                      "validation/main/loss",
                      "main/accuracy",
                      "validation/main/accuracy",
                      "lr",
                  ]
              ),
              trigger=log_interval,
          )
          trainer.extend(extensions.ProgressBar(update_interval=10))
  
      if args.resume:
          chainer.serializers.load_npz(args.resume, trainer)
  
      trainer.run()
  
imports: from __future__ import print_function
  import argparse
  import multiprocessing
  import random
  import sys
  import numpy
  import chainer
  import chainer.cuda
  from chainer import training
  from chainer.training import extensions
  import chainermn
  import models.alex
  import models.googlenet
  import models.googlenetbn
  import models.nin
  import models.resnet50
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types