code: def train(self):
      dur = []
      for epoch in range(self.config["epochs"]):
          self.model.train()
          train_loss = []
          train_acc = []
          t0 = time.time()
          for data in self.train_dataloader:
              tgt = to_cuda(data["tgt_tensor"], self.config["device"])
              data["graph_data"] = data["graph_data"].to(
                  self.config["device"]
              )
              logits, loss = self.model(
                  data["graph_data"], tgt, require_loss=True
              )
  
              # add graph regularization loss if available
              if (
                  data["graph_data"].graph_attributes.get(
                      "graph_reg", None
                  )
                  is not None
              ):
                  loss = (
                      loss
                      + data["graph_data"].graph_attributes["graph_reg"]
                  )
  
              self.optimizer.zero_grad()
              loss.backward()
              self.optimizer.step()
              train_loss.append(loss.item())
  
              pred = torch.max(logits, dim=-1)[1].cpu()
              train_acc.append(
                  self.metric.calculate_scores(
                      ground_truth=tgt.cpu(), predict=pred.cpu()
                  )[0]
              )
              dur.append(time.time() - t0)
  
          val_acc = self.evaluate(self.val_dataloader)
          self.scheduler.step(val_acc)
          print(
              "Epoch: [{} / {}] | Time: {:.2f}s | Loss: {:.4f} |"
              "Train Acc: {:.4f} | Val Acc: {:.4f}".format(
                  epoch + 1,
                  self.config["epochs"],
                  np.mean(dur),
                  np.mean(train_loss),
                  np.mean(train_acc),
                  val_acc,
              )
          )
          self.logger.write(
              "Epoch: [{} / {}] | Time: {:.2f}s | Loss: {:.4f} |"
              "Train Acc: {:.4f} | Val Acc: {:.4f}".format(
                  epoch + 1,
                  self.config["epochs"],
                  np.mean(dur),
                  np.mean(train_loss),
                  np.mean(train_acc),
                  val_acc,
              )
          )
  
          if self.stopper.step(val_acc, self.model):
              break
  
      return self.stopper.best_score
  
imports: import argparse
  import os
  import time
  import numpy
  import torch
  import torch.backends.cudnn
  import torch.multiprocessing
  import torch.nn
  import torch.nn.functional
  import torch.optim
  import yaml
  from torch.optim.lr_scheduler import ReduceLROnPlateau
  from torch.utils.data import DataLoader
  from graph4nlp.pytorch.datasets.trec import TrecDataset
  from graph4nlp.pytorch.modules.evaluation.accuracy import Accuracy
  from graph4nlp.pytorch.modules.graph_construction import NodeEmbeddingBasedGraphConstruction, NodeEmbeddingBasedRefinedGraphConstruction
  from graph4nlp.pytorch.modules.graph_embedding_initialization.embedding_construction import WordEmbedding
  from graph4nlp.pytorch.modules.graph_embedding_initialization.graph_embedding_initialization import GraphEmbeddingInitialization
  from graph4nlp.pytorch.modules.graph_embedding_learning import GAT, GGNN, GraphSAGE
  from graph4nlp.pytorch.modules.loss.general_loss import GeneralLoss
  from graph4nlp.pytorch.modules.prediction.classification.graph_classification import FeedForwardNN
  from graph4nlp.pytorch.modules.utils import constants
  from graph4nlp.pytorch.modules.utils.generic_utils import EarlyStopping, grid, to_cuda
  from graph4nlp.pytorch.modules.utils.logger import Logger
label_desc: Use image node_id 6 for calling the ModelHandler obj's underlying member method code with example usage: obj.train() and returns: self