code: def fit_and_save_model(
      model,
      fit_kwargs,
      train_data,
      val_data,
      eval_metric,
      time_start,
      time_limit=None,
  ):
      time_current = time.time()
      time_elapsed = time_current - time_start
      if time_limit is not None:
          time_left = time_limit - time_elapsed
          if time_left <= 0:
              raise TimeLimitExceeded
      else:
          time_left = None
  
      time_fit_start = time.time()
      model.fit(
          train_data=train_data,
          val_data=val_data,
          time_limit=time_left,
          **fit_kwargs,
      )
      model.fit_time = time.time() - time_fit_start
      model.score_and_cache_oof(
          val_data, store_val_score=True, store_predict_time=True
      )
  
      logger.debug(f"\tHyperparameter tune run: {model.name}")
      logger.debug(
          f"\t\t{model.val_score:<7.4f}".ljust(15)
          + f"= Validation score ({eval_metric.name_with_sign})"
      )
      logger.debug(
          f"\t\t{model.fit_time:<7.3f} s".ljust(15)
          + "= Training runtime"
      )
      logger.debug(
          f"\t\t{model.predict_time:<7.3f} s".ljust(15)
          + "= Training runtime"
      )
      model.save()
      return model
  
file_path: autogluon/timeseries/src/autogluon/timeseries/models/abstract/model_trial.py
imports: import logging
  import os
  import time
  import traceback
  from autogluon.core.models.abstract.model_trial import init_model
  from autogluon.core.utils.exceptions import TimeLimitExceeded
  from autogluon.core.utils.loaders import load_pkl
label_desc: Use image node_id 2 for calling a global function with example usage: fit_and_save_model(model, fit_kwargs, train_data, val_data, eval_metric, time_start, time_limit) and returns: model