
'''simple docstring'''




import functools
import operator

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


lowerCAmelCase__          =						logging.get_logger(__name__)

lowerCAmelCase__          =						{
    '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					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''unispeech'''

	def __init__(      self   :						Union[str, Any]  ,					UpperCAmelCase_   :						Optional[Any]=32  ,					UpperCAmelCase_   :						Dict=768  ,					UpperCAmelCase_   :						Tuple=12  ,					UpperCAmelCase_   :						Any=12  ,					UpperCAmelCase_   :						Dict=3_072  ,					UpperCAmelCase_   :						Any="gelu"  ,					UpperCAmelCase_   :						List[str]=0.1  ,					UpperCAmelCase_   :						Dict=0.1  ,					UpperCAmelCase_   :						List[str]=0.1  ,					UpperCAmelCase_   :						Tuple=0.0  ,					UpperCAmelCase_   :						Optional[Any]=0.0  ,					UpperCAmelCase_   :						List[Any]=0.1  ,					UpperCAmelCase_   :						Optional[Any]=0.1  ,					UpperCAmelCase_   :						int=0.02  ,					UpperCAmelCase_   :						Optional[Any]=1e-5  ,					UpperCAmelCase_   :						Any="group"  ,					UpperCAmelCase_   :						List[str]="gelu"  ,					UpperCAmelCase_   :						Union[str, Any]=(512, 512, 512, 512, 512, 512, 512)  ,					UpperCAmelCase_   :						int=(5, 2, 2, 2, 2, 2, 2)  ,					UpperCAmelCase_   :						List[str]=(10, 3, 3, 3, 3, 2, 2)  ,					UpperCAmelCase_   :						Dict=False  ,					UpperCAmelCase_   :						Optional[Any]=128  ,					UpperCAmelCase_   :						List[Any]=16  ,					UpperCAmelCase_   :						Union[str, Any]=False  ,					UpperCAmelCase_   :						int=True  ,					UpperCAmelCase_   :						Dict=0.05  ,					UpperCAmelCase_   :						Optional[Any]=10  ,					UpperCAmelCase_   :						str=2  ,					UpperCAmelCase_   :						str=0.0  ,					UpperCAmelCase_   :						Tuple=10  ,					UpperCAmelCase_   :						Optional[Any]=0  ,					UpperCAmelCase_   :						Tuple=320  ,					UpperCAmelCase_   :						List[Any]=2  ,					UpperCAmelCase_   :						Union[str, Any]=0.1  ,					UpperCAmelCase_   :						Tuple=100  ,					UpperCAmelCase_   :						Optional[Any]=256  ,					UpperCAmelCase_   :						Dict=256  ,					UpperCAmelCase_   :						Any=0.1  ,					UpperCAmelCase_   :						int="mean"  ,					UpperCAmelCase_   :						Dict=False  ,					UpperCAmelCase_   :						List[Any]=False  ,					UpperCAmelCase_   :						Tuple=256  ,					UpperCAmelCase_   :						List[Any]=80  ,					UpperCAmelCase_   :						int=0  ,					UpperCAmelCase_   :						Any=1  ,					UpperCAmelCase_   :						Any=2  ,					UpperCAmelCase_   :						List[Any]=0.5  ,					**UpperCAmelCase_   :						Dict  ,					):
			super().__init__(**UpperCAmelCase_  ,					pad_token_id=UpperCAmelCase_  ,					bos_token_id=UpperCAmelCase_  ,					eos_token_id=UpperCAmelCase_)
			UpperCamelCase__				:					str					=					hidden_size
			UpperCamelCase__				:					Tuple					=					feat_extract_norm
			UpperCamelCase__				:					Any					=					feat_extract_activation
			UpperCamelCase__				:					Any					=					list(UpperCAmelCase_)
			UpperCamelCase__				:					Optional[Any]					=					list(UpperCAmelCase_)
			UpperCamelCase__				:					int					=					list(UpperCAmelCase_)
			UpperCamelCase__				:					Optional[int]					=					conv_bias
			UpperCamelCase__				:					Union[str, Any]					=					num_conv_pos_embeddings
			UpperCamelCase__				:					str					=					num_conv_pos_embedding_groups
			UpperCamelCase__				:					Union[str, Any]					=					len(self.conv_dim)
			UpperCamelCase__				:					Any					=					num_hidden_layers
			UpperCamelCase__				:					Union[str, Any]					=					intermediate_size
			UpperCamelCase__				:					int					=					hidden_act
			UpperCamelCase__				:					List[str]					=					num_attention_heads
			UpperCamelCase__				:					str					=					hidden_dropout
			UpperCamelCase__				:					Optional[int]					=					attention_dropout
			UpperCamelCase__				:					List[str]					=					activation_dropout
			UpperCamelCase__				:					Any					=					feat_proj_dropout
			UpperCamelCase__				:					Any					=					final_dropout
			UpperCamelCase__				:					Union[str, Any]					=					layerdrop
			UpperCamelCase__				:					Tuple					=					layer_norm_eps
			UpperCamelCase__				:					Union[str, Any]					=					initializer_range
			UpperCamelCase__				:					Tuple					=					num_ctc_classes
			UpperCamelCase__				:					List[str]					=					vocab_size
			UpperCamelCase__				:					Optional[int]					=					do_stable_layer_norm
			UpperCamelCase__				:					List[Any]					=					use_weighted_layer_sum
			UpperCamelCase__				:					int					=					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
			UpperCamelCase__				:					int					=					apply_spec_augment
			UpperCamelCase__				:					Tuple					=					mask_time_prob
			UpperCamelCase__				:					List[Any]					=					mask_time_length
			UpperCamelCase__				:					List[Any]					=					mask_time_min_masks
			UpperCamelCase__				:					List[Any]					=					mask_feature_prob
			UpperCamelCase__				:					Tuple					=					mask_feature_length
			UpperCamelCase__				:					int					=					mask_feature_min_masks

			# parameters for pretraining with codevector quantized representations
			UpperCamelCase__				:					Dict					=					num_codevectors_per_group
			UpperCamelCase__				:					Tuple					=					num_codevector_groups
			UpperCamelCase__				:					List[Any]					=					contrastive_logits_temperature
			UpperCamelCase__				:					int					=					feat_quantizer_dropout
			UpperCamelCase__				:					Union[str, Any]					=					num_negatives
			UpperCamelCase__				:					List[str]					=					codevector_dim
			UpperCamelCase__				:					List[Any]					=					proj_codevector_dim
			UpperCamelCase__				:					Optional[Any]					=					diversity_loss_weight

			# ctc loss
			UpperCamelCase__				:					Any					=					ctc_loss_reduction
			UpperCamelCase__				:					Optional[int]					=					ctc_zero_infinity

			# pretraining loss
			UpperCamelCase__				:					List[Any]					=					replace_prob





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












'''simple docstring'''




from typing import Union

import fire
import torch
from tqdm import tqdm







def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_ = "cpu"     ,      lowerCamelCase_ = None)							->     None:
		UpperCamelCase__				:					List[Any]					=					torch.load(lowerCamelCase_     ,      map_location=lowerCamelCase_)
		for k, v in tqdm(state_dict.items()):
				if not isinstance(lowerCamelCase_     ,      torch.Tensor):
						raise TypeError('FP16 conversion only works on paths that are saved state dicts, like pytorch_model.bin')
				UpperCamelCase__				:					int					=					v.half()
		if save_path is None:  # overwrite src_path
				UpperCamelCase__				:					List[Any]					=					src_path
		torch.save(lowerCamelCase_     ,      lowerCamelCase_)


if __name__ == "__main__":
		fire.Fire(convert)




