code: def main(args):
      # Step 1: Prepare graph data and retrieve train/validation/test dataloader ============================= #
      if args.gpu >= 0 and torch.cuda.is_available():
          device = "cuda:{}".format(args.gpu)
      else:
          device = "cpu"
  
      if args.dataset == "PPI":
          (
              train_set,
              valid_set,
              test_set,
              etypes,
              in_size,
              out_size,
          ) = load_PPI(args.batch_size, device)
  
      # Step 2: Create model and training components=========================================================== #
      model = GNNFiLM(
          etypes, in_size, args.hidden_size, out_size, args.num_layers
      ).to(device)
      criterion = nn.BCELoss()
      optimizer = torch.optim.Adam(
          model.parameters(), lr=args.lr, weight_decay=args.wd
      )
      scheduler = torch.optim.lr_scheduler.StepLR(
          optimizer, args.step_size, gamma=args.gamma
      )
  
      # Step 4: training epoches ============================================================================== #
      lastf1 = 0
      cnt = 0
      best_val_f1 = 0
      for epoch in range(args.max_epoch):
          train_loss = []
          train_f1 = []
          val_loss = []
          val_f1 = []
          model.train()
          for batch in train_set:
              g = batch.graph
              g = g.to(device)
              logits = model.forward(g, "_N")
              labels = batch.label
              loss = criterion(logits, labels)
              f1 = evaluate_f1_score(
                  logits.detach().cpu().numpy(),
                  labels.detach().cpu().numpy(),
              )
  
              optimizer.zero_grad()
              loss.backward()
              optimizer.step()
              train_loss.append(loss.item())
              train_f1.append(f1)
  
          train_loss = np.mean(train_loss)
          train_f1 = np.mean(train_f1)
          scheduler.step()
  
          model.eval()
          with torch.no_grad():
              for batch in valid_set:
                  g = batch.graph
                  g = g.to(device)
                  logits = model.forward(g, "_N")
                  labels = batch.label
                  loss = criterion(logits, labels)
                  f1 = evaluate_f1_score(
                      logits.detach().cpu().numpy(),
                      labels.detach().cpu().numpy(),
                  )
                  val_loss.append(loss.item())
                  val_f1.append(f1)
  
          val_loss = np.mean(val_loss)
          val_f1 = np.mean(val_f1)
          print(
              "Epoch {:d} | Train Loss {:.4f} | Train F1 {:.4f} | Val Loss {:.4f} | Val F1 {:.4f} |".format(
                  epoch + 1, train_loss, train_f1, val_loss, val_f1
              )
          )
          if val_f1 > best_val_f1:
              best_val_f1 = val_f1
              torch.save(
                  model.state_dict(),
                  os.path.join(args.save_dir, args.name),
              )
  
          if val_f1 < lastf1:
              cnt += 1
              if cnt == args.early_stopping:
                  print("Early stop.")
                  break
          else:
              cnt = 0
              lastf1 = val_f1
  
      model.eval()
      test_loss = []
      test_f1 = []
      model.load_state_dict(
          torch.load(os.path.join(args.save_dir, args.name))
      )
      with torch.no_grad():
          for batch in test_set:
              g = batch.graph
              g = g.to(device)
              logits = model.forward(g, "_N")
              labels = batch.label
              loss = criterion(logits, labels)
              f1 = evaluate_f1_score(
                  logits.detach().cpu().numpy(),
                  labels.detach().cpu().numpy(),
              )
              test_loss.append(loss.item())
              test_f1.append(f1)
      test_loss = np.mean(test_loss)
      test_f1 = np.mean(test_f1)
  
      print(
          "Test F1: {:.4f} | Test loss: {:.4f}".format(
              test_f1, test_loss
          )
      )
  
file_path: dgl/examples/pytorch/GNN-FiLM/main.py
imports: import argparse
  import os
  import dgl
  import dgl.function
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from data_loader import load_PPI
  from utils import evaluate_f1_score
label_desc: Use image node_id 1 for calling a global function with example usage: main(args) without return types