
import functools
import operator

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


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

_lowerCamelCase       :				Any       =			{
    '''asapp/sew-d-tiny-100k''': '''https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json''',
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}




class    SCREAMING_SNAKE_CASE__     (	__A					):





	'''simple docstring'''



	_UpperCAmelCase       :		str       =					'sew-d'



	def __init__(  self	:    Dict			,  lowercase	:    Tuple=32			,  lowercase	:    str=768			,  lowercase	:    List[Any]=12			,  lowercase	:    Dict=12			,  lowercase	:    Union[str, Any]=3_072			,  lowercase	:    List[str]=2			,  lowercase	:    Union[str, Any]=512			,  lowercase	:    List[Any]=256			,  lowercase	:    Optional[Any]=True			,  lowercase	:    List[str]=True			,  lowercase	:    Dict=("p2c", "c2p")			,  lowercase	:    Dict="layer_norm"			,  lowercase	:    Union[str, Any]="gelu_python"			,  lowercase	:    Tuple=0.1			,  lowercase	:    str=0.1			,  lowercase	:    Union[str, Any]=0.1			,  lowercase	:    str=0.0			,  lowercase	:    List[str]=0.1			,  lowercase	:    Any=0.02			,  lowercase	:    int=1E-7			,  lowercase	:    Union[str, Any]=1E-5			,  lowercase	:    List[Any]="group"			,  lowercase	:    List[Any]="gelu"			,  lowercase	:    List[str]=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)			,  lowercase	:    Any=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)			,  lowercase	:    Optional[Any]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)			,  lowercase	:    Dict=False			,  lowercase	:    int=128			,  lowercase	:    List[str]=16			,  lowercase	:    List[str]=True			,  lowercase	:    Dict=0.05			,  lowercase	:    List[str]=10			,  lowercase	:    List[str]=2			,  lowercase	:    Any=0.0			,  lowercase	:    Union[str, Any]=10			,  lowercase	:    List[str]=0			,  lowercase	:    str="mean"			,  lowercase	:    Optional[int]=False			,  lowercase	:    Any=False			,  lowercase	:    Union[str, Any]=256			,  lowercase	:    List[Any]=0			,  lowercase	:    Dict=1			,  lowercase	:    List[Any]=2			,  **lowercase	:    List[str]			,  ):


				'''simple docstring'''


				super().__init__(**__UpperCAmelCase			,  pad_token_id=__UpperCAmelCase			,  bos_token_id=__UpperCAmelCase			,  eos_token_id=__UpperCAmelCase	)
				_snake_case		=			hidden_size
				_snake_case		=			feat_extract_norm
				_snake_case		=			feat_extract_activation
				_snake_case		=			list(__UpperCAmelCase	)
				_snake_case		=			list(__UpperCAmelCase	)
				_snake_case		=			list(__UpperCAmelCase	)
				_snake_case		=			conv_bias
				_snake_case		=			num_conv_pos_embeddings
				_snake_case		=			num_conv_pos_embedding_groups
				_snake_case		=			len(self.conv_dim	)
				_snake_case		=			num_hidden_layers
				_snake_case		=			intermediate_size
				_snake_case		=			squeeze_factor
				_snake_case		=			max_position_embeddings
				_snake_case		=			position_buckets
				_snake_case		=			share_att_key
				_snake_case		=			relative_attention
				_snake_case		=			norm_rel_ebd
				_snake_case		=			list(__UpperCAmelCase	)
				_snake_case		=			hidden_act
				_snake_case		=			num_attention_heads
				_snake_case		=			hidden_dropout
				_snake_case		=			attention_dropout
				_snake_case		=			activation_dropout
				_snake_case		=			feat_proj_dropout
				_snake_case		=			final_dropout
				_snake_case		=			layer_norm_eps
				_snake_case		=			feature_layer_norm_eps
				_snake_case		=			initializer_range
				_snake_case		=			vocab_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)`,'
							    f'''but is `len(config.conv_dim) = {len(self.conv_dim	)}`, `len(config.conv_stride)'''
							    f'''= {len(self.conv_stride	)}`, `len(config.conv_kernel) = {len(self.conv_kernel	)}`.'''	)

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

				# ctc loss
				_snake_case		=			ctc_loss_reduction
				_snake_case		=			ctc_zero_infinity

				# sequence classification
				_snake_case		=			use_weighted_layer_sum
				_snake_case		=			classifier_proj_size





	@property
	def  A							(  self	:    Optional[Any]	):


				'''simple docstring'''


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




import contextlib
import importlib
import io
import unittest

import transformers

# Try to import everything from transformers to ensure every object can be loaded.
from transformers import *  # noqa F406
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, require_tf, require_torch
from transformers.utils import ContextManagers, find_labels, is_flax_available, is_tf_available, is_torch_available


if is_torch_available():
				from transformers import BertForPreTraining, BertForQuestionAnswering, BertForSequenceClassification

if is_tf_available():
				from transformers import TFBertForPreTraining, TFBertForQuestionAnswering, TFBertForSequenceClassification

if is_flax_available():
				from transformers import FlaxBertForPreTraining, FlaxBertForQuestionAnswering, FlaxBertForSequenceClassification


__lowerCamelCase							 =     DUMMY_UNKNOWN_IDENTIFIER
# An actual model hosted on huggingface.co

__lowerCamelCase							 =     "main"
# Default branch name
__lowerCamelCase							 =     "f2c752cfc5c0ab6f4bdec59acea69eefbee381c2"
# One particular commit (not the top of `main`)
__lowerCamelCase							 =     "aaaaaaa"
# This commit does not exist, so we should 404.

__lowerCamelCase							 =     "d9e9f15bc825e4b2c9249e9578f884bbcb5e3684"
# Sha-1 of config.json on the top of `main`, for checking purposes
__lowerCamelCase							 =     "4b243c475af8d0a7754e87d7d096c92e5199ec2fe168a2ee7998e3b8e9bcb1d3"






@contextlib.contextmanager
def      UpperCAmelCase    (		):






							"""simple docstring"""





							print('Welcome!' )
							yield
							print('Bye!' )






@contextlib.contextmanager
def      UpperCAmelCase    (		):






							"""simple docstring"""





							print('Bonjour!' )
							yield
							print('Au revoir!' )
class 			UpperCamelCase__(	unittest.TestCase       ):





						def  snake_case__		(				self   )    -> List[str]:
													# If the spec is missing, importlib would not be able to import the module dynamically.
													assert transformers.__spec__ is not None
													assert importlib.util.find_spec('transformers'   ) is not None






class 			UpperCamelCase__(	unittest.TestCase       ):





						@unittest.mock.patch('sys.stdout'						,new_callable=io.StringIO   )
						def  snake_case__		(				self						,__UpperCAmelCase   )    -> Dict:
													with ContextManagers([]   ):
																				print('Transformers are awesome!'   )
													# The print statement adds a new line at the end of the output
													self.assertEqual(mock_stdout.getvalue()						,'Transformers are awesome!\n'   )





						@unittest.mock.patch('sys.stdout'						,new_callable=io.StringIO   )
						def  snake_case__		(				self						,__UpperCAmelCase   )    -> List[str]:
													with ContextManagers([context_en()]   ):
																				print('Transformers are awesome!'   )
													# The output should be wrapped with an English welcome and goodbye
													self.assertEqual(mock_stdout.getvalue()						,'Welcome!\nTransformers are awesome!\nBye!\n'   )





						@unittest.mock.patch('sys.stdout'						,new_callable=io.StringIO   )
						def  snake_case__		(				self						,__UpperCAmelCase   )    -> Any:
													with ContextManagers([context_fr(), context_en()]   ):
																				print('Transformers are awesome!'   )
													# The output should be wrapped with an English and French welcome and goodbye
													self.assertEqual(mock_stdout.getvalue()						,'Bonjour!\nWelcome!\nTransformers are awesome!\nBye!\nAu revoir!\n'   )





						@require_torch
						def  snake_case__		(				self   )    -> Union[str, Any]:
													self.assertEqual(find_labels(__UpperCAmelCase   )						,['labels']   )
													self.assertEqual(find_labels(__UpperCAmelCase   )						,['labels', 'next_sentence_label']   )
													self.assertEqual(find_labels(__UpperCAmelCase   )						,['start_positions', 'end_positions']   )
													class 			UpperCamelCase__(	__A       ):
																			pass






													self.assertEqual(find_labels(__UpperCAmelCase   )						,['labels']   )





						@require_tf
						def  snake_case__		(				self   )    -> str:
													self.assertEqual(find_labels(__UpperCAmelCase   )						,['labels']   )
													self.assertEqual(find_labels(__UpperCAmelCase   )						,['labels', 'next_sentence_label']   )
													self.assertEqual(find_labels(__UpperCAmelCase   )						,['start_positions', 'end_positions']   )
													class 			UpperCamelCase__(	__A       ):
																			pass






													self.assertEqual(find_labels(__UpperCAmelCase   )						,['labels']   )





						@require_flax
						def  snake_case__		(				self   )    -> List[Any]:
													# Flax models don't have labels
													self.assertEqual(find_labels(__UpperCAmelCase   )						,[]   )
													self.assertEqual(find_labels(__UpperCAmelCase   )						,[]   )
													self.assertEqual(find_labels(__UpperCAmelCase   )						,[]   )
													class 			UpperCamelCase__(	__A       ):
																			pass






													self.assertEqual(find_labels(__UpperCAmelCase   )						,[]   )





