code: def eval_model(model, test_loader):
      model.eval()
      test_loss = 0
      correct = 0
      with torch.no_grad():
          for data, target in test_loader:
              output = model(data)
              test_loss += F.nll_loss(
                  output, target, reduction="sum"
              ).item()
              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)
  
          print(
              "\nTest set: Average loss: {:.4f}, Accuracy: {:.1f}%\n".format(
                  test_loss, accuracy
              )
          )
      return accuracy
  
file_path: coremltools/docs/examples/optimize/torch/pruning/magnitude_pruning.py
imports: from collections import OrderedDict
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import os
  from torchvision import datasets, transforms
  from coremltools.optimize.torch.pruning import PolynomialDecayScheduler
  from coremltools.optimize.torch.pruning import MagnitudePruner, MagnitudePrunerConfig, ModuleMagnitudePrunerConfig
  import coremltools
label_desc: Use image node_id 4 for calling a global function with example usage: eval_model(model, test_loader) and returns: accuracy