code: def main():
      # Training settings
      parser = argparse.ArgumentParser(
          description="GNN baselines on ogbg-ppa data with Pytorch Geometrics"
      )
      parser.add_argument(
          "--device",
          type=int,
          default=0,
          help="which gpu to use if any (default: 0)",
      )
      parser.add_argument(
          "--gnn",
          type=str,
          default="gin-virtual",
          help="GNN gin, gin-virtual, or gcn, or gcn-virtual (default: gin-virtual)",
      )
      parser.add_argument(
          "--drop_ratio",
          type=float,
          default=0.5,
          help="dropout ratio (default: 0.5)",
      )
      parser.add_argument(
          "--num_layer",
          type=int,
          default=5,
          help="number of GNN message passing layers (default: 5)",
      )
      parser.add_argument(
          "--emb_dim",
          type=int,
          default=300,
          help="dimensionality of hidden units in GNNs (default: 300)",
      )
      parser.add_argument(
          "--batch_size",
          type=int,
          default=32,
          help="input batch size for training (default: 32)",
      )
      parser.add_argument(
          "--epochs",
          type=int,
          default=100,
          help="number of epochs to train (default: 100)",
      )
      parser.add_argument(
          "--num_workers",
          type=int,
          default=0,
          help="number of workers (default: 0)",
      )
      parser.add_argument(
          "--dataset",
          type=str,
          default="ogbg-ppa",
          help="dataset name (default: ogbg-ppa)",
      )
  
      parser.add_argument(
          "--filename",
          type=str,
          default="",
          help="filename to output result (default: )",
      )
      args = parser.parse_args()
  
      device = (
          torch.device("cuda:" + str(args.device))
          if torch.cuda.is_available()
          else torch.device("cpu")
      )
  
      ### automatic dataloading and splitting
  
      dataset = PygGraphPropPredDataset(
          name=args.dataset, transform=add_zeros
      )
  
      split_idx = dataset.get_idx_split()
  
      ### automatic evaluator. takes dataset name as input
      evaluator = Evaluator(args.dataset)
  
      train_loader = DataLoader(
          dataset[split_idx["train"]],
          batch_size=args.batch_size,
          shuffle=True,
          num_workers=args.num_workers,
      )
      valid_loader = DataLoader(
          dataset[split_idx["valid"]],
          batch_size=args.batch_size,
          shuffle=False,
          num_workers=args.num_workers,
      )
      test_loader = DataLoader(
          dataset[split_idx["test"]],
          batch_size=args.batch_size,
          shuffle=False,
          num_workers=args.num_workers,
      )
  
      if args.gnn == "gin":
          model = GNN(
              gnn_type="gin",
              num_class=dataset.num_classes,
              num_layer=args.num_layer,
              emb_dim=args.emb_dim,
              drop_ratio=args.drop_ratio,
              virtual_node=False,
          ).to(device)
      elif args.gnn == "gin-virtual":
          model = GNN(
              gnn_type="gin",
              num_class=dataset.num_classes,
              num_layer=args.num_layer,
              emb_dim=args.emb_dim,
              drop_ratio=args.drop_ratio,
              virtual_node=True,
          ).to(device)
      elif args.gnn == "gcn":
          model = GNN(
              gnn_type="gcn",
              num_class=dataset.num_classes,
              num_layer=args.num_layer,
              emb_dim=args.emb_dim,
              drop_ratio=args.drop_ratio,
              virtual_node=False,
          ).to(device)
      elif args.gnn == "gcn-virtual":
          model = GNN(
              gnn_type="gcn",
              num_class=dataset.num_classes,
              num_layer=args.num_layer,
              emb_dim=args.emb_dim,
              drop_ratio=args.drop_ratio,
              virtual_node=True,
          ).to(device)
      else:
          raise ValueError("Invalid GNN type")
  
      optimizer = optim.Adam(model.parameters(), lr=0.001)
  
      valid_curve = []
      test_curve = []
      train_curve = []
  
      for epoch in range(1, args.epochs + 1):
          print("=====Epoch {}".format(epoch))
          print("Training...")
          train(model, device, train_loader, optimizer)
  
          print("Evaluating...")
          train_perf = eval(model, device, train_loader, evaluator)
          valid_perf = eval(model, device, valid_loader, evaluator)
          test_perf = eval(model, device, test_loader, evaluator)
  
          print(
              {
                  "Train": train_perf,
                  "Validation": valid_perf,
                  "Test": test_perf,
              }
          )
  
          train_curve.append(train_perf[dataset.eval_metric])
          valid_curve.append(valid_perf[dataset.eval_metric])
          test_curve.append(test_perf[dataset.eval_metric])
  
      best_val_epoch = np.argmax(np.array(valid_curve))
      best_train = max(train_curve)
  
      print("Finished training!")
      print(
          "Best validation score: {}".format(
              valid_curve[best_val_epoch]
          )
      )
      print("Test score: {}".format(test_curve[best_val_epoch]))
  
      if not args.filename == "":
          torch.save(
              {
                  "Val": valid_curve[best_val_epoch],
                  "Test": test_curve[best_val_epoch],
                  "Train": train_curve[best_val_epoch],
                  "BestTrain": best_train,
              },
              args.filename,
          )
  
file_path: ogb/examples/graphproppred/ppa/main_pyg.py
imports: import torch
  from torch_geometric.loader import DataLoader
  import torch.optim
  import torch.nn.functional
  from gnn import GNN
  from tqdm.auto import tqdm
  import argparse
  import time
  import numpy
  from ogb.graphproppred import PygGraphPropPredDataset, Evaluator
label_desc: Use image node_id 4 for calling a global function with example usage: main() without return types