





'''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


UpperCAmelCase					:		Optional[int]		=							logging.get_logger(__name__)

UpperCAmelCase					:		Optional[int]		=							{
    '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 lowerCamelCase						(__a					):
  _lowercase  :	Optional[int]       					=				"""marian"""
  _lowercase  :	Any       					=				["""past_key_values"""]
  _lowercase  :	Optional[int]       					=				{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}







  def __init__(		self     ,     lowercase__=58_101     ,     lowercase__=None     ,     lowercase__=1_024     ,     lowercase__=12     ,     lowercase__=4_096     ,     lowercase__=16     ,     lowercase__=12     ,     lowercase__=4_096     ,     lowercase__=16     ,     lowercase__=0.0     ,     lowercase__=0.0     ,     lowercase__=True     ,     lowercase__=True     ,     lowercase__="gelu"     ,     lowercase__=1_024     ,     lowercase__=0.1     ,     lowercase__=0.0     ,     lowercase__=0.0     ,     lowercase__=0.02     ,     lowercase__=58_100     ,     lowercase__=False     ,     lowercase__=58_100     ,     lowercase__=0     ,     lowercase__=0     ,     lowercase__=True     ,     **lowercase__     ,     )		->						Tuple:






        """simple docstring"""





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





class lowerCamelCase						(__a					):







  @property
  # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
  def 				UpperCAmelCase_				(		self		)		->						Mapping[str, Mapping[int, str]]:






        """simple docstring"""





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

              if self.use_past:
                    _snake_case		:	Dict					     =     {0: '''batch'''}
                    _snake_case		:	Dict					     =     {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
              else:
                    _snake_case		:	List[str]					     =     {0: '''batch''', 1: '''decoder_sequence'''}
                    _snake_case		:	Dict					     =     {0: '''batch''', 1: '''decoder_sequence'''}

              if self.use_past:
                    self.fill_with_past_key_values_(A__     ,     direction='''inputs'''		)
        elif self.task == "causal-lm":
              # TODO: figure this case out.
              _snake_case		:	Tuple					     =     OrderedDict(
                  [
                      ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                      ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                  ]		)
              if self.use_past:
                    _snake_case     ,							_snake_case		:	Optional[Any]					     =     self.num_layers
                    for i in range(A__		):
                          _snake_case		:	Optional[int]					     =     {0: '''batch''', 2: '''past_sequence + sequence'''}
                          _snake_case		:	List[Any]					     =     {0: '''batch''', 2: '''past_sequence + sequence'''}
        else:
              _snake_case		:	str					     =     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		)		->						Mapping[str, Mapping[int, str]]:






        """simple docstring"""





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







  def 				UpperCAmelCase_				(		self     ,     lowercase__     ,     lowercase__ = -1     ,     lowercase__ = -1     ,     lowercase__ = False     ,     lowercase__ = None     ,     )		->						Mapping[str, Any]:






        """simple docstring"""





        _snake_case		:	Dict					     =     self._generate_dummy_inputs_for_encoder_and_decoder(
            A__     ,     A__     ,     A__     ,     A__     ,     A__		)

        # Generate decoder inputs
        _snake_case		:	Dict					     =     seq_length if not self.use_past else 1
        _snake_case		:	List[str]					     =     self._generate_dummy_inputs_for_encoder_and_decoder(
            A__     ,     A__     ,     A__     ,     A__     ,     A__		)
        _snake_case		:	str					     =     {F'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
        _snake_case		:	Optional[int]					     =     dict(**A__     ,     **A__		)

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

              _snake_case		:	Any					     =     torch.cat(
                  [common_inputs['''decoder_attention_mask'''], torch.ones(A__     ,     A__		)]     ,     dim=1		)

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

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







  def 				UpperCAmelCase_				(		self     ,     lowercase__     ,     lowercase__ = -1     ,     lowercase__ = -1     ,     lowercase__ = False     ,     lowercase__ = None     ,     )		->						Mapping[str, Any]:






        """simple docstring"""





        _snake_case		:	Optional[int]					     =     self._generate_dummy_inputs_for_encoder_and_decoder(
            A__     ,     A__     ,     A__     ,     A__     ,     A__		)

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

              _snake_case		:	Dict					     =     common_inputs['''attention_mask'''].dtype
              _snake_case		:	Union[str, Any]					     =     torch.cat(
                  [common_inputs['''attention_mask'''], torch.ones(A__     ,     A__     ,     dtype=A__		)]     ,     dim=1		)
              _snake_case		:	Optional[int]					     =     [
                  (torch.zeros(A__		), torch.zeros(A__		)) for _ in range(A__		)
              ]
        return common_inputs







  def 				UpperCAmelCase_				(		self     ,     lowercase__     ,     lowercase__ = -1     ,     lowercase__ = -1     ,     lowercase__ = False     ,     lowercase__ = None     ,     )		->						Mapping[str, Any]:






        """simple docstring"""





        _snake_case		:	Optional[Any]					     =     compute_effective_axis_dimension(
            A__     ,     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
        _snake_case		:	str					     =     tokenizer.num_special_tokens_to_add(A__		)
        _snake_case		:	Tuple					     =     compute_effective_axis_dimension(
            A__     ,     fixed_dimension=OnnxConfig.default_fixed_sequence     ,     num_token_to_add=A__		)

        # Generate dummy inputs according to compute batch and sequence
        _snake_case		:	Union[str, Any]					     =     [''' '''.join([tokenizer.unk_token]		) * seq_length] * batch_size
        _snake_case		:	Union[str, Any]					     =     dict(tokenizer(A__     ,     return_tensors=A__		)		)
        return common_inputs







  def 				UpperCAmelCase_				(		self     ,     lowercase__     ,     lowercase__ = -1     ,     lowercase__ = -1     ,     lowercase__ = False     ,     lowercase__ = None     ,     )		->						Mapping[str, Any]:






        """simple docstring"""





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

        else:
              _snake_case		:	Any					     =     self._generate_dummy_inputs_for_causal_lm(
                  A__     ,     batch_size=A__     ,     seq_length=A__     ,     is_pair=A__     ,     framework=A__		)

        return common_inputs







  def 				UpperCAmelCase_				(		self     ,     lowercase__     ,     lowercase__     ,     lowercase__     ,     lowercase__		)		->						List[str]:






        """simple docstring"""





        if self.task in ["default", "seq2seq-lm"]:
              _snake_case		:	Tuple					     =     super()._flatten_past_key_values_(A__     ,     A__     ,     A__     ,     A__		)
        else:
              _snake_case		:	Tuple					     =     super(A__     ,     self		)._flatten_past_key_values_(
                  A__     ,     A__     ,     A__     ,     A__		)







  @property
  def 				UpperCAmelCase_				(		self		)		->						float:






        """simple docstring"""





        return 1E-4









'''simple docstring'''

import functools
import operator

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


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

UpperCAmelCase					:		Dict		=							{
    '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 lowerCamelCase						(a__					):
  _lowercase  :	List[str]       					=				"""sew-d"""







  def __init__(		self     ,     lowercase__=32     ,     lowercase__=768     ,     lowercase__=12     ,     lowercase__=12     ,     lowercase__=3_072     ,     lowercase__=2     ,     lowercase__=512     ,     lowercase__=256     ,     lowercase__=True     ,     lowercase__=True     ,     lowercase__=("p2c", "c2p")     ,     lowercase__="layer_norm"     ,     lowercase__="gelu_python"     ,     lowercase__=0.1     ,     lowercase__=0.1     ,     lowercase__=0.1     ,     lowercase__=0.0     ,     lowercase__=0.1     ,     lowercase__=0.02     ,     lowercase__=1E-7     ,     lowercase__=1E-5     ,     lowercase__="group"     ,     lowercase__="gelu"     ,     lowercase__=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)     ,     lowercase__=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)     ,     lowercase__=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)     ,     lowercase__=False     ,     lowercase__=128     ,     lowercase__=16     ,     lowercase__=True     ,     lowercase__=0.05     ,     lowercase__=10     ,     lowercase__=2     ,     lowercase__=0.0     ,     lowercase__=10     ,     lowercase__=0     ,     lowercase__="mean"     ,     lowercase__=False     ,     lowercase__=False     ,     lowercase__=256     ,     lowercase__=0     ,     lowercase__=1     ,     lowercase__=2     ,     **lowercase__     ,     )		->						Dict:






        """simple docstring"""





        super().__init__(**lowercase__     ,     pad_token_id=lowercase__     ,     bos_token_id=lowercase__     ,     eos_token_id=lowercase__		)
        _snake_case		:	List[str]					     =     hidden_size
        _snake_case		:	Optional[Any]					     =     feat_extract_norm
        _snake_case		:	Tuple					     =     feat_extract_activation
        _snake_case		:	Tuple					     =     list(lowercase__		)
        _snake_case		:	Any					     =     list(lowercase__		)
        _snake_case		:	Any					     =     list(lowercase__		)
        _snake_case		:	Any					     =     conv_bias
        _snake_case		:	List[Any]					     =     num_conv_pos_embeddings
        _snake_case		:	Any					     =     num_conv_pos_embedding_groups
        _snake_case		:	Union[str, Any]					     =     len(self.conv_dim		)
        _snake_case		:	Optional[Any]					     =     num_hidden_layers
        _snake_case		:	Optional[int]					     =     intermediate_size
        _snake_case		:	Any					     =     squeeze_factor
        _snake_case		:	Optional[Any]					     =     max_position_embeddings
        _snake_case		:	Tuple					     =     position_buckets
        _snake_case		:	Tuple					     =     share_att_key
        _snake_case		:	Any					     =     relative_attention
        _snake_case		:	Optional[int]					     =     norm_rel_ebd
        _snake_case		:	Optional[Any]					     =     list(lowercase__		)
        _snake_case		:	List[Any]					     =     hidden_act
        _snake_case		:	List[Any]					     =     num_attention_heads
        _snake_case		:	Dict					     =     hidden_dropout
        _snake_case		:	Tuple					     =     attention_dropout
        _snake_case		:	Union[str, Any]					     =     activation_dropout
        _snake_case		:	List[Any]					     =     feat_proj_dropout
        _snake_case		:	Optional[int]					     =     final_dropout
        _snake_case		:	Optional[Any]					     =     layer_norm_eps
        _snake_case		:	Dict					     =     feature_layer_norm_eps
        _snake_case		:	List[Any]					     =     initializer_range
        _snake_case		:	Dict					     =     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		:	Union[str, Any]					     =     apply_spec_augment
        _snake_case		:	Any					     =     mask_time_prob
        _snake_case		:	List[str]					     =     mask_time_length
        _snake_case		:	Dict					     =     mask_time_min_masks
        _snake_case		:	Union[str, Any]					     =     mask_feature_prob
        _snake_case		:	Tuple					     =     mask_feature_length
        _snake_case		:	Union[str, Any]					     =     mask_feature_min_masks

        # ctc loss
        _snake_case		:	Optional[Any]					     =     ctc_loss_reduction
        _snake_case		:	Optional[Any]					     =     ctc_zero_infinity

        # sequence classification
        _snake_case		:	List[Any]					     =     use_weighted_layer_sum
        _snake_case		:	Any					     =     classifier_proj_size







  @property
  def 				UpperCAmelCase_				(		self		)		->						Any:






        """simple docstring"""





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


