


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


_A							     =       logging.get_logger(__name__)

_A							     =       {
    '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 			lowerCamelCase_					(    _SCREAMING_SNAKE_CASE    ):
							_lowerCamelCase				: List[Any]       =					"""mbart"""
							_lowerCamelCase				: List[str]       =					["""past_key_values"""]
							_lowerCamelCase				: Tuple       =					{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}





							def __init__(							self			,       _SCREAMING_SNAKE_CASE=5_0265			,       _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.0			,       _SCREAMING_SNAKE_CASE=0.0			,       _SCREAMING_SNAKE_CASE=True			,       _SCREAMING_SNAKE_CASE=True			,       _SCREAMING_SNAKE_CASE="gelu"			,       _SCREAMING_SNAKE_CASE=1024			,       _SCREAMING_SNAKE_CASE=0.1			,       _SCREAMING_SNAKE_CASE=0.0			,       _SCREAMING_SNAKE_CASE=0.0			,       _SCREAMING_SNAKE_CASE=0.0_2			,       _SCREAMING_SNAKE_CASE=0.0			,       _SCREAMING_SNAKE_CASE=False			,       _SCREAMING_SNAKE_CASE=1			,       _SCREAMING_SNAKE_CASE=0			,       _SCREAMING_SNAKE_CASE=2			,       _SCREAMING_SNAKE_CASE=2			,       **_SCREAMING_SNAKE_CASE			,       ):
								a_     			=   vocab_size
								a_     			=   max_position_embeddings
								a_     			=   d_model
								a_     			=   encoder_ffn_dim
								a_     			=   encoder_layers
								a_     			=   encoder_attention_heads
								a_     			=   decoder_ffn_dim
								a_     			=   decoder_layers
								a_     			=   decoder_attention_heads
								a_     			=   dropout
								a_     			=   attention_dropout
								a_     			=   activation_dropout
								a_     			=   activation_function
								a_     			=   init_std
								a_     			=   encoder_layerdrop
								a_     			=   decoder_layerdrop
								a_     			=   classifier_dropout
								a_     			=   use_cache
								a_     			=   encoder_layers
								a_     			=   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			,       forced_eos_token_id=_SCREAMING_SNAKE_CASE			,       **_SCREAMING_SNAKE_CASE			,       )







