





from collections import OrderedDict

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


UpperCAmelCase_     							= logging.get_logger(__name__)


UpperCAmelCase_     							= 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'),
    ]
)

UpperCAmelCase_     							= 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'),
    ]
)

UpperCAmelCase_     							= 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'),
    ]
)

UpperCAmelCase_     							= 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'),
    ]
)

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

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

UpperCAmelCase_     							= 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'),
    ]
)

UpperCAmelCase_     							= 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'),
    ]
)

UpperCAmelCase_     							= 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'),
    ]
)

UpperCAmelCase_     							= 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'),
    ]
)

UpperCAmelCase_     							= 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'),
    ]
)

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

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

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

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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							List[str]   		=		FLAX_MODEL_MAPPING




UpperCAmelCase_     							= auto_class_update(FlaxAutoModel)






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							List[Any]   		=		FLAX_MODEL_FOR_PRETRAINING_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							Union[str, Any]   		=		FLAX_MODEL_FOR_CAUSAL_LM_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							Union[str, Any]   		=		FLAX_MODEL_FOR_MASKED_LM_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							str   		=		FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							int   		=		FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							List[str]   		=		FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							Optional[Any]   		=		FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							Optional[Any]   		=		FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							Union[str, Any]   		=		FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							Dict   		=		FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							Union[str, Any]   		=		FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING




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






class     lowercase__       (	_BaseAutoModelClass				):

   '''simple docstring'''


   a						:							int   		=		FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING




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








from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


UpperCAmelCase_     							= logging.get_logger(__name__)






class     lowercase__       (	__lowerCamelCase				):

   '''simple docstring'''


   a						:							str   		=		["pixel_values"]




   def __init__(    self,		__magic_name__ = True,		__magic_name__ = 32,		__magic_name__=PILImageResampling.BILINEAR,		__magic_name__ = True,		**__magic_name__,		) ->      None:






       """simple docstring"""
       UpperCamelCase__							:				int          =      do_resize
       UpperCamelCase__							:				Tuple          =      do_rescale
       UpperCamelCase__							:				Any          =      size_divisor
       UpperCamelCase__							:				List[Any]          =      resample
       super().__init__(**__magic_name__							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__,		__magic_name__ = None,		**__magic_name__							) ->      np.ndarray:






       """simple docstring"""
       UpperCamelCase__   ,UpperCamelCase__							:				List[Any]          =      get_image_size(__magic_name__							)
       # Rounds the height and width down to the closest multiple of size_divisor
       UpperCamelCase__							:				Any          =      height // size_divisor * size_divisor
       UpperCamelCase__							:				Optional[int]          =      width // size_divisor * size_divisor
       UpperCamelCase__							:				str          =      resize(__magic_name__,		(new_h, new_w),		resample=__magic_name__,		data_format=__magic_name__,		**__magic_name__							)
       return image




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__,		__magic_name__ = None,		**__magic_name__							) ->      np.ndarray:






       """simple docstring"""
       return rescale(image=__magic_name__,		scale=__magic_name__,		data_format=__magic_name__,		**__magic_name__							)




   def       UpperCamelCase__  (    self,		__magic_name__,		__magic_name__ = None,		__magic_name__ = None,		__magic_name__=None,		__magic_name__ = None,		__magic_name__ = None,		__magic_name__ = ChannelDimension.FIRST,		**__magic_name__,		) ->      BatchFeature:






       """simple docstring"""
       UpperCamelCase__							:				str          =      do_resize if do_resize is not None else self.do_resize
       UpperCamelCase__							:				Union[str, Any]          =      do_rescale if do_rescale is not None else self.do_rescale
       UpperCamelCase__							:				Any          =      size_divisor if size_divisor is not None else self.size_divisor
       UpperCamelCase__							:				str          =      resample if resample is not None else self.resample

       if do_resize and size_divisor is None:
           raise ValueError('''size_divisor is required for resizing'''							)

       UpperCamelCase__							:				Union[str, Any]          =      make_list_of_images(__magic_name__							)

       if not valid_images(__magic_name__							):
           raise ValueError('''Invalid image(s)'''							)

       # All transformations expect numpy arrays.
       UpperCamelCase__							:				Optional[Any]          =      [to_numpy_array(__magic_name__							) for img in images]

       if do_resize:
           UpperCamelCase__							:				str          =      [self.resize(__magic_name__,		size_divisor=__magic_name__,		resample=__magic_name__							) for image in images]

       if do_rescale:
           UpperCamelCase__							:				List[Any]          =      [self.rescale(__magic_name__,		scale=1 / 255							) for image in images]

       UpperCamelCase__							:				Optional[Any]          =      [to_channel_dimension_format(__magic_name__,		__magic_name__							) for image in images]

       UpperCamelCase__							:				Tuple          =      {'''pixel_values''': images}
       return BatchFeature(data=__magic_name__,		tensor_type=__magic_name__							)

