


"""simple docstring"""






import functools
import operator

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


_lowerCAmelCase							:    Optional[Any]					   =	logging.get_logger(__name__)

_lowerCAmelCase							:    Union[str, Any]					   =	{
    '''microsoft/unispeech-sat-base-100h-libri-ft''': (
        '''https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json'''
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}




class 							A_      (       _a ):
  lowerCAmelCase__      			=	'unispeech-sat'


  def __init__(			self:						List[str]							,__lowerCAmelCase:						Any=32							,__lowerCAmelCase:						Optional[Any]=768							,__lowerCAmelCase:						Any=12							,__lowerCAmelCase:						Union[str, Any]=12							,__lowerCAmelCase:						Optional[int]=3_072							,__lowerCAmelCase:						List[Any]="gelu"							,__lowerCAmelCase:						Union[str, Any]=0.1							,__lowerCAmelCase:						List[Any]=0.1							,__lowerCAmelCase:						Tuple=0.1							,__lowerCAmelCase:						str=0.0							,__lowerCAmelCase:						int=0.0							,__lowerCAmelCase:						List[Any]=0.1							,__lowerCAmelCase:						List[Any]=0.1							,__lowerCAmelCase:						Optional[Any]=0.02							,__lowerCAmelCase:						Tuple=1e-5							,__lowerCAmelCase:						Tuple="group"							,__lowerCAmelCase:						Optional[Any]="gelu"							,__lowerCAmelCase:						List[Any]=(512, 512, 512, 512, 512, 512, 512)							,__lowerCAmelCase:						Dict=(5, 2, 2, 2, 2, 2, 2)							,__lowerCAmelCase:						Any=(10, 3, 3, 3, 3, 2, 2)							,__lowerCAmelCase:						int=False							,__lowerCAmelCase:						Union[str, Any]=128							,__lowerCAmelCase:						Optional[Any]=16							,__lowerCAmelCase:						Any=False							,__lowerCAmelCase:						List[Any]=True							,__lowerCAmelCase:						Optional[int]=0.05							,__lowerCAmelCase:						str=10							,__lowerCAmelCase:						List[str]=2							,__lowerCAmelCase:						Optional[int]=0.0							,__lowerCAmelCase:						Dict=10							,__lowerCAmelCase:						Dict=0							,__lowerCAmelCase:						int=320							,__lowerCAmelCase:						List[str]=2							,__lowerCAmelCase:						List[str]=0.1							,__lowerCAmelCase:						Any=100							,__lowerCAmelCase:						List[Any]=256							,__lowerCAmelCase:						Any=256							,__lowerCAmelCase:						Optional[int]=0.1							,__lowerCAmelCase:						List[str]="mean"							,__lowerCAmelCase:						str=False							,__lowerCAmelCase:						Optional[Any]=False							,__lowerCAmelCase:						Any=256							,__lowerCAmelCase:						Optional[int]=(512, 512, 512, 512, 1_500)							,__lowerCAmelCase:						Optional[Any]=(5, 3, 3, 1, 1)							,__lowerCAmelCase:						Optional[Any]=(1, 2, 3, 1, 1)							,__lowerCAmelCase:						Dict=512							,__lowerCAmelCase:						Any=0							,__lowerCAmelCase:						Any=1							,__lowerCAmelCase:						Optional[int]=2							,__lowerCAmelCase:						Optional[int]=504							,**__lowerCAmelCase:						Optional[Any]							,):







     '''simple docstring'''







     super().__init__(**__lowerCAmelCase							,pad_token_id=__lowerCAmelCase							,bos_token_id=__lowerCAmelCase							,eos_token_id=__lowerCAmelCase    )
     _lowerCamelCase   :				Optional[int]							=     hidden_size
     _lowerCamelCase   :				str							=     feat_extract_norm
     _lowerCamelCase   :				int							=     feat_extract_activation
     _lowerCamelCase   :				int							=     list(__lowerCAmelCase    )
     _lowerCamelCase   :				List[Any]							=     list(__lowerCAmelCase    )
     _lowerCamelCase   :				str							=     list(__lowerCAmelCase    )
     _lowerCamelCase   :				Dict							=     conv_bias
     _lowerCamelCase   :				List[Any]							=     num_conv_pos_embeddings
     _lowerCamelCase   :				int							=     num_conv_pos_embedding_groups
     _lowerCamelCase   :				List[Any]							=     len(self.conv_dim    )
     _lowerCamelCase   :				List[str]							=     num_hidden_layers
     _lowerCamelCase   :				Dict							=     intermediate_size
     _lowerCamelCase   :				List[Any]							=     hidden_act
     _lowerCamelCase   :				Tuple							=     num_attention_heads
     _lowerCamelCase   :				List[Any]							=     hidden_dropout
     _lowerCamelCase   :				int							=     attention_dropout
     _lowerCamelCase   :				List[Any]							=     activation_dropout
     _lowerCamelCase   :				Union[str, Any]							=     feat_proj_dropout
     _lowerCamelCase   :				List[Any]							=     final_dropout
     _lowerCamelCase   :				Union[str, Any]							=     layerdrop
     _lowerCamelCase   :				Any							=     layer_norm_eps
     _lowerCamelCase   :				Union[str, Any]							=     initializer_range
     _lowerCamelCase   :				Any							=     vocab_size
     _lowerCamelCase   :				Any							=     num_clusters
     _lowerCamelCase   :				int							=     do_stable_layer_norm
     _lowerCamelCase   :				Dict							=     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
     _lowerCamelCase   :				List[Any]							=     apply_spec_augment
     _lowerCamelCase   :				List[str]							=     mask_time_prob
     _lowerCamelCase   :				Optional[int]							=     mask_time_length
     _lowerCamelCase   :				str							=     mask_time_min_masks
     _lowerCamelCase   :				Optional[int]							=     mask_feature_prob
     _lowerCamelCase   :				Any							=     mask_feature_length
     _lowerCamelCase   :				Optional[int]							=     mask_feature_min_masks

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

     # ctc loss
     _lowerCamelCase   :				Tuple							=     ctc_loss_reduction
     _lowerCamelCase   :				List[Any]							=     ctc_zero_infinity

     # SequenceClassification-specific parameter. Feel free to ignore for other classes.
     _lowerCamelCase   :				Any							=     classifier_proj_size

     # XVector-specific parameters. Feel free to ignore for other classes.
     _lowerCamelCase   :				Any							=     list(__lowerCAmelCase    )
     _lowerCamelCase   :				Any							=     list(__lowerCAmelCase    )
     _lowerCamelCase   :				List[str]							=     list(__lowerCAmelCase    )
     _lowerCamelCase   :				Union[str, Any]							=     xvector_output_dim






  @property
  def 							_lowercase					(			self:						Optional[int]    ):







     '''simple docstring'''







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


'''simple docstring'''

import importlib.util
import json
import os
import warnings
from dataclasses import dataclass, field

import torch

from ..training_args import TrainingArguments
from ..utils import cached_property, is_sagemaker_dp_enabled, logging


SCREAMING_SNAKE_CASE							:				Optional[Any]     	=			logging.get_logger(__name__)




def 							_UpperCamelCase				(   )      -> List[Any]:
							# Get the sagemaker specific mp parameters from smp_options variable.
							SCREAMING_SNAKE_CASE_				=				os.getenv('SM_HP_MP_PARAMETERS'		,'{}'   )
							try:
														# Parse it and check the field "partitions" is included, it is required for model parallel.
														SCREAMING_SNAKE_CASE_				=				json.loads(lowerCAmelCase__   )
														if "partitions" not in smp_options:
																					return False
							except json.JSONDecodeError:
														return False

							# Get the sagemaker specific framework parameters from mpi_options variable.
							SCREAMING_SNAKE_CASE_				=				os.getenv('SM_FRAMEWORK_PARAMS'		,'{}'   )
							try:
														# Parse it and check the field "sagemaker_distributed_dataparallel_enabled".
														SCREAMING_SNAKE_CASE_				=				json.loads(lowerCAmelCase__   )
														if not mpi_options.get('sagemaker_mpi_enabled'		,lowerCAmelCase__   ):
																					return False
							except json.JSONDecodeError:
														return False
							# Lastly, check if the `smdistributed` module is present.
							return importlib.util.find_spec('smdistributed'   ) is not None


if is_sagemaker_model_parallel_available():
							import smdistributed.modelparallel.torch as smp

							smp.init()






@dataclass
class    snake_case     (      lowercase_		):






				"""simple docstring"""
				_a    	=     field(
				    default="""""",						metadata={"""help""": """Used by the SageMaker launcher to send mp-specific args. Ignored in SageMakerTrainer"""},						)



				def   a__					(    self       )     ->							Union[str, Any]:
											super().__post_init__()
											warnings.warn(
											    '`SageMakerTrainingArguments` is deprecated and will be removed in v5 of Transformers. You can use '
											    '`TrainingArguments` instead.',     _lowercase,     )



				@cached_property
				def   a__					(    self       )     ->							"torch.device":
											logger.info('PyTorch: setting up devices'       )
											if torch.distributed.is_available() and torch.distributed.is_initialized() and self.local_rank == -1:
																		logger.warning(
																		    'torch.distributed process group is initialized, but local_rank == -1. '
																		    'In order to use Torch DDP, launch your script with `python -m torch.distributed.launch'       )
											if self.no_cuda:
																		SCREAMING_SNAKE_CASE_				=				torch.device('cpu'       )
																		SCREAMING_SNAKE_CASE_				=				0
											elif is_sagemaker_model_parallel_available():
																		SCREAMING_SNAKE_CASE_				=				smp.local_rank()
																		SCREAMING_SNAKE_CASE_				=				torch.device('cuda',     _lowercase       )
																		SCREAMING_SNAKE_CASE_				=				1
											elif is_sagemaker_dp_enabled():
																		import smdistributed.dataparallel.torch.torch_smddp  # noqa: F401

																		torch.distributed.init_process_group(backend='smddp',     timeout=self.ddp_timeout_delta       )
																		SCREAMING_SNAKE_CASE_				=				int(os.getenv('SMDATAPARALLEL_LOCAL_RANK'       )       )
																		SCREAMING_SNAKE_CASE_				=				torch.device('cuda',     self.local_rank       )
																		SCREAMING_SNAKE_CASE_				=				1
											elif self.local_rank == -1:
																		# if n_gpu is > 1 we'll use nn.DataParallel.
																		# If you only want to use a specific subset of GPUs use `CUDA_VISIBLE_DEVICES=0`
																		# Explicitly set CUDA to the first (index 0) CUDA device, otherwise `set_device` will
																		# trigger an error that a device index is missing. Index 0 takes into account the
																		# GPUs available in the environment, so `CUDA_VISIBLE_DEVICES=1,2` with `cuda:0`
																		# will use the first GPU in that env, i.e. GPU#1
																		SCREAMING_SNAKE_CASE_				=				torch.device('cuda:0' if torch.cuda.is_available() else 'cpu'       )
																		# Sometimes the line in the postinit has not been run before we end up here, so just checking we're not at
																		# the default value.
																		SCREAMING_SNAKE_CASE_				=				torch.cuda.device_count()
											else:
																		# Here, we'll use torch.distributed.
																		# Initializes the distributed backend which will take care of synchronizing nodes/GPUs
																		if not torch.distributed.is_initialized():
																									torch.distributed.init_process_group(backend='nccl',     timeout=self.ddp_timeout_delta       )
																		SCREAMING_SNAKE_CASE_				=				torch.device('cuda',     self.local_rank       )
																		SCREAMING_SNAKE_CASE_				=				1

											if device.type == "cuda":
																		torch.cuda.set_device(_lowercase       )

											return device



				@property
				def   a__					(    self       )     ->							Optional[Any]:
											if is_sagemaker_model_parallel_available():
																		return smp.dp_size()

											return super().world_size



				@property
				def   a__					(    self       )     ->							Optional[Any]:
											return not is_sagemaker_model_parallel_available()





				@property
				def   a__					(    self       )     ->							Tuple:
											return False





