






"""simple docstring"""



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


_snake_case       :      Any       =					logging.get_logger(__name__)

_snake_case       :      List[Any]       =					{
    "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        __lowercase(       _UpperCamelCase  ):
						lowerCAmelCase_		:							List[str]=       """m2m_100"""
						lowerCAmelCase_		:							str=       ["""past_key_values"""]
						lowerCAmelCase_		:							List[Any]=       {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}






						def __init__(					self    ,						_SCREAMING_SNAKE_CASE=12_81_12    ,						_SCREAMING_SNAKE_CASE=10_24    ,						_SCREAMING_SNAKE_CASE=12    ,						_SCREAMING_SNAKE_CASE=40_96    ,						_SCREAMING_SNAKE_CASE=16    ,						_SCREAMING_SNAKE_CASE=12    ,						_SCREAMING_SNAKE_CASE=40_96    ,						_SCREAMING_SNAKE_CASE=16    ,						_SCREAMING_SNAKE_CASE=0.05    ,						_SCREAMING_SNAKE_CASE=0.05    ,						_SCREAMING_SNAKE_CASE=True    ,						_SCREAMING_SNAKE_CASE=True    ,						_SCREAMING_SNAKE_CASE="relu"    ,						_SCREAMING_SNAKE_CASE=10_24    ,						_SCREAMING_SNAKE_CASE=0.1    ,						_SCREAMING_SNAKE_CASE=0.1    ,						_SCREAMING_SNAKE_CASE=0.0    ,						_SCREAMING_SNAKE_CASE=0.02    ,						_SCREAMING_SNAKE_CASE=2    ,						_SCREAMING_SNAKE_CASE=True    ,						_SCREAMING_SNAKE_CASE=1    ,						_SCREAMING_SNAKE_CASE=0    ,						_SCREAMING_SNAKE_CASE=2    ,						**_SCREAMING_SNAKE_CASE    ,						)			->  int:




											"""simple docstring"""





											lowerCamelCase__				=vocab_size
											lowerCamelCase__				=max_position_embeddings
											lowerCamelCase__				=d_model
											lowerCamelCase__				=encoder_ffn_dim
											lowerCamelCase__				=encoder_layers
											lowerCamelCase__				=encoder_attention_heads
											lowerCamelCase__				=decoder_ffn_dim
											lowerCamelCase__				=decoder_layers
											lowerCamelCase__				=decoder_attention_heads
											lowerCamelCase__				=dropout
											lowerCamelCase__				=attention_dropout
											lowerCamelCase__				=activation_dropout
											lowerCamelCase__				=activation_function
											lowerCamelCase__				=init_std
											lowerCamelCase__				=encoder_layerdrop
											lowerCamelCase__				=decoder_layerdrop
											lowerCamelCase__				=use_cache
											lowerCamelCase__				=encoder_layers
											lowerCamelCase__				=scale_embedding  # scale factor will be sqrt(d_model) if True

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




class        __lowercase(       _UpperCamelCase  ):






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




											"""simple docstring"""





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

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

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






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




											"""simple docstring"""





											lowerCamelCase__				=compute_effective_axis_dimension(
											    _SCREAMING_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
											lowerCamelCase__				=tokenizer.num_special_tokens_to_add(_SCREAMING_SNAKE_CASE)
											lowerCamelCase__				=compute_effective_axis_dimension(
											    _SCREAMING_SNAKE_CASE    ,						fixed_dimension=OnnxConfig.default_fixed_sequence    ,						num_token_to_add=_SCREAMING_SNAKE_CASE)

											# Generate dummy inputs according to compute batch and sequence
											lowerCamelCase__				=[' '.join([tokenizer.unk_token]) * seq_length] * batch_size
											lowerCamelCase__				=dict(tokenizer(_SCREAMING_SNAKE_CASE    ,						return_tensors=_SCREAMING_SNAKE_CASE))
											return common_inputs






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




											"""simple docstring"""





											lowerCamelCase__				=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
											    _SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE)

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

																lowerCamelCase__				=torch.cat(
																    [common_inputs['decoder_attention_mask'], torch.ones(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE)]    ,						dim=1)

																lowerCamelCase__				=[]
																# If the number of encoder and decoder layers are present in the model configuration, both are considered
																lowerCamelCase__				,     lowerCamelCase__				=self.num_layers
																lowerCamelCase__				=min(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE)
																lowerCamelCase__				=max(_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE) - min_num_layers
																lowerCamelCase__				='encoder' if num_encoder_layers > num_decoder_layers else 'decoder'

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







"""simple docstring"""



_snake_case       :      Dict       =					[0.485, 0.456, 0.406]
_snake_case       :      int       =					[0.229, 0.224, 0.225]
_snake_case       :      Optional[int]       =					[0.5, 0.5, 0.5]
_snake_case       :      str       =					[0.5, 0.5, 0.5]
_snake_case       :      str       =					[0.4814_5466, 0.457_8275, 0.4082_1073]
_snake_case       :      str       =					[0.2686_2954, 0.2613_0258, 0.2757_7711]