



"""simple docstring"""





from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxSeqaSeqConfigWithPast
from ...utils import logging


if TYPE_CHECKING:
					from ...feature_extraction_utils import FeatureExtractionMixin
					from ...tokenization_utils_base import PreTrainedTokenizerBase
					from ...utils import TensorType

__lowerCAmelCase       :					Tuple      					=					logging.get_logger(__name__)

__lowerCAmelCase       :					int      					=					{
    '''openai/whisper-base''': '''https://huggingface.co/openai/whisper-base/resolve/main/config.json''',
}

# fmt: off
__lowerCAmelCase       :					List[str]      					=					[
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 357, 366, 438, 532, 685,
    705, 796, 930, 1058, 1220, 1267, 1279, 1303, 1343, 1377,
    1391, 1635, 1782, 1875, 2162, 2361, 2488, 3467, 4008, 4211,
    4600, 4808, 5299, 5855, 6329, 7203, 9609, 9959, 1_0563, 1_0786,
    1_1420, 1_1709, 1_1907, 1_3163, 1_3697, 1_3700, 1_4808, 1_5306, 1_6410, 1_6791,
    1_7992, 1_9203, 1_9510, 2_0724, 2_2305, 2_2935, 2_7007, 3_0109, 3_0420, 3_3409,
    3_4949, 4_0283, 4_0493, 4_0549, 4_7282, 4_9146, 5_0257, 5_0359, 5_0360, 5_0361
]
__lowerCAmelCase       :					Optional[Any]      					=					[
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 359, 503, 522, 542, 873,
    893, 902, 918, 922, 931, 1350, 1853, 1982, 2460, 2627,
    3246, 3253, 3268, 3536, 3846, 3961, 4183, 4667, 6585, 6647,
    7273, 9061, 9383, 1_0428, 1_0929, 1_1938, 1_2033, 1_2331, 1_2562, 1_3793,
    1_4157, 1_4635, 1_5265, 1_5618, 1_6553, 1_6604, 1_8362, 1_8956, 2_0075, 2_1675,
    2_2520, 2_6130, 2_6161, 2_6435, 2_8279, 2_9464, 3_1650, 3_2302, 3_2470, 3_6865,
    4_2863, 4_7425, 4_9870, 5_0254, 5_0258, 5_0360, 5_0361, 5_0362
]



class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       '''whisper'''
		_lowerCamelCase			  =       ['''past_key_values''']
		_lowerCamelCase			  =       {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}





		def __init__(					self							,    _lowercase=5_1_8_6_5							,    _lowercase=8_0							,    _lowercase=6							,    _lowercase=4							,    _lowercase=6							,    _lowercase=4							,    _lowercase=1_5_3_6							,    _lowercase=1_5_3_6							,    _lowercase=0.0							,    _lowercase=0.0							,    _lowercase=5_0_2_5_7							,    _lowercase=True							,    _lowercase=True							,    _lowercase="gelu"							,    _lowercase=2_5_6							,    _lowercase=0.0							,    _lowercase=0.0							,    _lowercase=0.0							,    _lowercase=0.02							,    _lowercase=False							,    _lowercase=1_5_0_0							,    _lowercase=4_4_8							,    _lowercase=5_0_2_5_6							,    _lowercase=5_0_2_5_6							,    _lowercase=5_0_2_5_6							,    _lowercase=None							,    _lowercase=[2_2_0, 5_0_2_5_6]							,    _lowercase=False							,    _lowercase=2_5_6							,    _lowercase=False							,    _lowercase=0.05							,    _lowercase=1_0							,    _lowercase=2							,    _lowercase=0.0							,    _lowercase=1_0							,    _lowercase=0							,    _lowercase=7							,    **_lowercase							,    ) ->						Any:







								'''simple docstring'''

								snake_case_   : Dict						=			vocab_size
								snake_case_   : Dict						=			num_mel_bins
								snake_case_   : Dict						=			d_model
								snake_case_   : List[Any]						=			encoder_layers
								snake_case_   : Dict						=			encoder_attention_heads
								snake_case_   : Any						=			decoder_layers
								snake_case_   : Union[str, Any]						=			decoder_attention_heads
								snake_case_   : str						=			decoder_ffn_dim
								snake_case_   : Union[str, Any]						=			encoder_ffn_dim
								snake_case_   : Dict						=			dropout
								snake_case_   : Any						=			attention_dropout
								snake_case_   : Dict						=			activation_dropout
								snake_case_   : str						=			activation_function
								snake_case_   : Tuple						=			init_std
								snake_case_   : Optional[int]						=			encoder_layerdrop
								snake_case_   : Any						=			decoder_layerdrop
								snake_case_   : List[Any]						=			use_cache
								snake_case_   : int						=			encoder_layers
								snake_case_   : str						=			scale_embedding  # scale factor will be sqrt(d_model) if True
								snake_case_   : str						=			max_source_positions
								snake_case_   : int						=			max_target_positions

								# Audio Classification-specific parameters. Feel free to ignore for other classes.
								snake_case_   : str						=			classifier_proj_size
								snake_case_   : int						=			use_weighted_layer_sum

								# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
								snake_case_   : List[str]						=			apply_spec_augment
								snake_case_   : Optional[int]						=			mask_time_prob
								snake_case_   : Any						=			mask_time_length
								snake_case_   : Tuple						=			mask_time_min_masks
								snake_case_   : Tuple						=			mask_feature_prob
								snake_case_   : List[Any]						=			mask_feature_length
								snake_case_   : Union[str, Any]						=			mask_feature_min_masks

								snake_case_   : Dict						=			median_filter_width

								super().__init__(
								    pad_token_id=_lowercase							,    bos_token_id=_lowercase							,    eos_token_id=_lowercase							,    is_encoder_decoder=_lowercase							,    decoder_start_token_id=_lowercase							,    suppress_tokens=_lowercase							,    begin_suppress_tokens=_lowercase							,    **_lowercase							,    )




