class_docstr: A distributed trainer for `AbstractComponent`s. Used mainly for supervised learning.
  
  Create a `DistributedModelTrainer` by passing a `AbstractNeuralModel` in the constructor.
  Invoke `train()` to initiate the training loop. The root `TNeuralModule` should return a scalar loss.
code: def _run_validation(
      self,
      distributed_neural_module: DDP,
      validation_tensors,
      epoch,
      best_target_metric,
      device,
      parallelize,
  ):
      distributed_neural_module.eval()
      sum_epoch_loss, num_minibatches, num_samples = 0.0, 0, 0
      start_time = time.time()
      try:
          with distributed_neural_module.join(), distributed_neural_module.no_sync(), torch.no_grad():
              for mb_data, raw_samples in self.model.minibatch_iterator(
                  validation_tensors(),
                  device=device,
                  max_minibatch_size=self._minibatch_size,
                  yield_partial_minibatches=True,
                  shuffle_input=False,
                  parallelize=parallelize,
              ):
                  with torch.cuda.amp.autocast(
                      enabled=self._enable_amp
                  ):
                      mb_loss = distributed_neural_module(**mb_data)
                  num_minibatches += 1
                  num_samples += len(raw_samples)
                  sum_epoch_loss += mb_loss.detach()
  
              elapsed_time = time.time() - start_time
              assert num_samples > 0, "No validation data was found."
  
          validation_loss = sum_epoch_loss / num_minibatches
  
      except RuntimeError as re:
          self.LOGGER.exception("Something went wrong: %s", str(re))
  
      self.LOGGER.info(
          "Validation complete in %.1fsec [%.2f samples/sec]",
          elapsed_time,
          (num_samples / elapsed_time),
      )
      self.LOGGER.info(
          "Epoch %i: Valid Loss %.2f", epoch + 1, validation_loss
      )
  
      validation_metrics = (
          distributed_neural_module.module.report_metrics()
      )
      for epoch_hook in self._validation_epoch_end_hooks:
          epoch_hook(
              self.model,
              distributed_neural_module.module,
              epoch,
              validation_metrics,
          )
      if len(validation_metrics) > 0:
          self.LOGGER.info(
              "Validation Metrics: %s",
              json.dumps(validation_metrics, indent=2),
          )
  
      if self._target_metric is not None:
          target_metric = validation_metrics[self._target_metric]
          target_metric = torch.tensor(
              [target_metric], device=mb_loss.device
          )
          dist.all_reduce(target_metric)
          target_metric = target_metric.item() / dist.get_world_size()
      else:
          dist.all_reduce(validation_loss)
          validation_loss = (
              validation_loss.item() / dist.get_world_size()
          )
          target_metric = validation_loss
  
      if self._target_metric_higher_is_better:
          target_metric_improved = target_metric > best_target_metric
      else:
          target_metric_improved = target_metric < best_target_metric
  
      return target_metric, target_metric_improved, validation_metrics
  
imports: from typing_extensions import Final
  import json
  import logging
  import math
  import os
  import time
  import torch
  import torch.distributed
  import torch.multiprocessing
  from functools import partial
  from torch.nn.parallel import DistributedDataParallel
  from typing import Callable, Iterable, Optional, TypeVar
  from ptgnn.baseneuralmodel import ModelTrainer
  from ptgnn.baseneuralmodel.abstractneuralmodel import AbstractNeuralModel
  from ptgnn.baseneuralmodel.modulewithmetrics import ModuleWithMetrics
  from ptgnn.baseneuralmodel.utils.data import ShardedLazyDataIterable
label_desc: Use image node_id 2 for calling the DistributedModelTrainer obj's underlying member method code with example usage: obj._run_validation(distributed_neural_module, validation_tensors, epoch, best_target_metric, device, parallelize) and returns: target_metric,  target_metric_improved,  validation_metrics