code: def test(model, test_loader):
      model.eval()
      test_loss = 0
      correct = 0
      test_len = 0
      with torch.no_grad():
          for batch in test_loader:
              data, target = batch["features"], batch["label"]
              output = model(data)
              test_loss += F.nll_loss(
                  output, target, reduction="sum"
              ).item()  # sum up batch loss
              pred = output.argmax(
                  dim=1, keepdim=True
              )  # get the index of the max log-probability
              correct += pred.eq(target.view_as(pred)).sum().item()
              test_len += data.shape[0]
  
      test_loss /= test_len
      accuracy = correct / test_len
  
      logging.info(
          "Test set: Average loss: %.4f, Accuracy: %d/%d (%.0f%%)",
          test_loss,
          correct,
          test_len,
          100.0 * accuracy,
      )
      return accuracy
  
file_path: petastorm/examples/spark_dataset_converter/pytorch_converter_example.py
imports: from __future__ import division
  import logging
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from pyspark.sql import SparkSession
  from torch.autograd import Variable
  from examples.spark_dataset_converter.utils import get_mnist_dir
  from petastorm.spark import SparkDatasetConverter, make_spark_converter
label_desc: Use image node_id 2 for calling a global function with example usage: test(model, test_loader) and returns: accuracy