class_docstr: State representation of a TensorFlow Keras model and optimizer.
  
  Supports TensorFlow 2 models and optimizers, as well as `keras` and `tf.keras`.
  
  Args:
      model: TensorFlow Keras model.
      optimizer: Optional optimizer, can be compiled into model instead.
      backend: For TensorFlow v1, backend used by Keras for obtaining the session.
      kwargs: Additional properties to sync, will be exposed as attributes of the object.
class_docstr_tok: ["State","representation","of","a","TensorFlow","Keras","model","and","optimizer",".","Supports","TensorFlow","2","models","and","optimizers",",","as","well","as","`","keras","`","and","`","tf.keras","`",".","Args",":","model",":","TensorFlow","Keras","model",".","optimizer",":","Optional","optimizer",",","can","be","compiled","into","model","instead",".","backend",":","For","TensorFlow","v1",",","backend","used","by","Keras","for","obtaining","the","session",".","kwargs",":","Additional","properties","to","sync",",","will","be","exposed","as","attributes","of","the","object","."]
code: def __init__(self, model, optimizer=None, backend=None, **kwargs):
      self.model = model
      if not _model_built(model):
          raise ValueError(
              "Model must be built first. Run `model.build(input_shape)`."
          )
  
      self.optimizer = optimizer or model.optimizer
      self.backend = backend
      self._save_model()
  
      if not backend or _executing_eagerly():
          self._bcast_model = lambda: _broadcast_model(
              self.model, self.optimizer, backend=self.backend
          )
          bcast_object = broadcast_object
      else:
          # For TensorFlow v1, we need to reuse the broadcast op to prevent incrementing the uids
          bcast_op = broadcast_variables(
              _global_variables(), root_rank=0
          )
          self._bcast_model = lambda: self.backend.get_session().run(
              bcast_op
          )
          bcast_object = broadcast_object_fn(
              session=self.backend.get_session()
          )
  
      super(TensorFlowKerasState, self).__init__(
          bcast_object=bcast_object, get_rank=rank, **kwargs
      )
  
imports: from packaging import version
  import tensorflow
  from tensorflow.python.framework import ops
  from horovod.common.elastic import run_fn, ObjectState
  from horovod.common.exceptions import HorovodInternalError
  from horovod.tensorflow.functions import broadcast_object, broadcast_object_fn, broadcast_variables
  from horovod.tensorflow.mpi_ops import _executing_eagerly, init, rank, shutdown
label_desc: Use image node_id 1 to create a new TensorFlowKerasState object from inherited base classes: ObjectState with example: obj = TensorFlowKerasState(model, optimizer, backend)