



from collections import OrderedDict

from ...utils import logging
from .auto_factory import _BaseAutoModelClass, _LazyAutoMapping, auto_class_update
from .configuration_auto import CONFIG_MAPPING_NAMES


A__								=						logging.get_logger(__name__)


A__								=						OrderedDict(
    [
        # Base model mapping
        ('''albert''', '''FlaxAlbertModel'''),
        ('''bart''', '''FlaxBartModel'''),
        ('''beit''', '''FlaxBeitModel'''),
        ('''bert''', '''FlaxBertModel'''),
        ('''big_bird''', '''FlaxBigBirdModel'''),
        ('''blenderbot''', '''FlaxBlenderbotModel'''),
        ('''blenderbot-small''', '''FlaxBlenderbotSmallModel'''),
        ('''clip''', '''FlaxCLIPModel'''),
        ('''distilbert''', '''FlaxDistilBertModel'''),
        ('''electra''', '''FlaxElectraModel'''),
        ('''gpt-sw3''', '''FlaxGPT2Model'''),
        ('''gpt2''', '''FlaxGPT2Model'''),
        ('''gpt_neo''', '''FlaxGPTNeoModel'''),
        ('''gptj''', '''FlaxGPTJModel'''),
        ('''longt5''', '''FlaxLongT5Model'''),
        ('''marian''', '''FlaxMarianModel'''),
        ('''mbart''', '''FlaxMBartModel'''),
        ('''mt5''', '''FlaxMT5Model'''),
        ('''opt''', '''FlaxOPTModel'''),
        ('''pegasus''', '''FlaxPegasusModel'''),
        ('''regnet''', '''FlaxRegNetModel'''),
        ('''resnet''', '''FlaxResNetModel'''),
        ('''roberta''', '''FlaxRobertaModel'''),
        ('''roberta-prelayernorm''', '''FlaxRobertaPreLayerNormModel'''),
        ('''roformer''', '''FlaxRoFormerModel'''),
        ('''t5''', '''FlaxT5Model'''),
        ('''vision-text-dual-encoder''', '''FlaxVisionTextDualEncoderModel'''),
        ('''vit''', '''FlaxViTModel'''),
        ('''wav2vec2''', '''FlaxWav2Vec2Model'''),
        ('''whisper''', '''FlaxWhisperModel'''),
        ('''xglm''', '''FlaxXGLMModel'''),
        ('''xlm-roberta''', '''FlaxXLMRobertaModel'''),
    ]
)

A__								=						OrderedDict(
    [
        # Model for pre-training mapping
        ('''albert''', '''FlaxAlbertForPreTraining'''),
        ('''bart''', '''FlaxBartForConditionalGeneration'''),
        ('''bert''', '''FlaxBertForPreTraining'''),
        ('''big_bird''', '''FlaxBigBirdForPreTraining'''),
        ('''electra''', '''FlaxElectraForPreTraining'''),
        ('''longt5''', '''FlaxLongT5ForConditionalGeneration'''),
        ('''mbart''', '''FlaxMBartForConditionalGeneration'''),
        ('''mt5''', '''FlaxMT5ForConditionalGeneration'''),
        ('''roberta''', '''FlaxRobertaForMaskedLM'''),
        ('''roberta-prelayernorm''', '''FlaxRobertaPreLayerNormForMaskedLM'''),
        ('''roformer''', '''FlaxRoFormerForMaskedLM'''),
        ('''t5''', '''FlaxT5ForConditionalGeneration'''),
        ('''wav2vec2''', '''FlaxWav2Vec2ForPreTraining'''),
        ('''whisper''', '''FlaxWhisperForConditionalGeneration'''),
        ('''xlm-roberta''', '''FlaxXLMRobertaForMaskedLM'''),
    ]
)