class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		@property
		def    UpperCAmelCase__							(					self   ) ->						Mapping[str, Mapping[int, str]]:







								'''simple docstring'''

								snake_case_   : List[str]						=			OrderedDict(
								    [
								        ("""input_features""", {0: """batch""", 1: """feature_size""", 2: """encoder_sequence"""}),
								    ]   )
								if self.use_past:
														snake_case_   : List[str]						=			{0: """batch"""}
								else:
														snake_case_   : str						=			{0: """batch""", 1: """decoder_sequence"""}

								if self.use_past:
														self.fill_with_past_key_values_(_lowercase							,    direction="""inputs"""   )

								return common_inputs





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase = -1							,    _lowercase = -1							,    _lowercase = False							,    _lowercase = None							,    _lowercase = 2_2_0_5_0							,    _lowercase = 5.0							,    _lowercase = 2_2_0							,    ) ->						Mapping[str, Any]:







								'''simple docstring'''

								snake_case_   : Dict						=			OrderedDict()
								snake_case_   : Optional[Any]						=			OnnxConfig.generate_dummy_inputs(
								    self							,    preprocessor=preprocessor.feature_extractor							,    batch_size=_lowercase							,    framework=_lowercase							,    sampling_rate=_lowercase							,    time_duration=_lowercase							,    frequency=_lowercase							,    )
								snake_case_   : Any						=			encoder_inputs["""input_features"""].shape[2]
								snake_case_   : Optional[int]						=			encoder_sequence_length // 2 if self.use_past else seq_length

								snake_case_   : List[str]						=			super().generate_dummy_inputs(
								    preprocessor.tokenizer							,    _lowercase							,    _lowercase							,    _lowercase							,    _lowercase   )

								snake_case_   : Optional[int]						=			encoder_inputs.pop("""input_features"""   )
								snake_case_   : str						=			decoder_inputs.pop("""decoder_input_ids"""   )

								if "past_key_values" in decoder_inputs:
														snake_case_   : List[Any]						=			decoder_inputs.pop("""past_key_values"""   )

								return dummy_inputs





		@property
		def    UpperCAmelCase__							(					self   ) ->						float:







								'''simple docstring'''

								return 1E-3






"""simple docstring"""





import unittest

import numpy as np

