class_docstr: Tests for ops in horovod.tensorflow.keras.
class_docstr_tok: ["Tests","for","ops","in","horovod.tensorflow.keras","."]
code: def test_legacy_optimizer(self):
      if not hasattr(keras.optimizers, "legacy"):
          self.skipTest("Keras legacy optimizers not available")
  
      opt = keras.optimizers.legacy.Adam(lr=0.0001)
      opt = hvd.DistributedOptimizer(opt)
  
      model = keras.models.Sequential()
      model.add(keras.layers.Dense(2, input_shape=(3,)))
      model.add(keras.layers.RepeatVector(3))
      model.add(keras.layers.ThresholdedReLU(0.5))
      model.compile(
          loss=keras.losses.mean_squared_error,
          optimizer=opt,
          metrics=[keras.metrics.categorical_accuracy],
          experimental_run_tf_function=False,
      )
      x = np.random.random((10, 3))
      y = np.random.random((10, 3, 2))
  
      # No assertions, we just need to verify that it doesn't crash
      model.train_on_batch(x, y)
  
imports: import tensorflow
  import numpy
  import warnings
  from packaging import version
  from parameterized import parameterized
  import pytest
  from tensorflow import keras
  from horovod.common.util import is_version_greater_equal_than
  import horovod.keras
  import horovod.tensorflow.keras
label_desc: Use image node_id 4 for calling the Tf2KerasTests obj's underlying member method code with example usage: obj.test_legacy_optimizer() without return types