A__								=						OrderedDict(
    [
        # Model for Masked LM mapping
        ('''albert''', '''FlaxAlbertForMaskedLM'''),
        ('''bart''', '''FlaxBartForConditionalGeneration'''),
        ('''bert''', '''FlaxBertForMaskedLM'''),
        ('''big_bird''', '''FlaxBigBirdForMaskedLM'''),
        ('''distilbert''', '''FlaxDistilBertForMaskedLM'''),
        ('''electra''', '''FlaxElectraForMaskedLM'''),
        ('''mbart''', '''FlaxMBartForConditionalGeneration'''),
        ('''roberta''', '''FlaxRobertaForMaskedLM'''),
        ('''roberta-prelayernorm''', '''FlaxRobertaPreLayerNormForMaskedLM'''),
        ('''roformer''', '''FlaxRoFormerForMaskedLM'''),
        ('''xlm-roberta''', '''FlaxXLMRobertaForMaskedLM'''),
    ]
)

A__								=						OrderedDict(
    [
        # Model for Seq2Seq Causal LM mapping
        ('''bart''', '''FlaxBartForConditionalGeneration'''),
        ('''blenderbot''', '''FlaxBlenderbotForConditionalGeneration'''),
        ('''blenderbot-small''', '''FlaxBlenderbotSmallForConditionalGeneration'''),
        ('''encoder-decoder''', '''FlaxEncoderDecoderModel'''),
        ('''longt5''', '''FlaxLongT5ForConditionalGeneration'''),
        ('''marian''', '''FlaxMarianMTModel'''),
        ('''mbart''', '''FlaxMBartForConditionalGeneration'''),
        ('''mt5''', '''FlaxMT5ForConditionalGeneration'''),
        ('''pegasus''', '''FlaxPegasusForConditionalGeneration'''),
        ('''t5''', '''FlaxT5ForConditionalGeneration'''),
    ]
)

A__								=						OrderedDict(
    [
        # Model for Image-classsification
        ('''beit''', '''FlaxBeitForImageClassification'''),
        ('''regnet''', '''FlaxRegNetForImageClassification'''),
        ('''resnet''', '''FlaxResNetForImageClassification'''),
        ('''vit''', '''FlaxViTForImageClassification'''),
    ]
)

A__								=						OrderedDict(
    [
        ('''vision-encoder-decoder''', '''FlaxVisionEncoderDecoderModel'''),
    ]
)

A__								=						OrderedDict(
    [
        # Model for Causal LM mapping
        ('''bart''', '''FlaxBartForCausalLM'''),
        ('''bert''', '''FlaxBertForCausalLM'''),
        ('''big_bird''', '''FlaxBigBirdForCausalLM'''),
        ('''electra''', '''FlaxElectraForCausalLM'''),
        ('''gpt-sw3''', '''FlaxGPT2LMHeadModel'''),
        ('''gpt2''', '''FlaxGPT2LMHeadModel'''),
        ('''gpt_neo''', '''FlaxGPTNeoForCausalLM'''),
        ('''gptj''', '''FlaxGPTJForCausalLM'''),
        ('''opt''', '''FlaxOPTForCausalLM'''),
        ('''roberta''', '''FlaxRobertaForCausalLM'''),
        ('''roberta-prelayernorm''', '''FlaxRobertaPreLayerNormForCausalLM'''),
        ('''xglm''', '''FlaxXGLMForCausalLM'''),
        ('''xlm-roberta''', '''FlaxXLMRobertaForCausalLM'''),
    ]
)

A__								=						OrderedDict(
    [
        # Model for Sequence Classification mapping
        ('''albert''', '''FlaxAlbertForSequenceClassification'''),
        ('''bart''', '''FlaxBartForSequenceClassification'''),
        ('''bert''', '''FlaxBertForSequenceClassification'''),
        ('''big_bird''', '''FlaxBigBirdForSequenceClassification'''),
        ('''distilbert''', '''FlaxDistilBertForSequenceClassification'''),
        ('''electra''', '''FlaxElectraForSequenceClassification'''),
        ('''mbart''', '''FlaxMBartForSequenceClassification'''),
        ('''roberta''', '''FlaxRobertaForSequenceClassification'''),
        ('''roberta-prelayernorm''', '''FlaxRobertaPreLayerNormForSequenceClassification'''),
        ('''roformer''', '''FlaxRoFormerForSequenceClassification'''),
        ('''xlm-roberta''', '''FlaxXLMRobertaForSequenceClassification'''),
    ]
)

