docstr: Train this tensorflow model with train data.
  
  :param data: train data. It can be XShards, Spark DataFrame or creator function which
         returns Iter or DataLoader.
         If data is XShards, each partition can be a Pandas DataFrame or a dictionary of
         {'x': feature, 'y': label}, where feature(label) is a numpy array or a tuple of
         numpy arrays.
  :param epochs: Number of epochs to train the model. Default: 1.
  :param batch_size: Batch size used for training. Default: 32.
  :param verbose: Prints output of one model if true.
  :param callbacks: List of Keras compatible callbacks to apply during training.
  :param validation_data: validation data. Validation data type should be the same
         as train data.
  :param class_weight: Optional dictionary mapping class indices (integers) to a weight
         (float) value, used for weighting the loss function. This can be useful to tell
         the model to "pay more attention" to samples from an under-represented class.
  :param steps_per_epoch: Total number of steps (batches of samples) before declaring one
         epoch finished and starting the next epoch. If `steps_pre_epoch` is `None`, the
         epoch will run until the input dataset is exhausted. When passing an infinitely
         repeating dataset, you must specify the `step_per_epoch` argument.
  :param validation_steps: Total number of steps (batches of samples) to draw before stopping
         when performing validation at the end of every epoch. Default: None.
  :param validation_freq: Only relevant if validation data is provided. Integer of
         `collections_abc.Container` instance (e.g. list, tuple, etc.). If an integer,
         specifies how many training epochs to run before a new validation run is performed,
         e.g. `validation_freq=2` runs validation every 2 epochs. If a Container, specifies
         the epochs on which to run validation, e.g. `validation_freq=[1, 2, 10]` runs
         validation at the end of the 1st, 2nd, and 10th epochs.
  :param data_config: An optional dictionary that can be passed to data creator function.
  :param feature_cols: Feature column name(s) of data. Only used when data is a Spark
         DataFrame or an XShards of Pandas DataFrame. Default: None.
  :param label_cols: Label column name(s) of data. Only used when data is a Spark DataFrame or
         an XShards of Pandas DataFrame.
         Default: None.
  :return:
