
'''simple docstring'''






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

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


__lowercase	=    logging.get_logger(__name__)

__lowercase	=    {
    '''facebook/mbart-large-cc25''': '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/config.json''',
    # See all MBART models at https://huggingface.co/models?filter=mbart
}

class 							_snake_case     (  lowerCAmelCase_ ):
	"""simple docstring"""





	_UpperCamelCase							:  Tuple								=		'''mbart'''
	_UpperCamelCase							:  List[Any]								=		['''past_key_values''']
	_UpperCamelCase							:  Tuple								=		{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}




	def __init__(						self				: int					,						UpperCamelCase_				: Optional[int]=50265					,						UpperCamelCase_				: str=1024					,						UpperCamelCase_				: Optional[Any]=12					,						UpperCamelCase_				: Optional[int]=4096					,						UpperCamelCase_				: int=16					,						UpperCamelCase_				: Dict=12					,						UpperCamelCase_				: Optional[int]=4096					,						UpperCamelCase_				: Dict=16					,						UpperCamelCase_				: List[Any]=0.0					,						UpperCamelCase_				: Optional[int]=0.0					,						UpperCamelCase_				: Union[str, Any]=True					,						UpperCamelCase_				: Any=True					,						UpperCamelCase_				: Union[str, Any]="gelu"					,						UpperCamelCase_				: str=1024					,						UpperCamelCase_				: Dict=0.1					,						UpperCamelCase_				: str=0.0					,						UpperCamelCase_				: Optional[Any]=0.0					,						UpperCamelCase_				: List[Any]=0.0_2					,						UpperCamelCase_				: Optional[int]=0.0					,						UpperCamelCase_				: Tuple=False					,						UpperCamelCase_				: str=1					,						UpperCamelCase_				: List[Any]=0					,						UpperCamelCase_				: Dict=2					,						UpperCamelCase_				: int=2					,						**UpperCamelCase_				: Tuple					,						):
			lowerCAmelCase_   :       List[str]    							=vocab_size
			lowerCAmelCase_   :       str    							=max_position_embeddings
			lowerCAmelCase_   :       List[Any]    							=d_model
			lowerCAmelCase_   :       Union[str, Any]    							=encoder_ffn_dim
			lowerCAmelCase_   :       Optional[Any]    							=encoder_layers
			lowerCAmelCase_   :       Union[str, Any]    							=encoder_attention_heads
			lowerCAmelCase_   :       Tuple    							=decoder_ffn_dim
			lowerCAmelCase_   :       Tuple    							=decoder_layers
			lowerCAmelCase_   :       Tuple    							=decoder_attention_heads
			lowerCAmelCase_   :       List[str]    							=dropout
			lowerCAmelCase_   :       Union[str, Any]    							=attention_dropout
			lowerCAmelCase_   :       List[Any]    							=activation_dropout
			lowerCAmelCase_   :       Optional[Any]    							=activation_function
			lowerCAmelCase_   :       int    							=init_std
			lowerCAmelCase_   :       Dict    							=encoder_layerdrop
			lowerCAmelCase_   :       str    							=decoder_layerdrop
			lowerCAmelCase_   :       str    							=classifier_dropout
			lowerCAmelCase_   :       str    							=use_cache
			lowerCAmelCase_   :       List[str]    							=encoder_layers
			lowerCAmelCase_   :       str    							=scale_embedding  # scale factor will be sqrt(d_model) if True
			super().__init__(
			    pad_token_id=UpperCamelCase_					,						bos_token_id=UpperCamelCase_					,						eos_token_id=UpperCamelCase_					,						is_encoder_decoder=UpperCamelCase_					,						forced_eos_token_id=UpperCamelCase_					,						**UpperCamelCase_					,						)







