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     __a						(					A__ ):
   _lowerCAmelCase : List[Any] 				=				'''m2m_100'''
   _lowerCAmelCase : List[str] 				=				['''past_key_values''']
   _lowerCAmelCase : List[str] 				=				{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}
  
  
  
  
  
  
  
   def __init__(	self      :     Optional[int]							,     SCREAMING_SNAKE_CASE      :     Any=12_81_12							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=10_24							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=12							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=40_96							,     SCREAMING_SNAKE_CASE      :     str=16							,     SCREAMING_SNAKE_CASE      :     Union[str, Any]=12							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=40_96							,     SCREAMING_SNAKE_CASE      :     Any=16							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=0.0_5							,     SCREAMING_SNAKE_CASE      :     List[str]=0.0_5							,     SCREAMING_SNAKE_CASE      :     Dict=True							,     SCREAMING_SNAKE_CASE      :     Tuple=True							,     SCREAMING_SNAKE_CASE      :     Optional[Any]="relu"							,     SCREAMING_SNAKE_CASE      :     Dict=10_24							,     SCREAMING_SNAKE_CASE      :     int=0.1							,     SCREAMING_SNAKE_CASE      :     Tuple=0.1							,     SCREAMING_SNAKE_CASE      :     Any=0.0							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=0.0_2							,     SCREAMING_SNAKE_CASE      :     List[Any]=2							,     SCREAMING_SNAKE_CASE      :     int=True							,     SCREAMING_SNAKE_CASE      :     str=1							,     SCREAMING_SNAKE_CASE      :     int=0							,     SCREAMING_SNAKE_CASE      :     Any=2							,     **SCREAMING_SNAKE_CASE      :     Tuple							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     int        =						vocab_size
        UpperCamelCase__    :     Dict        =						max_position_embeddings
        UpperCamelCase__    :     Tuple        =						d_model
        UpperCamelCase__    :     Tuple        =						encoder_ffn_dim
        UpperCamelCase__    :     Optional[int]        =						encoder_layers
        UpperCamelCase__    :     List[str]        =						encoder_attention_heads
        UpperCamelCase__    :     Tuple        =						decoder_ffn_dim
        UpperCamelCase__    :     List[str]        =						decoder_layers
        UpperCamelCase__    :     List[Any]        =						decoder_attention_heads
        UpperCamelCase__    :     Dict        =						dropout
        UpperCamelCase__    :     Tuple        =						attention_dropout
        UpperCamelCase__    :     List[str]        =						activation_dropout
        UpperCamelCase__    :     Union[str, Any]        =						activation_function
        UpperCamelCase__    :     str        =						init_std
        UpperCamelCase__    :     Union[str, Any]        =						encoder_layerdrop
        UpperCamelCase__    :     Tuple        =						decoder_layerdrop
        UpperCamelCase__    :     Any        =						use_cache
        UpperCamelCase__    :     List[Any]        =						encoder_layers
        UpperCamelCase__    :     Optional[Any]        =						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     __a						(					A__ ):
  
  
  
  
  
  
  
   @property
   def       __lowercase      (	self      :     str		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						OrderedDict(
            [
                ("input_ids", {0: "batch", 1: "encoder_sequence"}),
                ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
            ]		)
  
        if self.use_past:
             UpperCamelCase__    :     List[Any]        =						{0: "batch"}
             UpperCamelCase__    :     List[str]        =						{0: "batch", 1: "past_decoder_sequence + sequence"}
        else:
             UpperCamelCase__    :     List[Any]        =						{0: "batch", 1: "decoder_sequence"}
             UpperCamelCase__    :     Any        =						{0: "batch", 1: "decoder_sequence"}
  
        if self.use_past:
             self.fill_with_past_key_values_(SCREAMING_SNAKE_CASE							,     direction="inputs"		)
        return common_inputs
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[Any]							,     SCREAMING_SNAKE_CASE      :     PreTrainedTokenizer							,     SCREAMING_SNAKE_CASE      :     int = -1							,     SCREAMING_SNAKE_CASE      :     int = -1							,     SCREAMING_SNAKE_CASE      :     bool = False							,     SCREAMING_SNAKE_CASE      :     Optional[TensorType] = None							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Tuple        =						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
        UpperCamelCase__    :     Optional[Any]        =						tokenizer.num_special_tokens_to_add(SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     str        =						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
        UpperCamelCase__    :     Optional[Any]        =						[" ".join([tokenizer.unk_token]		) * seq_length] * batch_size
        UpperCamelCase__    :     List[str]        =						dict(tokenizer(SCREAMING_SNAKE_CASE							,     return_tensors=SCREAMING_SNAKE_CASE		)		)
        return common_inputs
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Any							,     SCREAMING_SNAKE_CASE      :     PreTrainedTokenizer							,     SCREAMING_SNAKE_CASE      :     int = -1							,     SCREAMING_SNAKE_CASE      :     int = -1							,     SCREAMING_SNAKE_CASE      :     bool = False							,     SCREAMING_SNAKE_CASE      :     Optional[TensorType] = None							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						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
        UpperCamelCase__    :     str        =						seq_length if not self.use_past else 1
        UpperCamelCase__    :     Tuple        =						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		)
        UpperCamelCase__    :     Any        =						{F'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
        UpperCamelCase__    :     str        =						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
             UpperCamelCase__       ,  UpperCamelCase__    :     List[Any]        =						common_inputs["input_ids"].shape
             UpperCamelCase__    :     Tuple        =						common_inputs["decoder_input_ids"].shape[1]
             UpperCamelCase__       ,  UpperCamelCase__    :     Any        =						self.num_attention_heads
             UpperCamelCase__    :     Dict        =						(
                 batch,
                 num_encoder_attention_heads,
                 encoder_seq_length,
                 self._config.hidden_size // num_encoder_attention_heads,
             )
             UpperCamelCase__    :     str        =						decoder_seq_length + 3
             UpperCamelCase__    :     Optional[Any]        =						(
                 batch,
                 num_decoder_attention_heads,
                 decoder_past_length,
                 self._config.hidden_size // num_decoder_attention_heads,
             )
  
             UpperCamelCase__    :     Union[str, Any]        =						torch.cat(
                 [common_inputs["decoder_attention_mask"], torch.ones(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)]							,     dim=1		)
  
             UpperCamelCase__    :     Optional[Any]        =						[]
             # If the number of encoder and decoder layers are present in the model configuration, both are considered
             UpperCamelCase__       ,  UpperCamelCase__    :     int        =						self.num_layers
             UpperCamelCase__    :     Tuple        =						min(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)
             UpperCamelCase__    :     Tuple        =						max(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		) - min_num_layers
             UpperCamelCase__    :     List[str]        =						"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.
             UpperCamelCase__    :     Optional[int]        =						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 : List[Any] 				=				_generate_dummy_inputs_for_default_and_seqaseq_lm
style_context: 
  
  
  
  
  
  
  from __future__ import annotations
  
  
  
  
  
  
  
  def 	SCREAMING_SNAKE_CASE							(      __lowerCAmelCase    )				->			list[int]:
       assert (
           isinstance(__lowerCAmelCase      ,					__lowerCAmelCase    ) and mask > 0
       ), f'mask needs to be positive integer, your input {mask}'
       UpperCamelCase__    :     Any        =						[]
       UpperCamelCase__    :     int        =						mask
  
       while submask:
            all_submasks.append(__lowerCAmelCase    )
            UpperCamelCase__    :     List[str]        =						(submask - 1) & mask
  
       return all_submasks
  
  
  if __name__ == "__main__":
   import doctest
  
   doctest.testmod()