code: def test(model, device, test_loader):
      model.to(device)
      model.eval()
      test_loss = 0
      correct = 0
      with torch.no_grad():
          start = time.time()
          for data, target in test_loader:
              data, target = data.to(device), target.to(device)
              output = model(data)
              if isinstance(output, QTensor):
                  output = output.dequantize()
              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()
          end = time.time()
  
      test_loss /= len(test_loader.dataset)
  
      print(
          "\nTest set evaluated in {:.2f} s: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n".format(
              end - start,
              test_loss,
              correct,
              len(test_loader.dataset),
              100.0 * correct / len(test_loader.dataset),
          )
      )
  
file_path: quanto/examples/vision/image-classification/mnist/quantize_mnist_model.py
imports: import argparse
  import io
  import time
  import torch
  import torch.nn.functional
  from torchvision import datasets, transforms
  from transformers import AutoModel
  from quanto import Calibration, QTensor, freeze, int4, quantize
label_desc: Use image node_id 1 for calling a global function with example usage: test(model, device, test_loader) without return types