code: def train(
      dataset,
      g,
      feats,
      model,
      node_embed,
      optimizer,
      train_loader,
      split_idx,
      labels,
      device,
  ):
      print("Start training...")
      category = "paper"
  
      # Typically, the best Validation performance is obtained after
      # the 1st or 2nd epoch. This is why the max epoch is set to 3.
      for epoch in range(3):
          num_train = split_idx["train"][category].shape[0]
          t0 = time.time()
          model.train()
  
          total_loss = 0
  
          for input_nodes, seeds, blocks in tqdm(
              train_loader, desc=f"Epoch {epoch:02d}"
          ):
              # Move the input data onto the device.
              blocks = [blk.to(device) for blk in blocks]
              # We only predict the nodes with type "category".
              seeds = seeds[category]
              batch_size = seeds.shape[0]
  
              # Extract the node features from embedding layer or raw features.
              node_features = extract_node_features(
                  dataset, g, input_nodes, node_embed, feats, device
              )
              lbl = labels[seeds.cpu()].to(device)
  
              # Reset gradients.
              optimizer.zero_grad()
              # Generate predictions.
              logits = model(node_features, blocks)[category]
  
              y_hat = logits.log_softmax(dim=-1)
              loss = F.nll_loss(y_hat, lbl)
              loss.backward()
              optimizer.step()
  
              total_loss += loss.item() * batch_size
  
          t1 = time.time()
          loss = total_loss / num_train
  
          # Evaluate the model on the val/test set.
          valid_acc = evaluate(
              dataset,
              g,
              feats,
              model,
              node_embed,
              labels,
              device,
              split_idx["valid"],
          )
          test_key = "test" if dataset == "ogbn-mag" else "test-dev"
          test_acc = evaluate(
              dataset,
              g,
              feats,
              model,
              node_embed,
              labels,
              device,
              split_idx[test_key],
              save_test_submission=(dataset == "ogb-lsc-mag240m"),
          )
          print(
              f"Epoch: {epoch +1 :02d}, "
              f"Loss: {loss:.4f}, "
              f"Valid: {100 * valid_acc:.2f}%, "
              f"Test: {100 * test_acc:.2f}%, "
              f"Time {t1 - t0:.4f}"
          )
  
imports: import argparse
  import itertools
  import sys
  import time
  import dgl
  import dgl.nn
  import numpy
  import psutil
  import torch
  import torch.nn
  import torch.nn.functional
  from dgl import AddReverse, Compose, ToSimple
  from dgl.nn import HeteroEmbedding
  from ogb.lsc import MAG240MDataset, MAG240MEvaluator
  from ogb.nodeproppred import DglNodePropPredDataset, Evaluator
  from tqdm import tqdm
label_desc: Use image node_id 5 for calling a global function with example usage: train(dataset, g, feats, model, node_embed, optimizer, train_loader, split_idx, labels, device) without return types