code: def test(
      args,
      model,
      device,
      test_loader,
      core_context,
      steps_completed,
      op,
  ) -> int:
      model.eval()
      test_loss = 0
      correct = 0
      with torch.no_grad():
          for data, target in test_loader:
              data, target = data.to(device), target.to(device)
              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_loss /= len(test_loader.dataset)
  
      print(
          "\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n".format(
              test_loss,
              correct,
              len(test_loader.dataset),
              100.0 * correct / len(test_loader.dataset),
          )
      )
  
      core_context.train.report_validation_metrics(
          steps_completed=steps_completed,
          metrics={"test_loss": test_loss},
      )
  
      # NEW: Return test_loss.
      return test_loss
  
file_path: determined/examples/tutorials/core_api_pytorch_mnist/model_def_adaptive.py
imports: from __future__ import print_function
  import argparse
  import pathlib
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from torch.optim.lr_scheduler import StepLR
  from torchvision import datasets, transforms
  import determined
label_desc: Use image node_id 2 for calling a global function with example usage: test(args, model, device, test_loader, core_context, steps_completed, op) and returns: test_loss