code: def cross_validation_with_val_set(
      dataset,
      model,
      folds,
      epochs,
      batch_size,
      lr,
      lr_decay_factor,
      lr_decay_step_size,
      weight_decay,
      logger=None,
  ):
      val_losses, accs, durations = [], [], []
      for fold, (train_idx, test_idx, val_idx) in enumerate(
          zip(*k_fold(dataset, folds))
      ):
          train_dataset = dataset[train_idx]
          test_dataset = dataset[test_idx]
          val_dataset = dataset[val_idx]
  
          if "adj" in train_dataset[0]:
              train_loader = DenseLoader(
                  train_dataset, batch_size, shuffle=True
              )
              val_loader = DenseLoader(
                  val_dataset, batch_size, shuffle=False
              )
              test_loader = DenseLoader(
                  test_dataset, batch_size, shuffle=False
              )
          else:
              train_loader = DataLoader(
                  train_dataset, batch_size, shuffle=True
              )
              val_loader = DataLoader(
                  val_dataset, batch_size, shuffle=False
              )
              test_loader = DataLoader(
                  test_dataset, batch_size, shuffle=False
              )
  
          model.to(device).reset_parameters()
          optimizer = Adam(
              model.parameters(), lr=lr, weight_decay=weight_decay
          )
  
          if torch.cuda.is_available():
              torch.cuda.synchronize()
          elif (
              hasattr(torch.backends, "mps")
              and torch.backends.mps.is_available()
          ):
              try:
                  import torch.mps
  
                  torch.mps.synchronize()
              except ImportError:
                  pass
  
          t_start = time.perf_counter()
  
          for epoch in range(1, epochs + 1):
              train_loss = train(model, optimizer, train_loader)
              val_losses.append(eval_loss(model, val_loader))
              accs.append(eval_acc(model, test_loader))
              eval_info = {
                  "fold": fold,
                  "epoch": epoch,
                  "train_loss": train_loss,
                  "val_loss": val_losses[-1],
                  "test_acc": accs[-1],
              }
  
              if logger is not None:
                  logger(eval_info)
  
              if epoch % lr_decay_step_size == 0:
                  for param_group in optimizer.param_groups:
                      param_group["lr"] = (
                          lr_decay_factor * param_group["lr"]
                      )
  
          if torch.cuda.is_available():
              torch.cuda.synchronize()
          elif (
              hasattr(torch.backends, "mps")
              and torch.backends.mps.is_available()
          ):
              torch.mps.synchronize()
  
          t_end = time.perf_counter()
          durations.append(t_end - t_start)
  
      loss, acc, duration = (
          tensor(val_losses),
          tensor(accs),
          tensor(durations),
      )
      loss, acc = loss.view(folds, epochs), acc.view(folds, epochs)
      loss, argmin = loss.min(dim=1)
      acc = acc[torch.arange(folds, dtype=torch.long), argmin]
  
      loss_mean = loss.mean().item()
      acc_mean = acc.mean().item()
      acc_std = acc.std().item()
      duration_mean = duration.mean().item()
      print(
          f"Val Loss: {loss_mean:.4f}, Test Accuracy: {acc_mean:.3f} "
          f"± {acc_std:.3f}, Duration: {duration_mean:.3f}"
      )
  
      return loss_mean, acc_mean, acc_std
  
file_path: pytorch_geometric/benchmark/kernel/train_eval.py
imports: import time
  import torch
  import torch.nn.functional
  from sklearn.model_selection import StratifiedKFold
  from torch import tensor
  from torch.optim import Adam
  from torch_geometric.loader import DataLoader
  from torch_geometric.loader import DenseDataLoader
label_desc: Use image node_id 1 for calling a global function with example usage: cross_validation_with_val_set(dataset, model, folds, epochs, batch_size, lr, lr_decay_factor, lr_decay_step_size, weight_decay, logger) and returns: loss_mean,  acc_mean,  acc_std