class 							_snake_case     (  lowerCAmelCase_ ):
	"""simple docstring"""





	@property
	def 	__A      (						self				: List[Any]      ):
			if self.task in ["default", "seq2seq-lm"]:
					lowerCAmelCase_   :       Union[str, Any]    							=OrderedDict(
					    [
					        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
					        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
					    ]      )

					if self.use_past:
							lowerCAmelCase_   :       List[Any]    							={0: '''batch'''}
							lowerCAmelCase_   :       List[str]    							={0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
					else:
							lowerCAmelCase_   :       Tuple    							={0: '''batch''', 1: '''decoder_sequence'''}
							lowerCAmelCase_   :       Optional[int]    							={0: '''batch''', 1: '''decoder_sequence'''}

					if self.use_past:
							self.fill_with_past_key_values_(UpperCamelCase_					,						direction='''inputs'''      )
			elif self.task == "causal-lm":
					# TODO: figure this case out.
					lowerCAmelCase_   :       List[str]    							=OrderedDict(
					    [
					        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
					        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
					    ]      )
					if self.use_past:
							lowerCAmelCase_							,		lowerCAmelCase_   :       Any    							=self.num_layers
							for i in range(UpperCamelCase_      ):
									lowerCAmelCase_   :       Tuple    							={0: '''batch''', 2: '''past_sequence + sequence'''}
									lowerCAmelCase_   :       Union[str, Any]    							={0: '''batch''', 2: '''past_sequence + sequence'''}
			else:
					lowerCAmelCase_   :       Optional[int]    							=OrderedDict(
					    [
					        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
					        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
					        ('''decoder_input_ids''', {0: '''batch''', 1: '''decoder_sequence'''}),
					        ('''decoder_attention_mask''', {0: '''batch''', 1: '''decoder_sequence'''}),
					    ]      )

			return common_inputs




	@property
	def 	__A      (						self				: Any      ):
			if self.task in ["default", "seq2seq-lm"]:
					lowerCAmelCase_   :       int    							=super().outputs
			else:
					lowerCAmelCase_   :       Optional[int]    							=super(UpperCamelCase_					,						self      ).outputs
					if self.use_past:
							lowerCAmelCase_							,		lowerCAmelCase_   :       Optional[int]    							=self.num_layers
							for i in range(UpperCamelCase_      ):
									lowerCAmelCase_   :       int    							={0: '''batch''', 2: '''past_sequence + sequence'''}
									lowerCAmelCase_   :       str    							={0: '''batch''', 2: '''past_sequence + sequence'''}
			return common_outputs




	def 	__A      (						self				: str					,						UpperCamelCase_				: PreTrainedTokenizer					,						UpperCamelCase_				: int = -1					,						UpperCamelCase_				: int = -1					,						UpperCamelCase_				: bool = False					,						UpperCamelCase_				: Optional[TensorType] = None					,						):
			lowerCAmelCase_   :       int    							=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
			    UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_      )

			# Generate decoder inputs
			lowerCAmelCase_   :       Union[str, Any]    							=seq_length if not self.use_past else 1
			lowerCAmelCase_   :       int    							=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
			    UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_      )
			lowerCAmelCase_   :       List[Any]    							={F'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
			lowerCAmelCase_   :       Any    							=dict(**UpperCamelCase_					,						**UpperCamelCase_      )

			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_   :       Tuple    							=common_inputs['''input_ids'''].shape
					lowerCAmelCase_   :       Any    							=common_inputs['''decoder_input_ids'''].shape[1]
					lowerCAmelCase_							,		lowerCAmelCase_   :       Union[str, Any]    							=self.num_attention_heads
					lowerCAmelCase_   :       Tuple    							=(
					    batch,
					    num_encoder_attention_heads,
					    encoder_seq_length,
					    self._config.hidden_size // num_encoder_attention_heads,
					)
					lowerCAmelCase_   :       List[Any]    							=decoder_seq_length + 3
					lowerCAmelCase_   :       Optional[Any]    							=(
					    batch,
					    num_decoder_attention_heads,
					    decoder_past_length,
					    self._config.hidden_size // num_decoder_attention_heads,
					)

					lowerCAmelCase_   :       Dict    							=torch.cat(
					    [common_inputs['''decoder_attention_mask'''], torch.ones(UpperCamelCase_					,						UpperCamelCase_      )]					,						dim=1      )

					lowerCAmelCase_   :       List[Any]    							=[]
					# If the number of encoder and decoder layers are present in the model configuration, both are considered
					lowerCAmelCase_							,		lowerCAmelCase_   :       List[str]    							=self.num_layers
					lowerCAmelCase_   :       Optional[int]    							=min(UpperCamelCase_					,						UpperCamelCase_      )
					lowerCAmelCase_   :       str    							=max(UpperCamelCase_					,						UpperCamelCase_      ) - min_num_layers
					lowerCAmelCase_   :       Union[str, Any]    							='''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

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




	def 	__A      (						self				: int					,						UpperCamelCase_				: PreTrainedTokenizer					,						UpperCamelCase_				: int = -1					,						UpperCamelCase_				: int = -1					,						UpperCamelCase_				: bool = False					,						UpperCamelCase_				: Optional[TensorType] = None					,						):
			lowerCAmelCase_   :       Tuple    							=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
			    UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_      )

			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_   :       str    							=common_inputs['''input_ids'''].shape
					# Not using the same length for past_key_values
					lowerCAmelCase_   :       str    							=seqlen + 2
					lowerCAmelCase_							,		lowerCAmelCase_   :       Tuple    							=self.num_layers
					lowerCAmelCase_							,		lowerCAmelCase_   :       List[str]    							=self.num_attention_heads
					lowerCAmelCase_   :       List[Any]    							=(
					    batch,
					    num_encoder_attention_heads,
					    past_key_values_length,
					    self._config.hidden_size // num_encoder_attention_heads,
					)

					lowerCAmelCase_   :       Union[str, Any]    							=common_inputs['''attention_mask'''].dtype
					lowerCAmelCase_   :       Any    							=torch.cat(
					    [common_inputs['''attention_mask'''], torch.ones(UpperCamelCase_					,						UpperCamelCase_					,						dtype=UpperCamelCase_      )]					,						dim=1      )
					lowerCAmelCase_   :       int    							=[
					    (torch.zeros(UpperCamelCase_      ), torch.zeros(UpperCamelCase_      )) for _ in range(UpperCamelCase_      )
					]
			return common_inputs




	def 	__A      (						self				: int					,						UpperCamelCase_				: PreTrainedTokenizer					,						UpperCamelCase_				: int = -1					,						UpperCamelCase_				: int = -1					,						UpperCamelCase_				: bool = False					,						UpperCamelCase_				: Optional[TensorType] = None					,						):
			# 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
			lowerCAmelCase_   :       Dict    							=compute_effective_axis_dimension(
			    UpperCamelCase_					,						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_   :       List[str]    							=tokenizer.num_special_tokens_to_add(UpperCamelCase_      )
			lowerCAmelCase_   :       List[Any]    							=compute_effective_axis_dimension(
			    UpperCamelCase_					,						fixed_dimension=OnnxConfig.default_fixed_sequence					,						num_token_to_add=UpperCamelCase_      )

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




	def 	__A      (						self				: Union[str, Any]					,						UpperCamelCase_				: PreTrainedTokenizer					,						UpperCamelCase_				: int = -1					,						UpperCamelCase_				: int = -1					,						UpperCamelCase_				: bool = False					,						UpperCamelCase_				: Optional[TensorType] = None					,						):
			if self.task in ["default", "seq2seq-lm"]:
					lowerCAmelCase_   :       List[Any]    							=self._generate_dummy_inputs_for_default_and_seqaseq_lm(
					    UpperCamelCase_					,						batch_size=UpperCamelCase_					,						seq_length=UpperCamelCase_					,						is_pair=UpperCamelCase_					,						framework=UpperCamelCase_      )

			elif self.task == "causal-lm":
					lowerCAmelCase_   :       Any    							=self._generate_dummy_inputs_for_causal_lm(
					    UpperCamelCase_					,						batch_size=UpperCamelCase_					,						seq_length=UpperCamelCase_					,						is_pair=UpperCamelCase_					,						framework=UpperCamelCase_      )
			else:
					lowerCAmelCase_   :       Dict    							=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
					    UpperCamelCase_					,						batch_size=UpperCamelCase_					,						seq_length=UpperCamelCase_					,						is_pair=UpperCamelCase_					,						framework=UpperCamelCase_      )

			return common_inputs





	def 	__A      (						self				: Any					,						UpperCamelCase_				: Optional[int]					,						UpperCamelCase_				: str					,						UpperCamelCase_				: Tuple					,						UpperCamelCase_				: List[str]      ):
			if self.task in ["default", "seq2seq-lm"]:
					lowerCAmelCase_   :       List[Any]    							=super()._flatten_past_key_values_(UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_      )
			else:
					lowerCAmelCase_   :       Dict    							=super(UpperCamelCase_					,						self      )._flatten_past_key_values_(
					    UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_					,						UpperCamelCase_      )








'''simple docstring'''






from typing import TYPE_CHECKING

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


__lowercase	=    {
    '''configuration_xlm_prophetnet''': ['''XLM_PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''XLMProphetNetConfig'''],
}

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

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__lowercase	=    [
							    '''XLM_PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''XLMProphetNetDecoder''',
							    '''XLMProphetNetEncoder''',
							    '''XLMProphetNetForCausalLM''',
							    '''XLMProphetNetForConditionalGeneration''',
							    '''XLMProphetNetModel''',
							    '''XLMProphetNetPreTrainedModel''',
							]


if TYPE_CHECKING:
							from .configuration_xlm_prophetnet import XLM_PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMProphetNetConfig

							try:
														if not is_sentencepiece_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_xlm_prophetnet import XLMProphetNetTokenizer

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_xlm_prophetnet import (
														    XLM_PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST,
														    XLMProphetNetDecoder,
														    XLMProphetNetEncoder,
														    XLMProphetNetForCausalLM,
														    XLMProphetNetForConditionalGeneration,
														    XLMProphetNetModel,
														    XLMProphetNetPreTrainedModel,
														)

else:
							import sys

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






