code: def main(args):
      dataset = load(args.dataset)
  
      train_index = dataset.train_index
      train_label = np.expand_dims(dataset.y[train_index], -1)
      train_index = np.expand_dims(train_index, -1)
  
      val_index = dataset.val_index
      val_label = np.expand_dims(dataset.y[val_index], -1)
      val_index = np.expand_dims(val_index, -1)
  
      test_index = dataset.test_index
      test_label = np.expand_dims(dataset.y[test_index], -1)
      test_index = np.expand_dims(test_index, -1)
  
      place = fluid.CUDAPlace(0) if args.use_cuda else fluid.CPUPlace()
      train_program = fluid.Program()
      startup_program = fluid.Program()
      test_program = fluid.Program()
      hidden_size = 16
  
      with fluid.program_guard(train_program, startup_program):
          gw = pgl.graph_wrapper.StaticGraphWrapper(
              name="graph", graph=dataset.graph, place=place
          )
  
          output = pgl.layers.gat(
              gw,
              gw.node_feat["words"],
              hidden_size,
              activation="elu",
              name="gat_layer_1",
              num_heads=8,
              feat_drop=0.6,
              attn_drop=0.6,
              is_test=False,
          )
          output = pgl.layers.gat(
              gw,
              output,
              dataset.num_classes,
              num_heads=1,
              activation=None,
              name="gat_layer_2",
              feat_drop=0.6,
              attn_drop=0.6,
              is_test=False,
          )
  
      val_program = train_program.clone(for_test=True)
      test_program = train_program.clone(for_test=True)
  
      initializer = []
      with fluid.program_guard(train_program, startup_program):
          train_node_index, init = paddle_helper.constant(
              "train_node_index", dtype="int64", value=train_index
          )
          initializer.append(init)
  
          train_node_label, init = paddle_helper.constant(
              "train_node_label", dtype="int64", value=train_label
          )
          initializer.append(init)
          pred = fluid.layers.gather(output, train_node_index)
          train_loss_t = fluid.layers.softmax_with_cross_entropy(
              logits=pred, label=train_node_label
          )
          train_loss_t = fluid.layers.reduce_mean(train_loss_t)
  
          adam = fluid.optimizer.Adam(
              learning_rate=1e-2,
              regularization=fluid.regularizer.L2DecayRegularizer(
                  regularization_coeff=0.0005
              ),
          )
          adam.minimize(train_loss_t)
  
      with fluid.program_guard(val_program, startup_program):
          val_node_index, init = paddle_helper.constant(
              "val_node_index", dtype="int64", value=val_index
          )
          initializer.append(init)
  
          val_node_label, init = paddle_helper.constant(
              "val_node_label", dtype="int64", value=val_label
          )
          initializer.append(init)
  
          pred = fluid.layers.gather(output, val_node_index)
          val_loss_t, pred = fluid.layers.softmax_with_cross_entropy(
              logits=pred, label=val_node_label, return_softmax=True
          )
          val_acc_t = fluid.layers.accuracy(
              input=pred, label=val_node_label, k=1
          )
          val_loss_t = fluid.layers.reduce_mean(val_loss_t)
  
      with fluid.program_guard(test_program, startup_program):
          test_node_index, init = paddle_helper.constant(
              "test_node_index", dtype="int64", value=test_index
          )
          initializer.append(init)
  
          test_node_label, init = paddle_helper.constant(
              "test_node_label", dtype="int64", value=test_label
          )
          initializer.append(init)
  
          pred = fluid.layers.gather(output, test_node_index)
          test_loss_t, pred = fluid.layers.softmax_with_cross_entropy(
              logits=pred, label=test_node_label, return_softmax=True
          )
          test_acc_t = fluid.layers.accuracy(
              input=pred, label=test_node_label, k=1
          )
          test_loss_t = fluid.layers.reduce_mean(test_loss_t)
  
      exe = fluid.Executor(place)
      exe.run(startup_program)
      gw.initialize(place)
      for init in initializer:
          init(place)
  
      dur = []
      for epoch in range(200):
          if epoch >= 3:
              t0 = time.time()
  
          train_loss = exe.run(
              train_program,
              feed={},
              fetch_list=[train_loss_t],
              return_numpy=True,
          )
          train_loss = train_loss[0]
  
          if epoch >= 3:
              time_per_epoch = 1.0 * (time.time() - t0)
              dur.append(time_per_epoch)
  
          val_loss, val_acc = exe.run(
              val_program,
              feed={},
              fetch_list=[val_loss_t, val_acc_t],
              return_numpy=True,
          )
  
          log.info(
              "Epoch %d " % epoch
              + "(%.5lf sec) " % np.mean(dur)
              + "Train Loss: %f " % train_loss
              + "Val Loss: %f " % val_loss
              + "Val Acc: %f " % val_acc
          )
  
      test_loss, test_acc = exe.run(
          test_program,
          feed={},
          fetch_list=[test_loss_t, test_acc_t],
          return_numpy=True,
      )
      log.info("Accuracy: %f" % test_acc)
  
file_path: PGL/legacy/examples/static_gat/train.py
imports: import pgl
  from pgl import data_loader
  from pgl.utils import paddle_helper
  from pgl.utils.logger import log
  import paddle.fluid
  import numpy
  import time
  import argparse
label_desc: Use image node_id 2 for calling a global function with example usage: main(args) without return types