code: def main(args):
      """ "Main function."""
      dataset = load(args.dataset)
  
      # normalize
      indegree = dataset.graph.indegree()
      norm = np.zeros_like(indegree, dtype="float32")
      norm[indegree > 0] = np.power(indegree[indegree > 0], -0.5)
      dataset.graph.node_feat["norm"] = np.expand_dims(norm, -1)
  
      data = expand_data_dim(dataset)
  
      place = fluid.CUDAPlace(0) if args.use_cuda else fluid.CPUPlace()
      precompute_program = fluid.Program()
      startup_program = fluid.Program()
      train_program = fluid.Program()
      val_program = train_program.clone(for_test=True)
      test_program = train_program.clone(for_test=True)
  
      # precompute message passing and gather
      initializer = []
      with fluid.program_guard(precompute_program, startup_program):
          gw = pgl.graph_wrapper.StaticGraphWrapper(
              name="graph", place=place, graph=dataset.graph
          )
  
          cached_h = MessagePassing(
              gw,
              gw.node_feat["words"],
              num_layers=args.num_layers,
              norm=gw.node_feat["norm"],
          )
  
          train_cached_h, init = pre_gather(
              cached_h, "train", data["train_index"]
          )
          initializer.append(init)
          val_cached_h, init = pre_gather(
              cached_h, "val", data["val_index"]
          )
          initializer.append(init)
          test_cached_h, init = pre_gather(
              cached_h, "test", data["test_index"]
          )
          initializer.append(init)
  
      exe = fluid.Executor(place)
      gw.initialize(place)
      for init in initializer:
          init(place)
  
      # get train features, val features and test features
      np_train_cached_h, np_val_cached_h, np_test_cached_h = exe.run(
          precompute_program,
          feed={},
          fetch_list=[train_cached_h, val_cached_h, test_cached_h],
          return_numpy=True,
      )
  
      initializer = []
      with fluid.program_guard(train_program, startup_program):
          with fluid.unique_name.guard():
              train_handle = calculate_loss(
                  "train",
                  np_train_cached_h,
                  data["train_label"],
                  dataset.num_classes,
                  args,
              )
              initializer += train_handle["initializer"]
              adam = fluid.optimizer.Adam(
                  learning_rate=args.lr,
                  regularization=fluid.regularizer.L2DecayRegularizer(
                      regularization_coeff=args.weight_decay
                  ),
              )
              adam.minimize(train_handle["loss"])
  
      with fluid.program_guard(val_program, startup_program):
          with fluid.unique_name.guard():
              val_handle = calculate_loss(
                  "val",
                  np_val_cached_h,
                  data["val_label"],
                  dataset.num_classes,
                  args,
              )
              initializer += val_handle["initializer"]
  
      with fluid.program_guard(test_program, startup_program):
          with fluid.unique_name.guard():
              test_handle = calculate_loss(
                  "test",
                  np_test_cached_h,
                  data["test_label"],
                  dataset.num_classes,
                  args,
              )
              initializer += test_handle["initializer"]
  
      exe.run(startup_program)
      for init in initializer:
          init(place)
  
      dur = []
      for epoch in range(args.epochs):
          if epoch >= 3:
              t0 = time.time()
          train_loss_t = exe.run(
              train_program,
              feed={},
              fetch_list=[train_handle["loss"]],
              return_numpy=True,
          )[0]
  
          if epoch >= 3:
              time_per_epoch = 1.0 * (time.time() - t0)
              dur.append(time_per_epoch)
  
          val_loss_t, val_acc_t = exe.run(
              val_program,
              feed={},
              fetch_list=[val_handle["loss"], val_handle["acc"]],
              return_numpy=True,
          )
  
          log.info(
              "Epoch %d " % epoch
              + "(%.5lf sec) " % np.mean(dur)
              + "Train Loss: %f " % train_loss_t
              + "Val Loss: %f " % val_loss_t
              + "Val Acc: %f " % val_acc_t
          )
  
      test_loss_t, test_acc_t = exe.run(
          test_program,
          feed={},
          fetch_list=[test_handle["loss"], test_handle["acc"]],
          return_numpy=True,
      )
      log.info("Test Accuracy: %f" % test_acc_t)
  
file_path: PGL/legacy/examples/sgc/sgc.py
imports: import os
  import argparse
  import numpy
  import random
  import time
  import pgl
  from pgl import data_loader
  from pgl.utils.logger import log
  from pgl.utils import paddle_helper
  import paddle.fluid
label_desc: Use image node_id 6 for calling a global function with example usage: main(args) without return types