


'''simple docstring'''
import collections
import importlib.util
import os
import re
from pathlib import Path


__SCREAMING_SNAKE_CASE					:				str									=		'''src/transformers'''


# Matches is_xxx_available()
__SCREAMING_SNAKE_CASE					:				Dict									=		re.compile(r'''is\_([a-z_]*)_available()''')
# Catches a one-line _import_struct = {xxx}
__SCREAMING_SNAKE_CASE					:				Optional[Any]									=		re.compile(r'''^_import_structure\s+=\s+\{([^\}]+)\}''')
# Catches a line with a key-values pattern: "bla": ["foo", "bar"]
__SCREAMING_SNAKE_CASE					:				Tuple									=		re.compile(r'''\s+"\S*":\s+\[([^\]]*)\]''')
# Catches a line if not is_foo_available
__SCREAMING_SNAKE_CASE					:				List[Any]									=		re.compile(r'''^\s*if\s+not\s+is\_[a-z_]*\_available\(\)''')
# Catches a line _import_struct["bla"].append("foo")
__SCREAMING_SNAKE_CASE					:				Dict									=		re.compile(r'''^\s*_import_structure\["\S*"\]\.append\("(\S*)"\)''')
# Catches a line _import_struct["bla"].extend(["foo", "bar"]) or _import_struct["bla"] = ["foo", "bar"]
__SCREAMING_SNAKE_CASE					:				Optional[Any]									=		re.compile(r'''^\s*_import_structure\[\S*\](?:\.extend\(|\s*=\s+)\[([^\]]*)\]''')
# Catches a line with an object between quotes and a comma:     "MyModel",
__SCREAMING_SNAKE_CASE					:				Optional[int]									=		re.compile('''^\s+"([^"]+)",''')
# Catches a line with objects between brackets only:    ["foo", "bar"],
__SCREAMING_SNAKE_CASE					:				int									=		re.compile('''^\s+\[([^\]]+)\]''')
# Catches a line with from foo import bar, bla, boo
__SCREAMING_SNAKE_CASE					:				Optional[int]									=		re.compile(r'''\s+from\s+\S*\s+import\s+([^\(\s].*)\n''')
# Catches a line with try:
__SCREAMING_SNAKE_CASE					:				Union[str, Any]									=		re.compile(r'''^\s*try:''')
# Catches a line with else:
__SCREAMING_SNAKE_CASE					:				int									=		re.compile(r'''^\s*else:''')







def       a_				(	UpperCamelCase_ ):
							if _re_test_backend.search(UpperCamelCase_ ) is None:
														return None
							A_			    =		[b[0] for b in _re_backend.findall(UpperCamelCase_ )]
							backends.sort()
							return "_and_".join(UpperCamelCase_ )







