
"""simple docstring"""





import functools
import operator

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


UpperCamelCase_					:						Dict				= logging.get_logger(__name__)

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



class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			snake_case	      =				"sew"




			def __init__(				self						:					Dict       ,   _snake_case						:					List[str]=32       ,   _snake_case						:					Any=768       ,   _snake_case						:					int=12       ,   _snake_case						:					Optional[int]=12       ,   _snake_case						:					Any=3_072       ,   _snake_case						:					int=2       ,   _snake_case						:					int="gelu"       ,   _snake_case						:					Optional[int]=0.1       ,   _snake_case						:					int=0.1       ,   _snake_case						:					int=0.1       ,   _snake_case						:					Optional[int]=0.0       ,   _snake_case						:					List[Any]=0.1       ,   _snake_case						:					List[str]=0.1       ,   _snake_case						:					List[str]=0.0_2       ,   _snake_case						:					Union[str, Any]=1e-5       ,   _snake_case						:					int="group"       ,   _snake_case						:					Optional[int]="gelu"       ,   _snake_case						:					Optional[Any]=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)       ,   _snake_case						:					Union[str, Any]=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)       ,   _snake_case						:					Optional[Any]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)       ,   _snake_case						:					Dict=False       ,   _snake_case						:					str=128       ,   _snake_case						:					List[Any]=16       ,   _snake_case						:					Dict=True       ,   _snake_case						:					Optional[Any]=0.0_5       ,   _snake_case						:					Tuple=10       ,   _snake_case						:					Tuple=2       ,   _snake_case						:					List[str]=0.0       ,   _snake_case						:					Dict=10       ,   _snake_case						:					Union[str, Any]=0       ,   _snake_case						:					Tuple="mean"       ,   _snake_case						:					List[Any]=False       ,   _snake_case						:					Optional[int]=False       ,   _snake_case						:					List[str]=256       ,   _snake_case						:					int=0       ,   _snake_case						:					Any=1       ,   _snake_case						:					int=2       ,   **_snake_case						:					Dict       ,   )      -> Any:







								"""simple docstring"""
								super().__init__(**_snake_case       ,   pad_token_id=_snake_case       ,   bos_token_id=_snake_case       ,   eos_token_id=_snake_case	)
								A_				 =						hidden_size
								A_				 =						feat_extract_norm
								A_				 =						feat_extract_activation
								A_				 =						list(_snake_case	)
								A_				 =						list(_snake_case	)
								A_				 =						list(_snake_case	)
								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_				 =						squeeze_factor
								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

								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
								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

								# ctc loss
								A_				 =						ctc_loss_reduction
								A_				 =						ctc_zero_infinity

								# sequence classification
								A_				 =						use_weighted_layer_sum
								A_				 =						classifier_proj_size






			@property
			def      lowerCamelCase__     (				self						:					int	)      -> Optional[int]:







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






"""simple docstring"""





from argparse import ArgumentParser, Namespace

from ..utils import logging
from . import BaseTransformersCLICommand
def 							A_     (__a				):

					'''simple docstring'''





					return ConvertCommand(
					    args.model_type				,   args.tf_checkpoint				,   args.pytorch_dump_output				,   args.config				,   args.finetuning_task_name				)


UpperCamelCase_					:						Tuple				= '''
transformers can only be used from the commandline to convert TensorFlow models in PyTorch, In that case, it requires
TensorFlow to be installed. Please see https://www.tensorflow.org/install/ for installation instructions.
'''




