code: def _train_with_val(
      self, labels, idx_train, idx_val, train_iters, verbose
  ):
      if verbose:
          print("=== training gcn model ===")
      optimizer = optim.Adam(
          self.parameters(), lr=self.lr, weight_decay=self.weight_decay
      )
  
      best_loss_val = 100
      best_acc_val = 0
  
      for i in range(train_iters):
          # print('epoch', i)
          self.train()
          optimizer.zero_grad()
          output = self.forward(self.features, self.adj_norm)
          loss_train = F.nll_loss(output[idx_train], labels[idx_train])
          loss_train.backward()
          optimizer.step()
          self.eval()
  
          loss_val = F.nll_loss(output[idx_val], labels[idx_val])
          acc_val = utils.accuracy(output[idx_val], labels[idx_val])
          # acc_test = utils.accuracy(output[self.idx_test], labels[self.idx_test])
  
          # if verbose and i % 5 == 0:
          #     print('Epoch {}, training loss: {}, val acc: {}, '.format(i, loss_train.item(), acc_val))
  
          if best_loss_val > loss_val:
              best_loss_val = loss_val
              self.output = output
              weights = deepcopy(self.state_dict())
  
          if acc_val > best_acc_val:
              best_acc_val = acc_val
              self.output = output
              weights = deepcopy(self.state_dict())
  
      if verbose:
          print(
              "=== picking the best model according to the performance on validation ==="
          )
      self.load_state_dict(weights)
  
imports: import numpy
  from copy import deepcopy
  from numba import njit
  import torch.nn
  import torch.nn.functional
  import math
  import torch
  import torch.optim
  import typing
  from torch_geometric.data import Data
  from sklearn.metrics.pairwise import euclidean_distances, cosine_similarity
  from scipy.sparse import lil_matrix
  from sklearn.preprocessing import normalize
  import scipy.sparse
  import autogl.data
  from ..None import register_model
  from .None import utils
  from ..gcn import GCN
  from .nn import GCNConv
  from ..base import BaseAutoModel
  from .....utils import get_logger
  from .utils import accuracy
label_desc: Use image node_id 7 for calling the GCN4GNNGuard obj's underlying member method code with example usage: obj._train_with_val(labels, idx_train, idx_val, train_iters, verbose) without return types