

"""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									=						{
    """facebook/mbart-large-cc25""": """https://huggingface.co/facebook/mbart-large-cc25/resolve/main/config.json""",
    # See all MBART models at https://huggingface.co/models?filter=mbart
}

class        _UpperCamelCase	(						lowerCamelCase__	):


  """simple docstring"""





  snake_case_        =    'mbart'
  snake_case_        =    ['past_key_values']
  snake_case_        =    {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}



  def __init__( self					: Tuple       ,       snake_case					: str=5_0265       ,       snake_case					: Optional[int]=1024       ,       snake_case					: List[Any]=12       ,       snake_case					: Dict=4096       ,       snake_case					: Optional[Any]=16       ,       snake_case					: List[str]=12       ,       snake_case					: Dict=4096       ,       snake_case					: Optional[int]=16       ,       snake_case					: Union[str, Any]=0.0       ,       snake_case					: Optional[Any]=0.0       ,       snake_case					: Dict=True       ,       snake_case					: Union[str, Any]=True       ,       snake_case					: Tuple="gelu"       ,       snake_case					: Dict=1024       ,       snake_case					: int=0.1       ,       snake_case					: List[Any]=0.0       ,       snake_case					: int=0.0       ,       snake_case					: Any=0.02       ,       snake_case					: str=0.0       ,       snake_case					: Dict=False       ,       snake_case					: Optional[Any]=1       ,       snake_case					: Any=0       ,       snake_case					: str=2       ,       snake_case					: Tuple=2       ,       **snake_case					: List[Any]       ,       )	->			Union[str, Any]:


         '''simple docstring'''





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

class        _UpperCamelCase	(						lowerCamelCase__	):


  """simple docstring"""





  @property
  def 							_UpperCAmelCase      ( self					: Union[str, Any]      )	->			Mapping[str, Mapping[int, str]]:


         '''simple docstring'''





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

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

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


         '''simple docstring'''





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



  def 							_UpperCAmelCase      ( self					: Any       ,       snake_case					: PreTrainedTokenizer       ,       snake_case					: int = -1       ,       snake_case					: int = -1       ,       snake_case					: bool = False       ,       snake_case					: Optional[TensorType] = None       ,       )	->			Mapping[str, Any]:


         '''simple docstring'''





         __magic_name__			:		int        =     self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             snake_case       ,       snake_case       ,       snake_case       ,       snake_case       ,       snake_case      )

         # Generate decoder inputs
         __magic_name__			:		Optional[int]        =     seq_length if not self.use_past else 1
         __magic_name__			:		Any        =     self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             snake_case       ,       snake_case       ,       snake_case       ,       snake_case       ,       snake_case      )
         __magic_name__			:		str        =     {f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
         __magic_name__			:		Any        =     dict(**snake_case       ,       **snake_case      )

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

                __magic_name__			:		Tuple        =     torch.cat(
                    [common_inputs['''decoder_attention_mask'''], torch.ones(snake_case       ,       snake_case      )]       ,       dim=1      )

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

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



  def 							_UpperCAmelCase      ( self					: Any       ,       snake_case					: PreTrainedTokenizer       ,       snake_case					: int = -1       ,       snake_case					: int = -1       ,       snake_case					: bool = False       ,       snake_case					: Optional[TensorType] = None       ,       )	->			Mapping[str, Any]:


         '''simple docstring'''





         __magic_name__			:		str        =     self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             snake_case       ,       snake_case       ,       snake_case       ,       snake_case       ,       snake_case      )

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

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



  def 							_UpperCAmelCase      ( self					: Optional[int]       ,       snake_case					: PreTrainedTokenizer       ,       snake_case					: int = -1       ,       snake_case					: int = -1       ,       snake_case					: bool = False       ,       snake_case					: Optional[TensorType] = None       ,       )	->			Mapping[str, Any]:


         '''simple docstring'''





         __magic_name__			:		str        =     compute_effective_axis_dimension(
             snake_case       ,       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
         __magic_name__			:		Dict        =     tokenizer.num_special_tokens_to_add(snake_case      )
         __magic_name__			:		Optional[int]        =     compute_effective_axis_dimension(
             snake_case       ,       fixed_dimension=OnnxConfig.default_fixed_sequence       ,       num_token_to_add=snake_case      )

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



  def 							_UpperCAmelCase      ( self					: str       ,       snake_case					: PreTrainedTokenizer       ,       snake_case					: int = -1       ,       snake_case					: int = -1       ,       snake_case					: bool = False       ,       snake_case					: Optional[TensorType] = None       ,       )	->			Mapping[str, Any]:


         '''simple docstring'''





         if self.task in ["default", "seq2seq-lm"]:
                __magic_name__			:		List[str]        =     self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                    snake_case       ,       batch_size=snake_case       ,       seq_length=snake_case       ,       is_pair=snake_case       ,       framework=snake_case      )

         elif self.task == "causal-lm":
                __magic_name__			:		Any        =     self._generate_dummy_inputs_for_causal_lm(
                    snake_case       ,       batch_size=snake_case       ,       seq_length=snake_case       ,       is_pair=snake_case       ,       framework=snake_case      )
         else:
                __magic_name__			:		Any        =     self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
                    snake_case       ,       batch_size=snake_case       ,       seq_length=snake_case       ,       is_pair=snake_case       ,       framework=snake_case      )

         return common_inputs




  def 							_UpperCAmelCase      ( self					: Union[str, Any]       ,       snake_case					: Optional[int]       ,       snake_case					: Tuple       ,       snake_case					: List[str]       ,       snake_case					: int      )	->			Optional[int]:


         '''simple docstring'''





         if self.task in ["default", "seq2seq-lm"]:
                __magic_name__			:		List[Any]        =     super()._flatten_past_key_values_(snake_case       ,       snake_case       ,       snake_case       ,       snake_case      )
         else:
                __magic_name__			:		Union[str, Any]        =     super(snake_case       ,       self      )._flatten_past_key_values_(
                    snake_case       ,       snake_case       ,       snake_case       ,       snake_case      )



