

'''simple docstring'''



import functools
import operator

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


SCREAMING_SNAKE_CASE_     = logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_     = {
    'asapp/sew-tiny-100k': 'https://huggingface.co/asapp/sew-tiny-100k/resolve/main/config.json',
    # See all SEW models at https://huggingface.co/models?filter=sew
}

class       SCREAMING_SNAKE_CASE       (				lowercase_       ):






      '''simple docstring'''






      SCREAMING_SNAKE_CASE__			:					Optional[Any]     =					'''sew'''




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



          """simple docstring"""





          super().__init__(**_A  ,       pad_token_id=_A  ,       bos_token_id=_A  ,       eos_token_id=_A )
          _snake_case			:			int				       =		hidden_size
          _snake_case			:			List[str]				       =		feat_extract_norm
          _snake_case			:			Dict				       =		feat_extract_activation
          _snake_case			:			Dict				       =		list(_A )
          _snake_case			:			List[Any]				       =		list(_A )
          _snake_case			:			Union[str, Any]				       =		list(_A )
          _snake_case			:			Tuple				       =		conv_bias
          _snake_case			:			Optional[int]				       =		num_conv_pos_embeddings
          _snake_case			:			List[Any]				       =		num_conv_pos_embedding_groups
          _snake_case			:			Optional[Any]				       =		len(self.conv_dim )
          _snake_case			:			str				       =		num_hidden_layers
          _snake_case			:			Dict				       =		intermediate_size
          _snake_case			:			List[str]				       =		squeeze_factor
          _snake_case			:			int				       =		hidden_act
          _snake_case			:			str				       =		num_attention_heads
          _snake_case			:			int				       =		hidden_dropout
          _snake_case			:			List[Any]				       =		attention_dropout
          _snake_case			:			Tuple				       =		activation_dropout
          _snake_case			:			List[Any]				       =		feat_proj_dropout
          _snake_case			:			Dict				       =		final_dropout
          _snake_case			:			Union[str, Any]				       =		layerdrop
          _snake_case			:			Union[str, Any]				       =		layer_norm_eps
          _snake_case			:			Dict				       =		initializer_range
          _snake_case			:			Dict				       =		vocab_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)`,'
                  F"""but is `len(config.conv_dim) = {len(self.conv_dim )}`, `len(config.conv_stride)"""
                  F"""= {len(self.conv_stride )}`, `len(config.conv_kernel) = {len(self.conv_kernel )}`.""" )

          # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
          _snake_case			:			Tuple				       =		apply_spec_augment
          _snake_case			:			Optional[Any]				       =		mask_time_prob
          _snake_case			:			List[Any]				       =		mask_time_length
          _snake_case			:			int				       =		mask_time_min_masks
          _snake_case			:			Optional[int]				       =		mask_feature_prob
          _snake_case			:			List[Any]				       =		mask_feature_length
          _snake_case			:			List[Any]				       =		mask_feature_min_masks

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

          # sequence classification
          _snake_case			:			str				       =		use_weighted_layer_sum
          _snake_case			:			Dict				       =		classifier_proj_size




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



          """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_torch


if is_torch_available():
						import torch

						from transformers.generation import DisjunctiveConstraint


@require_torch
class  snake_case__      (					unittest.TestCase):




					def 		A      (  self  :		Union[str, Any]      )    ->							List[str]:
								# For consistency across different places the DisjunctiveConstraint is called,
								# dc.token_ids is a list of integers. It is also initialized only by integers.

								UpperCAmelCase_      :       Union[str, Any]          =       [[1, 2, 4], [1, 2, 3, 4]]
								UpperCAmelCase_      :       Dict          =       DisjunctiveConstraint(_A      )
								self.assertTrue(isinstance(dc.token_ids				, _A      )      )

								with self.assertRaises(_A      ):
											DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]      )      )

								with self.assertRaises(_A      ):
											DisjunctiveConstraint([torch.LongTensor([1, 2, 4]      ), torch.LongTensor([1, 2, 3, 4, 5]      )]      )




					def 		A      (  self  :		Optional[int]      )    ->							List[Any]:
								# We can't have constraints that are complete subsets of another. This leads to a preverse
								# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
								# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
								# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
								# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
								UpperCAmelCase_      :       Optional[Any]          =       [[1, 2], [1, 2, 3, 4]]

								with self.assertRaises(_A      ):
											DisjunctiveConstraint(_A      )  # fails here




					def 		A      (  self  :		List[str]      )    ->							int:
								UpperCAmelCase_      :       Dict          =       [[1, 2, 3], [1, 2, 4]]

								UpperCAmelCase_      :       List[Any]          =       DisjunctiveConstraint(_A      )

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       List[str]          =       dc.update(1      )
								UpperCAmelCase_      :       int          =       stepped is True and completed is False and reset is False
								self.assertTrue(_A      )
								self.assertTrue(not dc.completed      )
								self.assertTrue(dc.current_seq == [1]      )

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       Tuple          =       dc.update(2      )
								UpperCAmelCase_      :       Optional[int]          =       stepped is True and completed is False and reset is False
								self.assertTrue(_A      )
								self.assertTrue(not dc.completed      )
								self.assertTrue(dc.current_seq == [1, 2]      )

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       Any          =       dc.update(3      )
								UpperCAmelCase_      :       List[Any]          =       stepped is True and completed is True and reset is False
								self.assertTrue(_A      )
								self.assertTrue(dc.completed      )  # Completed!
								self.assertTrue(dc.current_seq == [1, 2, 3]      )





					def 		A      (  self  :		List[Any]      )    ->							Any:
								UpperCAmelCase_      :       int          =       [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

								UpperCAmelCase_      :       str          =       DisjunctiveConstraint(_A      )

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       Tuple          =       dc.update(1      )
								self.assertTrue(not dc.completed      )
								self.assertTrue(dc.current_seq == [1]      )

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       str          =       dc.update(2      )
								self.assertTrue(not dc.completed      )
								self.assertTrue(dc.current_seq == [1, 2]      )

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       str          =       dc.update(4      )
								self.assertTrue(not dc.completed      )
								self.assertTrue(dc.current_seq == [1, 2, 4]      )

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       Any          =       dc.update(5      )
								self.assertTrue(dc.completed      )  # Completed!
								self.assertTrue(dc.current_seq == [1, 2, 4, 5]      )

								dc.reset()

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       List[str]          =       dc.update(1      )
								self.assertTrue(not dc.completed      )
								self.assertTrue(dc.remaining() == 3      )
								self.assertTrue(dc.current_seq == [1]      )

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       Optional[int]          =       dc.update(2      )
								self.assertTrue(not dc.completed      )
								self.assertTrue(dc.remaining() == 2      )
								self.assertTrue(dc.current_seq == [1, 2]      )

								UpperCAmelCase_    ,      UpperCAmelCase_    ,      UpperCAmelCase_      :       int          =       dc.update(5      )
								self.assertTrue(dc.completed      )  # Completed!
								self.assertTrue(dc.remaining() == 0      )
								self.assertTrue(dc.current_seq == [1, 2, 5]      )