def       a_				(	UpperCamelCase_ ):
							with open(UpperCamelCase_						,  "r"						,  encoding="utf-8"						,  newline="\n" ) as f:
														A_			    =		f.readlines()

							A_			    =		0
							while line_index < len(UpperCamelCase_ ) and not lines[line_index].startswith("_import_structure = {" ):
														line_index += 1

							# If this is a traditional init, just return.
							if line_index >= len(UpperCamelCase_ ):
														return None

							# First grab the objects without a specific backend in _import_structure
							A_			    =		[]
							while not lines[line_index].startswith("if TYPE_CHECKING" ) and find_backend(lines[line_index] ) is None:
														A_			    =		lines[line_index]
														# If we have everything on a single line, let's deal with it.
														if _re_one_line_import_struct.search(UpperCamelCase_ ):
																					A_			    =		_re_one_line_import_struct.search(UpperCamelCase_ ).groups()[0]
																					A_			    =		re.findall("\[([^\]]+)\]"						,  UpperCamelCase_ )
																					for imp in imports:
																												objects.extend([obj[1:-1] for obj in imp.split(", " )] )
																					line_index += 1
																					continue
														A_			    =		_re_import_struct_key_value.search(UpperCamelCase_ )
														if single_line_import_search is not None:
																					A_			    =		[obj[1:-1] for obj in single_line_import_search.groups()[0].split(", " ) if len(UpperCamelCase_ ) > 0]
																					objects.extend(UpperCamelCase_ )
														elif line.startswith(" " * 8 + "\"" ):
																					objects.append(line[9:-3] )
														line_index += 1

							A_			    =		{"none": objects}
							# Let's continue with backend-specific objects in _import_structure
							while not lines[line_index].startswith("if TYPE_CHECKING" ):
														# If the line is an if not is_backend_available, we grab all objects associated.
														A_			    =		find_backend(lines[line_index] )
														# Check if the backend declaration is inside a try block:
														if _re_try.search(lines[line_index - 1] ) is None:
																					A_			    =		None

														if backend is not None:
																					line_index += 1

																					# Scroll until we hit the else block of try-except-else
																					while _re_else.search(lines[line_index] ) is None:
																												line_index += 1

																					line_index += 1

																					A_			    =		[]
																					# Until we unindent, add backend objects to the list
																					while len(lines[line_index] ) <= 1 or lines[line_index].startswith(" " * 4 ):
																												A_			    =		lines[line_index]
																												if _re_import_struct_add_one.search(UpperCamelCase_ ) is not None:
																																			objects.append(_re_import_struct_add_one.search(UpperCamelCase_ ).groups()[0] )
																												elif _re_import_struct_add_many.search(UpperCamelCase_ ) is not None:
																																			A_			    =		_re_import_struct_add_many.search(UpperCamelCase_ ).groups()[0].split(", " )
																																			A_			    =		[obj[1:-1] for obj in imports if len(UpperCamelCase_ ) > 0]
																																			objects.extend(UpperCamelCase_ )
																												elif _re_between_brackets.search(UpperCamelCase_ ) is not None:
																																			A_			    =		_re_between_brackets.search(UpperCamelCase_ ).groups()[0].split(", " )
																																			A_			    =		[obj[1:-1] for obj in imports if len(UpperCamelCase_ ) > 0]
																																			objects.extend(UpperCamelCase_ )
																												elif _re_quote_object.search(UpperCamelCase_ ) is not None:
																																			objects.append(_re_quote_object.search(UpperCamelCase_ ).groups()[0] )
																												elif line.startswith(" " * 8 + "\"" ):
																																			objects.append(line[9:-3] )
																												elif line.startswith(" " * 1_2 + "\"" ):
																																			objects.append(line[1_3:-3] )
																												line_index += 1

																					A_			    =		objects
														else:
																					line_index += 1

    # At this stage we are in the TYPE_CHECKING part, first grab the objects without a specific backend
							A_			    =		[]
							while (
							    line_index < len(UpperCamelCase_ )
							    and find_backend(lines[line_index] ) is None
							    and not lines[line_index].startswith("else" )
							):
														A_			    =		lines[line_index]
														A_			    =		_re_import.search(UpperCamelCase_ )
														if single_line_import_search is not None:
																					objects.extend(single_line_import_search.groups()[0].split(", " ) )
														elif line.startswith(" " * 8 ):
																					objects.append(line[8:-2] )
														line_index += 1

							A_			    =		{"none": objects}
							# Let's continue with backend-specific objects
							while line_index < len(UpperCamelCase_ ):
														# If the line is an if is_backend_available, we grab all objects associated.
														A_			    =		find_backend(lines[line_index] )
														# Check if the backend declaration is inside a try block:
														if _re_try.search(lines[line_index - 1] ) is None:
																					A_			    =		None

														if backend is not None:
																					line_index += 1

																					# Scroll until we hit the else block of try-except-else
																					while _re_else.search(lines[line_index] ) is None:
																												line_index += 1

																					line_index += 1

																					A_			    =		[]
																					# Until we unindent, add backend objects to the list
																					while len(lines[line_index] ) <= 1 or lines[line_index].startswith(" " * 8 ):
																												A_			    =		lines[line_index]
																												A_			    =		_re_import.search(UpperCamelCase_ )
																												if single_line_import_search is not None:
																																			objects.extend(single_line_import_search.groups()[0].split(", " ) )
																												elif line.startswith(" " * 1_2 ):
																																			objects.append(line[1_2:-2] )
																												line_index += 1

																					A_			    =		objects
														else:
																					line_index += 1

							return import_dict_objects, type_hint_objects







def       a_				(	UpperCamelCase_						,  UpperCamelCase_ ):

							def find_duplicates(UpperCamelCase_ ):
														return [k for k, v in collections.Counter(UpperCamelCase_ ).items() if v > 1]

							if list(import_dict_objects.keys() ) != list(type_hint_objects.keys() ):
														return ["Both sides of the init do not have the same backends!"]

							A_			    =		[]
							for key in import_dict_objects.keys():
														A_			    =		find_duplicates(import_dict_objects[key] )
														if duplicate_imports:
																					errors.append(f"Duplicate _import_structure definitions for: {duplicate_imports}" )
														A_			    =		find_duplicates(type_hint_objects[key] )
														if duplicate_type_hints:
																					errors.append(f"Duplicate TYPE_CHECKING objects for: {duplicate_type_hints}" )

														if sorted(set(import_dict_objects[key] ) ) != sorted(set(type_hint_objects[key] ) ):
																					A_			    =		"base imports" if key == "none" else f"{key} backend"
																					errors.append(f"Differences for {name}:" )
																					for a in type_hint_objects[key]:
																												if a not in import_dict_objects[key]:
																																			errors.append(f"  {a} in TYPE_HINT but not in _import_structure." )
																					for a in import_dict_objects[key]:
																												if a not in type_hint_objects[key]:
																																			errors.append(f"  {a} in _import_structure but not in TYPE_HINT." )
							return errors







