import argparse

import requests
import torch
from PIL import Image

from transformers import (
    CLIPSegConfig,
    CLIPSegForImageSegmentation,
    CLIPSegProcessor,
    CLIPSegTextConfig,
    CLIPSegVisionConfig,
    CLIPTokenizer,
    ViTImageProcessor,
)


def       a__      (					a							)		->	Optional[int]:
       A_							:       str	      =				CLIPSegTextConfig()
       A_							:       int	      =				CLIPSegVisionConfig(patch_size=1_6							)

       A_							:       Optional[int]	      =				True if '''refined''' in model_name else False
       A_							:       Optional[Any]	      =				1_6 if '''rd16''' in model_name else 6_4

       A_							:       Dict	      =				CLIPSegConfig.from_text_vision_configs(
           a  ,   a  ,   use_complex_transposed_convolution=a  ,   reduce_dim=a  ,   )
       return config


def       a__      (					a							)		->	Tuple:
       # update prefixes
       if "clip_model" in name:
              A_							:       Optional[Any]	      =				name.replace('''clip_model'''  ,   '''clip'''							)
       if "transformer" in name:
              if "visual" in name:
                     A_							:       List[Any]	      =				name.replace('''visual.transformer'''  ,   '''vision_model'''							)
              else:
                     A_							:       int	      =				name.replace('''transformer'''  ,   '''text_model'''							)
       if "resblocks" in name:
              A_							:       Any	      =				name.replace('''resblocks'''  ,   '''encoder.layers'''							)
       if "ln_1" in name:
              A_							:       List[Any]	      =				name.replace('''ln_1'''  ,   '''layer_norm1'''							)
       if "ln_2" in name:
              A_							:       List[str]	      =				name.replace('''ln_2'''  ,   '''layer_norm2'''							)
       if "c_fc" in name:
              A_							:       int	      =				name.replace('''c_fc'''  ,   '''fc1'''							)
       if "c_proj" in name:
              A_							:       List[str]	      =				name.replace('''c_proj'''  ,   '''fc2'''							)
       if "attn" in name and "self" not in name:
              A_							:       Dict	      =				name.replace('''attn'''  ,   '''self_attn'''							)
       # text encoder
       if "token_embedding" in name:
              A_							:       int	      =				name.replace('''token_embedding'''  ,   '''text_model.embeddings.token_embedding'''							)
       if "positional_embedding" in name and "visual" not in name:
              A_							:       Optional[int]	      =				name.replace('''positional_embedding'''  ,   '''text_model.embeddings.position_embedding.weight'''							)
       if "ln_final" in name:
              A_							:       str	      =				name.replace('''ln_final'''  ,   '''text_model.final_layer_norm'''							)
       # vision encoder
       if "visual.class_embedding" in name:
              A_							:       Union[str, Any]	      =				name.replace('''visual.class_embedding'''  ,   '''vision_model.embeddings.class_embedding'''							)
       if "visual.conv1" in name:
              A_							:       List[Any]	      =				name.replace('''visual.conv1'''  ,   '''vision_model.embeddings.patch_embedding'''							)
       if "visual.positional_embedding" in name:
              A_							:       List[Any]	      =				name.replace('''visual.positional_embedding'''  ,   '''vision_model.embeddings.position_embedding.weight'''							)
       if "visual.ln_pre" in name:
              A_							:       Any	      =				name.replace('''visual.ln_pre'''  ,   '''vision_model.pre_layrnorm'''							)
       if "visual.ln_post" in name:
              A_							:       str	      =				name.replace('''visual.ln_post'''  ,   '''vision_model.post_layernorm'''							)
       # projection layers
       if "visual.proj" in name:
              A_							:       List[str]	      =				name.replace('''visual.proj'''  ,   '''visual_projection.weight'''							)
       if "text_projection" in name:
              A_							:       List[Any]	      =				name.replace('''text_projection'''  ,   '''text_projection.weight'''							)
       # decoder
       if "trans_conv" in name:
              A_							:       str	      =				name.replace('''trans_conv'''  ,   '''transposed_convolution'''							)
       if "film_mul" in name or "film_add" in name or "reduce" in name or "transposed_convolution" in name:
              A_							:       List[Any]	      =				'''decoder.''' + name
       if "blocks" in name:
              A_							:       Any	      =				name.replace('''blocks'''  ,   '''decoder.layers'''							)
       if "linear1" in name:
              A_							:       int	      =				name.replace('''linear1'''  ,   '''mlp.fc1'''							)
       if "linear2" in name:
              A_							:       List[Any]	      =				name.replace('''linear2'''  ,   '''mlp.fc2'''							)
       if "norm1" in name and "layer_" not in name:
              A_							:       Union[str, Any]	      =				name.replace('''norm1'''  ,   '''layer_norm1'''							)
       if "norm2" in name and "layer_" not in name:
              A_							:       str	      =				name.replace('''norm2'''  ,   '''layer_norm2'''							)

       return name


