






import functools
import operator

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


a_     :   List[Any]							=    logging.get_logger(__name__)

a_     :   str							=    {
    '''microsoft/unispeech-large-1500h-cv''': (
        '''https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json'''
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}


class      lowercase__     (			_UpperCAmelCase	):
	a_         ="""unispeech"""

	def __init__(							self		,    __UpperCAmelCase=32		,    __UpperCAmelCase=768		,    __UpperCAmelCase=12		,    __UpperCAmelCase=12		,    __UpperCAmelCase=3072		,    __UpperCAmelCase="gelu"		,    __UpperCAmelCase=0.1		,    __UpperCAmelCase=0.1		,    __UpperCAmelCase=0.1		,    __UpperCAmelCase=0.0		,    __UpperCAmelCase=0.0		,    __UpperCAmelCase=0.1		,    __UpperCAmelCase=0.1		,    __UpperCAmelCase=0.02		,    __UpperCAmelCase=1E-5		,    __UpperCAmelCase="group"		,    __UpperCAmelCase="gelu"		,    __UpperCAmelCase=(512, 512, 512, 512, 512, 512, 512)		,    __UpperCAmelCase=(5, 2, 2, 2, 2, 2, 2)		,    __UpperCAmelCase=(10, 3, 3, 3, 3, 2, 2)		,    __UpperCAmelCase=False		,    __UpperCAmelCase=128		,    __UpperCAmelCase=16		,    __UpperCAmelCase=False		,    __UpperCAmelCase=True		,    __UpperCAmelCase=0.05		,    __UpperCAmelCase=10		,    __UpperCAmelCase=2		,    __UpperCAmelCase=0.0		,    __UpperCAmelCase=10		,    __UpperCAmelCase=0		,    __UpperCAmelCase=320		,    __UpperCAmelCase=2		,    __UpperCAmelCase=0.1		,    __UpperCAmelCase=100		,    __UpperCAmelCase=256		,    __UpperCAmelCase=256		,    __UpperCAmelCase=0.1		,    __UpperCAmelCase="mean"		,    __UpperCAmelCase=False		,    __UpperCAmelCase=False		,    __UpperCAmelCase=256		,    __UpperCAmelCase=80		,    __UpperCAmelCase=0		,    __UpperCAmelCase=1		,    __UpperCAmelCase=2		,    __UpperCAmelCase=0.5		,    **__UpperCAmelCase		,    )->					Union[str, Any]:







							'''simple docstring'''





							super().__init__(**__UpperCAmelCase		,    pad_token_id=__UpperCAmelCase		,    bos_token_id=__UpperCAmelCase		,    eos_token_id=__UpperCAmelCase       )
							lowerCAmelCase__       =						hidden_size
							lowerCAmelCase__       =						feat_extract_norm
							lowerCAmelCase__       =						feat_extract_activation
							lowerCAmelCase__       =						list(__UpperCAmelCase       )
							lowerCAmelCase__       =						list(__UpperCAmelCase       )
							lowerCAmelCase__       =						list(__UpperCAmelCase       )
							lowerCAmelCase__       =						conv_bias
							lowerCAmelCase__       =						num_conv_pos_embeddings
							lowerCAmelCase__       =						num_conv_pos_embedding_groups
							lowerCAmelCase__       =						len(self.conv_dim       )
							lowerCAmelCase__       =						num_hidden_layers
							lowerCAmelCase__       =						intermediate_size
							lowerCAmelCase__       =						hidden_act
							lowerCAmelCase__       =						num_attention_heads
							lowerCAmelCase__       =						hidden_dropout
							lowerCAmelCase__       =						attention_dropout
							lowerCAmelCase__       =						activation_dropout
							lowerCAmelCase__       =						feat_proj_dropout
							lowerCAmelCase__       =						final_dropout
							lowerCAmelCase__       =						layerdrop
							lowerCAmelCase__       =						layer_norm_eps
							lowerCAmelCase__       =						initializer_range
							lowerCAmelCase__       =						num_ctc_classes
							lowerCAmelCase__       =						vocab_size
							lowerCAmelCase__       =						do_stable_layer_norm
							lowerCAmelCase__       =						use_weighted_layer_sum
							lowerCAmelCase__       =						classifier_proj_size

							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__       =						apply_spec_augment
							lowerCAmelCase__       =						mask_time_prob
							lowerCAmelCase__       =						mask_time_length
							lowerCAmelCase__       =						mask_time_min_masks
							lowerCAmelCase__       =						mask_feature_prob
							lowerCAmelCase__       =						mask_feature_length
							lowerCAmelCase__       =						mask_feature_min_masks

							# parameters for pretraining with codevector quantized representations
							lowerCAmelCase__       =						num_codevectors_per_group
							lowerCAmelCase__       =						num_codevector_groups
							lowerCAmelCase__       =						contrastive_logits_temperature
							lowerCAmelCase__       =						feat_quantizer_dropout
							lowerCAmelCase__       =						num_negatives
							lowerCAmelCase__       =						codevector_dim
							lowerCAmelCase__       =						proj_codevector_dim
							lowerCAmelCase__       =						diversity_loss_weight

							# ctc loss
							lowerCAmelCase__       =						ctc_loss_reduction
							lowerCAmelCase__       =						ctc_zero_infinity

							# pretraining loss
							lowerCAmelCase__       =						replace_prob


	@property
	def 		UpperCAmelCase  (							self       )->					Any:







							'''simple docstring'''





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














import json
import logging
import os
import sys
from time import time
from unittest.mock import patch

from transformers.testing_utils import TestCasePlus, require_torch_tpu


logging.basicConfig(level=logging.DEBUG)

a_							=    logging.getLogger()


def        _a  (     UpperCamelCase_					:				Union[str, Any]   ) ->   Dict:
						"""simple docstring"""







						lowerCAmelCase__       =						{}
						lowerCAmelCase__       =						os.path.join(UpperCamelCase_    ,   "all_results.json"   )
						if os.path.exists(UpperCamelCase_   ):
												with open(UpperCamelCase_    ,   "r"   ) as f:
																		lowerCAmelCase__       =						json.load(UpperCamelCase_   )
						else:
												raise ValueError(F"can't find {path}"   )
						return results


a_							=    logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)