from transformers import RobertaPreLayerNormConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
					import jax.numpy as jnp

					from transformers.models.roberta_prelayernorm.modeling_flax_roberta_prelayernorm import (
					    FlaxRobertaPreLayerNormForCausalLM,
					    FlaxRobertaPreLayerNormForMaskedLM,
					    FlaxRobertaPreLayerNormForMultipleChoice,
					    FlaxRobertaPreLayerNormForQuestionAnswering,
					    FlaxRobertaPreLayerNormForSequenceClassification,
					    FlaxRobertaPreLayerNormForTokenClassification,
					    FlaxRobertaPreLayerNormModel,
					)



class    _lowerCAmelCase    (				unittest.TestCase		):





		"""simple docstring"""






		def __init__(					self							,    _lowercase							,    _lowercase=1_3							,    _lowercase=7							,    _lowercase=True							,    _lowercase=True							,    _lowercase=True							,    _lowercase=True							,    _lowercase=9_9							,    _lowercase=3_2							,    _lowercase=5							,    _lowercase=4							,    _lowercase=3_7							,    _lowercase="gelu"							,    _lowercase=0.1							,    _lowercase=0.1							,    _lowercase=5_1_2							,    _lowercase=1_6							,    _lowercase=2							,    _lowercase=0.02							,    _lowercase=4							,    ) ->						Union[str, Any]:







								'''simple docstring'''

								snake_case_   : Optional[int]						=			parent
								snake_case_   : Dict						=			batch_size
								snake_case_   : Any						=			seq_length
								snake_case_   : Tuple						=			is_training
								snake_case_   : Dict						=			use_attention_mask
								snake_case_   : int						=			use_token_type_ids
								snake_case_   : List[Any]						=			use_labels
								snake_case_   : List[str]						=			vocab_size
								snake_case_   : str						=			hidden_size
								snake_case_   : Optional[Any]						=			num_hidden_layers
								snake_case_   : List[Any]						=			num_attention_heads
								snake_case_   : Any						=			intermediate_size
								snake_case_   : Optional[Any]						=			hidden_act
								snake_case_   : Tuple						=			hidden_dropout_prob
								snake_case_   : List[Any]						=			attention_probs_dropout_prob
								snake_case_   : int						=			max_position_embeddings
								snake_case_   : Dict						=			type_vocab_size
								snake_case_   : Dict						=			type_sequence_label_size
								snake_case_   : Optional[Any]						=			initializer_range
								snake_case_   : Tuple						=			num_choices





		def    UpperCAmelCase__							(					self   ) ->						Union[str, Any]:







								'''simple docstring'''

								snake_case_   : int						=			ids_tensor([self.batch_size, self.seq_length]							,    self.vocab_size   )

								snake_case_   : Tuple						=			None
								if self.use_attention_mask:
														snake_case_   : Optional[Any]						=			random_attention_mask([self.batch_size, self.seq_length]   )

								snake_case_   : List[str]						=			None
								if self.use_token_type_ids:
														snake_case_   : int						=			ids_tensor([self.batch_size, self.seq_length]							,    self.type_vocab_size   )

								snake_case_   : Tuple						=			RobertaPreLayerNormConfig(
								    vocab_size=self.vocab_size							,    hidden_size=self.hidden_size							,    num_hidden_layers=self.num_hidden_layers							,    num_attention_heads=self.num_attention_heads							,    intermediate_size=self.intermediate_size							,    hidden_act=self.hidden_act							,    hidden_dropout_prob=self.hidden_dropout_prob							,    attention_probs_dropout_prob=self.attention_probs_dropout_prob							,    max_position_embeddings=self.max_position_embeddings							,    type_vocab_size=self.type_vocab_size							,    is_decoder=_lowercase							,    initializer_range=self.initializer_range							,    )

								return config, input_ids, token_type_ids, attention_mask





		def    UpperCAmelCase__							(					self   ) ->						Any:







								'''simple docstring'''

								snake_case_   : Any						=			self.prepare_config_and_inputs()
								snake_case_			,		snake_case_			,		snake_case_			,		snake_case_   : List[Any]						=			config_and_inputs
								snake_case_   : int						=			{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
								return config, inputs_dict





		def    UpperCAmelCase__							(					self   ) ->						str:







								'''simple docstring'''

								snake_case_   : Tuple						=			self.prepare_config_and_inputs()
								snake_case_			,		snake_case_			,		snake_case_			,		snake_case_   : Any						=			config_and_inputs

								snake_case_   : Union[str, Any]						=			True
								snake_case_   : List[Any]						=			floats_tensor([self.batch_size, self.seq_length, self.hidden_size]   )
								snake_case_   : Optional[int]						=			ids_tensor([self.batch_size, self.seq_length]							,    vocab_size=2   )

								return (
								    config,
								    input_ids,
								    token_type_ids,
								    encoder_hidden_states,
								    encoder_attention_mask,
								)




@require_flax
# Copied from tests.models.roberta.test_modelling_flax_roberta.FlaxRobertaPreLayerNormModelTest with ROBERTA->ROBERTA_PRELAYERNORM,Roberta->RobertaPreLayerNorm,roberta-base->andreasmadsen/efficient_mlm_m0.40
class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__  ,				unittest.TestCase		):





		"""simple docstring"""






		_lowerCamelCase			  =       True

		_lowerCamelCase			  =       (
		    (
		        FlaxRobertaPreLayerNormModel,
		        FlaxRobertaPreLayerNormForCausalLM,
		        FlaxRobertaPreLayerNormForMaskedLM,
		        FlaxRobertaPreLayerNormForSequenceClassification,
		        FlaxRobertaPreLayerNormForTokenClassification,
		        FlaxRobertaPreLayerNormForMultipleChoice,
		        FlaxRobertaPreLayerNormForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)





		def    UpperCAmelCase__							(					self   ) ->						int:







								'''simple docstring'''

								snake_case_   : Any						=			FlaxRobertaPreLayerNormModelTester(self   )





		@slow
		def    UpperCAmelCase__							(					self   ) ->						Tuple:







								'''simple docstring'''

								for model_class_name in self.all_model_classes:
														snake_case_   : Tuple						=			model_class_name.from_pretrained("""andreasmadsen/efficient_mlm_m0.40"""							,    from_pt=_lowercase   )
														snake_case_   : Tuple						=			model(np.ones((1, 1)   )   )
														self.assertIsNotNone(_lowercase   )




@require_flax
class    _lowerCAmelCase    (				unittest.TestCase		):





		"""simple docstring"""






		@slow
		def    UpperCAmelCase__							(					self   ) ->						Union[str, Any]:







								'''simple docstring'''

								snake_case_   : Union[str, Any]						=			FlaxRobertaPreLayerNormForMaskedLM.from_pretrained("""andreasmadsen/efficient_mlm_m0.40"""							,    from_pt=_lowercase   )

								snake_case_   : List[str]						=			np.array([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]							,    dtype=jnp.intaa   )
								snake_case_   : str						=			model(_lowercase   )[0]
								snake_case_   : int						=			[1, 1_1, 5_0_2_6_5]
								self.assertEqual(list(output.shape   )							,    _lowercase   )
								# compare the actual values for a slice.
								snake_case_   : Tuple						=			np.array(
								    [[[40.4880, 18.0199, -5.2367], [-1.8877, -4.0885, 10.7085], [-2.2613, -5.6110, 7.2665]]]							,    dtype=np.floataa   )
								self.assertTrue(np.allclose(output[:, :3, :3]							,    _lowercase							,    atol=1E-4   )   )





		@slow
		def    UpperCAmelCase__							(					self   ) ->						int:







								'''simple docstring'''

								snake_case_   : Any						=			FlaxRobertaPreLayerNormModel.from_pretrained("""andreasmadsen/efficient_mlm_m0.40"""							,    from_pt=_lowercase   )

								snake_case_   : Dict						=			np.array([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]							,    dtype=jnp.intaa   )
								snake_case_   : Any						=			model(_lowercase   )[0]
								# compare the actual values for a slice.
								snake_case_   : Optional[Any]						=			np.array(
								    [[[0.0208, -0.0356, 0.0237], [-0.1569, -0.0411, -0.2626], [0.1879, 0.0125, -0.0089]]]							,    dtype=np.floataa   )
								self.assertTrue(np.allclose(output[:, :3, :3]							,    _lowercase							,    atol=1E-4   )   )