"""simple docstring"""
from typing import Callable, Optional, Union

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


A									=						logging.get_logger(__name__)

A									=						{
    """microsoft/prophetnet-large-uncased""": (
        """https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json"""
    ),
}

class        _UpperCamelCase	(						lowerCamelCase__	):


  """simple docstring"""





  snake_case_        =    'prophetnet'
  snake_case_        =    ['past_key_values']
  snake_case_        =    {
      'num_attention_heads': 'num_encoder_attention_heads',
  }



  def __init__( self					: Union[str, Any]       ,       snake_case					: Optional[float] = 0.1       ,       snake_case					: Optional[Union[str, Callable]] = "gelu"       ,       snake_case					: Optional[int] = 3_0522       ,       snake_case					: Optional[int] = 1024       ,       snake_case					: Optional[int] = 4096       ,       snake_case					: Optional[int] = 12       ,       snake_case					: Optional[int] = 16       ,       snake_case					: Optional[int] = 4096       ,       snake_case					: Optional[int] = 12       ,       snake_case					: Optional[int] = 16       ,       snake_case					: Optional[float] = 0.1       ,       snake_case					: Optional[float] = 0.1       ,       snake_case					: Optional[int] = 512       ,       snake_case					: Optional[float] = 0.02       ,       snake_case					: Optional[bool] = True       ,       snake_case					: Optional[bool] = True       ,       snake_case					: Optional[int] = 0       ,       snake_case					: Optional[int] = 2       ,       snake_case					: Optional[int] = 32       ,       snake_case					: Optional[int] = 128       ,       snake_case					: Optional[bool] = False       ,       snake_case					: Optional[float] = 0.0       ,       snake_case					: Optional[bool] = True       ,       snake_case					: Optional[int] = 0       ,       snake_case					: Optional[int] = 1       ,       snake_case					: Optional[int] = 2       ,       **snake_case					: Optional[int]       ,       )	->			List[Any]:


         '''simple docstring'''





         __magic_name__			:		Union[str, Any]        =     vocab_size
         __magic_name__			:		Tuple        =     hidden_size
         __magic_name__			:		str        =     encoder_ffn_dim
         __magic_name__			:		Tuple        =     num_encoder_layers
         __magic_name__			:		int        =     num_encoder_attention_heads
         __magic_name__			:		int        =     decoder_ffn_dim
         __magic_name__			:		Optional[int]        =     num_decoder_layers
         __magic_name__			:		str        =     num_decoder_attention_heads
         __magic_name__			:		Optional[Any]        =     max_position_embeddings
         __magic_name__			:		Union[str, Any]        =     init_std  # Normal(0, this parameter)
         __magic_name__			:		Tuple        =     activation_function

         # parameters for prophetnet
         __magic_name__			:		int        =     ngram
         __magic_name__			:		str        =     num_buckets
         __magic_name__			:		Any        =     relative_max_distance
         __magic_name__			:		Optional[int]        =     disable_ngram_loss
         __magic_name__			:		str        =     eps

         # 3 Types of Dropout
         __magic_name__			:		Dict        =     attention_dropout
         __magic_name__			:		Optional[int]        =     activation_dropout
         __magic_name__			:		List[Any]        =     dropout

         __magic_name__			:		str        =     use_cache

         super().__init__(
             pad_token_id=snake_case       ,       bos_token_id=snake_case       ,       eos_token_id=snake_case       ,       is_encoder_decoder=snake_case       ,       add_cross_attention=snake_case       ,       decoder_start_token_id=snake_case       ,       **snake_case       ,       )



  @property
  def 							_UpperCAmelCase      ( self					: str      )	->			int:


         '''simple docstring'''





         return self.num_encoder_layers + self.num_decoder_layers




  @num_hidden_layers.setter
  def 							_UpperCAmelCase      ( self					: Dict       ,       snake_case					: int      )	->			Optional[int]:


         '''simple docstring'''





         raise NotImplementedError(
             '''This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'''
             ''' `num_decoder_layers`.'''      )
