code: def _calculate_metrics(
      model: Union[DDP, DMP],
      batch: List[torch.LongTensor],
      metric_ks: List[int],
      device: torch.device,
  ) -> Dict[str, float]:
      seqs, candidates, labels = batch
      kjt = _to_kjt(seqs, device)
      scores = model(kjt)
      scores = scores[:, -1, :]
      scores = scores.gather(1, candidates)
  
      metrics = recalls_and_ndcgs_for_ks(scores, labels, metric_ks)
      return metrics
  
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 4 for calling a global function with example usage: _calculate_metrics(model, batch, metric_ks, device) and returns: metrics