class_docstr: DeepSpeed trials are created by subclassing this abstract class.
  
  We can do the following things in this trial class:
  
  * **Define the DeepSpeed model engine which includes the model, optimizer, and lr_scheduler**.
  
     In the :meth:`__init__` method, initialize models and, optionally, optimizers and
     LR schedulers and pass them to ``deepspeed.initialize`` to build the model engine.  Then
     pass the created model engine to ``wrap_model_engine`` provided by
     :class:`~determined.pytorch.deepspeed.DeepSpeedTrialContext`.
     We support multiple DeepSpeed model engines if they only use data parallelism or if
     they use the same model parallel unit.
  
  * **Run forward and backward passes**.
  
     In :meth:`train_batch`, use the methods provided by the DeepSpeed model engine to perform
     the backward pass and optimizer step.  These methods will differ depending on whether
     you are using pipeline parallelism or not.
class_docstr_tok: ["DeepSpeed","trials","are","created","by","subclassing","this","abstract","class",".","We","can","do","the","following","things","in","this","trial","class",":","*","*","*","Define","the","DeepSpeed","model","engine","which","includes","the","model",",","optimizer",",","and","lr_scheduler","*","*",".","In","the",":","meth",":","`","__init__","`","method",",","initialize","models","and",",","optionally",",","optimizers","and","LR","schedulers","and","pass","them","to","``","deepspeed.initialize","``","to","build","the","model","engine",".","Then","pass","the","created","model","engine","to","``","wrap_model_engine","``","provided","by",":","class",":","`","~determined.pytorch.deepspeed.DeepSpeedTrialContext","`",".","We","support","multiple","DeepSpeed","model","engines","if","they","only","use","data","parallelism","or","if","they","use","the","same","model","parallel","unit",".","*","*","*","Run","forward","and","backward","passes","*","*",".","In",":","meth",":","`","train_batch","`",",","use","the","methods","provided","by","the","DeepSpeed","model","engine","to","perform","the","backward","pass","and","optimizer","step",".","These","methods","will","differ","depending","on","whether","you","are","using","pipeline","parallelism","or","not","."]
docstr: Calculate validation metrics for a batch and return them as a
  dictionary mapping metric names to metric values. Per-batch validation metrics
  are averaged to produce a single set of validation metrics for the entire
  validation set by default.
  
  The metrics returned from this function must be JSON-serializable.
  
  DeepSpeedTrial supports more flexible metrics computation via our custom reducer API,
  see :class:`~determined.pytorch.MetricReducer` for more details.
  
  Arguments:
      dataloader_iter (Iterator[torch.utils.data.DataLoader], optional): iterator over the
          validation DataLoader.
code: def evaluate_batch(
      self,
      dataloader_iter: Optional[Iterator[pytorch.TorchData]],
      batch_idx: int,
  ) -> Dict[str, Any]:
      """
      Calculate validation metrics for a batch and return them as a
      dictionary mapping metric names to metric values. Per-batch validation metrics
      are averaged to produce a single set of validation metrics for the entire
      validation set by default.
  
      The metrics returned from this function must be JSON-serializable.
  
      DeepSpeedTrial supports more flexible metrics computation via our custom reducer API,
      see :class:`~determined.pytorch.MetricReducer` for more details.
  
      Arguments:
          dataloader_iter (Iterator[torch.utils.data.DataLoader], optional): iterator over the
              validation DataLoader.
      """
      pass
  
imports: import abc
  import contextlib
  import logging
  import os
  import pathlib
  import pickle
  import random
  import time
  import warnings
  from typing import Any, Callable, Dict, Iterator, List, Optional, Type, Union, cast
  import deepspeed
  import numpy
  import torch
  from deepspeed.runtime import dataloader
  import determined
  from determined import layers, pytorch, util, workload
  from determined.pytorch import deepspeed
  from determined.pytorch import dsat
label_desc: Use image node_id 6 for calling the DeepSpeedTrial obj's underlying member method code with example usage: obj.evaluate_batch(dataloader_iter, batch_idx) without return types