code: def main(args):
      hidden_size = args.hidden_size
      epoch = args.epoch
      ckpt_path = args.ckpt_path
  
      dataset = load(args.dataset)
  
      num_edges = len(dataset.pos_edges) + len(dataset.neg_edges)
      train_num_edges = int(len(dataset.pos_edges) * 0.5) + int(
          len(dataset.neg_edges) * 0.5
      )
      test_num_edges = num_edges - train_num_edges
  
      train_steps = (train_num_edges // train_num_edges) * epoch
  
      place = fluid.CUDAPlace(0) if args.use_cuda else fluid.CPUPlace()
      train_prog = fluid.Program()
      test_prog = fluid.Program()
      startup_prog = fluid.Program()
  
      with fluid.program_guard(train_prog, startup_prog):
          with fluid.unique_name.guard():
              (
                  train_pyreader,
                  train_loss,
                  train_probs,
                  train_labels,
              ) = link_predict_model(
                  dataset.graph.num_nodes,
                  hidden_size=hidden_size,
                  name="train",
              )
              lr = l.polynomial_decay(0.025, train_steps, 0.0001)
              adam = fluid.optimizer.Adam(lr)
              adam.minimize(train_loss)
  
      with fluid.program_guard(test_prog, startup_prog):
          with fluid.unique_name.guard():
              (
                  test_pyreader,
                  test_loss,
                  test_probs,
                  test_labels,
              ) = link_predict_model(
                  dataset.graph.num_nodes,
                  hidden_size=hidden_size,
                  name="test",
              )
      test_prog = test_prog.clone(for_test=True)
  
      train_pyreader.decorate_tensor_provider(
          link_predict_generator(
              dataset.pos_edges[: train_num_edges // 2],
              dataset.neg_edges[: train_num_edges // 2],
              batch_size=train_num_edges,
              epoch=epoch,
          )
      )
  
      test_pyreader.decorate_tensor_provider(
          link_predict_generator(
              dataset.pos_edges[train_num_edges // 2 :],
              dataset.neg_edges[train_num_edges // 2 :],
              batch_size=test_num_edges,
              epoch=1,
          )
      )
  
      exe = fluid.Executor(place)
      exe.run(startup_prog)
      train_pyreader.start()
  
      def existed_params(var):
          if not isinstance(var, fluid.framework.Parameter):
              return False
          return os.path.exists(os.path.join(ckpt_path, var.name))
  
      fluid.io.load_vars(
          exe,
          ckpt_path,
          main_program=train_prog,
          predicate=existed_params,
      )
      step = 0
      prev_time = time.time()
  
      while 1:
          try:
              (
                  train_loss_val,
                  train_probs_val,
                  train_labels_val,
              ) = exe.run(
                  train_prog,
                  fetch_list=[train_loss, train_probs, train_labels],
                  return_numpy=True,
              )
              fpr, tpr, thresholds = metrics.roc_curve(
                  train_labels_val, train_probs_val
              )
              train_auc = metrics.auc(fpr, tpr)
              step += 1
              log.info(
                  "Step %d " % step
                  + "Train Loss: %f " % train_loss_val
                  + "Train AUC: %f " % train_auc
              )
          except fluid.core.EOFException:
              train_pyreader.reset()
              break
  
          test_pyreader.start()
          test_probs_vals, test_labels_vals = [], []
          while 1:
              try:
                  (
                      test_loss_val,
                      test_probs_val,
                      test_labels_val,
                  ) = exe.run(
                      test_prog,
                      fetch_list=[test_loss, test_probs, test_labels],
                      return_numpy=True,
                  )
                  test_probs_vals.append(
                      test_probs_val
                  ), test_labels_vals.append(test_labels_val)
              except fluid.core.EOFException:
                  test_pyreader.reset()
                  test_probs_array = np.concatenate(test_probs_vals)
                  test_labels_array = np.concatenate(test_labels_vals)
                  fpr, tpr, thresholds = metrics.roc_curve(
                      test_labels_array, test_probs_array
                  )
                  test_auc = metrics.auc(fpr, tpr)
                  log.info(
                      "\t\tStep %d " % step
                      + "Test Loss: %f " % test_loss_val
                      + "Test AUC: %f " % test_auc
                  )
                  break
  
file_path: PGL/legacy/examples/node2vec/link_predict.py
imports: import argparse
  import time
  import math
  import os
  import numpy
  from sklearn import metrics
  import pgl
  from pgl import data_loader
  from pgl.utils import op
  from pgl.utils.logger import log
  import paddle.fluid
  import paddle.fluid.layers
label_desc: Use image node_id 5 for calling a global function with example usage: main(args) and returns: os, False