class_docstr: Base context class that contains runtime information for any Determined
  workflow that uses the ``tf.keras`` API.
class_docstr_tok: ["Base","context","class","that","contains","runtime","information","for","any","Determined","workflow","that","uses","the","``","tf.keras","``","API","."]
code: def _get_horovod_optimizer_if_using_horovod(
      self, optimizer: tf.keras.optimizers.Optimizer
  ) -> tf.keras.optimizers.Optimizer:
      if self.distributed.size == 1:
          return optimizer
  
      # Horovod doesn't know how to handle string-based optimizers.
      if isinstance(optimizer, str):
          raise det.errors.InvalidExperimentException(
              "string optimizers are not supported"
          )
  
      # The signature of our horovod optimizer changed after we rebased onto 0.21.
      hvd_sig = inspect.signature(hvd.DistributedOptimizer)
      horovod_kwargs = {
          "average_aggregated_gradients": self._average_aggregated_gradients,
      }  # type: Dict[str, Any]
      if "aggregation_frequency" in hvd_sig.parameters:
          horovod_kwargs[
              "aggregation_frequency"
          ] = self._aggregation_frequency
      else:
          horovod_kwargs[
              "backward_passes_per_step"
          ] = self._aggregation_frequency
  
      return hvd.DistributedOptimizer(optimizer, **horovod_kwargs)
  
imports: import inspect
  import logging
  from typing import Any, Callable, Dict, List, NamedTuple, Optional, Union, cast
  import tensorflow
  import determined
  from determined import errors, keras, util
  from determined.common import check
  from determined.horovod import hvd
label_desc: Use image node_id 7 for calling the TFKerasTrialContext obj's underlying member method code with example usage: obj._get_horovod_optimizer_if_using_horovod(optimizer) and returns: hvd, optimizer