code: def create_model(
      model_name: str,
      model_config: DictConfig,
      num_classes: Optional[int] = 0,
      classes: Optional[list] = None,
      num_numerical_columns: Optional[int] = None,
      num_categories: Optional[List[int]] = None,
      pretrained: Optional[bool] = True,
  ):
      """
      Create a single model.
  
      Parameters
      ----------
      model_name
          Name of the model.
      model_config
          Config of the model.
      num_classes
          The class number for a classification task. It should be 1 for a regression task.
      classes
          All classes in this dataset.
      num_numerical_columns
          The number of numerical columns in the training dataframe.
      num_categories
          The category number for each categorical column in the training dataframe.
      pretrained
          Whether using the pretrained timm models. If pretrained=True, download the pretrained model.
  
      Returns
      -------
      A model.
      """
      if model_name.lower().startswith(CLIP):
          model = CLIPForImageText(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
              num_classes=num_classes,
              pretrained=pretrained,
              tokenizer_name=model_config.tokenizer_name,
          )
      elif model_name.lower().startswith(TIMM_IMAGE):
          model = TimmAutoModelForImagePrediction(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
              num_classes=num_classes,
              mix_choice=model_config.mix_choice,
              pretrained=pretrained,
          )
      elif model_name.lower().startswith(HF_TEXT):
          model = HFAutoModelForTextPrediction(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
              num_classes=num_classes,
              pooling_mode=OmegaConf.select(
                  model_config, "pooling_mode", default="cls"
              ),
              gradient_checkpointing=OmegaConf.select(
                  model_config, "gradient_checkpointing"
              ),
              low_cpu_mem_usage=OmegaConf.select(
                  model_config, "low_cpu_mem_usage", default=False
              ),
              pretrained=pretrained,
              tokenizer_name=model_config.tokenizer_name,
              use_fast=OmegaConf.select(
                  model_config, "use_fast", default=True
              ),
          )
      elif model_name.lower().startswith(T_FEW):
          model = TFewModel(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
              length_norm=model_config.length_norm,  # Normalizes length to adjust for length bias in target template
              unlikely_loss=model_config.unlikely_loss,  # Adds loss term that lowers probability of incorrect outputs
              mc_loss=model_config.mc_loss,  # Adds multiple choice cross entropy loss
              num_classes=num_classes,
              gradient_checkpointing=OmegaConf.select(
                  model_config, "gradient_checkpointing"
              ),
              low_cpu_mem_usage=OmegaConf.select(
                  model_config, "low_cpu_mem_usage", default=False
              ),
              pretrained=pretrained,
              tokenizer_name=model_config.tokenizer_name,
          )
      elif model_name.lower().startswith(NUMERICAL_MLP):
          model = NumericalMLP(
              prefix=model_name,
              in_features=num_numerical_columns,
              hidden_features=model_config.hidden_size,
              out_features=model_config.hidden_size,
              num_layers=model_config.num_layers,
              activation=model_config.activation,
              dropout_prob=model_config.drop_rate,
              normalization=model_config.normalization,
              d_token=OmegaConf.select(model_config, "d_token"),
              embedding_arch=OmegaConf.select(
                  model_config, "embedding_arch"
              ),
              num_classes=num_classes,
          )
      elif model_name.lower().startswith(CATEGORICAL_MLP):
          model = CategoricalMLP(
              prefix=model_name,
              num_categories=num_categories,
              out_features=model_config.hidden_size,
              num_layers=model_config.num_layers,
              activation=model_config.activation,
              dropout_prob=model_config.drop_rate,
              normalization=model_config.normalization,
              num_classes=num_classes,
          )
      elif model_name.lower().startswith(DOCUMENT_TRANSFORMER):
          model = DocumentTransformer(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
              num_classes=num_classes,
              pooling_mode=OmegaConf.select(
                  model_config, "pooling_mode", default="cls"
              ),
              gradient_checkpointing=OmegaConf.select(
                  model_config, "gradient_checkpointing"
              ),
              low_cpu_mem_usage=OmegaConf.select(
                  model_config, "low_cpu_mem_usage", default=False
              ),
              pretrained=pretrained,
              tokenizer_name=model_config.tokenizer_name,
          )
      elif model_name.lower().startswith(MMDET_IMAGE):
          model = MMDetAutoModelForObjectDetection(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
              config_file=OmegaConf.select(
                  model_config, "config_file", default=None
              ),
              classes=classes,
              pretrained=pretrained,
              output_bbox_format=OmegaConf.select(
                  model_config, "output_bbox_format", default=XYXY
              ),
              frozen_layers=OmegaConf.select(
                  model_config, "frozen_layers", default=None
              ),
          )
      elif model_name.lower().startswith(OVD):
          model = OVDModel(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
              pretrained=pretrained,
          )
      elif model_name.lower().startswith(MMOCR_TEXT_DET):
          model = MMOCRAutoModelForTextDetection(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
          )
      elif model_name.lower().startswith(MMOCR_TEXT_RECOG):
          model = MMOCRAutoModelForTextRecognition(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
          )
      elif model_name.lower().startswith(NER_TEXT):
          model = HFAutoModelForNER(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
              num_classes=num_classes,
              gradient_checkpointing=OmegaConf.select(
                  model_config, "gradient_checkpointing"
              ),
              low_cpu_mem_usage=OmegaConf.select(
                  model_config, "low_cpu_mem_usage", default=False
              ),
              pretrained=pretrained,
              tokenizer_name=model_config.tokenizer_name,
          )
      elif model_name.lower().startswith(FUSION_MLP):
          model = functools.partial(
              MultimodalFusionMLP,
              prefix=model_name,
              hidden_features=model_config.hidden_sizes,
              num_classes=num_classes,
              adapt_in_features=model_config.adapt_in_features,
              activation=model_config.activation,
              dropout_prob=model_config.drop_rate,
              normalization=model_config.normalization,
              loss_weight=model_config.weight
              if hasattr(model_config, "weight")
              else None,
          )
      elif model_name.lower().startswith(FUSION_NER):
          model = functools.partial(
              MultimodalFusionNER,
              prefix=model_name,
              hidden_features=model_config.hidden_sizes,
              num_classes=num_classes,
              adapt_in_features=model_config.adapt_in_features,
              activation=model_config.activation,
              dropout_prob=model_config.drop_rate,
              normalization=model_config.normalization,
              loss_weight=model_config.weight
              if hasattr(model_config, "weight")
              else None,
          )
      elif model_name.lower().startswith(FUSION_TRANSFORMER):
          model = functools.partial(
              MultimodalFusionTransformer,
              prefix=model_name,
              hidden_features=model_config.hidden_size,
              num_classes=num_classes,
              n_blocks=model_config.n_blocks,
              attention_n_heads=model_config.attention_n_heads,
              ffn_d_hidden=model_config.ffn_d_hidden,
              attention_dropout=model_config.attention_dropout,
              residual_dropout=model_config.residual_dropout,
              ffn_dropout=model_config.ffn_dropout,
              attention_normalization=model_config.normalization,
              ffn_normalization=model_config.normalization,
              head_normalization=model_config.normalization,
              ffn_activation=model_config.ffn_activation,
              head_activation=model_config.head_activation,
              adapt_in_features=model_config.adapt_in_features,
              loss_weight=model_config.weight
              if hasattr(model_config, "weight")
              else None,
              additive_attention=OmegaConf.select(
                  model_config, "additive_attention", default=False
              ),
              share_qv_weights=OmegaConf.select(
                  model_config, "share_qv_weights", default=False
              ),
          )
      elif model_name.lower().startswith(FT_TRANSFORMER):
          model = FT_Transformer(
              prefix=model_name,
              num_numerical_columns=num_numerical_columns,
              num_categories=num_categories,
              embedding_arch=model_config.embedding_arch,
              token_dim=model_config.token_dim,
              hidden_size=model_config.hidden_size,
              hidden_features=model_config.hidden_size,
              num_classes=num_classes,
              num_blocks=model_config.num_blocks,
              attention_n_heads=model_config.attention_n_heads,
              attention_dropout=model_config.attention_dropout,
              attention_normalization=model_config.normalization,
              ffn_hidden_size=model_config.ffn_hidden_size,
              ffn_dropout=model_config.ffn_dropout,
              ffn_normalization=model_config.normalization,
              ffn_activation=model_config.ffn_activation,
              residual_dropout=model_config.residual_dropout,
              head_normalization=model_config.normalization,
              head_activation=model_config.head_activation,
              additive_attention=OmegaConf.select(
                  model_config, "additive_attention", default=False
              ),
              share_qv_weights=OmegaConf.select(
                  model_config, "share_qv_weights", default=False
              ),
              pooling_mode=OmegaConf.select(
                  model_config, "pooling_mode", default="cls"
              ),
          )
      elif model_name.lower().startswith(SAM):
          model = SAMForSemanticSegmentation(
              prefix=model_name,
              checkpoint_name=model_config.checkpoint_name,
              num_classes=num_classes,
              pretrained=pretrained,
              frozen_layers=OmegaConf.select(
                  model_config, "frozen_layers", default=None
              ),
              num_mask_tokens=OmegaConf.select(
                  model_config, "num_mask_tokens", default=1
              ),
          )
      else:
          raise ValueError(f"unknown model name: {model_name}")
  
      return model
  
