




import functools
import operator

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


_lowerCamelCase     :		str								=       logging.get_logger(__name__)

_lowerCamelCase     :		Optional[Any]								=       {
    """asapp/sew-d-tiny-100k""": """https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json""",
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}


class     UpperCamelCase_   (			UpperCAmelCase__					):

    '''simple docstring'''






    UpperCAmelCase__							  =				'''sew-d'''


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





           '''simple docstring'''

           super().__init__(**UpperCAmelCase__ ,			pad_token_id=UpperCAmelCase__ ,			bos_token_id=UpperCAmelCase__ ,			eos_token_id=UpperCAmelCase__)
           A__							=   hidden_size
           A__							=   feat_extract_norm
           A__							=   feat_extract_activation
           A__							=   list(UpperCAmelCase__)
           A__							=   list(UpperCAmelCase__)
           A__							=   list(UpperCAmelCase__)
           A__							=   conv_bias
           A__							=   num_conv_pos_embeddings
           A__							=   num_conv_pos_embedding_groups
           A__							=   len(self.conv_dim)
           A__							=   num_hidden_layers
           A__							=   intermediate_size
           A__							=   squeeze_factor
           A__							=   max_position_embeddings
           A__							=   position_buckets
           A__							=   share_att_key
           A__							=   relative_attention
           A__							=   norm_rel_ebd
           A__							=   list(UpperCAmelCase__)
           A__							=   hidden_act
           A__							=   num_attention_heads
           A__							=   hidden_dropout
           A__							=   attention_dropout
           A__							=   activation_dropout
           A__							=   feat_proj_dropout
           A__							=   final_dropout
           A__							=   layer_norm_eps
           A__							=   feature_layer_norm_eps
           A__							=   initializer_range
           A__							=   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
           A__							=   apply_spec_augment
           A__							=   mask_time_prob
           A__							=   mask_time_length
           A__							=   mask_time_min_masks
           A__							=   mask_feature_prob
           A__							=   mask_feature_length
           A__							=   mask_feature_min_masks

           # ctc loss
           A__							=   ctc_loss_reduction
           A__							=   ctc_zero_infinity

           # sequence classification
           A__							=   use_weighted_layer_sum
           A__							=   classifier_proj_size





    @property
    def 	SCREAMING_SNAKE_CASE							(      self				:     int)						->List[str]:





           '''simple docstring'''

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








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     UpperCamelCase_   (			unittest.TestCase					):

    '''simple docstring'''






    def 	SCREAMING_SNAKE_CASE							(      self				:     Dict)						->Tuple:





           '''simple docstring'''

           A__							=   [[1, 2, 4], [1, 2, 3, 4]]
           A__							=   DisjunctiveConstraint(UpperCAmelCase__)
           self.assertTrue(isinstance(dc.token_ids ,			UpperCAmelCase__))

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

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


    def 	SCREAMING_SNAKE_CASE							(      self				:     int)						->str:





           '''simple docstring'''

           A__							=   [[1, 2], [1, 2, 3, 4]]

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


    def 	SCREAMING_SNAKE_CASE							(      self				:     Any)						->str:





           '''simple docstring'''

           A__							=   [[1, 2, 3], [1, 2, 4]]

           A__							=   DisjunctiveConstraint(UpperCAmelCase__)

           A__			,							A__			,							A__							=   dc.update(1)
           A__							=   stepped is True and completed is False and reset is False
           self.assertTrue(UpperCAmelCase__)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1])

           A__			,							A__			,							A__							=   dc.update(2)
           A__							=   stepped is True and completed is False and reset is False
           self.assertTrue(UpperCAmelCase__)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1, 2])

           A__			,							A__			,							A__							=   dc.update(3)
           A__							=   stepped is True and completed is True and reset is False
           self.assertTrue(UpperCAmelCase__)
           self.assertTrue(dc.completed)  # Completed!
           self.assertTrue(dc.current_seq == [1, 2, 3])





    def 	SCREAMING_SNAKE_CASE							(      self				:     Optional[Any])						->Tuple:





           '''simple docstring'''

           A__							=   [[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

           A__							=   DisjunctiveConstraint(UpperCAmelCase__)

           A__			,							A__			,							A__							=   dc.update(1)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.current_seq == [1])

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

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

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

           dc.reset()

           A__			,							A__			,							A__							=   dc.update(1)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.remaining() == 3)
           self.assertTrue(dc.current_seq == [1])

           A__			,							A__			,							A__							=   dc.update(2)
           self.assertTrue(not dc.completed)
           self.assertTrue(dc.remaining() == 2)
           self.assertTrue(dc.current_seq == [1, 2])

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