@require_torch_tpu
class      lowercase__     (			_UpperCAmelCase	):

	def 		UpperCAmelCase  (							self       )->					Optional[Any]:







							'''simple docstring'''





							import xla_spawn

							lowerCAmelCase__       =						self.get_auto_remove_tmp_dir()
							lowerCAmelCase__       =						F"\n            ./examples/pytorch/text-classification/run_glue.py\n            --num_cores=8\n            ./examples/pytorch/text-classification/run_glue.py\n            --model_name_or_path distilbert-base-uncased\n            --output_dir {tmp_dir}\n            --overwrite_output_dir\n            --train_file ./tests/fixtures/tests_samples/MRPC/train.csv\n            --validation_file ./tests/fixtures/tests_samples/MRPC/dev.csv\n            --do_train\n            --do_eval\n            --debug tpu_metrics_debug\n            --per_device_train_batch_size=2\n            --per_device_eval_batch_size=1\n            --learning_rate=1e-4\n            --max_steps=10\n            --warmup_steps=2\n            --seed=42\n            --max_seq_length=128\n            ".split()

							with patch.object(__UpperCAmelCase		,    "argv"		,    __UpperCAmelCase       ):
													lowerCAmelCase__       =						time()
													xla_spawn.main()
													lowerCAmelCase__       =						time()

													lowerCAmelCase__       =						get_results(__UpperCAmelCase       )
													self.assertGreaterEqual(result["eval_accuracy"]		,    0.75       )

													# Assert that the script takes less than 500 seconds to make sure it doesn't hang.
													self.assertLess(end - start		,    500       )


	def 		UpperCAmelCase  (							self       )->					Dict:







							'''simple docstring'''





							import xla_spawn

							lowerCAmelCase__       =						"\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            ".split()
							with patch.object(__UpperCAmelCase		,    "argv"		,    __UpperCAmelCase       ):
													xla_spawn.main()






