





'''simple docstring'''






from collections import OrderedDict

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


snake_case_     =	logging.get_logger(__name__)


snake_case_     =	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"""),
    ]
)

snake_case_     =	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"""),
    ]
)

snake_case_     =	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"""),
    ]
)

snake_case_     =	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"""),
    ]
)

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

snake_case_     =	OrderedDict(
    [
        ("""vision-encoder-decoder""", """FlaxVisionEncoderDecoderModel"""),
    ]
)

snake_case_     =	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"""),
    ]
)

snake_case_     =	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"""),
    ]
)

snake_case_     =	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"""),
    ]
)

snake_case_     =	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"""),
    ]
)

snake_case_     =	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"""),
    ]
)

snake_case_     =	OrderedDict(
    [
        ("""bert""", """FlaxBertForNextSentencePrediction"""),
    ]
)

snake_case_     =	OrderedDict(
    [
        ("""speech-encoder-decoder""", """FlaxSpeechEncoderDecoderModel"""),
        ("""whisper""", """FlaxWhisperForConditionalGeneration"""),
    ]
)

snake_case_     =	OrderedDict(
    [
        ("""whisper""", """FlaxWhisperForAudioClassification"""),
    ]
)

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


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_MAPPING







snake_case_     =	auto_class_update(FlaxAutoModel)


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_PRETRAINING_MAPPING







snake_case_     =	auto_class_update(FlaxAutoModelForPreTraining, head_doc="""pretraining""")


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_CAUSAL_LM_MAPPING







snake_case_     =	auto_class_update(FlaxAutoModelForCausalLM, head_doc="""causal language modeling""")


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_MASKED_LM_MAPPING







snake_case_     =	auto_class_update(FlaxAutoModelForMaskedLM, head_doc="""masked language modeling""")


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING







snake_case_     =	auto_class_update(
    FlaxAutoModelForSeqaSeqLM, head_doc="""sequence-to-sequence language modeling""", checkpoint_for_example="""t5-base"""
)


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING







snake_case_     =	auto_class_update(
    FlaxAutoModelForSequenceClassification, head_doc="""sequence classification"""
)


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_QUESTION_ANSWERING_MAPPING







snake_case_     =	auto_class_update(FlaxAutoModelForQuestionAnswering, head_doc="""question answering""")


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING







snake_case_     =	auto_class_update(
    FlaxAutoModelForTokenClassification, head_doc="""token classification"""
)


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_MULTIPLE_CHOICE_MAPPING







snake_case_     =	auto_class_update(FlaxAutoModelForMultipleChoice, head_doc="""multiple choice""")


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING







snake_case_     =	auto_class_update(
    FlaxAutoModelForNextSentencePrediction, head_doc="""next sentence prediction"""
)


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING







snake_case_     =	auto_class_update(
    FlaxAutoModelForImageClassification, head_doc="""image classification"""
)


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_VISION_2_SEQ_MAPPING







snake_case_     =	auto_class_update(FlaxAutoModelForVisionaSeq, head_doc="""vision-to-text modeling""")


class   _lowercase						(							_BaseAutoModelClass				):
   _UpperCamelCase       		=   FLAX_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING







snake_case_     =	auto_class_update(
    FlaxAutoModelForSpeechSeqaSeq, head_doc="""sequence-to-sequence speech-to-text modeling"""
)







'''simple docstring'''






def 							_lowerCamelCase(  UpperCamelCase__    : int		)		->  None:
    A       :       List[Any]							=						generate_pascal_triangle(UpperCamelCase__		)
    for row_idx in range(UpperCamelCase__		):
        # Print left spaces
        for _ in range(num_rows - row_idx - 1		):
            print(end=''' '''		)
        # Print row values
        for col_idx in range(row_idx + 1		):
            if col_idx != row_idx:
                print(triangle[row_idx][col_idx]    ,       end=''' '''		)
            else:
                print(triangle[row_idx][col_idx]    ,       end=''''''		)
        print()
def 							_lowerCamelCase(  UpperCamelCase__    : int		)		->  list[list[int]]:

    if not isinstance(UpperCamelCase__    ,       UpperCamelCase__		):
        raise TypeError('''The input value of \'num_rows\' should be \'int\''''		)

    if num_rows == 0:
        return []
    elif num_rows < 0:
        raise ValueError(
            '''The input value of \'num_rows\' should be greater than or equal to 0'''		)

    A       :       list[list[int]]							=						[]
    for current_row_idx in range(UpperCamelCase__		):
        A       :       Optional[int]							=						populate_current_row(UpperCamelCase__    ,       UpperCamelCase__		)
        triangle.append(UpperCamelCase__		)
    return triangle
def 							_lowerCamelCase(  UpperCamelCase__    : list[list[int]]    ,       UpperCamelCase__    : int		)		->  list[int]:
    A       :       Dict							=						[-1] * (current_row_idx + 1)
    # first and last elements of current row are equal to 1
    A,	A       :       Union[str, Any]							=						1, 1
    for current_col_idx in range(1    ,       UpperCamelCase__		):
        calculate_current_element(
            UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__		)
    return current_row
def 							_lowerCamelCase(  UpperCamelCase__    : list[list[int]]    ,       UpperCamelCase__    : list[int]    ,       UpperCamelCase__    : int    ,       UpperCamelCase__    : int    ,       )		->  None:
    A       :       Dict							=						triangle[current_row_idx - 1][current_col_idx - 1]
    A       :       Any							=						triangle[current_row_idx - 1][current_col_idx]
    A       :       Optional[int]							=						above_to_left_elt + above_to_right_elt
def 							_lowerCamelCase(  UpperCamelCase__    : int		)		->  list[list[int]]:

    if not isinstance(UpperCamelCase__    ,       UpperCamelCase__		):
        raise TypeError('''The input value of \'num_rows\' should be \'int\''''		)

    if num_rows == 0:
        return []
    elif num_rows < 0:
        raise ValueError(
            '''The input value of \'num_rows\' should be greater than or equal to 0'''		)

    A       :       list[list[int]]							=						[[1]]

    for row_index in range(1    ,       UpperCamelCase__		):
        A       :       str							=						[0] + result[-1] + [0]
        A       :       Optional[Any]							=						row_index + 1
        # Calculate the number of distinct elements in a row
        A       :       str							=						sum(divmod(UpperCamelCase__    ,       2		)		)
        A       :       Optional[int]							=						[
            temp_row[i - 1] + temp_row[i] for i in range(1    ,       distinct_elements + 1		)
        ]
        A       :       Any							=						row_first_half[: (row_index + 1) // 2]
        row_second_half.reverse()
        A       :       Any							=						row_first_half + row_second_half
        result.append(UpperCamelCase__		)

    return result
def 							_lowerCamelCase(  )		->  None:
    from collections.abc import Callable
    from timeit import timeit

    def benchmark_a_function(UpperCamelCase__    : Callable    ,       UpperCamelCase__    : int		) -> None:
        A       :       Dict							=						F'''{func.__name__}({value})'''
        A       :       List[Any]							=						timeit(F'''__main__.{call}'''    ,       setup='''import __main__'''		)
        # print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
        print(F'''{call:38} -- {timing:.4f} seconds'''		)

    for value in range(15		):  # (1, 7, 14):
        for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
            benchmark_a_function(UpperCamelCase__    ,       UpperCamelCase__		)
        print()


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     benchmark()
