code: def _validate(
      model: Union[DDP, DMP],
      val_loader: data_utils.DataLoader,
      device: torch.device,
      epoch: int,
      metric_ks: List[int],
      is_testing: bool = False,
  ) -> None:
      """
      Evaluate model. Computes and prints metrics including Recalls and NDCGs. Helper
      function for train_val_test.
  
      Args:
          model (Union[DDP, DMP]): DMP or DDP model contains the Bert4Rec.
          val_loader (data_utils.DataLoader): DataLoader used for validation.
          device (torch.device): the device to train/val/test
          epoch (int): the current epoch number
          metric_ks (List[int]): the metrics we want to validate
          is_testing (bool): if validation or testing
  
      Returns:
          None.
      """
      model.eval()
      if torch.cuda.is_available():
          torch.cuda.set_device(dist.get_rank())
      outputs = [None for _ in range(dist.get_world_size())]
      keys = ["Recall@1", "Recall@5", "Recall@10", "NDCG@5", "NDCG@10"]
      metrics_log: Dict[str, List[float]] = {key: [] for key in keys}
  
      with torch.no_grad():
          for _, batch in enumerate(val_loader):
              batch = [x.to(device) for x in batch]
  
              metrics = _calculate_metrics(
                  model, batch, metric_ks, device
              )
  
              for key in keys:
                  metrics_log[key].append(metrics[key])
  
      metrics_avg = {
          key: sum(values) / len(values)
          for key, values in metrics_log.items()
      }
      dist.all_gather_object(outputs, metrics_avg)
      if dist.get_rank() == 0:
          print(
              # pyre-fixme[6] for 1st positional only parameter expected `List[Dict[str, float]]` but got `List[None]`
              f"{'Epoch ' + str(epoch + 1) if not is_testing else 'Test'}, metrics {_dict_mean(outputs)}"
          )
  
imports: import argparse
  import os
  import sys
  from typing import Any, cast, Dict, List, Union
  import numpy
  import torch
  import torch.nn
  import torch.optim
  import torch.utils.data
  from fbgemm_gpu.split_embedding_configs import EmbOptimType
  from torch import distributed
  from torch.nn.parallel import DistributedDataParallel
  from torchrec.distributed.embedding import EmbeddingCollectionSharder
  from torchrec.distributed.model_parallel import DistributedModelParallel
  from torchrec.distributed.types import ModuleSharder
  from torchrec.optim.keyed import CombinedOptimizer, KeyedOptimizerWrapper
  from torchrec.optim.optimizers import in_backward_optimizer_filter
  from torchrec.sparse.jagged_tensor import KeyedJaggedTensor
  from tqdm import tqdm
label_desc: Use image node_id 6 for calling a global function with example usage: _validate(model, val_loader, device, epoch, metric_ks, is_testing) without return types