docstr_tok: ["Train","this","tensorflow","model","with","train","data",".",":","param","data",":","train","data",".","It","can","be","XShards",",","Spark","DataFrame","or","creator","function","which","returns","Iter","or","DataLoader",".","If","data","is","XShards",",","each","partition","can","be","a","Pandas","DataFrame","or","a","dictionary","of","{","'","x","'",":","feature",",","'","y","'",":","label","}",",","where","feature","(","label",")","is","a","numpy","array","or","a","tuple","of","numpy","arrays",".",":","param","epochs",":","Number","of","epochs","to","train","the","model",".","Default",":","1.",":","param","batch_size",":","Batch","size","used","for","training",".","Default",":","32.",":","param","verbose",":","Prints","output","of","one","model","if","true",".",":","param","callbacks",":","List","of","Keras","compatible","callbacks","to","apply","during","training",".",":","param","validation_data",":","validation","data",".","Validation","data","type","should","be","the","same","as","train","data",".",":","param","class_weight",":","Optional","dictionary","mapping","class","indices","(","integers",")","to","a","weight","(","float",")","value",",","used","for","weighting","the","loss","function",".","This","can","be","useful","to","tell","the","model","to","``","pay","more","attention","''","to","samples","from","an","under-represented","class",".",":","param","steps_per_epoch",":","Total","number","of","steps","(","batches","of","samples",")","before","declaring","one","epoch","finished","and","starting","the","next","epoch",".","If","`","steps_pre_epoch","`","is","`","None","`",",","the","epoch","will","run","until","the","input","dataset","is","exhausted",".","When","passing","an","infinitely","repeating","dataset",",","you","must","specify","the","`","step_per_epoch","`","argument",".",":","param","validation_steps",":","Total","number","of","steps","(","batches","of","samples",")","to","draw","before","stopping","when","performing","validation","at","the","end","of","every","epoch",".","Default",":","None",".",":","param","validation_freq",":","Only","relevant","if","validation","data","is","provided",".","Integer","of","`","collections_abc.Container","`","instance","(","e.g",".","list",",","tuple",",","etc.",")",".","If","an","integer",",","specifies","how","many","training","epochs","to","run","before","a","new","validation","run","is","performed",",","e.g",".","`","validation_freq=2","`","runs","validation","every","2","epochs",".","If","a","Container",",","specifies","the","epochs","on","which","to","run","validation",",","e.g",".","`","validation_freq=","[","1",",","2",",","10","]","`","runs","validation","at","the","end","of","the","1st",",","2nd",",","and","10th","epochs",".",":","param","data_config",":","An","optional","dictionary","that","can","be","passed","to","data","creator","function",".",":","param","feature_cols",":","Feature","column","name","(","s",")","of","data",".","Only","used","when","data","is","a","Spark","DataFrame","or","an","XShards","of","Pandas","DataFrame",".","Default",":","None",".",":","param","label_cols",":","Label","column","name","(","s",")","of","data",".","Only","used","when","data","is","a","Spark","DataFrame","or","an","XShards","of","Pandas","DataFrame",".","Default",":","None",".",":","return",":"]
code: def fit(
      self,
      data,
      epochs=1,
      batch_size=32,
      verbose=1,
      callbacks=None,
      validation_data=None,
      class_weight=None,
      steps_per_epoch=None,
      validation_steps=None,
      validation_freq=1,
      data_config=None,
      feature_cols=None,
      label_cols=None,
  ):
      """
      Train this tensorflow model with train data.
  
      :param data: train data. It can be XShards, Spark DataFrame or creator function which
             returns Iter or DataLoader.
             If data is XShards, each partition can be a Pandas DataFrame or a dictionary of
             {'x': feature, 'y': label}, where feature(label) is a numpy array or a tuple of
             numpy arrays.
      :param epochs: Number of epochs to train the model. Default: 1.
      :param batch_size: Batch size used for training. Default: 32.
      :param verbose: Prints output of one model if true.
      :param callbacks: List of Keras compatible callbacks to apply during training.
      :param validation_data: validation data. Validation data type should be the same
             as train data.
      :param class_weight: Optional dictionary mapping class indices (integers) to a weight
             (float) value, used for weighting the loss function. This can be useful to tell
             the model to "pay more attention" to samples from an under-represented class.
      :param steps_per_epoch: Total number of steps (batches of samples) before declaring one
             epoch finished and starting the next epoch. If `steps_pre_epoch` is `None`, the
             epoch will run until the input dataset is exhausted. When passing an infinitely
             repeating dataset, you must specify the `step_per_epoch` argument.
      :param validation_steps: Total number of steps (batches of samples) to draw before stopping
             when performing validation at the end of every epoch. Default: None.
      :param validation_freq: Only relevant if validation data is provided. Integer of
             `collections_abc.Container` instance (e.g. list, tuple, etc.). If an integer,
             specifies how many training epochs to run before a new validation run is performed,
             e.g. `validation_freq=2` runs validation every 2 epochs. If a Container, specifies
             the epochs on which to run validation, e.g. `validation_freq=[1, 2, 10]` runs
             validation at the end of the 1st, 2nd, and 10th epochs.
      :param data_config: An optional dictionary that can be passed to data creator function.
      :param feature_cols: Feature column name(s) of data. Only used when data is a Spark
             DataFrame or an XShards of Pandas DataFrame. Default: None.
      :param label_cols: Label column name(s) of data. Only used when data is a Spark DataFrame or
             an XShards of Pandas DataFrame.
             Default: None.
      :return:
      """
      params = dict(
          epochs=epochs,
          batch_size=batch_size,
          verbose=verbose,
          callbacks=callbacks,
          class_weight=class_weight,
          steps_per_epoch=steps_per_epoch,
          validation_steps=validation_steps,
          validation_freq=validation_freq,
          data_config=data_config,
      )
  
      from zoo.orca.data import SparkXShards
  
      data, validation_data = maybe_dataframe_to_xshards(
          data,
          validation_data,
          feature_cols,
          label_cols,
          mode="fit",
          num_workers=self.num_workers,
          accept_str_col=True,
      )
  
      if isinstance(data, SparkXShards):
          if data._get_class_name() == "pandas.core.frame.DataFrame":
              (
                  data,
                  validation_data,
              ) = process_xshards_of_pandas_dataframe(
                  data, feature_cols, label_cols, validation_data, "fit"
              )
          ray_xshards = process_spark_xshards(data, self.num_workers)
  
          if validation_data is None:
  
              def transform_func(worker, partition_refs):
                  params["data_creator"] = make_data_creator(
                      partition_refs
                  )
                  return worker.step.remote(**params)
  
              worker_stats = ray_xshards.reduce_partitions_for_actors(
                  self.remote_workers, transform_func
              )
          else:
              val_ray_xshards = process_spark_xshards(
                  validation_data, self.num_workers
              )
  
              def zip_func(
                  worker, this_partition_refs, that_partition_refs
              ):
                  params["data_creator"] = make_data_creator(
                      this_partition_refs
                  )
                  params["validation_data_creator"] = make_data_creator(
                      that_partition_refs
                  )
                  return worker.step.remote(**params)
  
              worker_stats = ray_xshards.zip_reduce_shards_with_actors(
                  val_ray_xshards, self.remote_workers, zip_func
              )
      else:
          params["data_creator"] = data
          params["validation_data_creator"] = validation_data
          params_list = [params] * self.num_workers
  
          worker_stats = ray.get(
              [
                  self.remote_workers[i].step.remote(**params_list[i])
                  for i in range(self.num_workers)
              ]
          )
          worker_stats = list(
              itertools.chain.from_iterable(worker_stats)
          )
      stats = worker_stats[0].copy()
      return stats
  
imports: import itertools
  import logging
  import pickle
  import numpy
  import ray
  from zoo.common.utils import enable_multi_fs_load, enable_multi_fs_save
  from zoo.orca.data.ray_xshards import RayXShards
  from zoo.orca.learn.dl_cluster import RayDLCluster
  from zoo.orca.learn.tf2.tf_runner import TFRunner
  from zoo.orca.learn.ray_estimator import Estimator
  from zoo.orca.learn.utils import maybe_dataframe_to_xshards, dataframe_to_xshards, convert_predict_xshards_to_dataframe, update_predict_xshards, process_xshards_of_pandas_dataframe
  from zoo.orca.data.utils import process_spark_xshards
  from zoo.ray import RayContext
label_desc: Use image node_id 2 for calling the TensorFlow2Estimator obj's underlying member method code with example usage: obj.fit(data, epochs, batch_size, verbose, callbacks, validation_data, class_weight, steps_per_epoch, validation_steps, validation_freq, data_config, feature_cols, label_cols) and returns: stats, worker, worker