code: def train(model, dataloaders, optimizer, args):
      # training loop
      val_max = -np.inf
      best_model = model
      t_accu = []
      v_accu = []
      e_accu = []
      for epoch in range(1, args.epochs):
          t_accu_sum = 0
          t_accu_cnt = 0
          for iter_i, batch in enumerate(dataloaders["train"]):
              start_t = time.time()
              batch.to(args.device)
              model.train()
              optimizer.zero_grad()
              pred = model(batch)
              loss = model.loss(pred, batch.edge_label)
              t_accu_sum += metrics.f1_score(
                  batch.edge_label.cpu().numpy(),
                  model.inference(pred).cpu().numpy(),
                  average="micro",
              )
              t_accu_cnt += 1
              print("loss: ", loss.item())
              loss.backward()
              optimizer.step()
  
              log = "Epoch: {:03d}, Train: {:.4f}, Val: {:.4f}, Test: {:.4f}"
              accs, _ = test(
                  model,
                  {
                      key: val
                      for key, val in dataloaders.items()
                      if key != "train"
                  },
                  args,
              )
              accs["train"] = t_accu_sum / t_accu_cnt
              t_accu.append(accs["train"])
              v_accu.append(accs["val"])
              e_accu.append(accs["test"])
  
              print(
                  log.format(
                      epoch, accs["train"], accs["val"], accs["test"]
                  )
              )
              if val_max < accs["val"]:
                  val_max = accs["val"]
                  best_model = copy.deepcopy(model)
              print("Time: ", time.time() - start_t)
  
      log = "Best, Train: {:.4f}, Val: {:.4f}, Test: {:.4f}"
      accs, _ = test(best_model, dataloaders, args)
      print(log.format(accs["train"], accs["val"], accs["test"]))
  
imports: import copy
  import time
  import argparse
  import torch
  import torch.nn
  import torch.nn.functional
  import networkx
  import numpy
  import sklearn.metrics
  import torch_geometric.nn
  from torch.utils.data import DataLoader
  from deepsnap.dataset import GraphDataset
  from deepsnap.batch import Batch
  from deepsnap.graph import Graph
label_desc: Use image node_id 3 for calling a global function with example usage: train(model, dataloaders, optimizer, args) without return types