code: def train(model, dataloaders, optimizer, args, writer):
      # 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}'
              log = "Epoch: {:03d}, Train: {:.4f}, Val: {:.4f}"
              accs, _ = test(model, {"val": dataloaders["val"]}, 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']))
              print(log.format(epoch, accs["train"], accs["val"]))
              writer.add_scalar("Loss/train", accs["train"], iter_i)
              writer.add_scalar("Loss/val", accs["val"], iter_i)
              # writer.add_scalar('Loss/test', accs['test'], iter_i)
              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}'
      log = "Best, Train: {:.4f}, Val: {:.4f}"
      accs, _ = test(best_model, dataloaders, args)
      # print(log.format(accs['train'], accs['val'], accs['test']))
      print(log.format(accs["train"], accs["val"]))
  
imports: import argparse
  import copy
  import csv
  import numpy
  import time
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.utils.tensorboard import SummaryWriter
  import networkx
  import numpy
  import sklearn.metrics
  import torch_geometric.transforms
  import torch_geometric.nn
  from torch.utils.data import DataLoader
  from deepsnap.graph import Graph
  from deepsnap.dataset import GraphDataset
  from deepsnap.batch import Batch
label_desc: Use image node_id 3 for calling a global function with example usage: train(model, dataloaders, optimizer, args, writer) without return types