code: def patched_fit(original, self, *args, **kwargs):
      """
      A patched implementation of `pytorch_lightning.Trainer.fit` which enables logging the
      following parameters, metrics and artifacts:
  
      - Training epochs
      - Optimizer parameters
      - `EarlyStoppingCallback`_ parameters
      - Metrics stored in `trainer.callback_metrics`
      - Model checkpoints
      - Trained model
  
      .. _EarlyStoppingCallback:
          https://pytorch-lightning.readthedocs.io/en/latest/early_stopping.html
      """
      if not MIN_REQ_VERSION <= _pl_version <= MAX_REQ_VERSION:
          warnings.warn(
              "Autologging is known to be compatible with pytorch-lightning versions between "
              f"{MIN_REQ_VERSION} and {MAX_REQ_VERSION} and may not succeed with packages "
              "outside this range."
          )
  
      with _pytorch_autolog.disable_pytorch_autologging():
          run_id = mlflow.active_run().info.run_id
          tracking_uri = mlflow.get_tracking_uri()
          client = MlflowAutologgingQueueingClient(tracking_uri)
          metrics_logger = BatchMetricsLogger(run_id, tracking_uri)
  
          log_models = get_autologging_config(
              mlflow.pytorch.FLAVOR_NAME, "log_models", True
          )
          log_every_n_epoch = get_autologging_config(
              mlflow.pytorch.FLAVOR_NAME, "log_every_n_epoch", 1
          )
          log_every_n_step = get_autologging_config(
              mlflow.pytorch.FLAVOR_NAME, "log_every_n_step", None
          )
  
          early_stop_callback = None
          for callback in self.callbacks:
              if isinstance(
                  callback, pl.callbacks.early_stopping.EarlyStopping
              ):
                  early_stop_callback = callback
                  _log_early_stop_params(
                      early_stop_callback, client, run_id
                  )
  
          if not any(
              isinstance(callbacks, __MLflowPLCallback)
              for callbacks in self.callbacks
          ):
              self.callbacks += [
                  __MLflowPLCallback(
                      client,
                      metrics_logger,
                      run_id,
                      log_models,
                      log_every_n_epoch,
                      log_every_n_step,
                  )
              ]
  
          client.flush(synchronous=False)
  
          result = original(self, *args, **kwargs)
  
          if early_stop_callback is not None:
              _log_early_stop_metrics(
                  early_stop_callback, client, run_id
              )
  
          if Version(pl.__version__) < Version("1.4.0"):
              # pylint: disable-next=unexpected-keyword-arg
              summary = str(ModelSummary(self.model, mode="full"))
          else:
              summary = str(ModelSummary(self.model, max_depth=-1))
  
          with tempfile.TemporaryDirectory() as tempdir:
              summary_file = os.path.join(tempdir, "model_summary.txt")
              with open(summary_file, "w") as f:
                  f.write(summary)
  
              mlflow.log_artifact(local_path=summary_file)
  
          if log_models:
              registered_model_name = get_autologging_config(
                  mlflow.pytorch.FLAVOR_NAME,
                  "registered_model_name",
                  None,
              )
              mlflow.pytorch.log_model(
                  pytorch_model=self.model,
                  artifact_path="model",
                  registered_model_name=registered_model_name,
              )
  
              if (
                  early_stop_callback is not None
                  and self.checkpoint_callback.best_model_path
              ):
                  mlflow.log_artifact(
                      local_path=self.checkpoint_callback.best_model_path,
                      artifact_path="restored_model_checkpoint",
                  )
  
          client.flush(synchronous=True)
  
      return result
  
imports: import logging
  import os
  import tempfile
  import warnings
  from packaging.version import Version
  import mlflow.pytorch
  from mlflow.exceptions import MlflowException
  from mlflow.ml_package_versions import _ML_PACKAGE_VERSIONS
  from mlflow.pytorch import _pytorch_autolog
  from mlflow.utils.autologging_utils import BatchMetricsLogger, ExceptionSafeAbstractClass, MlflowAutologgingQueueingClient, get_autologging_config
  import pytorch_lightning
  from pytorch_lightning.utilities import rank_zero_only
label_desc: Use image node_id 4 for calling a global function with example usage: patched_fit(original, ) and returns: result