code: def build_composite_models(config_class, output_dir):
      import tempfile
  
      from transformers import (
          BertConfig,
          BertLMHeadModel,
          BertModel,
          BertTokenizer,
          BertTokenizerFast,
          EncoderDecoderModel,
          GPT2Config,
          GPT2LMHeadModel,
          GPT2Tokenizer,
          GPT2TokenizerFast,
          SpeechEncoderDecoderModel,
          TFEncoderDecoderModel,
          TFVisionEncoderDecoderModel,
          TFVisionTextDualEncoderModel,
          VisionEncoderDecoderModel,
          VisionTextDualEncoderModel,
          ViTConfig,
          ViTFeatureExtractor,
          ViTModel,
          Wav2Vec2Config,
          Wav2Vec2Model,
          Wav2Vec2Processor,
      )
  
      # These will be removed at the end if they are empty
      result = {"error": None, "warnings": []}
  
      if config_class.model_type == "encoder-decoder":
          encoder_config_class = BertConfig
          decoder_config_class = BertConfig
          encoder_processor = (BertTokenizerFast, BertTokenizer)
          decoder_processor = (BertTokenizerFast, BertTokenizer)
          encoder_class = BertModel
          decoder_class = BertLMHeadModel
          model_class = EncoderDecoderModel
          tf_model_class = TFEncoderDecoderModel
      elif config_class.model_type == "vision-encoder-decoder":
          encoder_config_class = ViTConfig
          decoder_config_class = GPT2Config
          encoder_processor = (ViTFeatureExtractor,)
          decoder_processor = (GPT2TokenizerFast, GPT2Tokenizer)
          encoder_class = ViTModel
          decoder_class = GPT2LMHeadModel
          model_class = VisionEncoderDecoderModel
          tf_model_class = TFVisionEncoderDecoderModel
      elif config_class.model_type == "speech-encoder-decoder":
          encoder_config_class = Wav2Vec2Config
          decoder_config_class = BertConfig
          encoder_processor = (Wav2Vec2Processor,)
          decoder_processor = (BertTokenizerFast, BertTokenizer)
          encoder_class = Wav2Vec2Model
          decoder_class = BertLMHeadModel
          model_class = SpeechEncoderDecoderModel
          tf_model_class = None
      elif config_class.model_type == "vision-text-dual-encoder":
          # Not encoder-decoder, but encoder-encoder. We just keep the same name as above to make code easier
          encoder_config_class = ViTConfig
          decoder_config_class = BertConfig
          encoder_processor = (ViTFeatureExtractor,)
          decoder_processor = (BertTokenizerFast, BertTokenizer)
          encoder_class = ViTModel
          decoder_class = BertModel
          model_class = VisionTextDualEncoderModel
          tf_model_class = TFVisionTextDualEncoderModel
  
      with tempfile.TemporaryDirectory() as tmpdir:
          try:
              # build encoder
              models_to_create = {
                  "processor": encoder_processor,
                  "pytorch": (encoder_class,),
                  "tensorflow": [],
              }
              encoder_output_dir = os.path.join(tmpdir, "encoder")
              build(
                  encoder_config_class,
                  models_to_create,
                  encoder_output_dir,
              )
  
              # build decoder
              models_to_create = {
                  "processor": decoder_processor,
                  "pytorch": (decoder_class,),
                  "tensorflow": [],
              }
              decoder_output_dir = os.path.join(tmpdir, "decoder")
              build(
                  decoder_config_class,
                  models_to_create,
                  decoder_output_dir,
              )
  
              # build encoder-decoder
              encoder_path = os.path.join(
                  encoder_output_dir, encoder_class.__name__
              )
              decoder_path = os.path.join(
                  decoder_output_dir, decoder_class.__name__
              )
  
              if config_class.model_type != "vision-text-dual-encoder":
                  # Specify these explicitly for encoder-decoder like models, but not for `vision-text-dual-encoder` as it
                  # has no decoder.
                  decoder_config = decoder_config_class.from_pretrained(
                      decoder_path
                  )
                  decoder_config.is_decoder = True
                  decoder_config.add_cross_attention = True
                  model = model_class.from_encoder_decoder_pretrained(
                      encoder_path,
                      decoder_path,
                      decoder_config=decoder_config,
                  )
              elif (
                  config_class.model_type == "vision-text-dual-encoder"
              ):
                  model = model_class.from_vision_text_pretrained(
                      encoder_path, decoder_path
                  )
  
              model_path = os.path.join(
                  output_dir,
                  f"{model_class.__name__}-{encoder_config_class.model_type}-{decoder_config_class.model_type}",
              )
              model.save_pretrained(model_path)
  
              if tf_model_class is not None:
                  model = tf_model_class.from_pretrained(model_path)
                  model.save_pretrained(model_path)
  
              # copy the processors
              encoder_processor_path = os.path.join(
                  encoder_output_dir, "processors"
              )
              decoder_processor_path = os.path.join(
                  decoder_output_dir, "processors"
              )
              if os.path.isdir(encoder_processor_path):
                  shutil.copytree(
                      encoder_processor_path,
                      model_path,
                      dirs_exist_ok=True,
                  )
              if os.path.isdir(decoder_processor_path):
                  shutil.copytree(
                      decoder_processor_path,
                      model_path,
                      dirs_exist_ok=True,
                  )
  
              # fill `result`
              result["processor"] = {
                  x.__name__: x.__name__
                  for x in encoder_processor + decoder_processor
              }
  
              result["pytorch"] = {
                  model_class.__name__: {
                      "model": model_class.__name__,
                      "checkpoint": model_path,
                  }
              }
  
              result["tensorflow"] = {}
              if tf_model_class is not None:
                  result["tensorflow"] = {
                      tf_model_class.__name__: {
                          "model": tf_model_class.__name__,
                          "checkpoint": model_path,
                      }
                  }
          except Exception:
              result["error"] = (
                  f"Failed to build models for {config_class.__name__}.",
                  traceback.format_exc(),
              )
  
      if not result["error"]:
          del result["error"]
      if not result["warnings"]:
          del result["warnings"]
  
      return result
  
imports: import argparse
  import collections.abc
  import copy
  import inspect
  import json
  import multiprocessing
  import os
  import shutil
  import tempfile
  import traceback
  from pathlib import Path
  from check_config_docstrings import get_checkpoint_from_config_class
  from datasets import load_dataset
  from get_test_info import get_model_to_tester_mapping, get_tester_classes_for_model
  from huggingface_hub import Repository, create_repo, hf_api, upload_folder
  from transformers import CONFIG_MAPPING, FEATURE_EXTRACTOR_MAPPING, IMAGE_PROCESSOR_MAPPING, PROCESSOR_MAPPING, TOKENIZER_MAPPING, AutoTokenizer, LayoutLMv3TokenizerFast, PreTrainedTokenizer, PreTrainedTokenizerFast, logging
  from transformers.feature_extraction_utils import FeatureExtractionMixin
  from transformers.file_utils import is_tf_available, is_torch_available
  from transformers.image_processing_utils import BaseImageProcessor
  from transformers.models.auto.configuration_auto import AutoConfig, model_type_to_module_name
  from transformers.models.fsmt import configuration_fsmt
  from transformers.processing_utils import ProcessorMixin, transformers_module
  from transformers.tokenization_utils_base import PreTrainedTokenizerBase
label_desc: Use image node_id 13 for calling a global function with example usage: build_composite_models(config_class, output_dir) and returns: result