

"""simple docstring"""
import functools
import operator

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


_A							=  logging.get_logger(__name__)

_A							=  {
    """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       lowerCamelCase	(       lowerCAmelCase__   ):


  '''simple docstring'''







  SCREAMING_SNAKE_CASE					      =  'unispeech'



  def __init__(self							,       _lowerCamelCase=32							,       _lowerCamelCase=768							,       _lowerCamelCase=12							,       _lowerCamelCase=12							,       _lowerCamelCase=3072							,       _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=(512, 512, 512, 512, 512, 512, 512)							,       _lowerCamelCase=(5, 2, 2, 2, 2, 2, 2)							,       _lowerCamelCase=(10, 3, 3, 3, 3, 2, 2)							,       _lowerCamelCase=False							,       _lowerCamelCase=128							,       _lowerCamelCase=16							,       _lowerCamelCase=False							,       _lowerCamelCase=True							,       _lowerCamelCase=0.05							,       _lowerCamelCase=10							,       _lowerCamelCase=2							,       _lowerCamelCase=0.0							,       _lowerCamelCase=10							,       _lowerCamelCase=0							,       _lowerCamelCase=320							,       _lowerCamelCase=2							,       _lowerCamelCase=0.1							,       _lowerCamelCase=100							,       _lowerCamelCase=256							,       _lowerCamelCase=256							,       _lowerCamelCase=0.1							,       _lowerCamelCase="mean"							,       _lowerCamelCase=False							,       _lowerCamelCase=False							,       _lowerCamelCase=256							,       _lowerCamelCase=80							,       _lowerCamelCase=0							,       _lowerCamelCase=1							,       _lowerCamelCase=2							,       _lowerCamelCase=0.5							,       **_lowerCamelCase							,       ):


        """simple docstring"""

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

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

        # ctc loss
        UpperCAmelCase__			:							int							=    ctc_loss_reduction
        UpperCAmelCase__			:							Tuple							=    ctc_zero_infinity

        # pretraining loss
        UpperCAmelCase__			:							List[Any]							=    replace_prob




  @property
  def  _a      (self	):


        """simple docstring"""

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




"""simple docstring"""
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
    from transformers import AutoModelForSeqaSeqLM, AutoTokenizer

@require_torch
@require_sentencepiece
@require_tokenizers
class       lowerCamelCase	(       unittest.TestCase   ):


  '''simple docstring'''







  @slow
  def  _a      (self	):


        """simple docstring"""

        UpperCAmelCase__			:							Dict							=    AutoModelForSeqaSeqLM.from_pretrained("""google/mt5-small"""							,       return_dict=_lowerCamelCase	).to(_lowerCamelCase	)
        UpperCAmelCase__			:							Optional[Any]							=    AutoTokenizer.from_pretrained("""google/mt5-small"""	)

        UpperCAmelCase__			:							Any							=    tokenizer("""Hello there"""							,       return_tensors="""pt"""	).input_ids
        UpperCAmelCase__			:							str							=    tokenizer("""Hi I am"""							,       return_tensors="""pt"""	).input_ids

        UpperCAmelCase__			:							Tuple							=    model(input_ids.to(_lowerCamelCase	)							,       labels=labels.to(_lowerCamelCase	)	).loss
        UpperCAmelCase__			:							Union[str, Any]							=    -(labels.shape[-1] * loss.item())

        UpperCAmelCase__			:							List[str]							=    -84.9_127
        self.assertTrue(abs(mtf_score - EXPECTED_SCORE	) < 1e-4	)

