code: def test(epoch):
      global best_acc
      global trainloader
      global testloader
      global net
      global criterion
      global optimizer
  
      net.eval()
      test_loss = 0
      correct = 0
      total = 0
      with torch.no_grad():
          for batch_idx, (inputs, targets) in enumerate(testloader):
              inputs, targets = inputs.to(device), targets.to(device)
              outputs = net(inputs)
              loss = criterion(outputs, targets)
  
              test_loss += loss.item()
              _, predicted = outputs.max(1)
              total += targets.size(0)
              correct += predicted.eq(targets).sum().item()
  
              acc = 100.0 * correct / total
  
              progress_bar(
                  batch_idx,
                  len(testloader),
                  "Loss: %.3f | Acc: %.3f%% (%d/%d)"
                  % (
                      test_loss / (batch_idx + 1),
                      100.0 * correct / total,
                      correct,
                      total,
                  ),
              )
  
      # Save checkpoint.
      acc = 100.0 * correct / total
      if acc > best_acc:
          print("Saving..")
          state = {
              "net": net.state_dict(),
              "acc": acc,
              "epoch": epoch,
          }
          if not os.path.isdir("checkpoint"):
              os.mkdir("checkpoint")
          torch.save(state, "./checkpoint/ckpt.t7")
          best_acc = acc
      return acc, best_acc
  
file_path: nni/examples/trials/cifar10_pytorch/main.py
imports: from __future__ import print_function
  import argparse
  import torch
  import torch.nn
  import torch.optim
  import torch.nn.functional
  import torch.backends.cudnn
  import torchvision
  import torchvision.transforms
  import os
  import argparse
  import logging
  from models import *
  from utils import progress_bar
  import nni
label_desc: Use image node_id 3 for calling a global function with example usage: test(epoch) and returns: acc,  best_acc