code: def test(record):
      model.eval()
      test_loss = 0.0
      test_accuracy = 0.0
      for data, target in test_loader:
          if args.cuda:
              data, target = data.cuda(), target.cuda()
          output = model(data)
          # sum up batch loss
          test_loss += F.nll_loss(
              output, target, size_average=False
          ).item()
          # get the index of the max log-probability
          pred = output.data.max(1, keepdim=True)[1]
          test_accuracy += (
              pred.eq(target.data.view_as(pred))
              .cpu()
              .float()
              .sum()
              .item()
          )
  
      # Bluefog: use test_sampler to determine the number of examples in
      # this worker's partition.
      test_loss /= (
          len(test_sampler) if test_sampler else len(test_dataset)
      )
      test_accuracy /= (
          len(test_sampler) if test_sampler else len(test_dataset)
      )
  
      # Bluefog: average metric values across workers.
      test_loss = metric_average(test_loss, "avg_loss")
      test_accuracy = metric_average(test_accuracy, "avg_accuracy")
  
      # Bluefog: print output only on first rank.
      if bf.rank() == 0:
          print(
              "\nTest set: Average loss: {:.4f}, Accuracy: {:.2f}%\n".format(
                  test_loss, 100.0 * test_accuracy
              ),
              flush=True,
          )
      record.append((test_loss, 100.0 * test_accuracy))
  
imports: from __future__ import print_function
  from bluefog.common import topology_util
  import bluefog.torch
  import argparse
  import os
  import sys
  import warnings
  import torch.nn
  import torch.nn.functional
  import torch.optim
  import torch.utils.data.distributed
  from torchvision import datasets, transforms
label_desc: Use image node_id 4 for calling a global function with example usage: test(record) without return types