code: def train(
      train_graphs, val_graphs, args, model, optimizer, mode="batch"
  ):
      best_val = 0
      best_model = None
      accs = []
      graph_train = train_graphs[0]
      graph_train.to(args.device)
      for epoch in range(1, 1 + args.epochs):
          model.train()
          optimizer.zero_grad()
          if mode == "community":
              graph = random.choice(train_graphs)
              graph = graph.to(args.device)
              pred = model(graph, mode="all")
              pred = pred[graph.node_label_index]
              label = graph.node_label[graph.node_label_index]
          else:
              pred = model(graph_train, mode="all")
              label = graph_train.node_label
              pred = pred[graph_train.node_label_index]
          loss = F.nll_loss(pred, label)
          loss.backward()
          optimizer.step()
  
          train_acc, val_acc, test_acc = test(val_graphs, model)
          accs.append((train_acc, val_acc, test_acc))
          if val_acc > best_val:
              best_val = val_acc
              best_model = copy.deepcopy(model)
          print(
              f"Epoch: {epoch:02d}, "
              f"Loss: {loss:.4f}, "
              f"Train: {100 * train_acc:.2f}%, "
              f"Valid: {100 * val_acc:.2f}% "
              f"Test: {100 * test_acc:.2f}%"
          )
      return best_model, accs
  
file_path: deepsnap/examples/sampling/cluster.py
imports: import copy
  import torch
  import random
  import argparse
  import numpy
  import networkx
  import torch.nn
  import torch.nn.functional
  import community
  from torch_geometric.nn import SAGEConv
  from torch.utils.data import DataLoader
  from torch_geometric.datasets import Planetoid
  from torch.nn import Sequential, Linear, ReLU
  from deepsnap.dataset import GraphDataset
  from deepsnap.graph import Graph
  from model import *
label_desc: Use image node_id 3 for calling a global function with example usage: train(train_graphs, val_graphs, args, model, optimizer, mode) and returns: best_model,  accs