code: def dgl_main():
      # Load from DGL dataset
      if args.dataset == "cora":
          dataset = CoraGraphDataset(reverse_edge=False)
      elif args.dataset == "citeseer":
          dataset = CiteseerGraphDataset(reverse_edge=False)
      elif args.dataset == "pubmed":
          dataset = PubmedGraphDataset(reverse_edge=False)
      else:
          raise NotImplementedError
      graph = dataset[0]
  
      # Extract node features
      feats = graph.ndata.pop("feat").to(device)
      in_dim = feats.shape[-1]
  
      # generate input
      adj_orig = graph.adj_external().to_dense()
  
      # build test set with 10% positive links
      (
          train_edge_idx,
          val_edges,
          val_edges_false,
          test_edges,
          test_edges_false,
      ) = mask_test_edges_dgl(graph, adj_orig)
  
      graph = graph.to(device)
  
      # create train graph
      train_edge_idx = torch.tensor(train_edge_idx).to(device)
      train_graph = dgl.edge_subgraph(
          graph, train_edge_idx, relabel_nodes=False
      )
      train_graph = train_graph.to(device)
      adj = train_graph.adj_external().to_dense().to(device)
  
      # compute loss parameters
      weight_tensor, norm = compute_loss_para(adj)
  
      # create model
      vgae_model = model.VGAEModel(in_dim, args.hidden1, args.hidden2)
      vgae_model = vgae_model.to(device)
  
      # create training component
      optimizer = torch.optim.Adam(
          vgae_model.parameters(), lr=args.learning_rate
      )
      print(
          "Total Parameters:",
          sum([p.nelement() for p in vgae_model.parameters()]),
      )
  
      # create training epoch
      for epoch in range(args.epochs):
          t = time.time()
  
          # Training and validation using a full graph
          vgae_model.train()
  
          logits = vgae_model.forward(graph, feats)
  
          # compute loss
          loss = norm * F.binary_cross_entropy(
              logits.view(-1), adj.view(-1), weight=weight_tensor
          )
          kl_divergence = (
              0.5
              / logits.size(0)
              * (
                  1
                  + 2 * vgae_model.log_std
                  - vgae_model.mean**2
                  - torch.exp(vgae_model.log_std) ** 2
              )
              .sum(1)
              .mean()
          )
          loss -= kl_divergence
  
          # backward
          optimizer.zero_grad()
          loss.backward()
          optimizer.step()
  
          train_acc = get_acc(logits, adj)
  
          val_roc, val_ap = get_scores(
              val_edges, val_edges_false, logits
          )
  
          # Print out performance
          print(
              "Epoch:",
              "%04d" % (epoch + 1),
              "train_loss=",
              "{:.5f}".format(loss.item()),
              "train_acc=",
              "{:.5f}".format(train_acc),
              "val_roc=",
              "{:.5f}".format(val_roc),
              "val_ap=",
              "{:.5f}".format(val_ap),
              "time=",
              "{:.5f}".format(time.time() - t),
          )
  
      test_roc, test_ap = get_scores(
          test_edges, test_edges_false, logits
      )
      # roc_means.append(test_roc)
      # ap_means.append(test_ap)
      print(
          "End of training!",
          "test_roc=",
          "{:.5f}".format(test_roc),
          "test_ap=",
          "{:.5f}".format(test_ap),
      )
  
file_path: dgl/examples/pytorch/vgae/train.py
imports: import argparse
  import os
  import time
  import dgl
  import model
  import numpy
  import scipy.sparse
  import torch
  import torch.nn.functional
  from dgl.data import CiteseerGraphDataset, CoraGraphDataset, PubmedGraphDataset
  from input_data import load_data
  from preprocess import mask_test_edges, mask_test_edges_dgl, preprocess_graph, sparse_to_tuple
  from sklearn.metrics import average_precision_score, roc_auc_score
label_desc: Use image node_id 4 for calling a global function with example usage: dgl_main() without return types