code: def train(model, G):
      best_val_acc = torch.tensor(0)
      best_test_acc = torch.tensor(0)
      for epoch in np.arange(args.n_epoch) + 1:
          model.train()
          logits = model(G, "paper")
          # The loss is computed only for labeled nodes.
          loss = F.cross_entropy(
              logits[train_idx], labels[train_idx].to(device)
          )
          optimizer.zero_grad()
          loss.backward()
          torch.nn.utils.clip_grad_norm_(model.parameters(), args.clip)
          optimizer.step()
          scheduler.step()
          if epoch % 5 == 0:
              model.eval()
              logits = model(G, "paper")
              pred = logits.argmax(1).cpu()
              train_acc = (
                  (pred[train_idx] == labels[train_idx]).float().mean()
              )
              val_acc = (
                  (pred[val_idx] == labels[val_idx]).float().mean()
              )
              test_acc = (
                  (pred[test_idx] == labels[test_idx]).float().mean()
              )
              if best_val_acc < val_acc:
                  best_val_acc = val_acc
                  best_test_acc = test_acc
              print(
                  "Epoch: %d LR: %.5f Loss %.4f, Train Acc %.4f, Val Acc %.4f (Best %.4f), Test Acc %.4f (Best %.4f)"
                  % (
                      epoch,
                      optimizer.param_groups[0]["lr"],
                      loss.item(),
                      train_acc.item(),
                      val_acc.item(),
                      best_val_acc.item(),
                      test_acc.item(),
                      best_test_acc.item(),
                  )
              )
  
file_path: dgl/examples/pytorch/hgt/train_acm.py
imports: import argparse
  import math
  import urllib.request
  import numpy
  import scipy.io
  from model import *
  import dgl
label_desc: Use image node_id 2 for calling a global function with example usage: train(model, G) without return types