'''simple docstring'''




import functools
import operator

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


_a   :	List[Any] 							=   logging.get_logger(__name__)

_a   :	Tuple 							=   {
    "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       (__magic_name__   ):
       snake_case       :Optional[int]				    =					"unispeech-sat"






       def __init__(      self				,     UpperCamelCase_=32				,     UpperCamelCase_=7_68				,     UpperCamelCase_=12				,     UpperCamelCase_=12				,     UpperCamelCase_=30_72				,     UpperCamelCase_="gelu"				,     UpperCamelCase_=0.1				,     UpperCamelCase_=0.1				,     UpperCamelCase_=0.1				,     UpperCamelCase_=0.0				,     UpperCamelCase_=0.0				,     UpperCamelCase_=0.1				,     UpperCamelCase_=0.1				,     UpperCamelCase_=0.0_2				,     UpperCamelCase_=1E-5				,     UpperCamelCase_="group"				,     UpperCamelCase_="gelu"				,     UpperCamelCase_=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)				,     UpperCamelCase_=(5, 2, 2, 2, 2, 2, 2)				,     UpperCamelCase_=(10, 3, 3, 3, 3, 2, 2)				,     UpperCamelCase_=False				,     UpperCamelCase_=1_28				,     UpperCamelCase_=16				,     UpperCamelCase_=False				,     UpperCamelCase_=True				,     UpperCamelCase_=0.0_5				,     UpperCamelCase_=10				,     UpperCamelCase_=2				,     UpperCamelCase_=0.0				,     UpperCamelCase_=10				,     UpperCamelCase_=0				,     UpperCamelCase_=3_20				,     UpperCamelCase_=2				,     UpperCamelCase_=0.1				,     UpperCamelCase_=1_00				,     UpperCamelCase_=2_56				,     UpperCamelCase_=2_56				,     UpperCamelCase_=0.1				,     UpperCamelCase_="mean"				,     UpperCamelCase_=False				,     UpperCamelCase_=False				,     UpperCamelCase_=2_56				,     UpperCamelCase_=(5_12, 5_12, 5_12, 5_12, 15_00)				,     UpperCamelCase_=(5, 3, 3, 1, 1)				,     UpperCamelCase_=(1, 2, 3, 1, 1)				,     UpperCamelCase_=5_12				,     UpperCamelCase_=0				,     UpperCamelCase_=1				,     UpperCamelCase_=2				,     UpperCamelCase_=5_04				,     **UpperCamelCase_				,     ):
              super().__init__(**UpperCamelCase_				,     pad_token_id=UpperCamelCase_				,     bos_token_id=UpperCamelCase_				,     eos_token_id=UpperCamelCase_      )
              __UpperCAmelCase  :				Tuple       				=		hidden_size
              __UpperCAmelCase  :				Union[str, Any]       				=		feat_extract_norm
              __UpperCAmelCase  :				Union[str, Any]       				=		feat_extract_activation
              __UpperCAmelCase  :				List[Any]       				=		list(UpperCamelCase_      )
              __UpperCAmelCase  :				Optional[int]       				=		list(UpperCamelCase_      )
              __UpperCAmelCase  :				Optional[Any]       				=		list(UpperCamelCase_      )
              __UpperCAmelCase  :				Tuple       				=		conv_bias
              __UpperCAmelCase  :				Optional[int]       				=		num_conv_pos_embeddings
              __UpperCAmelCase  :				int       				=		num_conv_pos_embedding_groups
              __UpperCAmelCase  :				List[str]       				=		len(self.conv_dim      )
              __UpperCAmelCase  :				Optional[Any]       				=		num_hidden_layers
              __UpperCAmelCase  :				str       				=		intermediate_size
              __UpperCAmelCase  :				Dict       				=		hidden_act
              __UpperCAmelCase  :				List[Any]       				=		num_attention_heads
              __UpperCAmelCase  :				List[str]       				=		hidden_dropout
              __UpperCAmelCase  :				Dict       				=		attention_dropout
              __UpperCAmelCase  :				Optional[Any]       				=		activation_dropout
              __UpperCAmelCase  :				str       				=		feat_proj_dropout
              __UpperCAmelCase  :				Dict       				=		final_dropout
              __UpperCAmelCase  :				List[str]       				=		layerdrop
              __UpperCAmelCase  :				Union[str, Any]       				=		layer_norm_eps
              __UpperCAmelCase  :				Optional[int]       				=		initializer_range
              __UpperCAmelCase  :				Optional[Any]       				=		vocab_size
              __UpperCAmelCase  :				Dict       				=		num_clusters
              __UpperCAmelCase  :				List[Any]       				=		do_stable_layer_norm
              __UpperCAmelCase  :				List[str]       				=		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
              __UpperCAmelCase  :				Union[str, Any]       				=		apply_spec_augment
              __UpperCAmelCase  :				Optional[Any]       				=		mask_time_prob
              __UpperCAmelCase  :				Optional[Any]       				=		mask_time_length
              __UpperCAmelCase  :				Any       				=		mask_time_min_masks
              __UpperCAmelCase  :				Optional[int]       				=		mask_feature_prob
              __UpperCAmelCase  :				List[str]       				=		mask_feature_length
              __UpperCAmelCase  :				int       				=		mask_feature_min_masks

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

              # ctc loss
              __UpperCAmelCase  :				str       				=		ctc_loss_reduction
              __UpperCAmelCase  :				Optional[Any]       				=		ctc_zero_infinity

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

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







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







