'''simple docstring'''





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


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

_lowerCAmelCase  :Optional[Any]  				=    {
    """MIT/ast-finetuned-audioset-10-10-0.4593""": (
        """https://huggingface.co/MIT/ast-finetuned-audioset-10-10-0.4593/resolve/main/config.json"""
    ),
}






class 				UpperCAmelCase (       _SCREAMING_SNAKE_CASE ):




    '''simple docstring'''







    snake_case__							:   Dict							=						"audio-spectrogram-transformer"






    def __init__(       self    ,							lowercase__=768    ,							lowercase__=12    ,							lowercase__=12    ,							lowercase__=3_072    ,							lowercase__="gelu"    ,							lowercase__=0.0    ,							lowercase__=0.0    ,							lowercase__=0.0_2    ,							lowercase__=1E-12    ,							lowercase__=16    ,							lowercase__=True    ,							lowercase__=10    ,							lowercase__=10    ,							lowercase__=1_024    ,							lowercase__=128    ,							**lowercase__    ,							)							-> List[Any]:
         super().__init__(**lowercase__ )

         SCREAMING_SNAKE_CASE					:			Any    	=       hidden_size
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       num_hidden_layers
         SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       num_attention_heads
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       intermediate_size
         SCREAMING_SNAKE_CASE					:			str    	=       hidden_act
         SCREAMING_SNAKE_CASE					:			Tuple    	=       hidden_dropout_prob
         SCREAMING_SNAKE_CASE					:			Optional[int]    	=       attention_probs_dropout_prob
         SCREAMING_SNAKE_CASE					:			Any    	=       initializer_range
         SCREAMING_SNAKE_CASE					:			Dict    	=       layer_norm_eps
         SCREAMING_SNAKE_CASE					:			Any    	=       patch_size
         SCREAMING_SNAKE_CASE					:			List[str]    	=       qkv_bias
         SCREAMING_SNAKE_CASE					:			Any    	=       frequency_stride
         SCREAMING_SNAKE_CASE					:			List[str]    	=       time_stride
         SCREAMING_SNAKE_CASE					:			Tuple    	=       max_length
         SCREAMING_SNAKE_CASE					:			Any    	=       num_mel_bins




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


_lowerCAmelCase  :Union[str, Any]  				=    logging.get_logger(__name__)

