



"""simple docstring"""


import functools
import operator

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


snake_case_				     =       logging.get_logger(__name__)

snake_case_				     =       {
    """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       A_			(     SCREAMING_SNAKE_CASE_				):



						"""simple docstring"""
						__UpperCamelCase						=							"""sew-d"""






						def __init__(					self :int   ,  lowercase_ :Tuple=32   ,  lowercase_ :Any=7_68   ,  lowercase_ :Dict=12   ,  lowercase_ :Optional[Any]=12   ,  lowercase_ :Optional[int]=30_72   ,  lowercase_ :Any=2   ,  lowercase_ :int=5_12   ,  lowercase_ :Optional[Any]=2_56   ,  lowercase_ :Tuple=True   ,  lowercase_ :Union[str, Any]=True   ,  lowercase_ :List[Any]=("p2c", "c2p")   ,  lowercase_ :int="layer_norm"   ,  lowercase_ :Any="gelu_python"   ,  lowercase_ :Union[str, Any]=0.1   ,  lowercase_ :Any=0.1   ,  lowercase_ :int=0.1   ,  lowercase_ :List[str]=0.0   ,  lowercase_ :Dict=0.1   ,  lowercase_ :int=0.02   ,  lowercase_ :List[str]=1E-7   ,  lowercase_ :Dict=1E-5   ,  lowercase_ :List[str]="group"   ,  lowercase_ :Any="gelu"   ,  lowercase_ :List[str]=(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)   ,  lowercase_ :List[Any]=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)   ,  lowercase_ :Optional[int]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)   ,  lowercase_ :str=False   ,  lowercase_ :Tuple=1_28   ,  lowercase_ :Union[str, Any]=16   ,  lowercase_ :Any=True   ,  lowercase_ :int=0.05   ,  lowercase_ :Union[str, Any]=10   ,  lowercase_ :List[str]=2   ,  lowercase_ :Any=0.0   ,  lowercase_ :Tuple=10   ,  lowercase_ :List[str]=0   ,  lowercase_ :str="mean"   ,  lowercase_ :Optional[int]=False   ,  lowercase_ :str=False   ,  lowercase_ :int=2_56   ,  lowercase_ :Optional[int]=0   ,  lowercase_ :List[str]=1   ,  lowercase_ :List[Any]=2   ,  **lowercase_ :Dict   ,  )				->			Optional[Any]:
												super().__init__(**lowercase_   ,  pad_token_id=lowercase_   ,  bos_token_id=lowercase_   ,  eos_token_id=lowercase_					)
												UpperCAmelCase             = hidden_size
												UpperCAmelCase             = feat_extract_norm
												UpperCAmelCase             = feat_extract_activation
												UpperCAmelCase             = list(lowercase_					)
												UpperCAmelCase             = list(lowercase_					)
												UpperCAmelCase             = list(lowercase_					)
												UpperCAmelCase             = conv_bias
												UpperCAmelCase             = num_conv_pos_embeddings
												UpperCAmelCase             = num_conv_pos_embedding_groups
												UpperCAmelCase             = len(self.conv_dim					)
												UpperCAmelCase             = num_hidden_layers
												UpperCAmelCase             = intermediate_size
												UpperCAmelCase             = squeeze_factor
												UpperCAmelCase             = max_position_embeddings
												UpperCAmelCase             = position_buckets
												UpperCAmelCase             = share_att_key
												UpperCAmelCase             = relative_attention
												UpperCAmelCase             = norm_rel_ebd
												UpperCAmelCase             = list(lowercase_					)
												UpperCAmelCase             = hidden_act
												UpperCAmelCase             = num_attention_heads
												UpperCAmelCase             = hidden_dropout
												UpperCAmelCase             = attention_dropout
												UpperCAmelCase             = activation_dropout
												UpperCAmelCase             = feat_proj_dropout
												UpperCAmelCase             = final_dropout
												UpperCAmelCase             = layer_norm_eps
												UpperCAmelCase             = feature_layer_norm_eps
												UpperCAmelCase             = initializer_range
												UpperCAmelCase             = 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
												UpperCAmelCase             = apply_spec_augment
												UpperCAmelCase             = mask_time_prob
												UpperCAmelCase             = mask_time_length
												UpperCAmelCase             = mask_time_min_masks
												UpperCAmelCase             = mask_feature_prob
												UpperCAmelCase             = mask_feature_length
												UpperCAmelCase             = mask_feature_min_masks

												# ctc loss
												UpperCAmelCase             = ctc_loss_reduction
												UpperCAmelCase             = ctc_zero_infinity

												# sequence classification
												UpperCAmelCase             = use_weighted_layer_sum
												UpperCAmelCase             = classifier_proj_size






						@property
						def 	UpperCAmelCase__     (					self :str					)				->			Dict:
												return functools.reduce(operator.mul   ,  self.conv_stride   ,  1					)










from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


A__  :  List[str]								=					logging.get_logger(__name__)



class 				__snake_case						(     UpperCamelCase_						,UpperCamelCase_						):
							_a			      = '''maskformer-swin'''

							_a			      = {
							    '''num_attention_heads''': '''num_heads''',
							    '''num_hidden_layers''': '''num_layers''',
							}




							def __init__(       self     :       Union[str, Any]				,				A_     :       Dict=2_2_4				,				A_     :       Optional[Any]=4				,				A_     :       List[str]=3				,				A_     :       str=9_6				,				A_     :       Optional[Any]=[2, 2, 6, 2]				,				A_     :       Tuple=[3, 6, 1_2, 2_4]				,				A_     :       List[Any]=7				,				A_     :       List[Any]=4.0				,				A_     :       List[str]=True				,				A_     :       Dict=0.0				,				A_     :       int=0.0				,				A_     :       str=0.1				,				A_     :       Optional[int]="gelu"				,				A_     :       List[Any]=False				,				A_     :       int=0.02				,				A_     :       int=1e-5				,				A_     :       Optional[int]=None				,				A_     :       List[str]=None				,				**A_     :       List[Any]				,				):
									super().__init__(**A_)

									lowerCAmelCase_			:     Dict									= image_size
									lowerCAmelCase_			:     Optional[Any]									= patch_size
									lowerCAmelCase_			:     Tuple									= num_channels
									lowerCAmelCase_			:     Any									= embed_dim
									lowerCAmelCase_			:     List[str]									= depths
									lowerCAmelCase_			:     Union[str, Any]									= len(A_)
									lowerCAmelCase_			:     List[str]									= num_heads
									lowerCAmelCase_			:     Dict									= window_size
									lowerCAmelCase_			:     Optional[int]									= mlp_ratio
									lowerCAmelCase_			:     Dict									= qkv_bias
									lowerCAmelCase_			:     str									= hidden_dropout_prob
									lowerCAmelCase_			:     List[str]									= attention_probs_dropout_prob
									lowerCAmelCase_			:     Optional[int]									= drop_path_rate
									lowerCAmelCase_			:     Any									= hidden_act
									lowerCAmelCase_			:     str									= use_absolute_embeddings
									lowerCAmelCase_			:     List[str]									= layer_norm_eps
									lowerCAmelCase_			:     int									= initializer_range
									# we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
									# this indicates the channel dimension after the last stage of the model
									lowerCAmelCase_			:     str									= int(embed_dim * 2 ** (len(A_) - 1))
									lowerCAmelCase_			:     Optional[Any]									= ['''stem'''] + [F"""stage{idx}""" for idx in range(1				,				len(A_) + 1)]
									lowerCAmelCase_					,  lowerCAmelCase_			:     int									= get_aligned_output_features_output_indices(
									    out_features=A_				,				out_indices=A_				,				stage_names=self.stage_names)





