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/palettization/dkm_palettization.py
imports: from collections import OrderedDict
  import torch
  import torch.nn
  import torch.nn.functional
  import os
  from torchvision import datasets, transforms
  from coremltools.optimize.torch.palettization import DKMPalettizer, DKMPalettizerConfig
  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