file_path: autogluon/multimodal/src/autogluon/multimodal/utils/model.py
imports: import functools
  import json
  import logging
  import warnings
  from typing import Dict, List, Optional, Tuple, Union
  import timm
  from omegaconf import DictConfig, OmegaConf
  from torch import Tensor, nn
  from ..constants import ALL_MODALITIES, AUTOMM, CATEGORICAL, CATEGORICAL_MLP, CLIP, DOCUMENT, DOCUMENT_TRANSFORMER, FT_TRANSFORMER, FUSION_MLP, FUSION_NER, FUSION_TRANSFORMER, HF_TEXT, IMAGE, MMDET_IMAGE, MMOCR_TEXT_DET, MMOCR_TEXT_RECOG, NER, NER_TEXT, NUMERICAL, NUMERICAL_MLP, OVD, PEFT_ADDITIVE_STRATEGIES, SAM, SEMANTIC_SEGMENTATION_IMG, T_FEW, TEXT, TEXT_NER, TIMM_IMAGE, XYXY
  from ..data import MultiModalFeaturePreprocessor
  from ..models import CategoricalMLP, CLIPForImageText, DocumentTransformer, FT_Transformer, HFAutoModelForNER, HFAutoModelForTextPrediction, MMDetAutoModelForObjectDetection, MMOCRAutoModelForTextDetection, MMOCRAutoModelForTextRecognition, MultimodalFusionMLP, MultimodalFusionNER, MultimodalFusionTransformer, NumericalMLP, OVDModel, SAMForSemanticSegmentation, TFewModel, TimmAutoModelForImagePrediction
  from ..models.utils import inject_adaptation_to_linear_layer
label_desc: Use image node_id 2 for calling a global function with example usage: create_model(model_name, model_config, num_classes, classes, num_numerical_columns, num_categories, pretrained) and returns: model