
'''simple docstring'''







import functools
import operator

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


lowercase    :							Union[str, Any]      =					logging.get_logger(__name__)

lowercase    :							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 						__UpperCAmelCase      (					__snake_case						):
							__lowercase      		=       """unispeech"""


							def __init__(       self    ,   lowerCAmelCase_=32    ,   lowerCAmelCase_=7_68    ,   lowerCAmelCase_=12    ,   lowerCAmelCase_=12    ,   lowerCAmelCase_=30_72    ,   lowerCAmelCase_="gelu"    ,   lowerCAmelCase_=0.1    ,   lowerCAmelCase_=0.1    ,   lowerCAmelCase_=0.1    ,   lowerCAmelCase_=0.0    ,   lowerCAmelCase_=0.0    ,   lowerCAmelCase_=0.1    ,   lowerCAmelCase_=0.1    ,   lowerCAmelCase_=0.02    ,   lowerCAmelCase_=1E-5    ,   lowerCAmelCase_="group"    ,   lowerCAmelCase_="gelu"    ,   lowerCAmelCase_=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)    ,   lowerCAmelCase_=(5, 2, 2, 2, 2, 2, 2)    ,   lowerCAmelCase_=(10, 3, 3, 3, 3, 2, 2)    ,   lowerCAmelCase_=False    ,   lowerCAmelCase_=1_28    ,   lowerCAmelCase_=16    ,   lowerCAmelCase_=False    ,   lowerCAmelCase_=True    ,   lowerCAmelCase_=0.05    ,   lowerCAmelCase_=10    ,   lowerCAmelCase_=2    ,   lowerCAmelCase_=0.0    ,   lowerCAmelCase_=10    ,   lowerCAmelCase_=0    ,   lowerCAmelCase_=3_20    ,   lowerCAmelCase_=2    ,   lowerCAmelCase_=0.1    ,   lowerCAmelCase_=1_00    ,   lowerCAmelCase_=2_56    ,   lowerCAmelCase_=2_56    ,   lowerCAmelCase_=0.1    ,   lowerCAmelCase_="mean"    ,   lowerCAmelCase_=False    ,   lowerCAmelCase_=False    ,   lowerCAmelCase_=2_56    ,   lowerCAmelCase_=80    ,   lowerCAmelCase_=0    ,   lowerCAmelCase_=1    ,   lowerCAmelCase_=2    ,   lowerCAmelCase_=0.5    ,   **lowerCAmelCase_    ,   ):





								"""simple docstring"""






								super().__init__(**a_    ,   pad_token_id=a_    ,   bos_token_id=a_    ,   eos_token_id=a_  )
								_snake_case   						=		hidden_size
								_snake_case   						=		feat_extract_norm
								_snake_case   						=		feat_extract_activation
								_snake_case   						=		list(a_  )
								_snake_case   						=		list(a_  )
								_snake_case   						=		list(a_  )
								_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   						=		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   						=		layerdrop
								_snake_case   						=		layer_norm_eps
								_snake_case   						=		initializer_range
								_snake_case   						=		num_ctc_classes
								_snake_case   						=		vocab_size
								_snake_case   						=		do_stable_layer_norm
								_snake_case   						=		use_weighted_layer_sum
								_snake_case   						=		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
								_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

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

								# ctc loss
								_snake_case   						=		ctc_loss_reduction
								_snake_case   						=		ctc_zero_infinity

								# pretraining loss
								_snake_case   						=		replace_prob




							@property
							def  lowerCamelCase				(       self  ):





								"""simple docstring"""






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





"""simple docstring"""
import argparse

import torch

from transformers import OpenAIGPTConfig, OpenAIGPTModel, load_tf_weights_in_openai_gpt
from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, logging


logging.set_verbosity_info()






def 		lowercase							(     _snake_case						:      List[Any]     ,   _snake_case						:      Tuple     ,   _snake_case						:      int     )     ->List[Any]:
	"""simple docstring"""





	if openai_config_file == "":
		__snake_case	:						Dict						=				OpenAIGPTConfig()
	else:
		__snake_case	:						int						=				OpenAIGPTConfig.from_json_file(_snake_case     )
	__snake_case	:						Tuple						=				OpenAIGPTModel(_snake_case     )

	# Load weights from numpy
	load_tf_weights_in_openai_gpt(_snake_case     ,   _snake_case     ,   _snake_case     )

	# Save pytorch-model
	__snake_case	:						str						=				pytorch_dump_folder_path + '''/''' + WEIGHTS_NAME
	__snake_case	:						Optional[Any]						=				pytorch_dump_folder_path + '''/''' + CONFIG_NAME
	print(f"""Save PyTorch model to {pytorch_weights_dump_path}"""     )
	torch.save(model.state_dict()     ,   _snake_case     )
	print(f"""Save configuration file to {pytorch_config_dump_path}"""     )
	with open(_snake_case     ,   '''w'''     ,   encoding='''utf-8'''     ) as f:
		f.write(config.to_json_string()     )


if __name__ == "__main__":
			SCREAMING_SNAKE_CASE :    Any									=				argparse.ArgumentParser()
			# Required parameters
			parser.add_argument(
			    """--openai_checkpoint_folder_path""",
			    default=None,
			    type=str,
			    required=True,
			    help="""Path to the TensorFlow checkpoint path.""",
			)
			parser.add_argument(
			    """--pytorch_dump_folder_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
			)
			parser.add_argument(
			    """--openai_config_file""",
			    default="""""",
			    type=str,
			    help=(
			        """An optional config json file corresponding to the pre-trained OpenAI model. \n"""
			        """This specifies the model architecture."""
			    ),
			)
			SCREAMING_SNAKE_CASE :    Optional[int]									=				parser.parse_args()
			convert_openai_checkpoint_to_pytorch(
			    args.openai_checkpoint_folder_path, args.openai_config_file, args.pytorch_dump_folder_path
			)