def       a__      (					a  ,   a							)		->	str:
       for key in orig_state_dict.copy().keys():
              A_							:       Optional[Any]	      =				orig_state_dict.pop(a							)

              if key.startswith('''clip_model'''							) and "attn.in_proj" in key:
                     A_							:       List[str]	      =				key.split('''.'''							)
                     if "visual" in key:
                            A_							:       str	      =				int(key_split[4]							)
                            A_							:       Tuple	      =				config.vision_config.hidden_size
                            A_							:       List[Any]	      =				'''vision_model'''
                     else:
                            A_							:       int	      =				int(key_split[3]							)
                            A_							:       str	      =				config.text_config.hidden_size
                            A_							:       str	      =				'''text_model'''

                     if "weight" in key:
                            A_							:       str	      =				val[:dim, :]
                            A_							:       List[str]	      =				val[
                                dim : dim * 2, :
                            ]
                            A_							:       Any	      =				val[-dim:, :]
                     else:
                            A_							:       Optional[int]	      =				val[:dim]
                            A_							:       List[str]	      =				val[dim : dim * 2]
                            A_							:       str	      =				val[-dim:]
              elif "self_attn" in key and "out_proj" not in key:
                     A_							:       Any	      =				key.split('''.'''							)
                     A_							:       List[Any]	      =				int(key_split[1]							)
                     A_							:       Optional[int]	      =				config.reduce_dim
                     if "weight" in key:
                            A_							:       Dict	      =				val[:dim, :]
                            A_							:       List[str]	      =				val[dim : dim * 2, :]
                            A_							:       int	      =				val[-dim:, :]
                     else:
                            A_							:       List[str]	      =				val[:dim]
                            A_							:       str	      =				val[dim : dim * 2]
                            A_							:       Any	      =				val[-dim:]
              else:
                     A_							:       List[Any]	      =				rename_key(a							)
                     if "visual_projection" in new_name or "text_projection" in new_name:
                            A_							:       str	      =				val.T
                     A_							:       List[str]	      =				val

       return orig_state_dict


def       a__      (					)		->	int:
       A_							:       List[Any]	      =				'''http://images.cocodataset.org/val2017/000000039769.jpg'''
       A_							:       Union[str, Any]	      =				Image.open(requests.get(a  ,   stream=a							).raw							)
       return image