A__								=						OrderedDict(
    [
        # Model for Question Answering mapping
        ('''albert''', '''FlaxAlbertForQuestionAnswering'''),
        ('''bart''', '''FlaxBartForQuestionAnswering'''),
        ('''bert''', '''FlaxBertForQuestionAnswering'''),
        ('''big_bird''', '''FlaxBigBirdForQuestionAnswering'''),
        ('''distilbert''', '''FlaxDistilBertForQuestionAnswering'''),
        ('''electra''', '''FlaxElectraForQuestionAnswering'''),
        ('''mbart''', '''FlaxMBartForQuestionAnswering'''),
        ('''roberta''', '''FlaxRobertaForQuestionAnswering'''),
        ('''roberta-prelayernorm''', '''FlaxRobertaPreLayerNormForQuestionAnswering'''),
        ('''roformer''', '''FlaxRoFormerForQuestionAnswering'''),
        ('''xlm-roberta''', '''FlaxXLMRobertaForQuestionAnswering'''),
    ]
)

A__								=						OrderedDict(
    [
        # Model for Token Classification mapping
        ('''albert''', '''FlaxAlbertForTokenClassification'''),
        ('''bert''', '''FlaxBertForTokenClassification'''),
        ('''big_bird''', '''FlaxBigBirdForTokenClassification'''),
        ('''distilbert''', '''FlaxDistilBertForTokenClassification'''),
        ('''electra''', '''FlaxElectraForTokenClassification'''),
        ('''roberta''', '''FlaxRobertaForTokenClassification'''),
        ('''roberta-prelayernorm''', '''FlaxRobertaPreLayerNormForTokenClassification'''),
        ('''roformer''', '''FlaxRoFormerForTokenClassification'''),
        ('''xlm-roberta''', '''FlaxXLMRobertaForTokenClassification'''),
    ]
)

A__								=						OrderedDict(
    [
        # Model for Multiple Choice mapping
        ('''albert''', '''FlaxAlbertForMultipleChoice'''),
        ('''bert''', '''FlaxBertForMultipleChoice'''),
        ('''big_bird''', '''FlaxBigBirdForMultipleChoice'''),
        ('''distilbert''', '''FlaxDistilBertForMultipleChoice'''),
        ('''electra''', '''FlaxElectraForMultipleChoice'''),
        ('''roberta''', '''FlaxRobertaForMultipleChoice'''),
        ('''roberta-prelayernorm''', '''FlaxRobertaPreLayerNormForMultipleChoice'''),
        ('''roformer''', '''FlaxRoFormerForMultipleChoice'''),
        ('''xlm-roberta''', '''FlaxXLMRobertaForMultipleChoice'''),
    ]
)

A__								=						OrderedDict(
    [
        ('''bert''', '''FlaxBertForNextSentencePrediction'''),
    ]
)

A__								=						OrderedDict(
    [
        ('''speech-encoder-decoder''', '''FlaxSpeechEncoderDecoderModel'''),
        ('''whisper''', '''FlaxWhisperForConditionalGeneration'''),
    ]
)

A__								=						OrderedDict(
    [
        ('''whisper''', '''FlaxWhisperForAudioClassification'''),
    ]
)

A__								=						_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_MAPPING_NAMES)
A__								=						_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_PRETRAINING_MAPPING_NAMES)
A__								=						_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MASKED_LM_MAPPING_NAMES)
A__								=						_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES
)
A__								=						_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES
)
A__								=						_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES)
A__								=						_LazyAutoMapping(CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_CAUSAL_LM_MAPPING_NAMES)
A__								=						_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES
)
A__								=						_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES
)
A__								=						_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES
)
A__								=						_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES
)
A__								=						_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES
)
A__								=						_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES
)
A__								=						_LazyAutoMapping(
    CONFIG_MAPPING_NAMES, FLAX_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES
)


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    List[Any]											=					FLAX_MODEL_MAPPING

A__								=						auto_class_update(FlaxAutoModel)


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Any											=					FLAX_MODEL_FOR_PRETRAINING_MAPPING

A__								=						auto_class_update(FlaxAutoModelForPreTraining, head_doc='''pretraining''')


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    List[Any]											=					FLAX_MODEL_FOR_CAUSAL_LM_MAPPING