def       a_				(	):
							A_			    =		[]
							for root, _, files in os.walk(UpperCamelCase_ ):
														if "__init__.py" in files:
																					A_			    =		os.path.join(UpperCamelCase_						,  "__init__.py" )
																					A_			    =		parse_init(UpperCamelCase_ )
																					if objects is not None:
																												A_			    =		analyze_results(*UpperCamelCase_ )
																												if len(UpperCamelCase_ ) > 0:
																																			A_			    =		f"Problem in {fname}, both halves do not define the same objects.\n{errors[0]}"
																																			failures.append("\n".join(UpperCamelCase_ ) )
							if len(UpperCamelCase_ ) > 0:
														raise ValueError("\n\n".join(UpperCamelCase_ ) )







def       a_				(	):
							A_			    =		[]
							for path, directories, files in os.walk(UpperCamelCase_ ):
														for folder in directories:
																					# Ignore private modules
																					if folder.startswith("_" ):
																												directories.remove(UpperCamelCase_ )
																												continue
																					# Ignore leftovers from branches (empty folders apart from pycache)
																					if len(list((Path(UpperCamelCase_ ) / folder).glob("*.py" ) ) ) == 0:
																												continue
																					A_			    =		str((Path(UpperCamelCase_ ) / folder).relative_to(UpperCamelCase_ ) )
																					A_			    =		short_path.replace(os.path.sep						,  "." )
																					submodules.append(UpperCamelCase_ )
														for fname in files:
																					if fname == "__init__.py":
																												continue
																					A_			    =		str((Path(UpperCamelCase_ ) / fname).relative_to(UpperCamelCase_ ) )
																					A_			    =		short_path.replace(".py"						,  "" ).replace(os.path.sep						,  "." )
																					if len(submodule.split("." ) ) == 1:
																												submodules.append(UpperCamelCase_ )
							return submodules


__SCREAMING_SNAKE_CASE					:				Any									=		[
    '''convert_pytorch_checkpoint_to_tf2''',
    '''modeling_flax_pytorch_utils''',
]







def       a_				(	):
							# This is to make sure the transformers module imported is the one in the repo.
							A_			    =		importlib.util.spec_from_file_location(
							    "transformers"						,  os.path.join(UpperCamelCase_						,  "__init__.py" )						,  submodule_search_locations=[PATH_TO_TRANSFORMERS]						,  )
							A_			    =		spec.loader.load_module()

							A_			    =		[
							    module
							    for module in get_transformers_submodules()
							    if module not in IGNORE_SUBMODULES and module not in transformers._import_structure.keys()
							]
							if len(UpperCamelCase_ ) > 0:
														A_			    =		"\n".join(f"- {module}" for module in module_not_registered )
														raise ValueError(
														    "The following submodules are not properly registered in the main init of Transformers:\n"
														    f"{list_of_modules}\n"
														    "Make sure they appear somewhere in the keys of `_import_structure` with an empty list as value." )


if __name__ == "__main__":
							check_all_inits()
							check_submodules()









'''simple docstring'''
import functools
import operator

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