def       a__      (					a  ,   a  ,   a  ,   a							)		->	int:
       A_							:       Any	      =				get_clipseg_config(a							)
       A_							:       Tuple	      =				CLIPSegForImageSegmentation(a							)
       model.eval()

       A_							:       List[str]	      =				torch.load(a  ,   map_location='''cpu'''							)

       # remove some keys
       for key in state_dict.copy().keys():
              if key.startswith('''model'''							):
                     state_dict.pop(a  ,   a							)

    # rename some keys
       A_							:       List[str]	      =				convert_state_dict(a  ,   a							)
       A_      ,							A_							:       Any	      =				model.load_state_dict(a  ,   strict=a							)

       if missing_keys != ["clip.text_model.embeddings.position_ids", "clip.vision_model.embeddings.position_ids"]:
              raise ValueError('''Missing keys that are not expected: {}'''.format(a							)							)
       if unexpected_keys != ["decoder.reduce.weight", "decoder.reduce.bias"]:
              raise ValueError(f"""Unexpected keys: {unexpected_keys}"""							)

       A_							:       List[Any]	      =				ViTImageProcessor(size=3_5_2							)
       A_							:       int	      =				CLIPTokenizer.from_pretrained('''openai/clip-vit-base-patch32'''							)
       A_							:       List[str]	      =				CLIPSegProcessor(image_processor=a  ,   tokenizer=a							)

       A_							:       int	      =				prepare_img()
       A_							:       List[str]	      =				['''a glass''', '''something to fill''', '''wood''', '''a jar''']

       A_							:       int	      =				processor(text=a  ,   images=[image] * len(a							)  ,   padding='''max_length'''  ,   return_tensors='''pt'''							)

       with torch.no_grad():
              A_							:       Dict	      =				model(**a							)

       # verify values
       A_							:       str	      =				torch.tensor([0.1_1_1_0, -0.1_8_8_2, 0.1_6_4_5]							)
       A_							:       int	      =				torch.tensor([0.2_6_9_2, -0.7_1_9_7, -0.1_3_2_8]							)
       if model_name == "clipseg-rd64-refined":
              A_							:       Dict	      =				torch.tensor(
                  [[-1_0.0_4_0_7, -9.9_4_3_1, -1_0.2_6_4_6], [-9.9_7_5_1, -9.7_0_6_4, -9.9_5_8_6], [-9.6_8_9_1, -9.5_6_4_5, -9.9_6_1_8]]							)
       elif model_name == "clipseg-rd64":
              A_							:       Tuple	      =				torch.tensor(
                  [[-7.2_8_7_7, -7.2_7_1_1, -7.2_4_6_3], [-7.2_6_5_2, -7.2_7_8_0, -7.2_5_2_0], [-7.2_2_3_9, -7.2_2_0_4, -7.2_0_0_1]]							)
       elif model_name == "clipseg-rd16":
              A_							:       Union[str, Any]	      =				torch.tensor(
                  [[-6.3_9_5_5, -6.4_0_5_5, -6.4_1_5_1], [-6.3_9_1_1, -6.4_0_3_3, -6.4_1_0_0], [-6.3_4_7_4, -6.3_7_0_2, -6.3_7_6_2]]							)
       else:
              raise ValueError(f"""Model name {model_name} not supported."""							)

       assert torch.allclose(outputs.logits[0, :3, :3]  ,   a  ,   atol=1E-3							)
       assert torch.allclose(outputs.conditional_embeddings[0, :3]  ,   a  ,   atol=1E-3							)
       assert torch.allclose(outputs.pooled_output[0, :3]  ,   a  ,   atol=1E-3							)
       print('''Looks ok!'''							)

       if pytorch_dump_folder_path is not None:
              print(f"""Saving model and processor to {pytorch_dump_folder_path}"""							)
              model.save_pretrained(a							)
              processor.save_pretrained(a							)

       if push_to_hub:
              print(f"""Pushing model and processor for {model_name} to the hub"""							)
              model.push_to_hub(f"""CIDAS/{model_name}"""							)
              processor.push_to_hub(f"""CIDAS/{model_name}"""							)


if __name__ == "__main__":
    _lowerCAmelCase        =       argparse.ArgumentParser()
    # Required parameters
    parser.add_argument(
        '--model_name',
        default='clipseg-rd64',
        type=str,
        choices=['clipseg-rd16', 'clipseg-rd64', 'clipseg-rd64-refined'],
        help=(
            'Name of the model. Supported models are: clipseg-rd64, clipseg-rd16 and clipseg-rd64-refined (rd meaning'
            ' reduce dimension)'
        ),
    )
    parser.add_argument(
        '--checkpoint_path',
        default='/Users/nielsrogge/Documents/CLIPSeg/clip_plus_rd64-uni.pth',
        type=str,
        help=(
            'Path to the original checkpoint. Note that the script assumes that the checkpoint includes both CLIP and'
            ' the decoder weights.'
        ),
    )
    parser.add_argument(
        '--pytorch_dump_folder_path', default=None, type=str, help='Path to the output PyTorch model directory.'
    )
    parser.add_argument(
        '--push_to_hub', action='store_true', help='Whether or not to push the converted model to the 🤗 hub.'
    )

    _lowerCAmelCase        =       parser.parse_args()
    convert_clipseg_checkpoint(args.model_name, args.checkpoint_path, args.pytorch_dump_folder_path, args.push_to_hub)



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


