
"""simple docstring"""






import functools
import operator

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


__UpperCAmelCase       =  logging.get_logger(__name__)

__UpperCAmelCase       =  {
    'microsoft/unispeech-large-1500h-cv': (
        'https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json'
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}




class 			_SCREAMING_SNAKE_CASE					(			A__							):
			UpperCAmelCase_  :List[Any]				 =						"unispeech"






			def __init__(					self       ,   __A=32       ,   __A=768       ,   __A=12       ,   __A=12       ,   __A=3072       ,   __A="gelu"       ,   __A=0.1       ,   __A=0.1       ,   __A=0.1       ,   __A=0.0       ,   __A=0.0       ,   __A=0.1       ,   __A=0.1       ,   __A=0.0_2       ,   __A=1E-5       ,   __A="group"       ,   __A="gelu"       ,   __A=(512, 512, 512, 512, 512, 512, 512)       ,   __A=(5, 2, 2, 2, 2, 2, 2)       ,   __A=(10, 3, 3, 3, 3, 2, 2)       ,   __A=False       ,   __A=128       ,   __A=16       ,   __A=False       ,   __A=True       ,   __A=0.0_5       ,   __A=10       ,   __A=2       ,   __A=0.0       ,   __A=10       ,   __A=0       ,   __A=320       ,   __A=2       ,   __A=0.1       ,   __A=100       ,   __A=256       ,   __A=256       ,   __A=0.1       ,   __A="mean"       ,   __A=False       ,   __A=False       ,   __A=256       ,   __A=80       ,   __A=0       ,   __A=1       ,   __A=2       ,   __A=0.5       ,   **__A       ,   )			->     Tuple:
						super().__init__(**__A       ,   pad_token_id=__A       ,   bos_token_id=__A       ,   eos_token_id=__A       )
						lowerCAmelCase_    :str			     =  hidden_size
						lowerCAmelCase_    :Dict			     =  feat_extract_norm
						lowerCAmelCase_    :Optional[int]			     =  feat_extract_activation
						lowerCAmelCase_    :List[str]			     =  list(__A       )
						lowerCAmelCase_    :Dict			     =  list(__A       )
						lowerCAmelCase_    :int			     =  list(__A       )
						lowerCAmelCase_    :List[str]			     =  conv_bias
						lowerCAmelCase_    :Tuple			     =  num_conv_pos_embeddings
						lowerCAmelCase_    :Dict			     =  num_conv_pos_embedding_groups
						lowerCAmelCase_    :Optional[Any]			     =  len(self.conv_dim       )
						lowerCAmelCase_    :Optional[Any]			     =  num_hidden_layers
						lowerCAmelCase_    :Any			     =  intermediate_size
						lowerCAmelCase_    :List[Any]			     =  hidden_act
						lowerCAmelCase_    :Optional[int]			     =  num_attention_heads
						lowerCAmelCase_    :str			     =  hidden_dropout
						lowerCAmelCase_    :str			     =  attention_dropout
						lowerCAmelCase_    :Optional[Any]			     =  activation_dropout
						lowerCAmelCase_    :Tuple			     =  feat_proj_dropout
						lowerCAmelCase_    :Tuple			     =  final_dropout
						lowerCAmelCase_    :Tuple			     =  layerdrop
						lowerCAmelCase_    :Optional[int]			     =  layer_norm_eps
						lowerCAmelCase_    :List[str]			     =  initializer_range
						lowerCAmelCase_    :Union[str, Any]			     =  num_ctc_classes
						lowerCAmelCase_    :List[str]			     =  vocab_size
						lowerCAmelCase_    :int			     =  do_stable_layer_norm
						lowerCAmelCase_    :Dict			     =  use_weighted_layer_sum
						lowerCAmelCase_    :Any			     =  classifier_proj_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)`, 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
						lowerCAmelCase_    :Dict			     =  apply_spec_augment
						lowerCAmelCase_    :Optional[Any]			     =  mask_time_prob
						lowerCAmelCase_    :Dict			     =  mask_time_length
						lowerCAmelCase_    :int			     =  mask_time_min_masks
						lowerCAmelCase_    :Optional[Any]			     =  mask_feature_prob
						lowerCAmelCase_    :Dict			     =  mask_feature_length
						lowerCAmelCase_    :Any			     =  mask_feature_min_masks

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

						# ctc loss
						lowerCAmelCase_    :Union[str, Any]			     =  ctc_loss_reduction
						lowerCAmelCase_    :int			     =  ctc_zero_infinity

						# pretraining loss
						lowerCAmelCase_    :Union[str, Any]			     =  replace_prob






			@property
			def  __lowerCAmelCase (					self       )			->     List[Any]:
						return functools.reduce(operator.mul       ,   self.conv_stride       ,   1       )













import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel

class    lowerCAmelCase							(					__UpperCamelCase			):
 UpperCAmelCase__													=		"""M-CLIP"""
 def __init__(      self  :      Optional[Any]			,     UpperCAmelCase  :      Union[str, Any]=1024			,     UpperCAmelCase  :      Tuple=768			,     **UpperCAmelCase  :      Optional[int]	)			->	Dict:
     lowerCamelCase__    :      Optional[int]					 =		transformerDimSize
     lowerCamelCase__    :      Optional[Any]					 =		imageDimSize
     super().__init__(**UpperCAmelCase	)


class    lowerCAmelCase							(					__UpperCamelCase			):
 UpperCAmelCase__													=		MCLIPConfig
 def __init__(      self  :      List[Any]			,     UpperCAmelCase  :      Dict			,     *UpperCAmelCase  :      Any			,     **UpperCAmelCase  :      Dict	)			->	Dict:
     super().__init__(UpperCAmelCase			,     *UpperCAmelCase			,     **UpperCAmelCase	)
     lowerCamelCase__    :      Tuple					 =		XLMRobertaModel(UpperCAmelCase	)
     lowerCamelCase__    :      Union[str, Any]					 =		torch.nn.Linear(
         in_features=config.transformerDimensions			,     out_features=config.numDims	)







 def      A_	(      self  :      Optional[int]			,     UpperCAmelCase  :      Optional[Any]			,     UpperCAmelCase  :      Dict	)			->	Tuple:
     lowerCamelCase__    :      Any					 =		self.transformer(input_ids=UpperCAmelCase			,     attention_mask=UpperCAmelCase	)[0]
     lowerCamelCase__    :      int					 =		(embs * attention_mask.unsqueeze(2	)).sum(dim=1	) / attention_mask.sum(dim=1	)[:, None]
     return self.LinearTransformation(UpperCAmelCase	), embs





