code: def validate(model, valid_loader, device):
      """This is the validation code"""
  
      model.eval()
  
      valid_loss = 0
      correct = 0
      with torch.no_grad():
          for data, target in valid_loader:
              data, target = data.to(device), target.to(device)
  
              output = model(data)
              valid_loss += F.cross_entropy(
                  output, target, reduction="sum"
              ).item()
  
              pred = output.argmax(dim=1, keepdim=True)
              correct += pred.eq(target.view_as(pred)).sum().item()
  
      valid_loss /= len(valid_loader.dataset)
      valid_accuracy = 100.0 * correct / len(valid_loader.dataset)
  
      # **Save stats**
      tracker.save(
          {"loss.valid": valid_loss, "accuracy.valid": valid_accuracy}
      )
  
file_path: labml/samples/pytorch/mnist/b_labml_tracker.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  import torch.utils.data
  from torchvision import datasets, transforms
  from labml import lab, tracker, experiment, logger
label_desc: Use image node_id 2 for calling a global function with example usage: validate(model, valid_loader, device) without return types