'''simple docstring'''




import time
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, torch_device

from ..test_modeling_common import ids_tensor


if is_torch_available():
   import torch

   from transformers.generation import (
       MaxLengthCriteria,
       MaxNewTokensCriteria,
       MaxTimeCriteria,
       StoppingCriteriaList,
       validate_stopping_criteria,
   )






@require_torch
class 		__A       (unittest.TestCase   ):






       def 			_snake_case						(      self				,     UpperCamelCase_      ):
              __UpperCAmelCase  :				List[str]       				=		3
              __UpperCAmelCase  :				Tuple       				=		2_50

              __UpperCAmelCase  :				str       				=		ids_tensor((batch_size, length)				,     UpperCamelCase_      )
              __UpperCAmelCase  :				Any       				=		torch.ones((batch_size, length)				,     device=UpperCamelCase_				,     dtype=torch.float      ) / length
              return input_ids, scores






       def 			_snake_case						(      self      ):
              __UpperCAmelCase				, __UpperCAmelCase  :				Tuple       				=		self._get_tensors(5      )

              __UpperCAmelCase  :				Tuple       				=		StoppingCriteriaList(
                  [
                      MaxLengthCriteria(max_length=10      ),
                      MaxTimeCriteria(max_time=0.1      ),
                  ]      )

              self.assertFalse(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )

              __UpperCAmelCase				, __UpperCAmelCase  :				int       				=		self._get_tensors(9      )
              self.assertFalse(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )

              __UpperCAmelCase				, __UpperCAmelCase  :				Optional[int]       				=		self._get_tensors(10      )
              self.assertTrue(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				int       				=		MaxLengthCriteria(max_length=10      )

              __UpperCAmelCase				, __UpperCAmelCase  :				Tuple       				=		self._get_tensors(5      )
              self.assertFalse(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )

              __UpperCAmelCase				, __UpperCAmelCase  :				Dict       				=		self._get_tensors(9      )
              self.assertFalse(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )

              __UpperCAmelCase				, __UpperCAmelCase  :				Optional[int]       				=		self._get_tensors(10      )
              self.assertTrue(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )






       def 			_snake_case						(      self      ):
              __UpperCAmelCase  :				Optional[Any]       				=		MaxNewTokensCriteria(start_length=5				,     max_new_tokens=5      )

              __UpperCAmelCase				, __UpperCAmelCase  :				List[str]       				=		self._get_tensors(5      )
              self.assertFalse(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )

              __UpperCAmelCase				, __UpperCAmelCase  :				Dict       				=		self._get_tensors(9      )
              self.assertFalse(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )

              __UpperCAmelCase				, __UpperCAmelCase  :				Optional[Any]       				=		self._get_tensors(10      )
              self.assertTrue(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )

              __UpperCAmelCase  :				Union[str, Any]       				=		StoppingCriteriaList([criteria]      )
              self.assertEqual(criteria_list.max_length				,     10      )






       def 			_snake_case						(      self      ):
              __UpperCAmelCase				, __UpperCAmelCase  :				Optional[Any]       				=		self._get_tensors(5      )

              __UpperCAmelCase  :				str       				=		MaxTimeCriteria(max_time=0.1      )
              self.assertFalse(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )

              __UpperCAmelCase  :				str       				=		MaxTimeCriteria(max_time=0.1				,     initial_timestamp=time.time() - 0.2      )
              self.assertTrue(criteria(UpperCamelCase_				,     UpperCamelCase_      )      )







       def 			_snake_case						(      self      ):
              validate_stopping_criteria(StoppingCriteriaList([MaxLengthCriteria(10      )]      )				,     10      )

              with self.assertWarns(UpperCamelCase_      ):
                     validate_stopping_criteria(StoppingCriteriaList([MaxLengthCriteria(10      )]      )				,     11      )

              __UpperCAmelCase  :				Optional[int]       				=		validate_stopping_criteria(StoppingCriteriaList()				,     11      )

              self.assertEqual(len(UpperCamelCase_      )				,     1      )