A__								=						auto_class_update(FlaxAutoModelForCausalLM, head_doc='''causal language modeling''')


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Optional[Any]											=					FLAX_MODEL_FOR_MASKED_LM_MAPPING

A__								=						auto_class_update(FlaxAutoModelForMaskedLM, head_doc='''masked language modeling''')


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Tuple											=					FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

A__								=						auto_class_update(
    FlaxAutoModelForSeqaSeqLM, head_doc='''sequence-to-sequence language modeling''', checkpoint_for_example='''t5-base'''
)


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Tuple											=					FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

A__								=						auto_class_update(
    FlaxAutoModelForSequenceClassification, head_doc='''sequence classification'''
)


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Tuple											=					FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING

A__								=						auto_class_update(FlaxAutoModelForQuestionAnswering, head_doc='''question answering''')


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    List[str]											=					FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING

A__								=						auto_class_update(
    FlaxAutoModelForTokenClassification, head_doc='''token classification'''
)


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Dict											=					FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING

A__								=						auto_class_update(FlaxAutoModelForMultipleChoice, head_doc='''multiple choice''')


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Optional[int]											=					FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING

A__								=						auto_class_update(
    FlaxAutoModelForNextSentencePrediction, head_doc='''next sentence prediction'''
)


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Dict											=					FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING

A__								=						auto_class_update(
    FlaxAutoModelForImageClassification, head_doc='''image classification'''
)


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Optional[Any]											=					FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING

A__								=						auto_class_update(FlaxAutoModelForVisionaSeq, head_doc='''vision-to-text modeling''')


class       a							(			_BaseAutoModelClass				):
		__lowerCAmelCase	:    Optional[int]											=					FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING

A__								=						auto_class_update(
    FlaxAutoModelForSpeechSeqaSeq, head_doc='''sequence-to-sequence speech-to-text modeling'''
)





import copy
from typing import Dict, List, Optional

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


UpperCAmelCase_      : Optional[int]  					=       {
    'facebook/mask2former-swin-small-coco-instance': (
        'https://huggingface.co/facebook/mask2former-swin-small-coco-instance/blob/main/config.json'
    )
    # See all Mask2Former models at https://huggingface.co/models?filter=mask2former
}

