code: def evaluator(model):
      # evaluating the model accuracy and average test loss
      model.eval()
      test_loss = 0
      correct = 0
      test_dataset_length = len(test_loader.dataset)
      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 /= test_dataset_length
      accuracy = 100.0 * correct / test_dataset_length
      print(
          "Average test loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)".format(
              test_loss, correct, test_dataset_length, accuracy
          )
      )
  
file_path: nni/nni_assets/compression/mnist_model.py
imports: from pathlib import Path
  import torch
  from torch import nn
  from torch.nn import functional
  from torchvision import datasets, transforms
label_desc: Use image node_id 2 for calling a global function with example usage: evaluator(model) without return types