





"""simple docstring"""



from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


a_					=     logging.get_logger(__name__)

a_					=     {
    """Helsinki-NLP/opus-mt-en-de""": """https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json""",
    # See all Marian models at https://huggingface.co/models?filter=marian
}






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 _lowerCamelCase								=	"""marian"""
 _lowerCamelCase								=	["""past_key_values"""]
 _lowerCamelCase								=	{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}

 def __init__(       self   ,		__lowerCamelCase=5_8101   ,		__lowerCamelCase=None   ,		__lowerCamelCase=1024   ,		__lowerCamelCase=12   ,		__lowerCamelCase=4096   ,		__lowerCamelCase=16   ,		__lowerCamelCase=12   ,		__lowerCamelCase=4096   ,		__lowerCamelCase=16   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=True   ,		__lowerCamelCase=True   ,		__lowerCamelCase="gelu"   ,		__lowerCamelCase=1024   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.0_2   ,		__lowerCamelCase=5_8100   ,		__lowerCamelCase=False   ,		__lowerCamelCase=5_8100   ,		__lowerCamelCase=0   ,		__lowerCamelCase=0   ,		__lowerCamelCase=True   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     __A       :		List[Any]							=	vocab_size
     __A       :		int							=	decoder_vocab_size or vocab_size
     __A       :		Any							=	max_position_embeddings
     __A       :		List[str]							=	d_model
     __A       :		List[str]							=	encoder_ffn_dim
     __A       :		List[Any]							=	encoder_layers
     __A       :		Optional[int]							=	encoder_attention_heads
     __A       :		Tuple							=	decoder_ffn_dim
     __A       :		Optional[Any]							=	decoder_layers
     __A       :		List[str]							=	decoder_attention_heads
     __A       :		Optional[int]							=	dropout
     __A       :		str							=	attention_dropout
     __A       :		Any							=	activation_dropout
     __A       :		List[str]							=	activation_function
     __A       :		List[Any]							=	init_std
     __A       :		Optional[Any]							=	encoder_layerdrop
     __A       :		Any							=	decoder_layerdrop
     __A       :		Optional[int]							=	use_cache
     __A       :		Tuple							=	encoder_layers
     __A       :		List[Any]							=	scale_embedding  # scale factor will be sqrt(d_model) if True
     __A       :		Optional[int]							=	share_encoder_decoder_embeddings
     super().__init__(
         pad_token_id=__lowerCamelCase   ,		eos_token_id=__lowerCamelCase   ,		is_encoder_decoder=__lowerCamelCase   ,		decoder_start_token_id=__lowerCamelCase   ,		forced_eos_token_id=__lowerCamelCase   ,		**__lowerCamelCase   ,		)






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 @property
 # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     if self.task in ["default", "seq2seq-lm"]:
         __A       :		Any							=	OrderedDict(
             [
                 ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
             ]    )

         if self.use_past:
             __A       :		Optional[Any]							=	{0: '''batch'''}
             __A       :		Tuple							=	{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
         else:
             __A       :		List[str]							=	{0: '''batch''', 1: '''decoder_sequence'''}
             __A       :		Union[str, Any]							=	{0: '''batch''', 1: '''decoder_sequence'''}

         if self.use_past:
             self.fill_with_past_key_values_(__lowerCamelCase   ,		direction='''inputs'''    )
     elif self.task == "causal-lm":
         # TODO: figure this case out.
         __A       :		Optional[int]							=	OrderedDict(
             [
                 ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
             ]    )
         if self.use_past:
             __A					,			__A       :		Dict							=	self.num_layers
             for i in range(__lowerCamelCase    ):
                 __A       :		Optional[int]							=	{0: '''batch''', 2: '''past_sequence + sequence'''}
                 __A       :		List[Any]							=	{0: '''batch''', 2: '''past_sequence + sequence'''}
     else:
         __A       :		Dict							=	OrderedDict(
             [
                 ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ('''decoder_input_ids''', {0: '''batch''', 1: '''decoder_sequence'''}),
                 ('''decoder_attention_mask''', {0: '''batch''', 1: '''decoder_sequence'''}),
             ]    )

     return common_inputs

 @property
 # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     if self.task in ["default", "seq2seq-lm"]:
         __A       :		List[str]							=	super().outputs
     else:
         __A       :		str							=	super(__lowerCamelCase   ,		self    ).outputs
         if self.use_past:
             __A					,			__A       :		Optional[Any]							=	self.num_layers
             for i in range(__lowerCamelCase    ):
                 __A       :		List[Any]							=	{0: '''batch''', 2: '''past_sequence + sequence'''}
                 __A       :		List[str]							=	{0: '''batch''', 2: '''past_sequence + sequence'''}
     return common_outputs

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = False   ,		__lowerCamelCase = None   ,		):



     '''simple docstring'''




     __A       :		Tuple							=	self._generate_dummy_inputs_for_encoder_and_decoder(
         __lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    )

     # Generate decoder inputs
     __A       :		Union[str, Any]							=	seq_length if not self.use_past else 1
     __A       :		str							=	self._generate_dummy_inputs_for_encoder_and_decoder(
         __lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    )
     __A       :		List[str]							=	{F"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
     __A       :		int							=	dict(**__lowerCamelCase   ,		**__lowerCamelCase    )

     if self.use_past:
         if not is_torch_available():
             raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''    )
         else:
             import torch
         __A					,			__A       :		Tuple							=	common_inputs['''input_ids'''].shape
         __A       :		Optional[Any]							=	common_inputs['''decoder_input_ids'''].shape[1]
         __A					,			__A       :		str							=	self.num_attention_heads
         __A       :		Dict							=	(
             batch,
             num_encoder_attention_heads,
             encoder_seq_length,
             self._config.hidden_size // num_encoder_attention_heads,
         )
         __A       :		List[str]							=	decoder_seq_length + 3
         __A       :		str							=	(
             batch,
             num_decoder_attention_heads,
             decoder_past_length,
             self._config.hidden_size // num_decoder_attention_heads,
         )

         __A       :		int							=	torch.cat(
             [common_inputs['''decoder_attention_mask'''], torch.ones(__lowerCamelCase   ,		__lowerCamelCase    )]   ,		dim=1    )

         __A       :		str							=	[]
         # If the number of encoder and decoder layers are present in the model configuration, both are considered
         __A					,			__A       :		int							=	self.num_layers
         __A       :		Tuple							=	min(__lowerCamelCase   ,		__lowerCamelCase    )
         __A       :		Dict							=	max(__lowerCamelCase   ,		__lowerCamelCase    ) - min_num_layers
         __A       :		str							=	'''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

         for _ in range(__lowerCamelCase    ):
             common_inputs["past_key_values"].append(
                 (
                     torch.zeros(__lowerCamelCase    ),
                     torch.zeros(__lowerCamelCase    ),
                     torch.zeros(__lowerCamelCase    ),
                     torch.zeros(__lowerCamelCase    ),
                 )    )
         # TODO: test this.
         __A       :		Optional[int]							=	encoder_shape if remaining_side_name == '''encoder''' else decoder_shape
         for _ in range(__lowerCamelCase   ,		__lowerCamelCase    ):
             common_inputs["past_key_values"].append((torch.zeros(__lowerCamelCase    ), torch.zeros(__lowerCamelCase    ))    )
     return common_inputs

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = False   ,		__lowerCamelCase = None   ,		):



     '''simple docstring'''




     __A       :		List[Any]							=	self._generate_dummy_inputs_for_encoder_and_decoder(
         __lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    )

     if self.use_past:
         if not is_torch_available():
             raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''    )
         else:
             import torch
         __A					,			__A       :		int							=	common_inputs['''input_ids'''].shape
         # Not using the same length for past_key_values
         __A       :		Tuple							=	seqlen + 2
         __A					,			__A       :		Optional[Any]							=	self.num_layers
         __A					,			__A       :		Optional[Any]							=	self.num_attention_heads
         __A       :		Tuple							=	(
             batch,
             num_encoder_attention_heads,
             past_key_values_length,
             self._config.hidden_size // num_encoder_attention_heads,
         )

         __A       :		str							=	common_inputs['''attention_mask'''].dtype
         __A       :		Optional[int]							=	torch.cat(
             [common_inputs['''attention_mask'''], torch.ones(__lowerCamelCase   ,		__lowerCamelCase   ,		dtype=__lowerCamelCase    )]   ,		dim=1    )
         __A       :		str							=	[
             (torch.zeros(__lowerCamelCase    ), torch.zeros(__lowerCamelCase    )) for _ in range(__lowerCamelCase    )
         ]
     return common_inputs

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = False   ,		__lowerCamelCase = None   ,		):



     '''simple docstring'''




     __A       :		Dict							=	compute_effective_axis_dimension(
         __lowerCamelCase   ,		fixed_dimension=OnnxConfig.default_fixed_batch   ,		num_token_to_add=0    )

     # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
     __A       :		List[Any]							=	tokenizer.num_special_tokens_to_add(__lowerCamelCase    )
     __A       :		str							=	compute_effective_axis_dimension(
         __lowerCamelCase   ,		fixed_dimension=OnnxConfig.default_fixed_sequence   ,		num_token_to_add=__lowerCamelCase    )

     # Generate dummy inputs according to compute batch and sequence
     __A       :		Optional[int]							=	[''' '''.join([tokenizer.unk_token]    ) * seq_length] * batch_size
     __A       :		List[Any]							=	dict(tokenizer(__lowerCamelCase   ,		return_tensors=__lowerCamelCase    )    )
     return common_inputs

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = False   ,		__lowerCamelCase = None   ,		):



     '''simple docstring'''




     if self.task in ["default", "seq2seq-lm"]:
         __A       :		Tuple							=	self._generate_dummy_inputs_for_default_and_seqaseq_lm(
             __lowerCamelCase   ,		batch_size=__lowerCamelCase   ,		seq_length=__lowerCamelCase   ,		is_pair=__lowerCamelCase   ,		framework=__lowerCamelCase    )

     else:
         __A       :		int							=	self._generate_dummy_inputs_for_causal_lm(
             __lowerCamelCase   ,		batch_size=__lowerCamelCase   ,		seq_length=__lowerCamelCase   ,		is_pair=__lowerCamelCase   ,		framework=__lowerCamelCase    )

     return common_inputs

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    ):



     '''simple docstring'''




     if self.task in ["default", "seq2seq-lm"]:
         __A       :		int							=	super()._flatten_past_key_values_(__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    )
     else:
         __A       :		int							=	super(__lowerCamelCase   ,		self    )._flatten_past_key_values_(
             __lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase    )







 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return 1e-4











"""simple docstring"""



import functools
import operator

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


a_					=     logging.get_logger(__name__)

a_					=     {
    """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 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 _lowerCamelCase								=	"""unispeech"""

 def __init__(       self   ,		__lowerCamelCase=32   ,		__lowerCamelCase=768   ,		__lowerCamelCase=12   ,		__lowerCamelCase=12   ,		__lowerCamelCase=3072   ,		__lowerCamelCase="gelu"   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.0_2   ,		__lowerCamelCase=1e-5   ,		__lowerCamelCase="group"   ,		__lowerCamelCase="gelu"   ,		__lowerCamelCase=(512, 512, 512, 512, 512, 512, 512)   ,		__lowerCamelCase=(5, 2, 2, 2, 2, 2, 2)   ,		__lowerCamelCase=(10, 3, 3, 3, 3, 2, 2)   ,		__lowerCamelCase=False   ,		__lowerCamelCase=128   ,		__lowerCamelCase=16   ,		__lowerCamelCase=False   ,		__lowerCamelCase=True   ,		__lowerCamelCase=0.0_5   ,		__lowerCamelCase=10   ,		__lowerCamelCase=2   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=10   ,		__lowerCamelCase=0   ,		__lowerCamelCase=320   ,		__lowerCamelCase=2   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=100   ,		__lowerCamelCase=256   ,		__lowerCamelCase=256   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase="mean"   ,		__lowerCamelCase=False   ,		__lowerCamelCase=False   ,		__lowerCamelCase=256   ,		__lowerCamelCase=80   ,		__lowerCamelCase=0   ,		__lowerCamelCase=1   ,		__lowerCamelCase=2   ,		__lowerCamelCase=0.5   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase   ,		pad_token_id=__lowerCamelCase   ,		bos_token_id=__lowerCamelCase   ,		eos_token_id=__lowerCamelCase    )
     __A       :		Dict							=	hidden_size
     __A       :		Dict							=	feat_extract_norm
     __A       :		int							=	feat_extract_activation
     __A       :		Dict							=	list(__lowerCamelCase    )
     __A       :		str							=	list(__lowerCamelCase    )
     __A       :		Dict							=	list(__lowerCamelCase    )
     __A       :		str							=	conv_bias
     __A       :		Optional[int]							=	num_conv_pos_embeddings
     __A       :		int							=	num_conv_pos_embedding_groups
     __A       :		Union[str, Any]							=	len(self.conv_dim    )
     __A       :		List[str]							=	num_hidden_layers
     __A       :		Dict							=	intermediate_size
     __A       :		List[str]							=	hidden_act
     __A       :		int							=	num_attention_heads
     __A       :		str							=	hidden_dropout
     __A       :		str							=	attention_dropout
     __A       :		Optional[Any]							=	activation_dropout
     __A       :		Optional[int]							=	feat_proj_dropout
     __A       :		Optional[Any]							=	final_dropout
     __A       :		List[Any]							=	layerdrop
     __A       :		Any							=	layer_norm_eps
     __A       :		str							=	initializer_range
     __A       :		List[str]							=	num_ctc_classes
     __A       :		Dict							=	vocab_size
     __A       :		Dict							=	do_stable_layer_norm
     __A       :		Union[str, Any]							=	use_weighted_layer_sum
     __A       :		Tuple							=	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
     __A       :		List[Any]							=	apply_spec_augment
     __A       :		str							=	mask_time_prob
     __A       :		Dict							=	mask_time_length
     __A       :		List[str]							=	mask_time_min_masks
     __A       :		Union[str, Any]							=	mask_feature_prob
     __A       :		Tuple							=	mask_feature_length
     __A       :		Any							=	mask_feature_min_masks

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

     # ctc loss
     __A       :		Tuple							=	ctc_loss_reduction
     __A       :		Optional[int]							=	ctc_zero_infinity

     # pretraining loss
     __A       :		str							=	replace_prob







 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




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




