code: def test(args, model, device, test_loader):
      model.eval()
      test_loss = 0
      correct = 0
      with torch.no_grad():
          for data, target in test_loader:
              data, target = data.to(device), target.to(device)
              output = model(data)
              # sum up batch loss
              test_loss += F.nll_loss(
                  output, target, reduction="sum"
              ).item()
              # get the index of the max log-probability
              pred = output.argmax(dim=1, keepdim=True)
              correct += pred.eq(target.view_as(pred)).sum().item()
  
      test_loss /= len(test_loader.dataset)
  
      accuracy = 100.0 * correct / len(test_loader.dataset)
  
      logger.info(
          "\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n".format(
              test_loss, correct, len(test_loader.dataset), accuracy
          )
      )
  
      return accuracy
  
file_path: nni/examples/trials/mnist-pbt-tuner-pytorch/mnist.py
imports: import argparse
  import logging
  import os
  import nni
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from torchvision import datasets, transforms
label_desc: Use image node_id 2 for calling a global function with example usage: test(args, model, device, test_loader) and returns: accuracy