code: 
  
  
  
  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__	:  Optional[Any] 		=logging.get_logger(__name__)
  
  lowerCAmelCase__	:  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      UpperCAmelCase_						(     A__ ):
  
  						'''simple docstring'''
  
  
  
  
  						UpperCamelCase__    :				List[Any]       						=						'''m2m_100'''
  						UpperCamelCase__    :				List[str]       						=						['''past_key_values''']
  						UpperCamelCase__    :				List[str]       						=						{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}
  
  
  
  
  
  
  						def __init__(					self   ,							_A=128_112   ,							_A=1_024   ,							_A=12   ,							_A=4_096   ,							_A=16   ,							_A=12   ,							_A=4_096   ,							_A=16   ,							_A=0.0_5   ,							_A=0.0_5   ,							_A=True   ,							_A=True   ,							_A="relu"   ,							_A=1_024   ,							_A=0.1   ,							_A=0.1   ,							_A=0.0   ,							_A=0.0_2   ,							_A=2   ,							_A=True   ,							_A=1   ,							_A=0   ,							_A=2   ,							**_A   ,							):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      vocab_size
  													__SCREAMING_SNAKE_CASE								=      max_position_embeddings
  													__SCREAMING_SNAKE_CASE								=      d_model
  													__SCREAMING_SNAKE_CASE								=      encoder_ffn_dim
  													__SCREAMING_SNAKE_CASE								=      encoder_layers
  													__SCREAMING_SNAKE_CASE								=      encoder_attention_heads
  													__SCREAMING_SNAKE_CASE								=      decoder_ffn_dim
  													__SCREAMING_SNAKE_CASE								=      decoder_layers
  													__SCREAMING_SNAKE_CASE								=      decoder_attention_heads
  													__SCREAMING_SNAKE_CASE								=      dropout
  													__SCREAMING_SNAKE_CASE								=      attention_dropout
  													__SCREAMING_SNAKE_CASE								=      activation_dropout
  													__SCREAMING_SNAKE_CASE								=      activation_function
  													__SCREAMING_SNAKE_CASE								=      init_std
  													__SCREAMING_SNAKE_CASE								=      encoder_layerdrop
  													__SCREAMING_SNAKE_CASE								=      decoder_layerdrop
  													__SCREAMING_SNAKE_CASE								=      use_cache
  													__SCREAMING_SNAKE_CASE								=      encoder_layers
  													__SCREAMING_SNAKE_CASE								=      scale_embedding  # scale factor will be sqrt(d_model) if True
  
  													super().__init__(
  													    pad_token_id=_A   ,							bos_token_id=_A   ,							eos_token_id=_A   ,							is_encoder_decoder=_A   ,							decoder_start_token_id=_A   ,							**_A   ,							)
  
  
  
  
  
  
  
  class      UpperCAmelCase_						(     A__ ):
  
  						'''simple docstring'''
  
  
  
  
  						@property
  						def  _A			(					self	):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      OrderedDict(
  													    [
  													        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
  													        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
  													    ]	)
  
  													if self.use_past:
  																				__SCREAMING_SNAKE_CASE								=      {0: "batch"}
  																				__SCREAMING_SNAKE_CASE								=      {0: "batch", 1: "past_decoder_sequence + sequence"}
  													else:
  																				__SCREAMING_SNAKE_CASE								=      {0: "batch", 1: "decoder_sequence"}
  																				__SCREAMING_SNAKE_CASE								=      {0: "batch", 1: "decoder_sequence"}
  
  													if self.use_past:
  																				self.fill_with_past_key_values_(_A   ,							direction='inputs'	)
  													return common_inputs
  
  
  
  
  
  
  						def  _A			(					self   ,							_A   ,							_A = -1   ,							_A = -1   ,							_A = False   ,							_A = None   ,							):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      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
  													__SCREAMING_SNAKE_CASE								=      tokenizer.num_special_tokens_to_add(_A	)
  													__SCREAMING_SNAKE_CASE								=      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
  													__SCREAMING_SNAKE_CASE								=      [" ".join([tokenizer.unk_token]	) * seq_length] * batch_size
  													__SCREAMING_SNAKE_CASE								=      dict(tokenizer(_A   ,							return_tensors=_A	)	)
  													return common_inputs
  
  
  
  
  
  
  						def  _A			(					self   ,							_A   ,							_A = -1   ,							_A = -1   ,							_A = False   ,							_A = None   ,							):
  
  
  
  
  
  
  
  													'''simple docstring'''
  
  													__SCREAMING_SNAKE_CASE								=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
  													    _A   ,							_A   ,							_A   ,							_A   ,							_A	)
  
  													# Generate decoder inputs
  													__SCREAMING_SNAKE_CASE								=      seq_length if not self.use_past else 1
  													__SCREAMING_SNAKE_CASE								=      self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
  													    _A   ,							_A   ,							_A   ,							_A   ,							_A	)
  													__SCREAMING_SNAKE_CASE								=      {f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
  													__SCREAMING_SNAKE_CASE								=      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
  																				__SCREAMING_SNAKE_CASE								=      common_inputs["input_ids"].shape
  																				__SCREAMING_SNAKE_CASE								=      common_inputs["decoder_input_ids"].shape[1]
  																				__SCREAMING_SNAKE_CASE								=      self.num_attention_heads
  																				__SCREAMING_SNAKE_CASE								=      (
  																				    batch,
  																				    num_encoder_attention_heads,
  																				    encoder_seq_length,
  																				    self._config.hidden_size // num_encoder_attention_heads,
  																				)
  																				__SCREAMING_SNAKE_CASE								=      decoder_seq_length + 3
  																				__SCREAMING_SNAKE_CASE								=      (
  																				    batch,
  																				    num_decoder_attention_heads,
  																				    decoder_past_length,
  																				    self._config.hidden_size // num_decoder_attention_heads,
  																				)
  
  																				__SCREAMING_SNAKE_CASE								=      torch.cat(
  																				    [common_inputs['decoder_attention_mask'], torch.ones(_A   ,							_A	)]   ,							dim=1	)
  
  																				__SCREAMING_SNAKE_CASE								=      []
  																				# If the number of encoder and decoder layers are present in the model configuration, both are considered
  																				__SCREAMING_SNAKE_CASE								=      self.num_layers
  																				__SCREAMING_SNAKE_CASE								=      min(_A   ,							_A	)
  																				__SCREAMING_SNAKE_CASE								=      max(_A   ,							_A	) - min_num_layers
  																				__SCREAMING_SNAKE_CASE								=      "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.
  																				__SCREAMING_SNAKE_CASE								=      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
  
  
  
  
  
  
  						UpperCamelCase__    :				List[Any]       						=						_generate_dummy_inputs_for_default_and_seqaseq_lm
style_context: 
  
  
  
  def 			__lowercase     (				a__     )       ->				int:
  							return int(a__     ) if x - int(a__     ) <= 0 else int(a__     ) + 1
  
  
  if __name__ == "__main__":
  			import doctest
  
  			doctest.testmod()
  
  
  
  
  
  
  