






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


lowercase     :							Tuple	     =			logging.get_logger(__name__)

lowercase     :							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_  (		SCREAMING_SNAKE_CASE__    ):


						'''simple docstring'''




						A   :      Optional[int]						 =    'm2m_100'
						A   :      Tuple						 =    ['past_key_values']
						A   :      List[str]						 =    {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}






						def __init__(		self						, _SCREAMING_SNAKE_CASE=12_8112						, _SCREAMING_SNAKE_CASE=1024						, _SCREAMING_SNAKE_CASE=12						, _SCREAMING_SNAKE_CASE=4096						, _SCREAMING_SNAKE_CASE=16						, _SCREAMING_SNAKE_CASE=12						, _SCREAMING_SNAKE_CASE=4096						, _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=1024						, _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:
								snake_case_ :							List[Any]         =				vocab_size
								snake_case_ :							Optional[int]         =				max_position_embeddings
								snake_case_ :							List[str]         =				d_model
								snake_case_ :							Optional[int]         =				encoder_ffn_dim
								snake_case_ :							Dict         =				encoder_layers
								snake_case_ :							int         =				encoder_attention_heads
								snake_case_ :							Optional[Any]         =				decoder_ffn_dim
								snake_case_ :							Union[str, Any]         =				decoder_layers
								snake_case_ :							str         =				decoder_attention_heads
								snake_case_ :							Tuple         =				dropout
								snake_case_ :							Union[str, Any]         =				attention_dropout
								snake_case_ :							Tuple         =				activation_dropout
								snake_case_ :							Union[str, Any]         =				activation_function
								snake_case_ :							Optional[Any]         =				init_std
								snake_case_ :							int         =				encoder_layerdrop
								snake_case_ :							Any         =				decoder_layerdrop
								snake_case_ :							Optional[Any]         =				use_cache
								snake_case_ :							int         =				encoder_layers
								snake_case_ :							Union[str, 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 						UpperCAmelCase_  (		SCREAMING_SNAKE_CASE__    ):


						'''simple docstring'''




						@property
						def 					_lowerCAmelCase				(		self )       -> Mapping[str, Mapping[int, str]]:
								snake_case_ :							List[str]         =				OrderedDict(
								    [
								        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
								        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
								    ] )

								if self.use_past:
										snake_case_ :							List[Any]         =				{0: "batch"}
										snake_case_ :							Any         =				{0: "batch", 1: "past_decoder_sequence + sequence"}
								else:
										snake_case_ :							Optional[int]         =				{0: "batch", 1: "decoder_sequence"}
										snake_case_ :							str         =				{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]:
								# Copied from OnnxConfig.generate_dummy_inputs
								# Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
								# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
								snake_case_ :							List[str]         =				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
								snake_case_ :							List[str]         =				tokenizer.num_special_tokens_to_add(_SCREAMING_SNAKE_CASE )
								snake_case_ :							Any         =				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
								snake_case_ :							List[str]         =				[" ".join([tokenizer.unk_token] ) * seq_length] * batch_size
								snake_case_ :							Optional[int]         =				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]:
								snake_case_ :							Optional[int]         =				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
								snake_case_ :							Optional[Any]         =				seq_length if not self.use_past else 1
								snake_case_ :							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 )
								snake_case_ :							Union[str, Any]         =				{f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
								snake_case_ :							Union[str, Any]         =				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
										snake_case_       ,				snake_case_ :							Optional[int]         =				common_inputs["input_ids"].shape
										snake_case_ :							Optional[Any]         =				common_inputs["decoder_input_ids"].shape[1]
										snake_case_       ,				snake_case_ :							Optional[Any]         =				self.num_attention_heads
										snake_case_ :							int         =				(
										    batch,
										    num_encoder_attention_heads,
										    encoder_seq_length,
										    self._config.hidden_size // num_encoder_attention_heads,
										)
										snake_case_ :							str         =				decoder_seq_length + 3
										snake_case_ :							str         =				(
										    batch,
										    num_decoder_attention_heads,
										    decoder_past_length,
										    self._config.hidden_size // num_decoder_attention_heads,
										)

										snake_case_ :							Union[str, Any]         =				torch.cat(
										    [common_inputs["decoder_attention_mask"], torch.ones(_SCREAMING_SNAKE_CASE						, _SCREAMING_SNAKE_CASE )]						, dim=1 )

										snake_case_ :							Optional[Any]         =				[]
										# If the number of encoder and decoder layers are present in the model configuration, both are considered
										snake_case_       ,				snake_case_ :							str         =				self.num_layers
										snake_case_ :							List[Any]         =				min(_SCREAMING_SNAKE_CASE						, _SCREAMING_SNAKE_CASE )
										snake_case_ :							str         =				max(_SCREAMING_SNAKE_CASE						, _SCREAMING_SNAKE_CASE ) - min_num_layers
										snake_case_ :							Union[str, Any]         =				"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.
										snake_case_ :							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
						A   :      Any						 =    _generate_dummy_inputs_for_default_and_seqaseq_lm








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


lowercase     :							Any	     =			logging.get_logger(__name__)

lowercase     :							int	     =			{
    # pcqm4mv1 now deprecated
    '''graphormer-base''': '''https://huggingface.co/clefourrier/graphormer-base-pcqm4mv2/resolve/main/config.json''',
    # See all Graphormer models at https://huggingface.co/models?filter=graphormer
}




class 						UpperCAmelCase_  (		SCREAMING_SNAKE_CASE__    ):


						'''simple docstring'''




						A   :      Optional[int]						 =    'graphormer'
						A   :      List[str]						 =    ['past_key_values']






						def __init__(		self						, _SCREAMING_SNAKE_CASE = 1						, _SCREAMING_SNAKE_CASE = 512 * 9						, _SCREAMING_SNAKE_CASE = 512 * 3						, _SCREAMING_SNAKE_CASE = 512						, _SCREAMING_SNAKE_CASE = 512						, _SCREAMING_SNAKE_CASE = 512						, _SCREAMING_SNAKE_CASE = 128						, _SCREAMING_SNAKE_CASE = 5						, _SCREAMING_SNAKE_CASE = 1024						, _SCREAMING_SNAKE_CASE = "multi_hop"						, _SCREAMING_SNAKE_CASE = 512						, _SCREAMING_SNAKE_CASE = False						, _SCREAMING_SNAKE_CASE = 12						, _SCREAMING_SNAKE_CASE = 768						, _SCREAMING_SNAKE_CASE = 768						, _SCREAMING_SNAKE_CASE = 32						, _SCREAMING_SNAKE_CASE = 0.1						, _SCREAMING_SNAKE_CASE = 0.1						, _SCREAMING_SNAKE_CASE = 0.0						, _SCREAMING_SNAKE_CASE = False						, _SCREAMING_SNAKE_CASE = False						, _SCREAMING_SNAKE_CASE = False						, _SCREAMING_SNAKE_CASE = "gelu"						, _SCREAMING_SNAKE_CASE = None						, _SCREAMING_SNAKE_CASE = False						, _SCREAMING_SNAKE_CASE = 0						, _SCREAMING_SNAKE_CASE = False						, _SCREAMING_SNAKE_CASE = 0.0						, _SCREAMING_SNAKE_CASE = 8						, _SCREAMING_SNAKE_CASE = None						, _SCREAMING_SNAKE_CASE = None						, _SCREAMING_SNAKE_CASE = True						, _SCREAMING_SNAKE_CASE = True						, _SCREAMING_SNAKE_CASE=0						, _SCREAMING_SNAKE_CASE=1						, _SCREAMING_SNAKE_CASE=2						, **_SCREAMING_SNAKE_CASE						, )       -> List[str]:
								snake_case_ :							str         =				num_classes
								snake_case_ :							Union[str, Any]         =				num_atoms
								snake_case_ :							Dict         =				num_in_degree
								snake_case_ :							Union[str, Any]         =				num_out_degree
								snake_case_ :							List[Any]         =				num_edges
								snake_case_ :							Union[str, Any]         =				num_spatial
								snake_case_ :							int         =				num_edge_dis
								snake_case_ :							List[Any]         =				edge_type
								snake_case_ :							Any         =				multi_hop_max_dist
								snake_case_ :							Tuple         =				spatial_pos_max
								snake_case_ :							Union[str, Any]         =				max_nodes
								snake_case_ :							str         =				num_hidden_layers
								snake_case_ :							str         =				embedding_dim
								snake_case_ :							List[str]         =				embedding_dim
								snake_case_ :							Dict         =				ffn_embedding_dim
								snake_case_ :							Any         =				num_attention_heads
								snake_case_ :							List[str]         =				dropout
								snake_case_ :							List[str]         =				attention_dropout
								snake_case_ :							Optional[Any]         =				layerdrop
								snake_case_ :							Optional[int]         =				encoder_normalize_before
								snake_case_ :							Union[str, Any]         =				pre_layernorm
								snake_case_ :							int         =				apply_graphormer_init
								snake_case_ :							List[Any]         =				activation_fn
								snake_case_ :							str         =				embed_scale
								snake_case_ :							int         =				freeze_embeddings
								snake_case_ :							Optional[Any]         =				num_trans_layers_to_freeze
								snake_case_ :							int         =				share_input_output_embed
								snake_case_ :							int         =				traceable
								snake_case_ :							Tuple         =				q_noise
								snake_case_ :							Tuple         =				qn_block_size

								# These parameters are here for future extensions
								# atm, the model only supports self attention
								snake_case_ :							List[Any]         =				kdim
								snake_case_ :							Tuple         =				vdim
								snake_case_ :							Any         =				self_attention
								snake_case_ :							Any         =				bias

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