'''simple docstring'''


import functools
import operator

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


__snake_case						  =		logging.get_logger(__name__)

__snake_case						  =		{
    """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       _a    (		__a      ):


  """simple docstring"""

  A_    							=						'''unispeech'''




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







    '''simple docstring'''


    super().__init__(**lowercase_   ,				pad_token_id=lowercase_   ,				bos_token_id=lowercase_   ,				eos_token_id=lowercase_      )
    lowercase_     =       hidden_size
    lowercase_     =       feat_extract_norm
    lowercase_     =       feat_extract_activation
    lowercase_     =       list(lowercase_      )
    lowercase_     =       list(lowercase_      )
    lowercase_     =       list(lowercase_      )
    lowercase_     =       conv_bias
    lowercase_     =       num_conv_pos_embeddings
    lowercase_     =       num_conv_pos_embedding_groups
    lowercase_     =       len(self.conv_dim      )
    lowercase_     =       num_hidden_layers
    lowercase_     =       intermediate_size
    lowercase_     =       hidden_act
    lowercase_     =       num_attention_heads
    lowercase_     =       hidden_dropout
    lowercase_     =       attention_dropout
    lowercase_     =       activation_dropout
    lowercase_     =       feat_proj_dropout
    lowercase_     =       final_dropout
    lowercase_     =       layerdrop
    lowercase_     =       layer_norm_eps
    lowercase_     =       initializer_range
    lowercase_     =       num_ctc_classes
    lowercase_     =       vocab_size
    lowercase_     =       do_stable_layer_norm
    lowercase_     =       use_weighted_layer_sum
    lowercase_     =       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
    lowercase_     =       apply_spec_augment
    lowercase_     =       mask_time_prob
    lowercase_     =       mask_time_length
    lowercase_     =       mask_time_min_masks
    lowercase_     =       mask_feature_prob
    lowercase_     =       mask_feature_length
    lowercase_     =       mask_feature_min_masks

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

    # ctc loss
    lowercase_     =       ctc_loss_reduction
    lowercase_     =       ctc_zero_infinity

    # pretraining loss
    lowercase_     =       replace_prob





  @property
  def 		lowerCamelCase__  (		self      :       str      ):







    '''simple docstring'''


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


'''simple docstring'''


from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_torch_available, is_torch_tpu_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_torch_available():
       import torch

if is_torch_tpu_available(check_device=False):
       import torch_xla.core.xla_model as xm


__snake_case						  =		logging.get_logger(__name__)





@dataclass
class       _a    (		__a      ):


  """simple docstring"""

  A_    							=						[
      '''no_inference''',
      '''no_cuda''',
      '''no_tpu''',
      '''no_speed''',
      '''no_memory''',
      '''no_env_print''',
      '''no_multi_process''',
  ]




  def __init__(		self      :       int   ,				**lowercase_      :       int      ):







    '''simple docstring'''


    for deprecated_arg in self.deprecated_args:
      if deprecated_arg in kwargs:
        lowercase_     =       deprecated_arg[3:]
        setattr(self   ,				lowercase_   ,				not kwargs.pop(lowercase_      )      )
        logger.warning(
            F"""{deprecated_arg} is depreciated. Please use --no_{positive_arg} or"""
            F""" {positive_arg}={kwargs[positive_arg]}"""      )

    lowercase_     =       kwargs.pop("""torchscript"""   ,				self.torchscript      )
    lowercase_     =       kwargs.pop("""torch_xla_tpu_print_metrics"""   ,				self.torch_xla_tpu_print_metrics      )
    lowercase_     =       kwargs.pop("""fp16_opt_level"""   ,				self.fpaa_opt_level      )
    super().__init__(**lowercase_      )

  A_    							=						field(default=__a ,				metadata={'''help''': '''Trace the models using torchscript'''}      )
  A_    							=						field(default=__a ,				metadata={'''help''': '''Print Xla/PyTorch tpu metrics'''}      )
  A_    							=						field(
      default='''O1''' ,				metadata={
          '''help''': (
              '''For fp16: Apex AMP optimization level selected in [\'O0\', \'O1\', \'O2\', and \'O3\']. '''
              '''See details at https://nvidia.github.io/apex/amp.html'''
          )
      } ,				)




  @cached_property
  def 		lowerCamelCase__  (		self      :       Dict      ):







    '''simple docstring'''


    requires_backends(self   ,				["""torch"""]      )
    logger.info("""PyTorch: setting up devices"""      )
    if not self.cuda:
      lowercase_     =       torch.device("""cpu"""      )
      lowercase_     =       0
    elif is_torch_tpu_available():
      lowercase_     =       xm.xla_device()
      lowercase_     =       0
    else:
      lowercase_     =       torch.device("""cuda""" if torch.cuda.is_available() else """cpu"""      )
      lowercase_     =       torch.cuda.device_count()
    return device, n_gpu




  @property
  def 		lowerCamelCase__  (		self      :       List[str]      ):







    '''simple docstring'''


    return is_torch_tpu_available() and self.tpu




  @property
  def 		lowerCamelCase__  (		self      :       Tuple      ):







    '''simple docstring'''


    requires_backends(self   ,				["""torch"""]      )
    # TODO(PVP): currently only single GPU is supported
    return torch.cuda.current_device()




  @property
  def 		lowerCamelCase__  (		self      :       Dict      ):







    '''simple docstring'''


    requires_backends(self   ,				["""torch"""]      )
    return self._setup_devices[0]




  @property
  def 		lowerCamelCase__  (		self      :       Any      ):







    '''simple docstring'''


    requires_backends(self   ,				["""torch"""]      )
    return self._setup_devices[1]





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







    '''simple docstring'''


    return self.n_gpu > 0

