



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

__A       =						logging.get_logger(__name__)

__A       =						{
    "openai/whisper-base": "https://huggingface.co/openai/whisper-base/resolve/main/config.json",
}

# fmt: off
__A       =						[
    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
]
__A       =						[
    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 		lowercase						(			SCREAMING_SNAKE_CASE__):






	"""simple docstring"""


	a__				: Any		       =							'whisper'
	a__				: Tuple		       =							['past_key_values']
	a__				: str		       =							{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}




	def __init__(     self     :						List[str]						,  __UpperCAmelCase     :						int=51_865						,  __UpperCAmelCase     :						Dict=80						,  __UpperCAmelCase     :						int=6						,  __UpperCAmelCase     :						Tuple=4						,  __UpperCAmelCase     :						Dict=6						,  __UpperCAmelCase     :						str=4						,  __UpperCAmelCase     :						Optional[Any]=1_536						,  __UpperCAmelCase     :						Optional[Any]=1_536						,  __UpperCAmelCase     :						List[Any]=0.0						,  __UpperCAmelCase     :						str=0.0						,  __UpperCAmelCase     :						Union[str, Any]=50_257						,  __UpperCAmelCase     :						Any=True						,  __UpperCAmelCase     :						List[str]=True						,  __UpperCAmelCase     :						Any="gelu"						,  __UpperCAmelCase     :						Union[str, Any]=256						,  __UpperCAmelCase     :						Dict=0.0						,  __UpperCAmelCase     :						Union[str, Any]=0.0						,  __UpperCAmelCase     :						List[Any]=0.0						,  __UpperCAmelCase     :						str=0.02						,  __UpperCAmelCase     :						int=False						,  __UpperCAmelCase     :						str=1_500						,  __UpperCAmelCase     :						List[str]=448						,  __UpperCAmelCase     :						List[Any]=50_256						,  __UpperCAmelCase     :						Dict=50_256						,  __UpperCAmelCase     :						Tuple=50_256						,  __UpperCAmelCase     :						Tuple=None						,  __UpperCAmelCase     :						Tuple=[220, 50_256]						,  __UpperCAmelCase     :						List[str]=False						,  __UpperCAmelCase     :						int=256						,  __UpperCAmelCase     :						int=False						,  __UpperCAmelCase     :						List[str]=0.05						,  __UpperCAmelCase     :						Union[str, Any]=10						,  __UpperCAmelCase     :						List[Any]=2						,  __UpperCAmelCase     :						Dict=0.0						,  __UpperCAmelCase     :						Any=10						,  __UpperCAmelCase     :						Any=0						,  __UpperCAmelCase     :						str=7						,  **__UpperCAmelCase     :						Union[str, Any]						,  )      ->			Any:
							UpperCAmelCase_=       vocab_size
							UpperCAmelCase_=       num_mel_bins
							UpperCAmelCase_=       d_model
							UpperCAmelCase_=       encoder_layers
							UpperCAmelCase_=       encoder_attention_heads
							UpperCAmelCase_=       decoder_layers
							UpperCAmelCase_=       decoder_attention_heads
							UpperCAmelCase_=       decoder_ffn_dim
							UpperCAmelCase_=       encoder_ffn_dim
							UpperCAmelCase_=       dropout
							UpperCAmelCase_=       attention_dropout
							UpperCAmelCase_=       activation_dropout
							UpperCAmelCase_=       activation_function
							UpperCAmelCase_=       init_std
							UpperCAmelCase_=       encoder_layerdrop
							UpperCAmelCase_=       decoder_layerdrop
							UpperCAmelCase_=       use_cache
							UpperCAmelCase_=       encoder_layers
							UpperCAmelCase_=       scale_embedding  # scale factor will be sqrt(d_model) if True
							UpperCAmelCase_=       max_source_positions
							UpperCAmelCase_=       max_target_positions

							# Audio Classification-specific parameters. Feel free to ignore for other classes.
							UpperCAmelCase_=       classifier_proj_size
							UpperCAmelCase_=       use_weighted_layer_sum

							# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
							UpperCAmelCase_=       apply_spec_augment
							UpperCAmelCase_=       mask_time_prob
							UpperCAmelCase_=       mask_time_length
							UpperCAmelCase_=       mask_time_min_masks
							UpperCAmelCase_=       mask_feature_prob
							UpperCAmelCase_=       mask_feature_length
							UpperCAmelCase_=       mask_feature_min_masks

							UpperCAmelCase_=       median_filter_width

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






class 		lowercase						(			SCREAMING_SNAKE_CASE__):






	"""simple docstring"""


	@property
	def   _SCREAMING_SNAKE_CASE		(     self     :						str					)      ->			Dict:
							UpperCAmelCase_=       OrderedDict(
							    [
							        ("""input_features""", {0: """batch""", 1: """feature_size""", 2: """encoder_sequence"""}),
							    ]					)
							if self.use_past:
													UpperCAmelCase_=       {0: """batch"""}
							else:
													UpperCAmelCase_=       {0: """batch""", 1: """decoder_sequence"""}

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

							return common_inputs




	def   _SCREAMING_SNAKE_CASE		(     self     :						Union[str, Any]						,  __UpperCAmelCase     :						Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]						,  __UpperCAmelCase     :						int = -1						,  __UpperCAmelCase     :						int = -1						,  __UpperCAmelCase     :						bool = False						,  __UpperCAmelCase     :						Optional["TensorType"] = None						,  __UpperCAmelCase     :						int = 22_050						,  __UpperCAmelCase     :						float = 5.0						,  __UpperCAmelCase     :						int = 220						,  )      ->			Any:
							UpperCAmelCase_=       OrderedDict()
							UpperCAmelCase_=       OnnxConfig.generate_dummy_inputs(
							    self						,  preprocessor=preprocessor.feature_extractor						,  batch_size=a_						,  framework=a_						,  sampling_rate=a_						,  time_duration=a_						,  frequency=a_						,  )
							UpperCAmelCase_=       encoder_inputs["""input_features"""].shape[2]
							UpperCAmelCase_=       encoder_sequence_length // 2 if self.use_past else seq_length

							UpperCAmelCase_=       super().generate_dummy_inputs(
							    preprocessor.tokenizer						,  a_						,  a_						,  a_						,  a_					)

							UpperCAmelCase_=       encoder_inputs.pop("""input_features"""					)
							UpperCAmelCase_=       decoder_inputs.pop("""decoder_input_ids"""					)

							if "past_key_values" in decoder_inputs:
													UpperCAmelCase_=       decoder_inputs.pop("""past_key_values"""					)

							return dummy_inputs




	@property
	def   _SCREAMING_SNAKE_CASE		(     self     :						Optional[int]					)      ->			List[str]:
							return 1E-3









