code: def validate_dataloader(
      model, data_loader, fabric, hparams, fold, acc_metric
  ):
      model.eval()
      loss = 0
      with torch.no_grad():
          for data, target in data_loader:
              # NOTE: no need to call `.to(device)` on the data, target
              output = model(data)
              loss += F.nll_loss(output, target, reduction="sum").item()
  
              # Accuracy with torchmetrics
              acc_metric.update(output, target)
  
              if hparams.dry_run:
                  break
  
      # all_gather is used to aggregate the value across processes
      loss = fabric.all_gather(loss).sum() / len(data_loader.dataset)
  
      # compute acc
      acc = acc_metric.compute() * 100
  
      print(
          f"\nFor fold: {fold} Validation set: Average loss: {loss:.4f}, Accuracy: ({acc:.0f}%)\n"
      )
      return acc
  
file_path: pytorch-lightning/examples/fabric/kfold_cv/train_fabric.py
imports: import argparse
  from os import path
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  import torchvision.transforms
  from lightning.fabric import Fabric, seed_everything
  from sklearn import model_selection
  from torch.utils.data import DataLoader, SubsetRandomSampler
  from torchmetrics.classification import Accuracy
  from torchvision.datasets import MNIST
label_desc: Use image node_id 2 for calling a global function with example usage: validate_dataloader(model, data_loader, fabric, hparams, fold, acc_metric) and returns: acc