code: def train(train_loader, val_loader, test_loader, num_classes, model):
      # loss function and optimizer
      loss_fcn = nn.CrossEntropyLoss()
      opt = torch.optim.Adam(
          model.parameters(), lr=0.001, weight_decay=5e-4
      )
  
      # training loop
      for epoch in range(10):
          model.train()
          total_loss = 0
          for it, (input_nodes, output_nodes, blocks) in enumerate(
              tqdm.tqdm(train_dataloader, desc="Train")
          ):
              x = blocks[0].srcdata["feat"]
              y = blocks[-1].dstdata["label"]["paper"][:, 0]
              y_hat = model(blocks, x)
              loss = loss_fcn(y_hat, y)
              opt.zero_grad()
              loss.backward()
              opt.step()
              total_loss += loss.item()
          model.eval()
          val_acc = evaluate(
              num_classes, model, val_dataloader, "Val. "
          )
          test_acc = evaluate(
              num_classes, model, test_dataloader, "Test "
          )
          print(
              f"Epoch {epoch:05d} | Loss {total_loss/(it+1):.4f} | Validation Acc. {val_acc.item():.4f} | Test Acc. {test_acc.item():.4f}"
          )
  
file_path: dgl/examples/pytorch/rgat/train.py
imports: import dgl
  import dgl.function
  import dgl.nn
  import torch
  import torch.nn
  import torch.nn.functional
  import torchmetrics.functional
  import tqdm
  from dgl import apply_each
  from dgl.dataloading import DataLoader, NeighborSampler
  from ogb.nodeproppred import DglNodePropPredDataset
label_desc: Use image node_id 2 for calling a global function with example usage: train(train_loader, val_loader, test_loader, num_classes, model) without return types