class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			@staticmethod
			def      lowerCamelCase__     (				_snake_case						:					ArgumentParser	)      -> Union[str, Any]:







								"""simple docstring"""
								A_				 =						parser.add_parser(
								    "convert"       ,   help="CLI tool to run convert model from original author checkpoints to Transformers PyTorch checkpoints."       ,   )
								train_parser.add_argument("--model_type"       ,   type=_snake_case       ,   required=_snake_case       ,   help="Model's type."	)
								train_parser.add_argument(
								    "--tf_checkpoint"       ,   type=_snake_case       ,   required=_snake_case       ,   help="TensorFlow checkpoint path or folder."	)
								train_parser.add_argument(
								    "--pytorch_dump_output"       ,   type=_snake_case       ,   required=_snake_case       ,   help="Path to the PyTorch saved model output."	)
								train_parser.add_argument("--config"       ,   type=_snake_case       ,   default=""       ,   help="Configuration file path or folder."	)
								train_parser.add_argument(
								    "--finetuning_task_name"       ,   type=_snake_case       ,   default=_snake_case       ,   help="Optional fine-tuning task name if the TF model was a finetuned model."       ,   )
								train_parser.set_defaults(func=_snake_case	)




			def __init__(				self						:					str       ,   _snake_case						:					str       ,   _snake_case						:					str       ,   _snake_case						:					str       ,   _snake_case						:					str       ,   _snake_case						:					str       ,   *_snake_case						:					Optional[int]       ,   )      -> Union[str, Any]:







								"""simple docstring"""
								A_				 =						logging.get_logger("transformers-cli/converting"	)

								self._logger.info(F'Loading model {model_type}'	)
								A_				 =						model_type
								A_				 =						tf_checkpoint
								A_				 =						pytorch_dump_output
								A_				 =						config
								A_				 =						finetuning_task_name






			def      lowerCamelCase__     (				self						:					Tuple	)      -> Dict:







								"""simple docstring"""
								if self._model_type == "albert":
													try:
																		from ..models.albert.convert_albert_original_tf_checkpoint_to_pytorch import (
																		    convert_tf_checkpoint_to_pytorch,
																		)
													except ImportError:
																		raise ImportError(_snake_case	)

													convert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output	)
								elif self._model_type == "bert":
													try:
																		from ..models.bert.convert_bert_original_tf_checkpoint_to_pytorch import (
																		    convert_tf_checkpoint_to_pytorch,
																		)
													except ImportError:
																		raise ImportError(_snake_case	)

													convert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output	)
								elif self._model_type == "funnel":
													try:
																		from ..models.funnel.convert_funnel_original_tf_checkpoint_to_pytorch import (
																		    convert_tf_checkpoint_to_pytorch,
																		)
													except ImportError:
																		raise ImportError(_snake_case	)

													convert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output	)
								elif self._model_type == "t5":
													try:
																		from ..models.ta.convert_ta_original_tf_checkpoint_to_pytorch import convert_tf_checkpoint_to_pytorch
													except ImportError:
																		raise ImportError(_snake_case	)

													convert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output	)
								elif self._model_type == "gpt":
													from ..models.openai.convert_openai_original_tf_checkpoint_to_pytorch import (
													    convert_openai_checkpoint_to_pytorch,
													)

													convert_openai_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output	)
								elif self._model_type == "transfo_xl":
													try:
																		from ..models.transfo_xl.convert_transfo_xl_original_tf_checkpoint_to_pytorch import (
																		    convert_transfo_xl_checkpoint_to_pytorch,
																		)
													except ImportError:
																		raise ImportError(_snake_case	)

													if "ckpt" in self._tf_checkpoint.lower():
																		A_				 =						self._tf_checkpoint
																		A_				 =						""
													else:
																		A_				 =						self._tf_checkpoint
																		A_				 =						""
													convert_transfo_xl_checkpoint_to_pytorch(
													    _snake_case       ,   self._config       ,   self._pytorch_dump_output       ,   _snake_case	)
								elif self._model_type == "gpt2":
													try:
																		from ..models.gpta.convert_gpta_original_tf_checkpoint_to_pytorch import (
																		    convert_gpta_checkpoint_to_pytorch,
																		)
													except ImportError:
																		raise ImportError(_snake_case	)

													convert_gpta_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output	)
								elif self._model_type == "xlnet":
													try:
																		from ..models.xlnet.convert_xlnet_original_tf_checkpoint_to_pytorch import (
																		    convert_xlnet_checkpoint_to_pytorch,
																		)
													except ImportError:
																		raise ImportError(_snake_case	)

													convert_xlnet_checkpoint_to_pytorch(
													    self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output       ,   self._finetuning_task_name	)
								elif self._model_type == "xlm":
													from ..models.xlm.convert_xlm_original_pytorch_checkpoint_to_pytorch import (
													    convert_xlm_checkpoint_to_pytorch,
													)

													convert_xlm_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._pytorch_dump_output	)
								elif self._model_type == "lxmert":
													from ..models.lxmert.convert_lxmert_original_tf_checkpoint_to_pytorch import (
													    convert_lxmert_checkpoint_to_pytorch,
													)

													convert_lxmert_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._pytorch_dump_output	)
								elif self._model_type == "rembert":
													from ..models.rembert.convert_rembert_tf_checkpoint_to_pytorch import (
													    convert_rembert_tf_checkpoint_to_pytorch,
													)

													convert_rembert_tf_checkpoint_to_pytorch(self._tf_checkpoint       ,   self._config       ,   self._pytorch_dump_output	)
								else:
													raise ValueError(
													    "--model_type should be selected in the list [bert, gpt, gpt2, t5, transfo_xl, xlnet, xlm, lxmert]"	)