UpperCAmelCase_      : List[str]  					=       logging.get_logger(__name__)
class  SCREAMING_SNAKE_CASE__  (				lowercase__			):
      snake_case__				:     Any        =						'''mask2former'''
      snake_case__				:     Any        =						['''swin''']
      snake_case__				:     str        =						{'''hidden_size''': '''hidden_dim'''}
      def __init__(       self				:       Any     ,							SCREAMING_SNAKE_CASE__				:       Optional[Dict] = None     ,							SCREAMING_SNAKE_CASE__				:       int = 2_5_6     ,							SCREAMING_SNAKE_CASE__				:       int = 2_5_6     ,							SCREAMING_SNAKE_CASE__				:       int = 2_5_6     ,							SCREAMING_SNAKE_CASE__				:       int = 1_0_2_4     ,							SCREAMING_SNAKE_CASE__				:       str = "relu"     ,							SCREAMING_SNAKE_CASE__				:       int = 6     ,							SCREAMING_SNAKE_CASE__				:       int = 1_0     ,							SCREAMING_SNAKE_CASE__				:       int = 8     ,							SCREAMING_SNAKE_CASE__				:       float = 0.0     ,							SCREAMING_SNAKE_CASE__				:       int = 2_0_4_8     ,							SCREAMING_SNAKE_CASE__				:       bool = False     ,							SCREAMING_SNAKE_CASE__				:       bool = False     ,							SCREAMING_SNAKE_CASE__				:       int = 4     ,							SCREAMING_SNAKE_CASE__				:       int = 2_5_5     ,							SCREAMING_SNAKE_CASE__				:       int = 1_0_0     ,							SCREAMING_SNAKE_CASE__				:       float = 0.1     ,							SCREAMING_SNAKE_CASE__				:       float = 2.0     ,							SCREAMING_SNAKE_CASE__				:       float = 5.0     ,							SCREAMING_SNAKE_CASE__				:       float = 5.0     ,							SCREAMING_SNAKE_CASE__				:       int = 1_2_5_4_4     ,							SCREAMING_SNAKE_CASE__				:       float = 3.0     ,							SCREAMING_SNAKE_CASE__				:       float = 0.75     ,							SCREAMING_SNAKE_CASE__				:       float = 0.02     ,							SCREAMING_SNAKE_CASE__				:       float = 1.0     ,							SCREAMING_SNAKE_CASE__				:       bool = True     ,							SCREAMING_SNAKE_CASE__				:       List[int] = [4, 8, 1_6, 3_2]     ,							SCREAMING_SNAKE_CASE__				:       bool = None     ,							**SCREAMING_SNAKE_CASE__				:       int     ,							)		->			List[Any]:
             if backbone_config is None:
                    logger.info('`backbone_config` is `None`. Initializing the config with the default `Swin` backbone.'     )
                    a_					:		Dict							=  CONFIG_MAPPING['swin'](
                        image_size=2_2_4     ,							in_channels=3     ,							patch_size=4     ,							embed_dim=9_6     ,							depths=[2, 2, 1_8, 2]     ,							num_heads=[3, 6, 1_2, 2_4]     ,							window_size=7     ,							drop_path_rate=0.3     ,							use_absolute_embeddings=SCREAMING_SNAKE_CASE__     ,							out_features=['stage1', 'stage2', 'stage3', 'stage4']     ,							)

             if isinstance(SCREAMING_SNAKE_CASE__     ,							SCREAMING_SNAKE_CASE__     ):
                    a_					:		Any							=  backbone_config.pop('model_type'     )
                    a_					:		Optional[Any]							=  CONFIG_MAPPING[backbone_model_type]
                    a_					:		List[str]							=  config_class.from_dict(SCREAMING_SNAKE_CASE__     )

             # verify that the backbone is supported
             if backbone_config.model_type not in self.backbones_supported:
                    logger.warning_once(
                        F"""Backbone {backbone_config.model_type} is not a supported model and may not be compatible with Mask2Former. """
                        F"""Supported model types: {",".join(self.backbones_supported     )}"""     )

             a_					:		Dict							=  backbone_config
             a_					:		List[str]							=  feature_size
             a_					:		List[str]							=  mask_feature_size
             a_					:		int							=  hidden_dim
             a_					:		Dict							=  encoder_feedforward_dim
             a_					:		str							=  activation_function
             a_					:		List[str]							=  encoder_layers
             a_					:		List[str]							=  decoder_layers
             a_					:		Dict							=  num_attention_heads
             a_					:		str							=  dropout
             a_					:		Tuple							=  dim_feedforward
             a_					:		List[str]							=  pre_norm
             a_					:		Optional[int]							=  enforce_input_projection
             a_					:		Any							=  common_stride
             a_					:		Optional[int]							=  ignore_value
             a_					:		int							=  num_queries
             a_					:		Tuple							=  no_object_weight
             a_					:		Dict							=  class_weight
             a_					:		Optional[int]							=  mask_weight
             a_					:		Optional[int]							=  dice_weight
             a_					:		str							=  train_num_points
             a_					:		List[str]							=  oversample_ratio
             a_					:		List[Any]							=  importance_sample_ratio
             a_					:		Any							=  init_std
             a_					:		Union[str, Any]							=  init_xavier_std
             a_					:		Union[str, Any]							=  use_auxiliary_loss
             a_					:		Dict							=  feature_strides
             a_					:		List[str]							=  output_auxiliary_logits
             a_					:		Dict							=  decoder_layers

             super().__init__(**SCREAMING_SNAKE_CASE__     )
      @classmethod
      def        SCREAMING_SNAKE_CASE							(       cls				:       str     ,							SCREAMING_SNAKE_CASE__				:       PretrainedConfig     ,							**SCREAMING_SNAKE_CASE__				:       Union[str, Any]     )		->			List[Any]:
             return cls(
                 backbone_config=SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     ,							)

      def        SCREAMING_SNAKE_CASE							(       self				:       Tuple     )		->			Dict[str, any]:
             a_					:		Optional[int]							=  copy.deepcopy(self.__dict__     )
             a_					:		List[Any]							=  self.backbone_config.to_dict()
             a_					:		Optional[Any]							=  self.__class__.model_type
             return output


