code: def clean_model_cfg(
      model_cfg: dict,
      model_type=None,
      ag_args=None,
      ag_args_ensemble=None,
      ag_args_fit=None,
      problem_type=None,
  ):
      model_cfg = copy.deepcopy(model_cfg)
      if AG_ARGS not in model_cfg:
          model_cfg[AG_ARGS] = dict()
      if "model_type" not in model_cfg[AG_ARGS]:
          model_cfg[AG_ARGS]["model_type"] = model_type
      if model_cfg[AG_ARGS]["model_type"] is None:
          raise AssertionError(
              f"model_type was not specified for model! Model: {model_cfg}"
          )
      model_type = model_cfg[AG_ARGS]["model_type"]
      if not inspect.isclass(model_type):
          model_type = MODEL_TYPES[model_type]
      elif not issubclass(model_type, AbstractModel):
          logger.warning(
              f"Warning: Custom model type {model_type} does not inherit from {AbstractModel}. This may lead to instability. Consider wrapping {model_type} with an implementation of {AbstractModel}!"
          )
      else:
          logger.log(20, f"Custom Model Type Detected: {model_type}")
      model_cfg[AG_ARGS]["model_type"] = model_type
      model_type_real = model_cfg[AG_ARGS]["model_type"]
      if not inspect.isclass(model_type_real):
          model_type_real = MODEL_TYPES[model_type_real]
      default_ag_args = model_type_real._get_default_ag_args()
      if ag_args is not None:
          model_extra_ag_args = ag_args.copy()
          model_extra_ag_args.update(model_cfg[AG_ARGS])
          model_cfg[AG_ARGS] = model_extra_ag_args
      default_ag_args_ensemble = (
          model_type_real._get_default_ag_args_ensemble(
              problem_type=problem_type
          )
      )
      if ag_args_ensemble is not None:
          model_extra_ag_args_ensemble = ag_args_ensemble.copy()
          model_extra_ag_args_ensemble.update(
              model_cfg.get(AG_ARGS_ENSEMBLE, dict())
          )
          model_cfg[AG_ARGS_ENSEMBLE] = model_extra_ag_args_ensemble
      if ag_args_fit is not None:
          if AG_ARGS_FIT not in model_cfg:
              model_cfg[AG_ARGS_FIT] = dict()
          model_extra_ag_args_fit = ag_args_fit.copy()
          model_extra_ag_args_fit.update(model_cfg[AG_ARGS_FIT])
          model_cfg[AG_ARGS_FIT] = model_extra_ag_args_fit
      if default_ag_args is not None:
          default_ag_args.update(model_cfg[AG_ARGS])
          model_cfg[AG_ARGS] = default_ag_args
      if default_ag_args_ensemble is not None:
          default_ag_args_ensemble.update(
              model_cfg.get(AG_ARGS_ENSEMBLE, dict())
          )
          model_cfg[AG_ARGS_ENSEMBLE] = default_ag_args_ensemble
      return model_cfg
  
file_path: autogluon/tabular/src/autogluon/tabular/trainer/model_presets/presets.py
imports: import copy
  import inspect
  import logging
  from collections import defaultdict
  from autogluon.common.model_filter import ModelFilter
  from autogluon.core.constants import AG_ARGS, AG_ARGS_ENSEMBLE, AG_ARGS_FIT, BINARY, MULTICLASS, QUANTILE, REGRESSION, SOFTCLASS
  from autogluon.core.models import AbstractModel, DummyModel, GreedyWeightedEnsembleModel, SimpleWeightedEnsembleModel, StackerEnsembleModel
  from autogluon.core.trainer.utils import process_hyperparameters
  from ...models import BoostedRulesModel, CatBoostModel, FastTextModel, FigsModel, FTTransformerModel, GreedyTreeModel, HSTreeModel, ImagePredictorModel, KNNModel, LGBModel, LinearModel, MultiModalPredictorModel, NNFastAiTabularModel, RFModel, RuleFitModel, TabPFNModel, TabularNeuralNetTorchModel, TextPredictorModel, VowpalWabbitModel, XGBoostModel, XTModel
  from ...models.tab_transformer.tab_transformer_model import TabTransformerModel
  from .presets_custom import get_preset_custom
label_desc: Use image node_id 2 for calling a global function with example usage: clean_model_cfg(model_cfg, model_type, ag_args, ag_args_ensemble, ag_args_fit, problem_type) and returns: model_cfg