code: def DistributedOptimizer(
      optimizer,
      name=None,
      device_dense="",
      device_sparse="",
      compression=Compression.none,
      sparse_as_dense=False,
      gradient_predivide_factor=1.0,
      op=Average,
      backward_passes_per_step=1,
      average_aggregated_gradients=False,
  ):
      """
      An optimizer that wraps another keras.optimizers.Optimizer, using an allreduce
      to average gradient values before applying gradients to model weights.
      Args:
          optimizer: Optimizer to use for computing gradients and applying updates.
          name: Optional name prefix for the operations created when applying
                gradients. Defaults to "Distributed" followed by the provided
                optimizer type.
          device_dense: Device to be used for dense tensors. Uses GPU by default
                        if Horovod was build with HOROVOD_GPU_OPERATIONS.
          device_sparse: Device to be used for sparse tensors. Uses GPU by default
                         if Horovod was build with HOROVOD_GPU_OPERATIONS.
          compression: Compression algorithm used to reduce the amount of data
                       sent and received by each worker node.  Defaults to not
                       using compression.
          sparse_as_dense: Treat all sparse gradients as dense tensors.  This can
                           help improve performance and memory utilization if
                           the original sparse gradient has high density.
                           Defaults to false.
          gradient_predivide_factor: gradient_predivide_factor splits the averaging
                                     before and after the sum. Gradients are scaled
                                     by 1.0 / gradient_predivide_factor before the
                                     sum and gradient_predivide_factor / size after
                                     the sum.
          op: The reduction operation to use when combining gradients across
              different ranks. Defaults to Average.
          backward_passes_per_step: Number of backward passes to perform before
                                    calling hvd.allreduce. This allows accumulating
                                    updates over multiple mini-batches before
                                    reducing and applying them.
          average_aggregated_gradients: Whether to average the aggregated gradients
                                        that have been accumulated over multiple
                                        mini-batches. If true divides gradient
                                        updates by backward_passes_per_step.
                                        Only applicable for backward_passes_per_step
                                        > 1.
      """
      if gradient_predivide_factor != 1.0 and rocm_built():
          raise ValueError(
              "gradient_predivide_factor not supported yet with ROCm"
          )
  
      if op != Average and op != Sum:
          raise ValueError("op currently only supports Average and Sum")
  
      return create_distributed_optimizer(
          keras=keras,
          optimizer=optimizer,
          name=name,
          device_dense=device_dense,
          device_sparse=device_sparse,
          compression=compression,
          sparse_as_dense=sparse_as_dense,
          gradient_predivide_factor=gradient_predivide_factor,
          op=op,
          backward_passes_per_step=backward_passes_per_step,
          average_aggregated_gradients=average_aggregated_gradients,
      )
  
file_path: DALI/docs/examples/use_cases/tensorflow/resnet-n/nvutils/hvd_patch.py
imports: from tensorflow import keras
  from horovod.tensorflow import Compression
  from tensorflow.python.keras.optimizer_v2 import optimizer_v2
  import horovod.tensorflow
  import tensorflow
  from nvutils import common
  from distutils.version import LooseVersion
  from horovod.tensorflow import Average, Compression, Sum
label_desc: Use image node_id 2 for calling a global function with example usage: DistributedOptimizer(optimizer, name, device_dense, device_sparse, compression, sparse_as_dense, gradient_predivide_factor, op, backward_passes_per_step, average_aggregated_gradients) and returns: create_distributed_optimizer