code: def test(conf, model, device, test_loader, epoch, writer):
      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)
      fmt = "\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n"
      print(
          fmt.format(
              test_loss,
              correct,
              len(test_loader.dataset),
              100.0 * correct / len(test_loader.dataset),
          )
      )
  
      writer.add_scalar("Accuracy", correct, epoch)
      writer.add_scalar("Loss/test", test_loss, epoch)
  
file_path: pytorch-optimizer/examples/mnist.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from torch.optim.lr_scheduler import StepLR
  from torch.utils.tensorboard import SummaryWriter
  from torchvision import datasets, transforms, utils
  import torch_optimizer
label_desc: Use image node_id 2 for calling a global function with example usage: test(conf, model, device, test_loader, epoch, writer) without return types