_lowerCAmelCase  :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 				UpperCAmelCase (       _SCREAMING_SNAKE_CASE ):




    '''simple docstring'''







    snake_case__							:   List[str]							=						"marian"
    snake_case__							:   Union[str, Any]							=						["past_key_values"]
    snake_case__							:   str							=						{"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.0_2    ,							lowercase__=58_100    ,							lowercase__=False    ,							lowercase__=58_100    ,							lowercase__=0    ,							lowercase__=0    ,							lowercase__=True    ,							**lowercase__    ,							)							-> int:
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       vocab_size
         SCREAMING_SNAKE_CASE					:			Dict    	=       decoder_vocab_size or vocab_size
         SCREAMING_SNAKE_CASE					:			int    	=       max_position_embeddings
         SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       d_model
         SCREAMING_SNAKE_CASE					:			Dict    	=       encoder_ffn_dim
         SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       encoder_layers
         SCREAMING_SNAKE_CASE					:			Dict    	=       encoder_attention_heads
         SCREAMING_SNAKE_CASE					:			int    	=       decoder_ffn_dim
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       decoder_layers
         SCREAMING_SNAKE_CASE					:			str    	=       decoder_attention_heads
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       dropout
         SCREAMING_SNAKE_CASE					:			Optional[int]    	=       attention_dropout
         SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       activation_dropout
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       activation_function
         SCREAMING_SNAKE_CASE					:			Tuple    	=       init_std
         SCREAMING_SNAKE_CASE					:			int    	=       encoder_layerdrop
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       decoder_layerdrop
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       use_cache
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       encoder_layers
         SCREAMING_SNAKE_CASE					:			int    	=       scale_embedding  # scale factor will be sqrt(d_model) if True
         SCREAMING_SNAKE_CASE					:			str    	=       share_encoder_decoder_embeddings
         super().__init__(
             pad_token_id=lowercase__    ,							eos_token_id=lowercase__    ,							is_encoder_decoder=lowercase__    ,							decoder_start_token_id=lowercase__    ,							forced_eos_token_id=lowercase__    ,							**lowercase__    ,							)






class 				UpperCAmelCase (       _SCREAMING_SNAKE_CASE ):




    '''simple docstring'''







    @property
    # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
    def       _UpperCamelCase    (       self )							-> Mapping[str, Mapping[int, str]]:
         if self.task in ["default", "seq2seq-lm"]:
              SCREAMING_SNAKE_CASE					:			Dict    	=       OrderedDict(
                  [
                      ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                      ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
                  ] )

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

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

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

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

              SCREAMING_SNAKE_CASE					:			List[str]    	=       torch.cat(
                  [common_inputs['decoder_attention_mask'], torch.ones(lowercase__    ,							lowercase__ )]    ,							dim=1 )

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

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






    def       _UpperCamelCase    (       self    ,							lowercase__    ,							lowercase__ = -1    ,							lowercase__ = -1    ,							lowercase__ = False    ,							lowercase__ = None    ,							)							-> Mapping[str, Any]:
         SCREAMING_SNAKE_CASE					:			Optional[int]    	=       self._generate_dummy_inputs_for_encoder_and_decoder(
             lowercase__    ,							lowercase__    ,							lowercase__    ,							lowercase__    ,							lowercase__ )

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

              SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       common_inputs['attention_mask'].dtype
              SCREAMING_SNAKE_CASE					:			List[str]    	=       torch.cat(
                  [common_inputs['attention_mask'], torch.ones(lowercase__    ,							lowercase__    ,							dtype=lowercase__ )]    ,							dim=1 )
              SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       [
                  (torch.zeros(lowercase__ ), torch.zeros(lowercase__ )) for _ in range(lowercase__ )
              ]
         return common_inputs






    def       _UpperCamelCase    (       self    ,							lowercase__    ,							lowercase__ = -1    ,							lowercase__ = -1    ,							lowercase__ = False    ,							lowercase__ = None    ,							)							-> Mapping[str, Any]:
         # Copied from OnnxConfig.generate_dummy_inputs
         # Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
         # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
         SCREAMING_SNAKE_CASE					:			List[str]    	=       compute_effective_axis_dimension(
             lowercase__    ,							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
         SCREAMING_SNAKE_CASE					:			List[str]    	=       tokenizer.num_special_tokens_to_add(lowercase__ )
         SCREAMING_SNAKE_CASE					:			Dict    	=       compute_effective_axis_dimension(
             lowercase__    ,							fixed_dimension=OnnxConfig.default_fixed_sequence    ,							num_token_to_add=lowercase__ )

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






    def       _UpperCamelCase    (       self    ,							lowercase__    ,							lowercase__ = -1    ,							lowercase__ = -1    ,							lowercase__ = False    ,							lowercase__ = None    ,							)							-> Mapping[str, Any]:
         if self.task in ["default", "seq2seq-lm"]:
              SCREAMING_SNAKE_CASE					:			List[Any]    	=       self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                  lowercase__    ,							batch_size=lowercase__    ,							seq_length=lowercase__    ,							is_pair=lowercase__    ,							framework=lowercase__ )

         else:
              SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       self._generate_dummy_inputs_for_causal_lm(
                  lowercase__    ,							batch_size=lowercase__    ,							seq_length=lowercase__    ,							is_pair=lowercase__    ,							framework=lowercase__ )

         return common_inputs






    def       _UpperCamelCase    (       self    ,							lowercase__    ,							lowercase__    ,							lowercase__    ,							lowercase__ )							-> int:
         if self.task in ["default", "seq2seq-lm"]:
              SCREAMING_SNAKE_CASE					:			List[Any]    	=       super()._flatten_past_key_values_(lowercase__    ,							lowercase__    ,							lowercase__    ,							lowercase__ )
         else:
              SCREAMING_SNAKE_CASE					:			Any    	=       super(lowercase__    ,							self )._flatten_past_key_values_(
                  lowercase__    ,							lowercase__    ,							lowercase__    ,							lowercase__ )






    @property
    def       _UpperCamelCase    (       self )							-> float:
         return 1E-4



