code: def main():
      parser = argparse.ArgumentParser(
          description="ChainerMN example: pipelined neural network"
      )
      parser.add_argument(
          "--batchsize",
          "-b",
          type=int,
          default=100,
          help="Number of images in each mini-batch",
      )
      parser.add_argument(
          "--epoch",
          "-e",
          type=int,
          default=20,
          help="Number of sweeps over the dataset to train",
      )
      parser.add_argument(
          "--gpu", "-g", action="store_true", help="Use GPU"
      )
      parser.add_argument(
          "--out",
          "-o",
          default="result",
          help="Directory to output the result",
      )
      parser.add_argument(
          "--unit", "-u", type=int, default=1000, help="Number of units"
      )
      args = parser.parse_args()
  
      # Prepare ChainerMN communicator.
      if args.gpu:
          comm = chainermn.create_communicator("pure_nccl")
          device = comm.intra_rank
      else:
          comm = chainermn.create_communicator("naive")
          device = -1
  
      if comm.size != 2:
          raise ValueError(
              "This example can only be executed on exactly 2 processes."
          )
  
      if comm.rank == 0:
          print("==========================================")
          if args.gpu:
              print("Using GPUs")
          print("Num unit: {}".format(args.unit))
          print("Num Minibatch-size: {}".format(args.batchsize))
          print("Num epoch: {}".format(args.epoch))
          print("==========================================")
  
      if comm.rank == 0:
          model = L.Classifier(MLP0(comm, args.unit))
      elif comm.rank == 1:
          model = MLP1(comm, args.unit, 10)
  
      if device >= 0:
          chainer.cuda.get_device_from_id(device).use()
          model.to_gpu()
  
      optimizer = chainer.optimizers.Adam()
      optimizer.setup(model)
  
      # Iterate dataset only on worker 0.
      train, test = chainer.datasets.get_mnist()
      if comm.rank == 1:
          train = chainermn.datasets.create_empty_dataset(train)
          test = chainermn.datasets.create_empty_dataset(test)
  
      train_iter = chainer.iterators.SerialIterator(
          train, args.batchsize, shuffle=False
      )
      test_iter = chainer.iterators.SerialIterator(
          test, args.batchsize, repeat=False, shuffle=False
      )
  
      updater = training.StandardUpdater(
          train_iter, optimizer, device=device
      )
      trainer = training.Trainer(
          updater, (args.epoch, "epoch"), out=args.out
      )
      trainer.extend(
          extensions.Evaluator(test_iter, model, device=device)
      )
  
      # Some display and output extentions are necessary only for worker 0.
      if comm.rank == 0:
          trainer.extend(extensions.DumpGraph("main/loss"))
          trainer.extend(extensions.LogReport())
          trainer.extend(
              extensions.PrintReport(
                  [
                      "epoch",
                      "main/loss",
                      "validation/main/loss",
                      "main/accuracy",
                      "validation/main/accuracy",
                      "elapsed_time",
                  ]
              )
          )
          trainer.extend(extensions.ProgressBar())
  
      trainer.run()
  
imports: import argparse
  import chainer
  import chainer.cuda
  import chainer.functions
  import chainer.links
  from chainer import training
  from chainer.training import extensions
  import chainermn
  import chainermn.datasets
  import chainermn.functions
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types