


"""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


__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 ):


							"""simple docstring"""
							SCREAMING_SNAKE_CASE										=      """mbart"""
							SCREAMING_SNAKE_CASE										=      ["""past_key_values"""]
							SCREAMING_SNAKE_CASE										=      {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}






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




class 							lowerCamelCase       (			__SCREAMING_SNAKE_CASE ):


							"""simple docstring"""






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

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

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






							def 					lowerCAmelCase     (						self :     Tuple		, lowerCamelCase_ :     PreTrainedTokenizer		, lowerCamelCase_ :     int = -1		, lowerCamelCase_ :     int = -1		, lowerCamelCase_ :     bool = False		, lowerCamelCase_ :     Optional[TensorType] = None		, ):
													UpperCAmelCase__		=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
													    lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_				)

													# Generate decoder inputs
													UpperCAmelCase__		=    seq_length if not self.use_past else 1
													UpperCAmelCase__		=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
													    lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_				)
													UpperCAmelCase__		=    {f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
													UpperCAmelCase__		=    dict(**lowerCamelCase_		, **lowerCamelCase_				)

													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__		=    common_inputs['''input_ids'''].shape
																			UpperCAmelCase__		=    common_inputs['''decoder_input_ids'''].shape[1]
																			UpperCAmelCase__	,				UpperCAmelCase__		=    self.num_attention_heads
																			UpperCAmelCase__		=    (
																			    batch,
																			    num_encoder_attention_heads,
																			    encoder_seq_length,
																			    self._config.hidden_size // num_encoder_attention_heads,
																			)
																			UpperCAmelCase__		=    decoder_seq_length + 3
																			UpperCAmelCase__		=    (
																			    batch,
																			    num_decoder_attention_heads,
																			    decoder_past_length,
																			    self._config.hidden_size // num_decoder_attention_heads,
																			)

																			UpperCAmelCase__		=    torch.cat(
																			    [common_inputs['''decoder_attention_mask'''], torch.ones(lowerCamelCase_		, lowerCamelCase_				)]		, dim=1				)

																			UpperCAmelCase__		=    []
																			# If the number of encoder and decoder layers are present in the model configuration, both are considered
																			UpperCAmelCase__	,				UpperCAmelCase__		=    self.num_layers
																			UpperCAmelCase__		=    min(lowerCamelCase_		, lowerCamelCase_				)
																			UpperCAmelCase__		=    max(lowerCamelCase_		, lowerCamelCase_				) - min_num_layers
																			UpperCAmelCase__		=    '''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

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






							def 					lowerCAmelCase     (						self :     Tuple		, lowerCamelCase_ :     PreTrainedTokenizer		, lowerCamelCase_ :     int = -1		, lowerCamelCase_ :     int = -1		, lowerCamelCase_ :     bool = False		, lowerCamelCase_ :     Optional[TensorType] = None		, ):
													UpperCAmelCase__		=    self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
													    lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_				)

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

																			UpperCAmelCase__		=    common_inputs['''attention_mask'''].dtype
																			UpperCAmelCase__		=    torch.cat(
																			    [common_inputs['''attention_mask'''], torch.ones(lowerCamelCase_		, lowerCamelCase_		, dtype=lowerCamelCase_				)]		, dim=1				)
																			UpperCAmelCase__		=    [
																			    (torch.zeros(lowerCamelCase_				), torch.zeros(lowerCamelCase_				)) for _ in range(lowerCamelCase_				)
																			]
													return common_inputs






							def 					lowerCAmelCase     (						self :     str		, lowerCamelCase_ :     PreTrainedTokenizer		, lowerCamelCase_ :     int = -1		, lowerCamelCase_ :     int = -1		, lowerCamelCase_ :     bool = False		, lowerCamelCase_ :     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
													UpperCAmelCase__		=    compute_effective_axis_dimension(
													    lowerCamelCase_		, 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__		=    tokenizer.num_special_tokens_to_add(lowerCamelCase_				)
													UpperCAmelCase__		=    compute_effective_axis_dimension(
													    lowerCamelCase_		, fixed_dimension=OnnxConfig.default_fixed_sequence		, num_token_to_add=lowerCamelCase_				)

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






							def 					lowerCAmelCase     (						self :     Tuple		, lowerCamelCase_ :     PreTrainedTokenizer		, lowerCamelCase_ :     int = -1		, lowerCamelCase_ :     int = -1		, lowerCamelCase_ :     bool = False		, lowerCamelCase_ :     Optional[TensorType] = None		, ):
													if self.task in ["default", "seq2seq-lm"]:
																			UpperCAmelCase__		=    self._generate_dummy_inputs_for_default_and_seqaseq_lm(
																			    lowerCamelCase_		, batch_size=lowerCamelCase_		, seq_length=lowerCamelCase_		, is_pair=lowerCamelCase_		, framework=lowerCamelCase_				)

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

													return common_inputs






							def 					lowerCAmelCase     (						self :     Any		, lowerCamelCase_ :     Dict		, lowerCamelCase_ :     List[str]		, lowerCamelCase_ :     int		, lowerCamelCase_ :     List[Any]				):
													if self.task in ["default", "seq2seq-lm"]:
																			UpperCAmelCase__		=    super()._flatten_past_key_values_(lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_				)
													else:
																			UpperCAmelCase__		=    super(lowerCamelCase_		, self				)._flatten_past_key_values_(
																			    lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_		, lowerCamelCase_				)



"""simple docstring"""







import safs
class 							lowerCamelCase       (			safs.SaFileSystem ):


							"""simple docstring"""