code: def train(model, dataset, device):
      # The first of two tasks in the dataset is node classification.
      task = dataset.tasks[0]
      dataloader = create_dataloader(dataset, task.train_set, device)
      optimizer = torch.optim.Adam(model.parameters(), lr=1e-2)
  
      for epoch in range(10):
          model.train()
          total_loss = 0
          ########################################################################
          # (HIGHLIGHT) Iterate over the dataloader and train the model with all
          # mini-batches.
          ########################################################################
          for step, data in enumerate(dataloader):
              # The features of sampled nodes.
              x = data.node_features["feat"]
  
              # The ground truth labels of the seed nodes.
              y = data.labels
  
              # Forward.
              y_hat = model(data.blocks, x)
  
              # Compute loss.
              loss = F.cross_entropy(y_hat, y)
  
              # Backward.
              optimizer.zero_grad()
              loss.backward()
              optimizer.step()
  
              total_loss += loss.item()
  
          # Evaluate the model.
          val_acc = evaluate(
              model, dataset, task.validation_set, device
          )
          test_acc = evaluate(model, dataset, task.test_set, device)
          print(
              f"Epoch {epoch:03d} | Loss {total_loss / (step + 1):.3f} | "
              f"Val Acc {val_acc.item():.3f} | Test Acc {test_acc.item():.3f}"
          )
  
file_path: dgl/examples/sampling/graphbolt/quickstart/node_classification.py
imports: import dgl.graphbolt
  import dgl.nn
  import torch
  import torch.nn
  import torch.nn.functional
  import torchmetrics.functional
label_desc: Use image node_id 3 for calling a global function with example usage: train(model, dataset, device) without return types