import dataclasses
import json
import warnings
from dataclasses import dataclass, field
from time import time
from typing import List

from ..utils import logging


__A       =						logging.get_logger(__name__)



def 	__a					(   lowerCAmelCase_       : Tuple=None      ,lowerCAmelCase_       : Optional[Any]=None    )				->			Tuple:






						'''simple docstring'''



						return field(default_factory=lambda: default      ,metadata=lowerCAmelCase_    )






@dataclass
class 		lowercase						:






	"""simple docstring"""


	a__				: List[str]		       =							list_field(
	    default=[]			,   metadata={
	        "help": (
	            "Model checkpoints to be provided to the AutoModel classes. Leave blank to benchmark the base version"
	            " of all available models"
	        )
	    }			,   )

	a__				: List[int]		       =							list_field(
	    default=[8]			,   metadata={"help": "List of batch sizes for which memory and time performance will be evaluated"})

	a__				: List[int]		       =							list_field(
	    default=[8, 32, 128, 512]			,   metadata={"help": "List of sequence lengths for which memory and time performance will be evaluated"}			,   )

	a__				: bool		       =							field(
	    default=snake_case__			,   metadata={"help": "Whether to benchmark inference of model. Inference can be disabled via --no-inference."}			,   )
	a__				: bool		       =							field(
	    default=snake_case__			,   metadata={"help": "Whether to run on available cuda devices. Cuda can be disabled via --no-cuda."}			,   )
	a__				: bool		       =							field(
	    default=snake_case__			,   metadata={"help": "Whether to run on available tpu devices. TPU can be disabled via --no-tpu."})
	a__				: bool		       =							field(default=snake_case__			,   metadata={"help": "Use FP16 to accelerate inference."})
	a__				: bool		       =							field(default=snake_case__			,   metadata={"help": "Benchmark training of model"})
	a__				: bool		       =							field(default=snake_case__			,   metadata={"help": "Verbose memory tracing"})
	a__				: bool		       =							field(
	    default=snake_case__			,   metadata={"help": "Whether to perform speed measurements. Speed measurements can be disabled via --no-speed."}			,   )
	a__				: bool		       =							field(
	    default=snake_case__			,   metadata={
	        "help": "Whether to perform memory measurements. Memory measurements can be disabled via --no-memory"
	    }			,   )
	a__				: bool		       =							field(default=snake_case__			,   metadata={"help": "Trace memory line by line"})
	a__				: bool		       =							field(default=snake_case__			,   metadata={"help": "Save result to a CSV file"})
	a__				: bool		       =							field(default=snake_case__			,   metadata={"help": "Save all print statements in a log file"})
	a__				: bool		       =							field(default=snake_case__			,   metadata={"help": "Whether to print environment information"})
	a__				: bool		       =							field(
	    default=snake_case__			,   metadata={
	        "help": (
	            "Whether to use multiprocessing for memory and speed measurement. It is highly recommended to use"
	            " multiprocessing for accurate CPU and GPU memory measurements. This option should only be disabled"
	            " for debugging / testing and on TPU."
	        )
	    }			,   )
	a__				: str		       =							field(
	    default=F'inference_time_{round(time())}.csv'			,   metadata={"help": "CSV filename used if saving time results to csv."}			,   )
	a__				: str		       =							field(
	    default=F'inference_memory_{round(time())}.csv'			,   metadata={"help": "CSV filename used if saving memory results to csv."}			,   )
	a__				: str		       =							field(
	    default=F'train_time_{round(time())}.csv'			,   metadata={"help": "CSV filename used if saving time results to csv for training."}			,   )
	a__				: str		       =							field(
	    default=F'train_memory_{round(time())}.csv'			,   metadata={"help": "CSV filename used if saving memory results to csv for training."}			,   )
	a__				: str		       =							field(
	    default=F'env_info_{round(time())}.csv'			,   metadata={"help": "CSV filename used if saving environment information."}			,   )
	a__				: str		       =							field(
	    default=F'log_{round(time())}.csv'			,   metadata={"help": "Log filename used if print statements are saved in log."}			,   )
	a__				: int		       =							field(default=3			,   metadata={"help": "Times an experiment will be run."})
	a__				: bool		       =							field(
	    default=snake_case__			,   metadata={
	        "help": (
	            "Instead of loading the model as defined in `config.architectures` if exists, just load the pretrain"
	            " model weights."
	        )
	    }			,   )




	def   _SCREAMING_SNAKE_CASE		(     self     :						Optional[int]					)      ->			str:
							warnings.warn(
							    F"""The class {self.__class__} is deprecated. Hugging Face Benchmarking utils"""
							    """ are deprecated in general and it is advised to use external Benchmarking libraries """
							    """ to benchmark Transformer models."""						,  __UpperCAmelCase						,  )




	def   _SCREAMING_SNAKE_CASE		(     self     :						Dict					)      ->			List[str]:
							return json.dumps(dataclasses.asdict(self					)						,  indent=2					)




	@property
	def   _SCREAMING_SNAKE_CASE		(     self     :						List[Any]					)      ->			List[str]:
							if len(self.models					) <= 0:
													raise ValueError(
													    """Please make sure you provide at least one model name / model identifier, *e.g.* `--models"""
													    """ bert-base-cased` or `args.models = ['bert-base-cased']."""					)
							return self.models




	@property
	def   _SCREAMING_SNAKE_CASE		(     self     :						Union[str, Any]					)      ->			Tuple:
							if not self.multi_process:
													return False
							elif self.is_tpu:
													logger.info("""Multiprocessing is currently not possible on TPU."""					)
													return False
							else:
													return True