class 			lowerCamelCase_					(    _SCREAMING_SNAKE_CASE    ):





							@property
							def   __magic_name__      (							self    ):
								if self.task in ["default", "seq2seq-lm"]:
									a_     			=   OrderedDict(
									    [
									        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
									        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
									    ]    )

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

									if self.use_past:
										self.fill_with_past_key_values_(_SCREAMING_SNAKE_CASE			,       direction="""inputs"""    )
								elif self.task == "causal-lm":
									# TODO: figure this case out.
									a_     			=   OrderedDict(
									    [
									        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
									        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
									    ]    )
									if self.use_past:
										a_			, a_     			=   self.num_layers
										for i in range(_SCREAMING_SNAKE_CASE    ):
											a_     			=   {0: """batch""", 2: """past_sequence + sequence"""}
											a_     			=   {0: """batch""", 2: """past_sequence + sequence"""}
								else:
									a_     			=   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   __magic_name__      (							self    ):
								if self.task in ["default", "seq2seq-lm"]:
									a_     			=   super().outputs
								else:
									a_     			=   super(_SCREAMING_SNAKE_CASE			,       self    ).outputs
									if self.use_past:
										a_			, a_     			=   self.num_layers
										for i in range(_SCREAMING_SNAKE_CASE    ):
											a_     			=   {0: """batch""", 2: """past_sequence + sequence"""}
											a_     			=   {0: """batch""", 2: """past_sequence + sequence"""}
								return common_outputs





							def   __magic_name__      (							self			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE = -1			,       _SCREAMING_SNAKE_CASE = -1			,       _SCREAMING_SNAKE_CASE = False			,       _SCREAMING_SNAKE_CASE = None			,       ):
								a_     			=   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
								a_     			=   seq_length if not self.use_past else 1
								a_     			=   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    )
								a_     			=   {f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
								a_     			=   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
									a_			, a_     			=   common_inputs["""input_ids"""].shape
									a_     			=   common_inputs["""decoder_input_ids"""].shape[1]
									a_			, a_     			=   self.num_attention_heads
									a_     			=   (
									    batch,
									    num_encoder_attention_heads,
									    encoder_seq_length,
									    self._config.hidden_size // num_encoder_attention_heads,
									)
									a_     			=   decoder_seq_length + 3
									a_     			=   (
									    batch,
									    num_decoder_attention_heads,
									    decoder_past_length,
									    self._config.hidden_size // num_decoder_attention_heads,
									)

									a_     			=   torch.cat(
									    [common_inputs["""decoder_attention_mask"""], torch.ones(_SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE    )]			,       dim=1    )

									a_     			=   []
									# If the number of encoder and decoder layers are present in the model configuration, both are considered
									a_			, a_     			=   self.num_layers
									a_     			=   min(_SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE    )
									a_     			=   max(_SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE    ) - min_num_layers
									a_     			=   """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.
									a_     			=   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





							def   __magic_name__      (							self			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE = -1			,       _SCREAMING_SNAKE_CASE = -1			,       _SCREAMING_SNAKE_CASE = False			,       _SCREAMING_SNAKE_CASE = None			,       ):
								a_     			=   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    )

								if self.use_past:
									if not is_torch_available():
										raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""    )
									else:
										import torch
									a_			, a_     			=   common_inputs["""input_ids"""].shape
									# Not using the same length for past_key_values
									a_     			=   seqlen + 2
									a_			, a_     			=   self.num_layers
									a_			, a_     			=   self.num_attention_heads
									a_     			=   (
									    batch,
									    num_encoder_attention_heads,
									    past_key_values_length,
									    self._config.hidden_size // num_encoder_attention_heads,
									)

									a_     			=   common_inputs["""attention_mask"""].dtype
									a_     			=   torch.cat(
									    [common_inputs["""attention_mask"""], torch.ones(_SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE			,       dtype=_SCREAMING_SNAKE_CASE    )]			,       dim=1    )
									a_     			=   [
									    (torch.zeros(_SCREAMING_SNAKE_CASE    ), torch.zeros(_SCREAMING_SNAKE_CASE    )) for _ in range(_SCREAMING_SNAKE_CASE    )
									]
								return common_inputs





							def   __magic_name__      (							self			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE = -1			,       _SCREAMING_SNAKE_CASE = -1			,       _SCREAMING_SNAKE_CASE = False			,       _SCREAMING_SNAKE_CASE = 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
								a_     			=   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
								a_     			=   tokenizer.num_special_tokens_to_add(_SCREAMING_SNAKE_CASE    )
								a_     			=   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
								a_     			=   [""" """.join([tokenizer.unk_token]    ) * seq_length] * batch_size
								a_     			=   dict(tokenizer(_SCREAMING_SNAKE_CASE			,       return_tensors=_SCREAMING_SNAKE_CASE    )    )
								return common_inputs





							def   __magic_name__      (							self			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE = -1			,       _SCREAMING_SNAKE_CASE = -1			,       _SCREAMING_SNAKE_CASE = False			,       _SCREAMING_SNAKE_CASE = None			,       ):
								if self.task in ["default", "seq2seq-lm"]:
									a_     			=   self._generate_dummy_inputs_for_default_and_seqaseq_lm(
									    _SCREAMING_SNAKE_CASE			,       batch_size=_SCREAMING_SNAKE_CASE			,       seq_length=_SCREAMING_SNAKE_CASE			,       is_pair=_SCREAMING_SNAKE_CASE			,       framework=_SCREAMING_SNAKE_CASE    )

								elif self.task == "causal-lm":
									a_     			=   self._generate_dummy_inputs_for_causal_lm(
									    _SCREAMING_SNAKE_CASE			,       batch_size=_SCREAMING_SNAKE_CASE			,       seq_length=_SCREAMING_SNAKE_CASE			,       is_pair=_SCREAMING_SNAKE_CASE			,       framework=_SCREAMING_SNAKE_CASE    )
								else:
									a_     			=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
									    _SCREAMING_SNAKE_CASE			,       batch_size=_SCREAMING_SNAKE_CASE			,       seq_length=_SCREAMING_SNAKE_CASE			,       is_pair=_SCREAMING_SNAKE_CASE			,       framework=_SCREAMING_SNAKE_CASE    )

								return common_inputs





							def   __magic_name__      (							self			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE    ):
								if self.task in ["default", "seq2seq-lm"]:
									a_     			=   super()._flatten_past_key_values_(_SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE    )
								else:
									a_     			=   super(_SCREAMING_SNAKE_CASE			,       self    )._flatten_past_key_values_(
									    _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE    )



import enum
import inspect
import warnings
from functools import wraps
from typing import Callable, Optional

from .logging import get_logger


_A							     =       set()
_A							     =       get_logger(__name__)

def 			__SCREAMING_SNAKE_CASE		(		UpperCamelCase		:      Optional[str] = None	)     ->	Optional[int]:



	"""simple docstring"""






	def decorator(UpperCamelCase		:      Callable	):
		global _emitted_deprecation_warnings

		if inspect.isclass(UpperCamelCase	):
			a_     			=   deprecated_class_or_function.__init__
			a_     			=   deprecated_class_or_function.__name__
		else:
			a_     			=   deprecated_class_or_function
			a_     			=   deprecated_function.__name__
			# Support deprecating __init__ class method: class name instead
			a_     			=   name if name != """__init__""" else deprecated_function.__qualname__.split("""."""	)[-2]

		a_     			=   (
		    F"""{name} is deprecated and will be removed in the next major version of datasets.""" + F""" {help_message}"""
		    if help_message
		    else """"""
		)

		@wraps(UpperCamelCase	)
		def wrapper(*UpperCamelCase		:      List[str]     ,					**UpperCamelCase		:      Union[str, Any]	):
			a_     			=   hash(UpperCamelCase	)
			if func_hash not in _emitted_deprecation_warnings:
				warnings.warn(UpperCamelCase     ,					category=UpperCamelCase     ,					stacklevel=2	)
				_emitted_deprecation_warnings.add(UpperCamelCase	)
			return deprecated_function(*UpperCamelCase     ,					**UpperCamelCase	)

		a_     			=   """deprecated"""

		if inspect.isclass(UpperCamelCase	):
			a_     			=   wrapper
			return deprecated_class_or_function
		else:
			return wrapper

	return decorator

class 			lowerCamelCase_					(    enum.EnumMeta    ):





							def __getattribute__(							cls			,       _SCREAMING_SNAKE_CASE    ):
								a_     			=   super().__getattribute__(_SCREAMING_SNAKE_CASE    )
								if isinstance(_SCREAMING_SNAKE_CASE			,       enum.Enum    ) and obj._on_access:
									obj._on_access()
								return obj





							def __getitem__(							cls			,       _SCREAMING_SNAKE_CASE    ):
								a_     			=   super().__getitem__(_SCREAMING_SNAKE_CASE    )
								if member._on_access:
									member._on_access()
								return member





							def __call__(							cls			,       _SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE=None			,       *, _SCREAMING_SNAKE_CASE=None			,       _SCREAMING_SNAKE_CASE=None			,       _SCREAMING_SNAKE_CASE=None			,       _SCREAMING_SNAKE_CASE=1    ):
								a_     			=   super().__call__(_SCREAMING_SNAKE_CASE			,       _SCREAMING_SNAKE_CASE			,       module=_SCREAMING_SNAKE_CASE			,       qualname=_SCREAMING_SNAKE_CASE			,       type=_SCREAMING_SNAKE_CASE			,       start=_SCREAMING_SNAKE_CASE    )
								if isinstance(_SCREAMING_SNAKE_CASE			,       enum.Enum    ) and obj._on_access:
									obj._on_access()
								return obj







class 			lowerCamelCase_					(    enum.Enum   ,		metaclass=_SCREAMING_SNAKE_CASE    ):





							def __new__(							cls			,       _SCREAMING_SNAKE_CASE    ):
								a_     			=   object.__new__(cls    )
								a_     			=   value
								a_     			=   member.deprecate
								return member





							@property
							def   __magic_name__      (							self    ):
								return ""





							def   __magic_name__      (							self    ):
								a_     			=   f""" {self.help_message}""" if self.help_message else """"""
								warnings.warn(
								    f"""'{self.__objclass__.__name__}' is deprecated and will be removed in the next major version of datasets."""
								    + help_message			,       _SCREAMING_SNAKE_CASE			,       stacklevel=3			,       )