code: def main(args):
      """main"""
      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)
  
      place = fluid.CUDAPlace(0) if args.use_cuda else fluid.CPUPlace()
      train_program = fluid.Program()
      startup_program = fluid.Program()
      hidden_size = 512
  
      with fluid.program_guard(train_program, startup_program):
          pos_gw = pgl.graph_wrapper.GraphWrapper(
              name="pos_graph",
              place=place,
              node_feat=dataset.graph.node_feat_info(),
          )
  
          neg_gw = pgl.graph_wrapper.GraphWrapper(
              name="neg_graph",
              place=place,
              node_feat=dataset.graph.node_feat_info(),
          )
  
          positive_feat = pgl.layers.gcn(
              pos_gw,
              pos_gw.node_feat["words"],
              hidden_size,
              activation="relu",
              norm=pos_gw.node_feat["norm"],
              name="gcn_layer_1",
          )
  
          negative_feat = pgl.layers.gcn(
              neg_gw,
              neg_gw.node_feat["words"],
              hidden_size,
              activation="relu",
              norm=neg_gw.node_feat["norm"],
              name="gcn_layer_1",
          )
  
          summary_feat = fluid.layers.sigmoid(
              fluid.layers.reduce_mean(
                  positive_feat, [0], keep_dim=True
              )
          )
  
          summary_feat = fluid.layers.fc(
              summary_feat,
              hidden_size,
              bias_attr=False,
              name="discriminator",
          )
          pos_logits = fluid.layers.matmul(
              positive_feat, summary_feat, transpose_y=True
          )
          neg_logits = fluid.layers.matmul(
              negative_feat, summary_feat, transpose_y=True
          )
          pos_loss = fluid.layers.sigmoid_cross_entropy_with_logits(
              x=pos_logits,
              label=fluid.layers.ones(
                  shape=[dataset.graph.num_nodes, 1], dtype="float32"
              ),
          )
          neg_loss = fluid.layers.sigmoid_cross_entropy_with_logits(
              x=neg_logits,
              label=fluid.layers.zeros(
                  shape=[dataset.graph.num_nodes, 1], dtype="float32"
              ),
          )
          loss = fluid.layers.reduce_mean(
              pos_loss
          ) + fluid.layers.reduce_mean(neg_loss)
  
          adam = fluid.optimizer.Adam(learning_rate=1e-3)
          adam.minimize(loss)
  
      exe = fluid.Executor(place)
      exe.run(startup_program)
  
      best_loss = 1e9
      dur = []
  
      for epoch in range(args.epoch):
          feed_dict = pos_gw.to_feed(dataset.graph)
          node_feat = dataset.graph.node_feat["words"].copy()
          perm = np.arange(0, dataset.graph.num_nodes)
          np.random.shuffle(perm)
  
          dataset.graph.node_feat["words"] = dataset.graph.node_feat[
              "words"
          ][perm]
  
          feed_dict.update(neg_gw.to_feed(dataset.graph))
          dataset.graph.node_feat["words"] = node_feat
          if epoch >= 3:
              t0 = time.time()
          train_loss = exe.run(
              train_program,
              feed=feed_dict,
              fetch_list=[loss],
              return_numpy=True,
          )
          if train_loss[0] < best_loss:
              best_loss = train_loss[0]
              save_param(
                  args.checkpoint, ["gcn_layer_1", "gcn_layer_1_bias"]
              )
  
          if epoch >= 3:
              time_per_epoch = 1.0 * (time.time() - t0)
              dur.append(time_per_epoch)
  
          log.info(
              "Epoch %d " % epoch
              + "(%.5lf sec) " % np.mean(dur)
              + "Train Loss: %f " % train_loss[0]
          )
  
file_path: PGL/legacy/examples/dgi/dgi.py
imports: import os
  import pgl
  from pgl import data_loader
  from pgl.utils.logger import log
  import paddle.fluid
  import numpy
  import time
  import argparse
label_desc: Use image node_id 3 for calling a global function with example usage: main(args) without return types