code: def main(args):
      role = role_maker.PaddleCloudRoleMaker()
      fleet.init(role)
      data = pgl.dataset.RedditDataset(args.normalize, args.symmetry)
      log.info("Preprocess finish")
      log.info("Train Examples: %s" % len(data.train_index))
      log.info("Val Examples: %s" % len(data.val_index))
      log.info("Test Examples: %s" % len(data.test_index))
      log.info("Num nodes %s" % data.graph.num_nodes)
      log.info("Num edges %s" % data.graph.num_edges)
      log.info("Average Degree %s" % np.mean(data.graph.indegree()))
  
      graph = data.graph
      train_index = data.train_index
      val_index = data.val_index
      test_index = data.test_index
  
      train_label = data.train_label
      val_label = data.val_label
      test_label = data.test_label
  
      loss, acc = build_net(
          input_size=data.feature.shape[-1],
          num_class=data.num_classes,
          hidden_size=args.hidden_size,
          num_layers=len(args.samples),
      )
      test_program = paddle.static.default_main_program().clone(
          for_test=True
      )
  
      strategy = fleet.DistributedStrategy()
      strategy.a_sync = True
      optimizer = paddle.optimizer.Adam(learning_rate=args.lr)
      optimizer = fleet.distributed_optimizer(optimizer, strategy)
      optimizer.minimize(loss)
  
      if fleet.is_server():
          fleet.init_server()
          fleet.run_server()
      else:
          place = paddle.CPUPlace()
          exe = paddle.static.Executor(place)
          exe.run(paddle.static.default_startup_program())
          fleet.init_worker()
  
          train_ds = ShardedDataset(train_index, train_label)
          valid_ds = ShardedDataset(val_index, val_label)
          test_ds = ShardedDataset(test_index, test_label)
  
          collate_fn = partial(
              batch_fn, graph=graph, samples=args.samples
          )
  
          train_loader = Dataloader(
              train_ds,
              batch_size=args.batch_size,
              shuffle=True,
              num_workers=args.sample_workers,
              collate_fn=collate_fn,
          )
  
          valid_loader = Dataloader(
              valid_ds,
              batch_size=args.batch_size,
              shuffle=True,
              num_workers=args.sample_workers,
              collate_fn=collate_fn,
          )
  
          test_loader = Dataloader(
              test_ds,
              batch_size=args.batch_size,
              shuffle=True,
              num_workers=args.sample_workers,
              collate_fn=collate_fn,
          )
  
          compiled_prog, cpu_num = setup_compiled_prog(loss)
  
          for epoch in tqdm.tqdm(range(args.epoch)):
              train_loss, train_acc = run(
                  train_loader,
                  data.feature,
                  exe,
                  compiled_prog,
                  loss,
                  acc,
                  phase="train",
                  cpu_num=cpu_num,
              )
  
              valid_loss, valid_acc = run(
                  valid_loader,
                  data.feature,
                  exe,
                  test_program,
                  loss,
                  acc,
                  phase="valid",
                  cpu_num=1,
              )
  
              log.info(
                  "Epoch %s Valid-Loss %s Valid-Acc %s"
                  % (epoch, valid_loss, valid_acc)
              )
          test_loss, test_acc = run(
              test_loader,
              data.feature,
              exe,
              test_program,
              loss,
              acc,
              phase="test",
              cpu_num=1,
          )
          log.info(
              "Epoch %s Test-Loss %s Test-Acc %s"
              % (epoch, test_loss, test_acc)
          )
  
          fleet.stop_worker()
  
file_path: PGL/examples/graphsage/cpu_sample_version/train_distributed_cpu.py
imports: import os
  import argparse
  import time
  from functools import partial
  import numpy
  import tqdm
  import pgl
  import paddle
  from pgl.utils.logger import log
  from pgl.utils.data import Dataloader
  from model import GraphSage
  from dataset import ShardedDataset, batch_fn
  import paddle.distributed.fleet
  import paddle.distributed.fleet.base.role_maker
label_desc: Use image node_id 4 for calling a global function with example usage: main(args) without return types