






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

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


lowerCamelCase					    =	logging.get_logger(__name__)

lowerCamelCase					    =	{
    '''facebook/m2m100_418M''': '''https://huggingface.co/facebook/m2m100_418M/resolve/main/config.json''',
    # See all M2M100 models at https://huggingface.co/models?filter=m2m_100
}

class        snake_case_				(							lowercase_   ):







   """simple docstring"""



   __lowerCAmelCase  =    """m2m_100"""
   __lowerCAmelCase  =    ["""past_key_values"""]
   __lowerCAmelCase  =    {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}

   def __init__(     self:						Optional[int] ,							snake_case__:						Tuple=128_112 ,							snake_case__:						List[str]=1_024 ,							snake_case__:						str=12 ,							snake_case__:						str=4_096 ,							snake_case__:						Any=16 ,							snake_case__:						Union[str, Any]=12 ,							snake_case__:						Tuple=4_096 ,							snake_case__:						Optional[int]=16 ,							snake_case__:						Optional[int]=0.05 ,							snake_case__:						Dict=0.05 ,							snake_case__:						str=True ,							snake_case__:						Union[str, Any]=True ,							snake_case__:						Dict="relu" ,							snake_case__:						str=1_024 ,							snake_case__:						int=0.1 ,							snake_case__:						str=0.1 ,							snake_case__:						Optional[int]=0.0 ,							snake_case__:						Tuple=0.02 ,							snake_case__:						Tuple=2 ,							snake_case__:						Any=True ,							snake_case__:						List[Any]=1 ,							snake_case__:						Dict=0 ,							snake_case__:						int=2 ,							**snake_case__:						str ,							)	->		List[str]:


       """simple docstring"""



       _lowercase     			=						vocab_size
       _lowercase     			=						max_position_embeddings
       _lowercase     			=						d_model
       _lowercase     			=						encoder_ffn_dim
       _lowercase     			=						encoder_layers
       _lowercase     			=						encoder_attention_heads
       _lowercase     			=						decoder_ffn_dim
       _lowercase     			=						decoder_layers
       _lowercase     			=						decoder_attention_heads
       _lowercase     			=						dropout
       _lowercase     			=						attention_dropout
       _lowercase     			=						activation_dropout
       _lowercase     			=						activation_function
       _lowercase     			=						init_std
       _lowercase     			=						encoder_layerdrop
       _lowercase     			=						decoder_layerdrop
       _lowercase     			=						use_cache
       _lowercase     			=						encoder_layers
       _lowercase     			=						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__ ,							decoder_start_token_id=snake_case__ ,							**snake_case__ ,							)






class        snake_case_				(							lowercase_   ):







   """simple docstring"""



   @property
   def       SCREAMING_SNAKE_CASE__					(     self:						str						)	->		Mapping[str, Mapping[int, str]]:


       """simple docstring"""



       _lowercase     			=						OrderedDict(
           [
               ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
               ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
           ]						)

       if self.use_past:
           _lowercase     			=						{0: 'batch'}
           _lowercase     			=						{0: 'batch', 1: 'past_decoder_sequence + sequence'}
       else:
           _lowercase     			=						{0: 'batch', 1: 'decoder_sequence'}
           _lowercase     			=						{0: 'batch', 1: 'decoder_sequence'}

       if self.use_past:
           self.fill_with_past_key_values_(snake_case__ ,							direction='inputs'						)
       return common_inputs

   def       SCREAMING_SNAKE_CASE__					(     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"""



       _lowercase     			=						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
       _lowercase     			=						tokenizer.num_special_tokens_to_add(snake_case__						)
       _lowercase     			=						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
       _lowercase     			=						[' '.join([tokenizer.unk_token]						) * seq_length] * batch_size
       _lowercase     			=						dict(tokenizer(snake_case__ ,							return_tensors=snake_case__						)						)
       return common_inputs

   def       SCREAMING_SNAKE_CASE__					(     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"""



       _lowercase     			=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           snake_case__ ,							snake_case__ ,							snake_case__ ,							snake_case__ ,							snake_case__						)

       # Generate decoder inputs
       _lowercase     			=						seq_length if not self.use_past else 1
       _lowercase     			=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           snake_case__ ,							snake_case__ ,							snake_case__ ,							snake_case__ ,							snake_case__						)
       _lowercase     			=						{f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
       _lowercase     			=						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
           _lowercase			,     _lowercase     			=						common_inputs['input_ids'].shape
           _lowercase     			=						common_inputs['decoder_input_ids'].shape[1]
           _lowercase			,     _lowercase     			=						self.num_attention_heads
           _lowercase     			=						(
               batch,
               num_encoder_attention_heads,
               encoder_seq_length,
               self._config.hidden_size // num_encoder_attention_heads,
           )
           _lowercase     			=						decoder_seq_length + 3
           _lowercase     			=						(
               batch,
               num_decoder_attention_heads,
               decoder_past_length,
               self._config.hidden_size // num_decoder_attention_heads,
           )

           _lowercase     			=						torch.cat(
               [common_inputs['decoder_attention_mask'], torch.ones(snake_case__ ,							snake_case__						)] ,							dim=1						)

           _lowercase     			=						[]
           # If the number of encoder and decoder layers are present in the model configuration, both are considered
           _lowercase			,     _lowercase     			=						self.num_layers
           _lowercase     			=						min(snake_case__ ,							snake_case__						)
           _lowercase     			=						max(snake_case__ ,							snake_case__						) - min_num_layers
           _lowercase     			=						'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.
           _lowercase     			=						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
   __lowerCAmelCase  =    _generate_dummy_inputs_for_default_and_seqaseq_lm








from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_tokenizers_available


lowerCamelCase					    =	{}

try:
   if not is_sentencepiece_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCamelCase					    =	['''MBart50Tokenizer''']

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCamelCase					    =	['''MBart50TokenizerFast''']


if TYPE_CHECKING:
   try:
      if not is_sentencepiece_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_mbartaa import MBartaaTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_mbartaa_fast import MBartaaTokenizerFast

else:
   import sys

   lowerCamelCase					    =	_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
