code: def fit(
      self,
      x=None,
      y=None,
      batch_size=None,
      epochs=1,
      verbose="auto",
      callbacks=None,
      validation_split=0.0,
      validation_data=None,
      shuffle=True,
      class_weight=None,
      sample_weight=None,
      initial_epoch=0,
      steps_per_epoch=None,
      validation_steps=None,
      validation_batch_size=None,
      validation_freq=1,
  ):
      if not self.compiled:
          raise ValueError(
              "You must call `compile()` before calling `fit()`."
          )
  
      # TODO: respect compiled trainable state
      self._eval_epoch_iterator = None
      if validation_split and validation_data is None:
          # Create the validation data using the training data. Only supported
          # for TF/numpy/jax arrays.
          # TODO: Support torch tensors for validation data.
          (
              x,
              y,
              sample_weight,
          ), validation_data = data_adapter_utils.train_validation_split(
              (x, y, sample_weight), validation_split=validation_split
          )
  
      if validation_data:
          (
              val_x,
              val_y,
              val_sample_weight,
          ) = data_adapter_utils.unpack_x_y_sample_weight(
              validation_data
          )
  
      # Create an iterator that yields batches for one epoch.
      epoch_iterator = TorchEpochIterator(
          x=x,
          y=y,
          sample_weight=sample_weight,
          batch_size=batch_size,
          steps_per_epoch=steps_per_epoch,
          shuffle=shuffle,
          class_weight=class_weight,
          steps_per_execution=self.steps_per_execution,
      )
  
      self._symbolic_build(iterator=epoch_iterator)
  
      # Container that configures and calls callbacks.
      if not isinstance(callbacks, callbacks_module.CallbackList):
          callbacks = callbacks_module.CallbackList(
              callbacks,
              add_history=True,
              add_progbar=verbose != 0,
              verbose=verbose,
              epochs=epochs,
              steps=epoch_iterator.num_batches,
              model=self,
          )
  
      self.stop_training = False
      self.make_train_function()
      callbacks.on_train_begin()
  
      for epoch in range(initial_epoch, epochs):
          self.reset_metrics()
          callbacks.on_epoch_begin(epoch)
  
          # Switch the torch Module to training mode. Inform torch layers to
          # do training behavior in case the user did not use `self.training`
          # when implementing a custom layer with torch layers.
          self.train()
          for step, data in epoch_iterator.enumerate_epoch():
              # Callbacks
              callbacks.on_train_batch_begin(step)
  
              logs = self.train_function(data)
  
              # Callbacks
              callbacks.on_train_batch_end(
                  step, self._pythonify_logs(logs)
              )
              if self.stop_training:
                  break
  
          # Override with model metrics instead of last step logs
          epoch_logs = self.get_metrics_result()
  
          # Switch the torch Module back to testing mode.
          self.eval()
  
          # Run validation.
          if validation_data and self._should_eval(
              epoch, validation_freq
          ):
              # Create TorchEpochIterator for evaluation and cache it.
              if getattr(self, "_eval_epoch_iterator", None) is None:
                  self._eval_epoch_iterator = TorchEpochIterator(
                      x=val_x,
                      y=val_y,
                      sample_weight=val_sample_weight,
                      batch_size=validation_batch_size or batch_size,
                      steps_per_execution=self.steps_per_execution,
                      steps_per_epoch=validation_steps,
                      shuffle=False,
                  )
              val_logs = self.evaluate(
                  x=val_x,
                  y=val_y,
                  sample_weight=val_sample_weight,
                  batch_size=validation_batch_size or batch_size,
                  steps=validation_steps,
                  callbacks=callbacks,
                  return_dict=True,
                  _use_cached_eval_dataset=True,
              )
              val_logs = {
                  "val_" + name: val for name, val in val_logs.items()
              }
              epoch_logs.update(val_logs)
  
          callbacks.on_epoch_end(epoch, epoch_logs)
          training_logs = epoch_logs
          if self.stop_training:
              break
  
      if (
          isinstance(self.optimizer, optimizers_module.Optimizer)
          and epochs > 0
      ):
          self.optimizer.finalize_variable_values(
              self.trainable_weights
          )
  
      # If _eval_epoch_iterator exists, delete it after all epochs are done.
      if getattr(self, "_eval_epoch_iterator", None) is not None:
          del self._eval_epoch_iterator
      callbacks.on_train_end(logs=training_logs)
      return self.history
  
imports: import collections
  import itertools
  import warnings
  import numpy
  import torch
  import tree
  from packaging.version import parse
  from keras import backend
  from keras import callbacks
  from keras import optimizers
  from keras.trainers import data_adapters
  from keras.trainers import trainer
  from keras.trainers.data_adapters import data_adapter_utils
  from keras.trainers.epoch_iterator import EpochIterator
  from keras.utils import traceback_utils
label_desc: Use image node_id 9 for calling the TorchTrainer obj's underlying member method code with example usage: obj.fit(x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq) and returns: self