




import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowerCamelCase      :  Optional[int]      						=						logging.get_logger(__name__)

_lowerCamelCase      :  int      						=						{
    "facebook/wav2vec2-base-960h": "https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}
class        __snake_case  (_a		):
				lowerCAmelCase__				=     "wav2vec2"



				def __init__(      self      :		Optional[Any]		,	_UpperCAmelCase      :		Union[str, Any]=32		,	_UpperCAmelCase      :		Tuple=768		,	_UpperCAmelCase      :		Optional[Any]=12		,	_UpperCAmelCase      :		int=12		,	_UpperCAmelCase      :		List[str]=3072		,	_UpperCAmelCase      :		List[str]="gelu"		,	_UpperCAmelCase      :		Optional[Any]=0.1		,	_UpperCAmelCase      :		List[str]=0.1		,	_UpperCAmelCase      :		int=0.1		,	_UpperCAmelCase      :		int=0.0		,	_UpperCAmelCase      :		int=0.0		,	_UpperCAmelCase      :		Union[str, Any]=0.1		,	_UpperCAmelCase      :		str=0.1		,	_UpperCAmelCase      :		int=0.02		,	_UpperCAmelCase      :		List[str]=1E-5		,	_UpperCAmelCase      :		int="group"		,	_UpperCAmelCase      :		int="gelu"		,	_UpperCAmelCase      :		Tuple=(512, 512, 512, 512, 512, 512, 512)		,	_UpperCAmelCase      :		Union[str, Any]=(5, 2, 2, 2, 2, 2, 2)		,	_UpperCAmelCase      :		List[str]=(10, 3, 3, 3, 3, 2, 2)		,	_UpperCAmelCase      :		List[str]=False		,	_UpperCAmelCase      :		Dict=128		,	_UpperCAmelCase      :		Optional[int]=16		,	_UpperCAmelCase      :		Dict=False		,	_UpperCAmelCase      :		Tuple=True		,	_UpperCAmelCase      :		Any=0.05		,	_UpperCAmelCase      :		Union[str, Any]=10		,	_UpperCAmelCase      :		int=2		,	_UpperCAmelCase      :		Union[str, Any]=0.0		,	_UpperCAmelCase      :		Optional[Any]=10		,	_UpperCAmelCase      :		str=0		,	_UpperCAmelCase      :		Any=320		,	_UpperCAmelCase      :		List[Any]=2		,	_UpperCAmelCase      :		Optional[int]=0.1		,	_UpperCAmelCase      :		Tuple=100		,	_UpperCAmelCase      :		Tuple=256		,	_UpperCAmelCase      :		Any=256		,	_UpperCAmelCase      :		int=0.1		,	_UpperCAmelCase      :		Optional[Any]="sum"		,	_UpperCAmelCase      :		List[Any]=False		,	_UpperCAmelCase      :		Tuple=False		,	_UpperCAmelCase      :		List[Any]=256		,	_UpperCAmelCase      :		Tuple=(512, 512, 512, 512, 1500)		,	_UpperCAmelCase      :		List[str]=(5, 3, 3, 1, 1)		,	_UpperCAmelCase      :		Optional[Any]=(1, 2, 3, 1, 1)		,	_UpperCAmelCase      :		Dict=512		,	_UpperCAmelCase      :		List[str]=0		,	_UpperCAmelCase      :		Dict=1		,	_UpperCAmelCase      :		Any=2		,	_UpperCAmelCase      :		Any=False		,	_UpperCAmelCase      :		Dict=3		,	_UpperCAmelCase      :		Optional[int]=2		,	_UpperCAmelCase      :		int=3		,	_UpperCAmelCase      :		Dict=None		,	_UpperCAmelCase      :		Dict=None		,	**_UpperCAmelCase      :		Optional[int]		,	)  ->    str:





								'''simple docstring'''




								super().__init__(**_UpperCAmelCase		,	pad_token_id=_UpperCAmelCase		,	bos_token_id=_UpperCAmelCase		,	eos_token_id=_UpperCAmelCase      )
								_lowerCAmelCase    :    Dict										=      hidden_size
								_lowerCAmelCase    :    Union[str, Any]										=      feat_extract_norm
								_lowerCAmelCase    :    str										=      feat_extract_activation
								_lowerCAmelCase    :    Any										=      list(_UpperCAmelCase      )
								_lowerCAmelCase    :    int										=      list(_UpperCAmelCase      )
								_lowerCAmelCase    :    int										=      list(_UpperCAmelCase      )
								_lowerCAmelCase    :    int										=      conv_bias
								_lowerCAmelCase    :    Dict										=      num_conv_pos_embeddings
								_lowerCAmelCase    :    List[str]										=      num_conv_pos_embedding_groups
								_lowerCAmelCase    :    List[str]										=      len(self.conv_dim      )
								_lowerCAmelCase    :    Optional[int]										=      num_hidden_layers
								_lowerCAmelCase    :    Tuple										=      intermediate_size
								_lowerCAmelCase    :    List[Any]										=      hidden_act
								_lowerCAmelCase    :    int										=      num_attention_heads
								_lowerCAmelCase    :    Optional[int]										=      hidden_dropout
								_lowerCAmelCase    :    Union[str, Any]										=      attention_dropout
								_lowerCAmelCase    :    str										=      activation_dropout
								_lowerCAmelCase    :    Optional[Any]										=      feat_proj_dropout
								_lowerCAmelCase    :    Optional[int]										=      final_dropout
								_lowerCAmelCase    :    List[Any]										=      layerdrop
								_lowerCAmelCase    :    Any										=      layer_norm_eps
								_lowerCAmelCase    :    List[Any]										=      initializer_range
								_lowerCAmelCase    :    Tuple										=      vocab_size
								_lowerCAmelCase    :    Any										=      do_stable_layer_norm
								_lowerCAmelCase    :    str										=      use_weighted_layer_sum

								if (
								    (len(self.conv_stride      ) != self.num_feat_extract_layers)
								    or (len(self.conv_kernel      ) != self.num_feat_extract_layers)
								    or (len(self.conv_dim      ) != self.num_feat_extract_layers)
								):
												raise ValueError(
												    """Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="""
												    """ `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="""
												    f" {len(self.conv_dim      )}`, `len(config.conv_stride) = {len(self.conv_stride      )}`,"
												    f" `len(config.conv_kernel) = {len(self.conv_kernel      )}`."      )

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

								# parameters for pretraining with codevector quantized representations
								_lowerCAmelCase    :    Optional[int]										=      num_codevectors_per_group
								_lowerCAmelCase    :    List[Any]										=      num_codevector_groups
								_lowerCAmelCase    :    Any										=      contrastive_logits_temperature
								_lowerCAmelCase    :    List[Any]										=      feat_quantizer_dropout
								_lowerCAmelCase    :    List[str]										=      num_negatives
								_lowerCAmelCase    :    Union[str, Any]										=      codevector_dim
								_lowerCAmelCase    :    List[Any]										=      proj_codevector_dim
								_lowerCAmelCase    :    str										=      diversity_loss_weight

								# ctc loss
								_lowerCAmelCase    :    List[str]										=      ctc_loss_reduction
								_lowerCAmelCase    :    Union[str, Any]										=      ctc_zero_infinity

								# adapter
								_lowerCAmelCase    :    str										=      add_adapter
								_lowerCAmelCase    :    int										=      adapter_kernel_size
								_lowerCAmelCase    :    str										=      adapter_stride
								_lowerCAmelCase    :    List[str]										=      num_adapter_layers
								_lowerCAmelCase    :    Union[str, Any]										=      output_hidden_size or hidden_size
								_lowerCAmelCase    :    Any										=      adapter_attn_dim

								# SequenceClassification-specific parameter. Feel free to ignore for other classes.
								_lowerCAmelCase    :    Tuple										=      classifier_proj_size

								# XVector-specific parameters. Feel free to ignore for other classes.
								_lowerCAmelCase    :    List[Any]										=      list(_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[int]										=      list(_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[int]										=      list(_UpperCAmelCase      )
								_lowerCAmelCase    :    Union[str, Any]										=      xvector_output_dim



				@property
				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    Tuple:





								'''simple docstring'''




								return functools.reduce(operator.mul		,	self.conv_stride		,	1      )







import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_torch_available
from transformers.testing_utils import require_torch, torch_device


if is_torch_available():
	from transformers import PyTorchBenchmark, PyTorchBenchmarkArguments
@require_torch
class        __snake_case  (unittest.TestCase		):



				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple		,	_UpperCAmelCase      :		List[str]      )  ->    List[str]:





								'''simple docstring'''




								for model_result in results.values():
												for batch_size, sequence_length in zip(model_result["""bs"""]		,	model_result["""ss"""]      ):
																_lowerCAmelCase    :    List[Any]										=      model_result["""result"""][batch_size][sequence_length]
																self.assertIsNotNone(_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      """sshleifer/tiny-gpt2"""
								_lowerCAmelCase    :    Dict										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    str										=      PyTorchBenchmark(_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[int]										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]      )  ->    Any:





								'''simple docstring'''




								_lowerCAmelCase    :    List[str]										=      """sgugger/tiny-distilbert-classification"""
								_lowerCAmelCase    :    Tuple										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	only_pretrain_model=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    List[Any]										=      PyTorchBenchmark(_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[Any]										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      """sshleifer/tiny-gpt2"""
								_lowerCAmelCase    :    Union[str, Any]										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	torchscript=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    List[str]										=      PyTorchBenchmark(_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[Any]										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )



				@unittest.skipIf(torch_device == """cpu"""		,	"""Cant do half precision"""      )
				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    str:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[Any]										=      """sshleifer/tiny-gpt2"""
								_lowerCAmelCase    :    Optional[Any]										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	fpaa=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    Union[str, Any]										=      PyTorchBenchmark(_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[Any]										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )



				def       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    List[Any]										=      """sshleifer/tiny-gpt2"""
								_lowerCAmelCase    :    int										=      AutoConfig.from_pretrained(_UpperCAmelCase      )
								# set architectures equal to `None`
								_lowerCAmelCase    :    Optional[int]										=      None
								_lowerCAmelCase    :    Union[str, Any]										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    Tuple										=      PyTorchBenchmark(_UpperCAmelCase		,	configs=[config]      )
								_lowerCAmelCase    :    List[Any]										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict      )  ->    str:





								'''simple docstring'''




								_lowerCAmelCase    :    str										=      """sshleifer/tiny-gpt2"""
								_lowerCAmelCase    :    List[str]										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    List[str]										=      PyTorchBenchmark(_UpperCAmelCase      )
								_lowerCAmelCase    :    Union[str, Any]										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result      )
								self.check_results_dict_not_empty(results.memory_train_result      )



				@unittest.skipIf(torch_device == """cpu"""		,	"""Can't do half precision"""      )
				def       SCREAMING_SNAKE_CASE       (      self      :		Any      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    int										=      """sshleifer/tiny-gpt2"""
								_lowerCAmelCase    :    Dict										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	fpaa=_UpperCAmelCase		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    Union[str, Any]										=      PyTorchBenchmark(_UpperCAmelCase      )
								_lowerCAmelCase    :    List[str]										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result      )
								self.check_results_dict_not_empty(results.memory_train_result      )



				def       SCREAMING_SNAKE_CASE       (      self      :		List[Any]      )  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    Union[str, Any]										=      """sshleifer/tiny-gpt2"""
								_lowerCAmelCase    :    List[Any]										=      AutoConfig.from_pretrained(_UpperCAmelCase      )
								_lowerCAmelCase    :    List[Any]										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    List[str]										=      PyTorchBenchmark(_UpperCAmelCase		,	configs=[config]      )
								_lowerCAmelCase    :    Optional[int]										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      """sshleifer/tinier_bart"""
								_lowerCAmelCase    :    Tuple										=      AutoConfig.from_pretrained(_UpperCAmelCase      )
								_lowerCAmelCase    :    Dict										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    Tuple										=      PyTorchBenchmark(_UpperCAmelCase		,	configs=[config]      )
								_lowerCAmelCase    :    Any										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_inference_result      )
								self.check_results_dict_not_empty(results.memory_inference_result      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]      )  ->    List[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    List[Any]										=      """sshleifer/tiny-gpt2"""
								_lowerCAmelCase    :    Optional[int]										=      AutoConfig.from_pretrained(_UpperCAmelCase      )
								_lowerCAmelCase    :    Any										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    Optional[Any]										=      PyTorchBenchmark(_UpperCAmelCase		,	configs=[config]      )
								_lowerCAmelCase    :    Optional[Any]										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result      )
								self.check_results_dict_not_empty(results.memory_train_result      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      """sshleifer/tinier_bart"""
								_lowerCAmelCase    :    Dict										=      AutoConfig.from_pretrained(_UpperCAmelCase      )
								_lowerCAmelCase    :    Any										=      PyTorchBenchmarkArguments(
								    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	multi_process=_UpperCAmelCase		,	)
								_lowerCAmelCase    :    Optional[Any]										=      PyTorchBenchmark(_UpperCAmelCase		,	configs=[config]      )
								_lowerCAmelCase    :    int										=      benchmark.run()
								self.check_results_dict_not_empty(results.time_train_result      )
								self.check_results_dict_not_empty(results.memory_train_result      )



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      """sshleifer/tiny-gpt2"""
								with tempfile.TemporaryDirectory() as tmp_dir:
												_lowerCAmelCase    :    Optional[int]										=      PyTorchBenchmarkArguments(
												    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	save_to_csv=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	inference_time_csv_file=os.path.join(_UpperCAmelCase		,	"""inf_time.csv"""      )		,	train_memory_csv_file=os.path.join(_UpperCAmelCase		,	"""train_mem.csv"""      )		,	inference_memory_csv_file=os.path.join(_UpperCAmelCase		,	"""inf_mem.csv"""      )		,	train_time_csv_file=os.path.join(_UpperCAmelCase		,	"""train_time.csv"""      )		,	env_info_csv_file=os.path.join(_UpperCAmelCase		,	"""env.csv"""      )		,	multi_process=_UpperCAmelCase		,	)
												_lowerCAmelCase    :    List[Any]										=      PyTorchBenchmark(_UpperCAmelCase      )
												benchmark.run()
												self.assertTrue(Path(os.path.join(_UpperCAmelCase		,	"""inf_time.csv"""      )      ).exists()      )
												self.assertTrue(Path(os.path.join(_UpperCAmelCase		,	"""train_time.csv"""      )      ).exists()      )
												self.assertTrue(Path(os.path.join(_UpperCAmelCase		,	"""inf_mem.csv"""      )      ).exists()      )
												self.assertTrue(Path(os.path.join(_UpperCAmelCase		,	"""train_mem.csv"""      )      ).exists()      )
												self.assertTrue(Path(os.path.join(_UpperCAmelCase		,	"""env.csv"""      )      ).exists()      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    str										=      """sshleifer/tiny-gpt2"""

								def _check_summary_is_not_empty(_UpperCAmelCase      :		int      ):
												self.assertTrue(hasattr(_UpperCAmelCase		,	"""sequential"""      )      )
												self.assertTrue(hasattr(_UpperCAmelCase		,	"""cumulative"""      )      )
												self.assertTrue(hasattr(_UpperCAmelCase		,	"""current"""      )      )
												self.assertTrue(hasattr(_UpperCAmelCase		,	"""total"""      )      )

								with tempfile.TemporaryDirectory() as tmp_dir:
												_lowerCAmelCase    :    Any										=      PyTorchBenchmarkArguments(
												    models=[MODEL_ID]		,	training=_UpperCAmelCase		,	inference=_UpperCAmelCase		,	sequence_lengths=[8]		,	batch_sizes=[1]		,	log_filename=os.path.join(_UpperCAmelCase		,	"""log.txt"""      )		,	log_print=_UpperCAmelCase		,	trace_memory_line_by_line=_UpperCAmelCase		,	multi_process=_UpperCAmelCase		,	)
												_lowerCAmelCase    :    str										=      PyTorchBenchmark(_UpperCAmelCase      )
												_lowerCAmelCase    :    Any										=      benchmark.run()
												_check_summary_is_not_empty(result.inference_summary      )
												_check_summary_is_not_empty(result.train_summary      )
												self.assertTrue(Path(os.path.join(_UpperCAmelCase		,	"""log.txt"""      )      ).exists()      )

