code: def fit_and_save_model(
      model,
      fit_args,
      predict_proba_args,
      y_val,
      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(**fit_args, time_limit=time_left)
      time_fit_end = time.time()
  
      if model._get_tags().get("valid_oof", False):
          oof_pred_proba = model.predict_proba_oof(
              X=fit_args["X"], y=fit_args["y"]
          )
          time_pred_end = time.time()
          # TODO: use sample_weight?
          # sample_weight = fit_args.get('sample_weight', None)
          model.val_score = model.score_with_y_pred_proba(
              y=fit_args["y"], y_pred_proba=oof_pred_proba
          )
      else:
          y_pred_proba = model.predict_proba(**predict_proba_args)
          time_pred_end = time.time()
          sample_weight_val = fit_args.get("sample_weight_val", None)
          model.val_score = model.score_with_y_pred_proba(
              y=y_val,
              y_pred_proba=y_pred_proba,
              sample_weight=sample_weight_val,
          )
  
      model.fit_time = time_fit_end - time_fit_start
      model.predict_time = time_pred_end - time_fit_end
      model.save()
      return model
  
file_path: autogluon/core/src/autogluon/core/models/abstract/model_trial.py
imports: import logging
  import os
  import time
  from ...hpo.constants import CUSTOM_BACKEND, RAY_BACKEND, VALID_BACKEND
  from ...utils.exceptions import TimeLimitExceeded
  from ...utils.loaders import load_pkl
label_desc: Use image node_id 3 for calling a global function with example usage: fit_and_save_model(model, fit_args, predict_proba_args, y_val, time_start, time_limit) and returns: model