__SCREAMING_SNAKE_CASE					:				Dict									=		logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE					:				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 					__lowerCAmelCase   (   lowercase						):

						"""simple docstring"""






						_UpperCAmelCase		:       Dict   						="wav2vec2"






						def __init__(  self							:      str ,  lowerCAmelCase							:      Dict=32 ,  lowerCAmelCase							:      List[Any]=7_68 ,  lowerCAmelCase							:      List[str]=12 ,  lowerCAmelCase							:      List[str]=12 ,  lowerCAmelCase							:      List[Any]=30_72 ,  lowerCAmelCase							:      Optional[Any]="gelu" ,  lowerCAmelCase							:      Optional[int]=0.1 ,  lowerCAmelCase							:      Optional[int]=0.1 ,  lowerCAmelCase							:      List[Any]=0.1 ,  lowerCAmelCase							:      Dict=0.0 ,  lowerCAmelCase							:      Union[str, Any]=0.0 ,  lowerCAmelCase							:      str=0.1 ,  lowerCAmelCase							:      List[str]=0.1 ,  lowerCAmelCase							:      Dict=0.0_2 ,  lowerCAmelCase							:      List[str]=1e-5 ,  lowerCAmelCase							:      Optional[Any]="group" ,  lowerCAmelCase							:      List[Any]="gelu" ,  lowerCAmelCase							:      int=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12) ,  lowerCAmelCase							:      Union[str, Any]=(5, 2, 2, 2, 2, 2, 2) ,  lowerCAmelCase							:      Any=(10, 3, 3, 3, 3, 2, 2) ,  lowerCAmelCase							:      str=False ,  lowerCAmelCase							:      Tuple=1_28 ,  lowerCAmelCase							:      Union[str, Any]=16 ,  lowerCAmelCase							:      List[str]=False ,  lowerCAmelCase							:      Union[str, Any]=True ,  lowerCAmelCase							:      Any=0.0_5 ,  lowerCAmelCase							:      Any=10 ,  lowerCAmelCase							:      Dict=2 ,  lowerCAmelCase							:      List[Any]=0.0 ,  lowerCAmelCase							:      int=10 ,  lowerCAmelCase							:      List[str]=0 ,  lowerCAmelCase							:      Tuple=3_20 ,  lowerCAmelCase							:      List[str]=2 ,  lowerCAmelCase							:      int=0.1 ,  lowerCAmelCase							:      List[Any]=1_00 ,  lowerCAmelCase							:      List[str]=2_56 ,  lowerCAmelCase							:      int=2_56 ,  lowerCAmelCase							:      Optional[Any]=0.1 ,  lowerCAmelCase							:      str="sum" ,  lowerCAmelCase							:      List[Any]=False ,  lowerCAmelCase							:      List[str]=False ,  lowerCAmelCase							:      Tuple=2_56 ,  lowerCAmelCase							:      str=(5_12, 5_12, 5_12, 5_12, 15_00) ,  lowerCAmelCase							:      List[str]=(5, 3, 3, 1, 1) ,  lowerCAmelCase							:      Tuple=(1, 2, 3, 1, 1) ,  lowerCAmelCase							:      Optional[Any]=5_12 ,  lowerCAmelCase							:      Any=0 ,  lowerCAmelCase							:      str=1 ,  lowerCAmelCase							:      Any=2 ,  lowerCAmelCase							:      Any=False ,  lowerCAmelCase							:      List[Any]=3 ,  lowerCAmelCase							:      Any=2 ,  lowerCAmelCase							:      List[str]=3 ,  lowerCAmelCase							:      int=None ,  lowerCAmelCase							:      Optional[int]=None ,  **lowerCAmelCase							:      Union[str, Any] ,  ):
													super().__init__(**lowerCAmelCase ,  pad_token_id=lowerCAmelCase ,  bos_token_id=lowerCAmelCase ,  eos_token_id=lowerCAmelCase	)
													A_			    =		hidden_size
													A_			    =		feat_extract_norm
													A_			    =		feat_extract_activation
													A_			    =		list(lowerCAmelCase	)
													A_			    =		list(lowerCAmelCase	)
													A_			    =		list(lowerCAmelCase	)
													A_			    =		conv_bias
													A_			    =		num_conv_pos_embeddings
													A_			    =		num_conv_pos_embedding_groups
													A_			    =		len(self.conv_dim	)
													A_			    =		num_hidden_layers
													A_			    =		intermediate_size
													A_			    =		hidden_act
													A_			    =		num_attention_heads
													A_			    =		hidden_dropout
													A_			    =		attention_dropout
													A_			    =		activation_dropout
													A_			    =		feat_proj_dropout
													A_			    =		final_dropout
													A_			    =		layerdrop
													A_			    =		layer_norm_eps
													A_			    =		initializer_range
													A_			    =		vocab_size
													A_			    =		do_stable_layer_norm
													A_			    =		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
													A_			    =		apply_spec_augment
													A_			    =		mask_time_prob
													A_			    =		mask_time_length
													A_			    =		mask_time_min_masks
													A_			    =		mask_feature_prob
													A_			    =		mask_feature_length
													A_			    =		mask_feature_min_masks

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

													# ctc loss
													A_			    =		ctc_loss_reduction
													A_			    =		ctc_zero_infinity

													# adapter
													A_			    =		add_adapter
													A_			    =		adapter_kernel_size
													A_			    =		adapter_stride
													A_			    =		num_adapter_layers
													A_			    =		output_hidden_size or hidden_size
													A_			    =		adapter_attn_dim

													# SequenceClassification-specific parameter. Feel free to ignore for other classes.
													A_			    =		classifier_proj_size

													# XVector-specific parameters. Feel free to ignore for other classes.
													A_			    =		list(lowerCAmelCase	)
													A_			    =		list(lowerCAmelCase	)
													A_			    =		list(lowerCAmelCase	)
													A_			    =		xvector_output_dim






						@property
						def 				_UpperCAmelCase       (  self							:      Tuple	):
													return functools.reduce(operator.mul ,  self.conv_stride ,  1	)





