code: def validate(epoch, model, criterion, loader, writer, args):
      model.eval()
      meters = AverageMeterGroup()
      with torch.no_grad():
          for step, (x, y) in enumerate(loader):
              x, y = x.to("cuda"), y.to("cuda")
              logits = model(x)
              loss = criterion(logits, y)
              metrics = accuracy(logits, y)
              metrics["loss"] = loss.item()
              meters.update(metrics)
  
              if step % args.log_frequency == 0 or step + 1 == len(
                  loader
              ):
                  logger.info(
                      "Epoch [%d/%d] Validation Step [%d/%d]  %s",
                      epoch + 1,
                      args.epochs,
                      step + 1,
                      len(loader),
                      meters,
                  )
  
      writer.add_scalar("loss/test", meters.loss.avg, global_step=epoch)
      writer.add_scalar("acc1/test", meters.acc1.avg, global_step=epoch)
      writer.add_scalar("acc5/test", meters.acc5.avg, global_step=epoch)
  
      logger.info(
          "Epoch %d validation: top1 = %f, top5 = %f",
          epoch + 1,
          meters.acc1.avg,
          meters.acc5.avg,
      )
  
file_path: nni/examples/nas/legacy/oneshot/spos/evaluation.py
imports: import os
  import argparse
  import logging
  import random
  import numpy
  import torch
  import torch.nn
  import torchvision.transforms
  import torchvision.datasets
  from nni.retiarii import fixed_arch
  from nni.retiarii.oneshot.pytorch.utils import AverageMeterGroup
  from torch.utils.tensorboard import SummaryWriter
  from network import ShuffleNetV2OneShot
  from utils import CrossEntropyLabelSmooth, accuracy, ToBGRTensor
label_desc: Use image node_id 2 for calling a global function with example usage: validate(epoch, model, criterion, loader, writer, args) without return types