class_docstr: Offer a similar interface as WorkloadResponseInterceptor, except let send() yield a whole
  progression of RUN_STEP and COMPUTE_VALIDATION_METRICS, and let result() return the accumulated
  metrics from each.
class_docstr_tok: ["Offer","a","similar","interface","as","WorkloadResponseInterceptor",",","except","let","send","(",")","yield","a","whole","progression","of","RUN_STEP","and","COMPUTE_VALIDATION_METRICS",",","and","let","result","(",")","return","the","accumulated","metrics","from","each","."]
code: def send(
      self,
      steps: int,
      validation_freq: int,
      initial_step_id: int = 1,
      scheduling_unit: int = 1,
      train_batch_calls: int = 1,
  ) -> workload.Stream:
      self._training_metrics = []
      self._avg_training_metrics = []
      self._validation_metrics = []
      self._steps_completed = 0
      interceptor = workload.WorkloadResponseInterceptor()
  
      for step_id in range(initial_step_id, initial_step_id + steps):
          stop_requested = False
          yield from interceptor.send(
              workload.train_workload(
                  step_id,
                  num_batches=scheduling_unit,
                  total_batches_processed=self._steps_completed,
              ),
          )
          metrics = interceptor.metrics_result()
          batch_metrics = metrics["metrics"]["batch_metrics"]
          assert (
              len(batch_metrics) == scheduling_unit * train_batch_calls
          )
          self._training_metrics.extend(batch_metrics)
          self._avg_training_metrics.append(
              metrics["metrics"]["avg_metrics"]
          )
          self._steps_completed += scheduling_unit
          if metrics.get("stop_requested"):
              assert step_id == self.request_stop_step_id, (
                  step_id,
                  self,
              )
              stop_requested = True
  
          if step_id % validation_freq == 0:
              yield from interceptor.send(
                  workload.validation_workload(
                      step_id,
                      total_batches_processed=self._steps_completed,
                  ),
              )
              validation = interceptor.metrics_result()
              v_metrics = validation["metrics"]["validation_metrics"]
              self._validation_metrics.append(v_metrics)
              if validation.get("stop_requested"):
                  assert step_id == self.request_stop_step_id, (
                      step_id,
                      self,
                  )
                  stop_requested = True
  
          if stop_requested:
              break
          else:
              assert step_id != self.request_stop_step_id
  
imports: import importlib
  import os
  import pathlib
  import re
  import unittest.mock
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type
  import numpy
  import pytest
  from mypy_extensions import DefaultNamedArg
  import determined
  from determined import core, gpu, workload
  from determined.common import util
label_desc: Use image node_id 2 for calling the TrainAndValidate obj's underlying member method code with example usage: obj.send(steps, validation_freq, initial_step_id, scheduling_unit, train_batch_calls) without return types