_lowerCAmelCase        =       {
    'auto_factory': ['get_values'],
    'configuration_auto': ['ALL_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CONFIG_MAPPING', 'MODEL_NAMES_MAPPING', 'AutoConfig'],
    'feature_extraction_auto': ['FEATURE_EXTRACTOR_MAPPING', 'AutoFeatureExtractor'],
    'image_processing_auto': ['IMAGE_PROCESSOR_MAPPING', 'AutoImageProcessor'],
    'processing_auto': ['PROCESSOR_MAPPING', 'AutoProcessor'],
    'tokenization_auto': ['TOKENIZER_MAPPING', 'AutoTokenizer'],
}

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _lowerCAmelCase        =       [
        'MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING',
        'MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING',
        'MODEL_FOR_AUDIO_XVECTOR_MAPPING',
        'MODEL_FOR_BACKBONE_MAPPING',
        'MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING',
        'MODEL_FOR_CAUSAL_LM_MAPPING',
        'MODEL_FOR_CTC_MAPPING',
        'MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING',
        'MODEL_FOR_DEPTH_ESTIMATION_MAPPING',
        'MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING',
        'MODEL_FOR_IMAGE_SEGMENTATION_MAPPING',
        'MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING',
        'MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING',
        'MODEL_FOR_MASKED_LM_MAPPING',
        'MODEL_FOR_MASK_GENERATION_MAPPING',
        'MODEL_FOR_MULTIPLE_CHOICE_MAPPING',
        'MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING',
        'MODEL_FOR_OBJECT_DETECTION_MAPPING',
        'MODEL_FOR_PRETRAINING_MAPPING',
        'MODEL_FOR_QUESTION_ANSWERING_MAPPING',
        'MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING',
        'MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING',
        'MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING',
        'MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING',
        'MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING',
        'MODEL_FOR_TEXT_ENCODING_MAPPING',
        'MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING',
        'MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING',
        'MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING',
        'MODEL_FOR_VISION_2_SEQ_MAPPING',
        'MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING',
        'MODEL_MAPPING',
        'MODEL_WITH_LM_HEAD_MAPPING',
        'MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING',
        'MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING',
        'AutoModel',
        'AutoBackbone',
        'AutoModelForAudioClassification',
        'AutoModelForAudioFrameClassification',
        'AutoModelForAudioXVector',
        'AutoModelForCausalLM',
        'AutoModelForCTC',
        'AutoModelForDepthEstimation',
        'AutoModelForImageClassification',
        'AutoModelForImageSegmentation',
        'AutoModelForInstanceSegmentation',
        'AutoModelForMaskGeneration',
        'AutoModelForTextEncoding',
        'AutoModelForMaskedImageModeling',
        'AutoModelForMaskedLM',
        'AutoModelForMultipleChoice',
        'AutoModelForNextSentencePrediction',
        'AutoModelForObjectDetection',
        'AutoModelForPreTraining',
        'AutoModelForQuestionAnswering',
        'AutoModelForSemanticSegmentation',
        'AutoModelForSeq2SeqLM',
        'AutoModelForSequenceClassification',
        'AutoModelForSpeechSeq2Seq',
        'AutoModelForTableQuestionAnswering',
        'AutoModelForTokenClassification',
        'AutoModelForUniversalSegmentation',
        'AutoModelForVideoClassification',
        'AutoModelForVision2Seq',
        'AutoModelForVisualQuestionAnswering',
        'AutoModelForDocumentQuestionAnswering',
        'AutoModelWithLMHead',
        'AutoModelForZeroShotImageClassification',
        'AutoModelForZeroShotObjectDetection',
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _lowerCAmelCase        =       [
        'TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING',
        'TF_MODEL_FOR_CAUSAL_LM_MAPPING',
        'TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING',
        'TF_MODEL_FOR_MASK_GENERATION_MAPPING',
        'TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING',
        'TF_MODEL_FOR_MASKED_LM_MAPPING',
        'TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING',
        'TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING',
        'TF_MODEL_FOR_PRETRAINING_MAPPING',
        'TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING',
        'TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING',
        'TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING',
        'TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING',
        'TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING',
        'TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING',
        'TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING',
        'TF_MODEL_FOR_TEXT_ENCODING_MAPPING',
        'TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING',
        'TF_MODEL_FOR_VISION_2_SEQ_MAPPING',
        'TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING',
        'TF_MODEL_MAPPING',
        'TF_MODEL_WITH_LM_HEAD_MAPPING',
        'TFAutoModel',
        'TFAutoModelForAudioClassification',
        'TFAutoModelForCausalLM',
        'TFAutoModelForImageClassification',
        'TFAutoModelForMaskedImageModeling',
        'TFAutoModelForMaskedLM',
        'TFAutoModelForMaskGeneration',
        'TFAutoModelForMultipleChoice',
        'TFAutoModelForNextSentencePrediction',
        'TFAutoModelForPreTraining',
        'TFAutoModelForDocumentQuestionAnswering',
        'TFAutoModelForQuestionAnswering',
        'TFAutoModelForSemanticSegmentation',
        'TFAutoModelForSeq2SeqLM',
        'TFAutoModelForSequenceClassification',
        'TFAutoModelForSpeechSeq2Seq',
        'TFAutoModelForTableQuestionAnswering',
        'TFAutoModelForTextEncoding',
        'TFAutoModelForTokenClassification',
        'TFAutoModelForVision2Seq',
        'TFAutoModelForZeroShotImageClassification',
        'TFAutoModelWithLMHead',
    ]

try:
    if not is_flax_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _lowerCAmelCase        =       [
        'FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING',
        'FLAX_MODEL_FOR_CAUSAL_LM_MAPPING',
        'FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING',
        'FLAX_MODEL_FOR_MASKED_LM_MAPPING',
        'FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING',
        'FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING',
        'FLAX_MODEL_FOR_PRETRAINING_MAPPING',
        'FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING',
        'FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING',
        'FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING',
        'FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING',
        'FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING',
        'FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING',
        'FLAX_MODEL_MAPPING',
        'FlaxAutoModel',
        'FlaxAutoModelForCausalLM',
        'FlaxAutoModelForImageClassification',
        'FlaxAutoModelForMaskedLM',
        'FlaxAutoModelForMultipleChoice',
        'FlaxAutoModelForNextSentencePrediction',
        'FlaxAutoModelForPreTraining',
        'FlaxAutoModelForQuestionAnswering',
        'FlaxAutoModelForSeq2SeqLM',
        'FlaxAutoModelForSequenceClassification',
        'FlaxAutoModelForSpeechSeq2Seq',
        'FlaxAutoModelForTokenClassification',
        'FlaxAutoModelForVision2Seq',
    ]


if TYPE_CHECKING:
    from .auto_factory import get_values
    from .configuration_auto import ALL_PRETRAINED_CONFIG_ARCHIVE_MAP, CONFIG_MAPPING, MODEL_NAMES_MAPPING, AutoConfig
    from .feature_extraction_auto import FEATURE_EXTRACTOR_MAPPING, AutoFeatureExtractor
    from .image_processing_auto import IMAGE_PROCESSOR_MAPPING, AutoImageProcessor
    from .processing_auto import PROCESSOR_MAPPING, AutoProcessor
    from .tokenization_auto import TOKENIZER_MAPPING, AutoTokenizer

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_auto import (
            MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
            MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING,
            MODEL_FOR_AUDIO_XVECTOR_MAPPING,
            MODEL_FOR_BACKBONE_MAPPING,
            MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING,
            MODEL_FOR_CAUSAL_LM_MAPPING,
            MODEL_FOR_CTC_MAPPING,
            MODEL_FOR_DEPTH_ESTIMATION_MAPPING,
            MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING,
            MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
            MODEL_FOR_IMAGE_SEGMENTATION_MAPPING,
            MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING,
            MODEL_FOR_MASK_GENERATION_MAPPING,
            MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING,
            MODEL_FOR_MASKED_LM_MAPPING,
            MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
            MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING,
            MODEL_FOR_OBJECT_DETECTION_MAPPING,
            MODEL_FOR_PRETRAINING_MAPPING,
            MODEL_FOR_QUESTION_ANSWERING_MAPPING,
            MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING,
            MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
            MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
            MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING,
            MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
            MODEL_FOR_TEXT_ENCODING_MAPPING,
            MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
            MODEL_FOR_UNIVERSAL_SEGMENTATION_MAPPING,
            MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING,
            MODEL_FOR_VISION_2_SEQ_MAPPING,
            MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING,
            MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING,
            MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING,
            MODEL_MAPPING,
            MODEL_WITH_LM_HEAD_MAPPING,
            AutoBackbone,
            AutoModel,
            AutoModelForAudioClassification,
            AutoModelForAudioFrameClassification,
            AutoModelForAudioXVector,
            AutoModelForCausalLM,
            AutoModelForCTC,
            AutoModelForDepthEstimation,
            AutoModelForDocumentQuestionAnswering,
            AutoModelForImageClassification,
            AutoModelForImageSegmentation,
            AutoModelForInstanceSegmentation,
            AutoModelForMaskedImageModeling,
            AutoModelForMaskedLM,
            AutoModelForMaskGeneration,
            AutoModelForMultipleChoice,
            AutoModelForNextSentencePrediction,
            AutoModelForObjectDetection,
            AutoModelForPreTraining,
            AutoModelForQuestionAnswering,
            AutoModelForSemanticSegmentation,
            AutoModelForSeqaSeqLM,
            AutoModelForSequenceClassification,
            AutoModelForSpeechSeqaSeq,
            AutoModelForTableQuestionAnswering,
            AutoModelForTextEncoding,
            AutoModelForTokenClassification,
            AutoModelForUniversalSegmentation,
            AutoModelForVideoClassification,
            AutoModelForVisionaSeq,
            AutoModelForVisualQuestionAnswering,
            AutoModelForZeroShotImageClassification,
            AutoModelForZeroShotObjectDetection,
            AutoModelWithLMHead,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_auto import (
            TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
            TF_MODEL_FOR_CAUSAL_LM_MAPPING,
            TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING,
            TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
            TF_MODEL_FOR_MASK_GENERATION_MAPPING,
            TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING,
            TF_MODEL_FOR_MASKED_LM_MAPPING,
            TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
            TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING,
            TF_MODEL_FOR_PRETRAINING_MAPPING,
            TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
            TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING,
            TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
            TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
            TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING,
            TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
            TF_MODEL_FOR_TEXT_ENCODING_MAPPING,
            TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
            TF_MODEL_FOR_VISION_2_SEQ_MAPPING,
            TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING,
            TF_MODEL_MAPPING,
            TF_MODEL_WITH_LM_HEAD_MAPPING,
            TFAutoModel,
            TFAutoModelForAudioClassification,
            TFAutoModelForCausalLM,
            TFAutoModelForDocumentQuestionAnswering,
            TFAutoModelForImageClassification,
            TFAutoModelForMaskedImageModeling,
            TFAutoModelForMaskedLM,
            TFAutoModelForMaskGeneration,
            TFAutoModelForMultipleChoice,
            TFAutoModelForNextSentencePrediction,
            TFAutoModelForPreTraining,
            TFAutoModelForQuestionAnswering,
            TFAutoModelForSemanticSegmentation,
            TFAutoModelForSeqaSeqLM,
            TFAutoModelForSequenceClassification,
            TFAutoModelForSpeechSeqaSeq,
            TFAutoModelForTableQuestionAnswering,
            TFAutoModelForTextEncoding,
            TFAutoModelForTokenClassification,
            TFAutoModelForVisionaSeq,
            TFAutoModelForZeroShotImageClassification,
            TFAutoModelWithLMHead,
        )

    try:
        if not is_flax_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_flax_auto import (
            FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
            FLAX_MODEL_FOR_CAUSAL_LM_MAPPING,
            FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
            FLAX_MODEL_FOR_MASKED_LM_MAPPING,
            FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
            FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING,
            FLAX_MODEL_FOR_PRETRAINING_MAPPING,
            FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
            FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
            FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
            FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING,
            FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
            FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING,
            FLAX_MODEL_MAPPING,
            FlaxAutoModel,
            FlaxAutoModelForCausalLM,
            FlaxAutoModelForImageClassification,
            FlaxAutoModelForMaskedLM,
            FlaxAutoModelForMultipleChoice,
            FlaxAutoModelForNextSentencePrediction,
            FlaxAutoModelForPreTraining,
            FlaxAutoModelForQuestionAnswering,
            FlaxAutoModelForSeqaSeqLM,
            FlaxAutoModelForSequenceClassification,
            FlaxAutoModelForSpeechSeqaSeq,
            FlaxAutoModelForTokenClassification,
            FlaxAutoModelForVisionaSeq,
        )

else:
    import sys

    _lowerCAmelCase        =       _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


