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   lowerCAmelCase_    (			lowerCAmelCase					):



				"""simple docstring"""
				_lowerCAmelCase     :    str			  =						"""sew"""

				def __init__(				self		,    lowerCAmelCase=32		,    lowerCAmelCase=7_68		,    lowerCAmelCase=12		,    lowerCAmelCase=12		,    lowerCAmelCase=30_72		,    lowerCAmelCase=2		,    lowerCAmelCase="gelu"		,    lowerCAmelCase=0.1		,    lowerCAmelCase=0.1		,    lowerCAmelCase=0.1		,    lowerCAmelCase=0.0		,    lowerCAmelCase=0.1		,    lowerCAmelCase=0.1		,    lowerCAmelCase=0.02		,    lowerCAmelCase=1E-5		,    lowerCAmelCase="group"		,    lowerCAmelCase="gelu"		,    lowerCAmelCase=(64, 1_28, 1_28, 1_28, 1_28, 2_56, 2_56, 2_56, 2_56, 5_12, 5_12, 5_12, 5_12)		,    lowerCAmelCase=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)		,    lowerCAmelCase=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)		,    lowerCAmelCase=False		,    lowerCAmelCase=1_28		,    lowerCAmelCase=16		,    lowerCAmelCase=True		,    lowerCAmelCase=0.05		,    lowerCAmelCase=10		,    lowerCAmelCase=2		,    lowerCAmelCase=0.0		,    lowerCAmelCase=10		,    lowerCAmelCase=0		,    lowerCAmelCase="mean"		,    lowerCAmelCase=False		,    lowerCAmelCase=False		,    lowerCAmelCase=2_56		,    lowerCAmelCase=0		,    lowerCAmelCase=1		,    lowerCAmelCase=2		,    **lowerCAmelCase		,    ):






										"""simple docstring"""

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

										# ctc loss
										snake_case								=			ctc_loss_reduction
										snake_case								=			ctc_zero_infinity

										# sequence classification
										snake_case								=			use_weighted_layer_sum
										snake_case								=			classifier_proj_size

				@property
				def 		snake_case (				self    ):






										"""simple docstring"""

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



"""simple docstring"""
import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)



class   lowerCAmelCase_    (			unittest.TestCase					):



				"""simple docstring"""

				def 		snake_case (				self    ):






										"""simple docstring"""

										snake_case								=			['a', 'b', 'c']

										# Defaults to last layer if both are None
										snake_case					,snake_case								=			get_aligned_output_features_output_indices(lowerCAmelCase		,    lowerCAmelCase		,    lowerCAmelCase    )
										self.assertEqual(lowerCAmelCase		,    ['c']    )
										self.assertEqual(lowerCAmelCase		,    [2]    )

										# Out indices set to match out features
										snake_case					,snake_case								=			get_aligned_output_features_output_indices(['a', 'c']		,    lowerCAmelCase		,    lowerCAmelCase    )
										self.assertEqual(lowerCAmelCase		,    ['a', 'c']    )
										self.assertEqual(lowerCAmelCase		,    [0, 2]    )

										# Out features set to match out indices
										snake_case					,snake_case								=			get_aligned_output_features_output_indices(lowerCAmelCase		,    [0, 2]		,    lowerCAmelCase    )
										self.assertEqual(lowerCAmelCase		,    ['a', 'c']    )
										self.assertEqual(lowerCAmelCase		,    [0, 2]    )

										# Out features selected from negative indices
										snake_case					,snake_case								=			get_aligned_output_features_output_indices(lowerCAmelCase		,    [-3, -1]		,    lowerCAmelCase    )
										self.assertEqual(lowerCAmelCase		,    ['a', 'c']    )
										self.assertEqual(lowerCAmelCase		,    [-3, -1]    )

				def 		snake_case (				self    ):






										"""simple docstring"""

										with self.assertRaises(lowerCAmelCase    ):
																verify_out_features_out_indices(['a', 'b']		,    (0, 1)		,    lowerCAmelCase    )

										# Out features must be a list
										with self.assertRaises(lowerCAmelCase    ):
																verify_out_features_out_indices(('a', 'b')		,    (0, 1)		,    ['a', 'b']    )

										# Out features must be a subset of stage names
										with self.assertRaises(lowerCAmelCase    ):
																verify_out_features_out_indices(['a', 'b']		,    (0, 1)		,    ['a']    )

										# Out indices must be a list or tuple
										with self.assertRaises(lowerCAmelCase    ):
																verify_out_features_out_indices(lowerCAmelCase		,    0		,    ['a', 'b']    )

										# Out indices must be a subset of stage names
										with self.assertRaises(lowerCAmelCase    ):
																verify_out_features_out_indices(lowerCAmelCase		,    (0, 1)		,    ['a']    )

										# Out features and out indices must be the same length
										with self.assertRaises(lowerCAmelCase    ):
																verify_out_features_out_indices(['a', 'b']		,    (0,)		,    ['a', 'b', 'c']    )

										# Out features should match out indices
										with self.assertRaises(lowerCAmelCase    ):
																verify_out_features_out_indices(['a', 'b']		,    (0, 2)		,    ['a', 'b', 'c']    )

										# Out features and out indices should be in order
										with self.assertRaises(lowerCAmelCase    ):
																verify_out_features_out_indices(['b', 'a']		,    (0, 1)		,    ['a', 'b']    )

										# Check passes with valid inputs
										verify_out_features_out_indices(['a', 'b', 'd']		,    (0, 1, -1)		,    ['a', 'b', 'c', 'd']    )

				def 		snake_case (				self    ):






										"""simple docstring"""

										snake_case								=			BackboneMixin()

										snake_case								=			['a', 'b', 'c']
										snake_case								=			['a', 'c']
										snake_case								=			[0, 2]

										# Check that the output features and indices are set correctly
										self.assertEqual(backbone.out_features		,    ['a', 'c']    )
										self.assertEqual(backbone.out_indices		,    [0, 2]    )

										# Check out features and indices are updated correctly
										snake_case								=			['a', 'b']
										self.assertEqual(backbone.out_features		,    ['a', 'b']    )
										self.assertEqual(backbone.out_indices		,    [0, 1]    )

										snake_case								=			[-3, -1]
										self.assertEqual(backbone.out_features		,    ['a', 'c']    )
										self.assertEqual(backbone.out_indices		,    [-3, -1]    )


