code: def valid(epoch):
      net.eval()
      stats = adl.Accumulator()
      with torch.no_grad():
          for inputs, targets in validloader:
              inputs, targets = inputs.to(device), targets.to(device)
              outputs = net(inputs)
              loss = criterion(outputs, targets)
  
              stats["loss_sum"] += loss.item() * targets.size(0)
              _, predicted = outputs.max(1)
              stats["total"] += targets.size(0)
              stats["correct"] += predicted.eq(targets).sum().item()
  
      with stats.synchronized():
          stats["loss_avg"] = stats["loss_sum"] / stats["total"]
          stats["accuracy"] = stats["correct"] / stats["total"]
          writer.add_scalar("Loss/Valid", stats["loss_avg"], epoch)
          writer.add_scalar("Accuracy/Valid", stats["accuracy"], epoch)
  
          if adaptdl.env.replica_rank() == 0:
              nni.report_intermediate_result(stats["accuracy"])
  
          print("Valid:", stats)
          return stats["accuracy"]
  
file_path: nni/examples/trials/cifar10_pytorch/main_adl.py
imports: import torch
  import torch.nn
  import torch.optim
  import torch.backends.cudnn
  import torch.distributed
  import torchvision
  import torchvision.transforms
  import os
  import argparse
  from models import *
  import adaptdl
  import adaptdl.torch
  from torch.optim.lr_scheduler import MultiStepLR
  from torch.utils.tensorboard import SummaryWriter
  import nni
label_desc: Use image node_id 2 for calling a global function with example usage: valid(epoch) and returns: stats